Ladybird: Add Ctrl-W action to close current tab (#28)

This commit is contained in:
Alec Murphy 2022-07-19 06:16:46 -04:00 committed by Andrew Kaster
parent 35eb696884
commit 700c709c00
2 changed files with 15 additions and 0 deletions

View file

@ -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);

View file

@ -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 = "");