summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlec Murphy <109390888+checksum-fail@users.noreply.github.com>2022-07-19 06:16:46 -0400
committerAndrew Kaster <andrewdkaster@gmail.com>2022-12-25 07:58:58 -0700
commit700c709c00d12a4d4d29e69586e5417a06b97b60 (patch)
treeecbaf8cbdcaf1da70bebe34f6e89b8d6351a1c0e
parent35eb69688405cb90ee299de4cc207a0bf1ab214c (diff)
downloadserenity-700c709c00d12a4d4d29e69586e5417a06b97b60.zip
Ladybird: Add Ctrl-W action to close current tab (#28)
-rw-r--r--Ladybird/BrowserWindow.cpp14
-rw-r--r--Ladybird/BrowserWindow.h1
2 files changed, 15 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);
diff --git a/Ladybird/BrowserWindow.h b/Ladybird/BrowserWindow.h
index 94d9892bd4..b97a76f119 100644
--- a/Ladybird/BrowserWindow.h
+++ b/Ladybird/BrowserWindow.h
@@ -35,6 +35,7 @@ public slots:
void tab_favicon_changed(int index, QIcon icon);
void new_tab();
void close_tab(int index);
+ void close_current_tab();
private:
void debug_request(String const& request, String const& argument = "");