Ladybird: Switch to next/previous tab with Ctrl+PageDown/PageUp

This commit is contained in:
Andreas Kling 2022-09-12 09:22:43 +02:00 committed by Andrew Kaster
parent 27b9cd13ee
commit 0f1644f62d
Notes: sideshowbarker 2024-07-17 08:43:11 +09:00
2 changed files with 36 additions and 0 deletions

View file

@ -46,6 +46,18 @@ BrowserWindow::BrowserWindow()
quit_action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_Q));
menu->addAction(quit_action);
auto* view_menu = menuBar()->addMenu("&View");
auto* open_next_tab_action = new QAction("Open &Next Tab");
open_next_tab_action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_PageDown));
view_menu->addAction(open_next_tab_action);
QObject::connect(open_next_tab_action, &QAction::triggered, this, &BrowserWindow::open_next_tab);
auto* open_previous_tab_action = new QAction("Open &Previous Tab");
open_previous_tab_action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_PageUp));
view_menu->addAction(open_previous_tab_action);
QObject::connect(open_previous_tab_action, &QAction::triggered, this, &BrowserWindow::open_previous_tab);
auto* inspect_menu = menuBar()->addMenu("&Inspect");
auto* view_source_action = new QAction("View &Source");
@ -258,3 +270,25 @@ void BrowserWindow::tab_favicon_changed(int index, QIcon icon)
m_tabs_container->setTabIcon(index, icon);
setWindowIcon(icon);
}
void BrowserWindow::open_next_tab()
{
if (m_tabs_container->count() <= 1)
return;
auto next_index = m_tabs_container->currentIndex() + 1;
if (next_index >= m_tabs_container->count())
next_index = 0;
m_tabs_container->setCurrentIndex(next_index);
}
void BrowserWindow::open_previous_tab()
{
if (m_tabs_container->count() <= 1)
return;
auto next_index = m_tabs_container->currentIndex() - 1;
if (next_index < 0)
next_index = m_tabs_container->count() - 1;
m_tabs_container->setCurrentIndex(next_index);
}

View file

@ -34,6 +34,8 @@ public slots:
void new_tab();
void close_tab(int index);
void close_current_tab();
void open_next_tab();
void open_previous_tab();
private:
void debug_request(String const& request, String const& argument = "");