mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 04:27:43 +00:00
Ladybird: Add Ctrl-W action to close current tab (#28)
This commit is contained in:
parent
35eb696884
commit
700c709c00
2 changed files with 15 additions and 0 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue