diff options
author | Alec Murphy <109390888+checksum-fail@users.noreply.github.com> | 2022-07-19 06:16:46 -0400 |
---|---|---|
committer | Andrew Kaster <andrewdkaster@gmail.com> | 2022-12-25 07:58:58 -0700 |
commit | 700c709c00d12a4d4d29e69586e5417a06b97b60 (patch) | |
tree | ecbaf8cbdcaf1da70bebe34f6e89b8d6351a1c0e /Ladybird/BrowserWindow.cpp | |
parent | 35eb69688405cb90ee299de4cc207a0bf1ab214c (diff) | |
download | serenity-700c709c00d12a4d4d29e69586e5417a06b97b60.zip |
Ladybird: Add Ctrl-W action to close current tab (#28)
Diffstat (limited to 'Ladybird/BrowserWindow.cpp')
-rw-r--r-- | Ladybird/BrowserWindow.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/Ladybird/BrowserWindow.cpp b/Ladybird/BrowserWindow.cpp index cca366632a..0da3447251 100644 --- a/Ladybird/BrowserWindow.cpp +++ b/Ladybird/BrowserWindow.cpp @@ -30,6 +30,10 @@ BrowserWindow::BrowserWindow(Core::EventLoop& event_loop) new_tab_action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_T)); menu->addAction(new_tab_action); + auto* close_current_tab_action = new QAction("Close Current Tab"); + close_current_tab_action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_W)); + menu->addAction(close_current_tab_action); + auto* quit_action = new QAction("&Quit"); quit_action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_Q)); menu->addAction(quit_action); @@ -165,6 +169,7 @@ BrowserWindow::BrowserWindow(Core::EventLoop& event_loop) setWindowIcon(m_tabs_container->tabIcon(index)); }); QObject::connect(m_tabs_container, &QTabWidget::tabCloseRequested, this, &BrowserWindow::close_tab); + QObject::connect(close_current_tab_action, &QAction::triggered, this, &BrowserWindow::close_current_tab); new_tab(); @@ -210,6 +215,15 @@ void BrowserWindow::close_tab(int index) m_tabs_bar->hide(); } +void BrowserWindow::close_current_tab() +{ + auto count = m_tabs_container->count() - 1; + if (!count) + close(); + else + close_tab(m_tabs_container->currentIndex()); +} + int BrowserWindow::tab_index(Tab* tab) { return m_tabs_container->indexOf(tab); |