From 312501f30917e8e22321a80fde294dd50a83012b Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 23 Apr 2020 21:36:17 +0200 Subject: Browser: Add "Close tab" action (Ctrl+W) :^) Note that this is a little bit unreliable with the keyboard shortcut since LibGUI can get confused about which Action it's supposed to use as each Browser::Tab has its own "close tab" action. This will need to be fixed in LibGUI. --- Applications/Browser/Tab.cpp | 3 +++ Applications/Browser/Tab.h | 1 + Applications/Browser/main.cpp | 8 ++++++++ 3 files changed, 12 insertions(+) diff --git a/Applications/Browser/Tab.cpp b/Applications/Browser/Tab.cpp index 7743ca48ba..b16b0f79b5 100644 --- a/Applications/Browser/Tab.cpp +++ b/Applications/Browser/Tab.cpp @@ -178,6 +178,9 @@ Tab::Tab() auto& app_menu = m_menubar->add_menu("Browser"); app_menu.add_action(WindowActions::the().create_new_tab_action()); + app_menu.add_action(GUI::Action::create("Close tab", { Mod_Ctrl, Key_W }, [this](auto&) { + on_tab_close_request(*this); + })); app_menu.add_action(GUI::Action::create("Reload", { Mod_None, Key_F5 }, Gfx::Bitmap::load_from_file("/res/icons/16x16/reload.png"), [this](auto&) { TemporaryChange change(m_should_push_loads_to_history, false); diff --git a/Applications/Browser/Tab.h b/Applications/Browser/Tab.h index c596b5afde..7c74c40560 100644 --- a/Applications/Browser/Tab.h +++ b/Applications/Browser/Tab.h @@ -44,6 +44,7 @@ public: void did_become_active(); Function on_title_change; + Function on_tab_close_request; const String& title() const { return m_title; } diff --git a/Applications/Browser/main.cpp b/Applications/Browser/main.cpp index 13ca696d17..16502bc97f 100644 --- a/Applications/Browser/main.cpp +++ b/Applications/Browser/main.cpp @@ -100,6 +100,14 @@ int main(int argc, char** argv) window->set_title(String::format("%s - Browser", title.characters())); }; + new_tab.on_tab_close_request = [&](auto& tab) { + tab_widget.deferred_invoke([&](auto&) { + tab_widget.remove_tab(tab); + if (tab_widget.children().is_empty()) + app.quit(); + }); + }; + window->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/filetype-html.png")); window->set_title("Browser"); -- cgit v1.2.3