Explorar el Código

Browser: Add more tab options

Add more tab options to Browser: "Duplicate Tab" and "Close Other Tabs".
TheFightingCatfish hace 4 años
padre
commit
9899addb1d

+ 8 - 0
Userland/Applications/Browser/BrowserWindow.cpp

@@ -542,6 +542,14 @@ void BrowserWindow::create_new_tab(URL url, bool activate)
         });
     };
 
+    new_tab.on_tab_close_other_request = [this](auto& tab) {
+        m_tab_widget->deferred_invoke([this, &tab](auto&) {
+            m_tab_widget->remove_all_tabs_except(tab);
+            VERIFY(m_tab_widget->children().size() == 1);
+            m_tab_widget->set_bar_visible(false);
+        });
+    };
+
     new_tab.on_get_cookie = [this](auto& url, auto source) -> String {
         return m_cookie_jar.get_cookie(url, source);
     };

+ 6 - 0
Userland/Applications/Browser/Tab.cpp

@@ -337,6 +337,12 @@ Tab::Tab(BrowserWindow& window, Type type)
     m_tab_context_menu->add_action(GUI::Action::create("&Close Tab", [this](auto&) {
         on_tab_close_request(*this);
     }));
+    m_tab_context_menu->add_action(GUI::Action::create("&Duplicate Tab", [this](auto&) {
+        on_tab_open_request(url());
+    }));
+    m_tab_context_menu->add_action(GUI::Action::create("Close &Other Tabs", [this](auto&) {
+        on_tab_close_other_request(*this);
+    }));
 
     m_page_context_menu = GUI::Menu::construct();
     m_page_context_menu->add_action(window.go_back_action());

+ 1 - 0
Userland/Applications/Browser/Tab.h

@@ -58,6 +58,7 @@ public:
     Function<void(const String&)> on_title_change;
     Function<void(const URL&)> on_tab_open_request;
     Function<void(Tab&)> on_tab_close_request;
+    Function<void(Tab&)> on_tab_close_other_request;
     Function<void(const Gfx::Bitmap&)> on_favicon_change;
     Function<String(const URL&, Web::Cookie::Source source)> on_get_cookie;
     Function<void(const URL&, const Web::Cookie::ParsedCookie& cookie, Web::Cookie::Source source)> on_set_cookie;