summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlivier De Cannière <icristalrope@gmail.com>2022-03-16 20:10:00 +0100
committerAndreas Kling <kling@serenityos.org>2022-04-02 23:38:32 +0200
commit3818840ee684bdd0b62ca71ea50823f00e718bd1 (patch)
tree7f6be87b0322cc75307eaaab4e2956f895e03fd5
parent1b7850f5114c22683e4c8115c5124409f41f4e42 (diff)
downloadserenity-3818840ee684bdd0b62ca71ea50823f00e718bd1.zip
Browser: Add Ctrl-<number> actions to changes tabs
It is now possible to quickly switch to specific tabs directly without having to 'search linearly'. Pressing Ctrl plus a number from 1 to 8 switches to the tab of that index. Pressing Ctrl-9 swithes to the last tab. This feature already exists in Firefox and Chrome.
-rw-r--r--Userland/Applications/Browser/BrowserWindow.cpp9
-rw-r--r--Userland/Applications/Browser/WindowActions.cpp17
-rw-r--r--Userland/Applications/Browser/WindowActions.h2
3 files changed, 28 insertions, 0 deletions
diff --git a/Userland/Applications/Browser/BrowserWindow.cpp b/Userland/Applications/Browser/BrowserWindow.cpp
index c631fafc62..fbf17a707c 100644
--- a/Userland/Applications/Browser/BrowserWindow.cpp
+++ b/Userland/Applications/Browser/BrowserWindow.cpp
@@ -114,6 +114,15 @@ BrowserWindow::BrowserWindow(CookieJar& cookie_jar, URL url)
m_tab_widget->activate_previous_tab();
};
+ for (int i = 0; i <= 7; ++i) {
+ m_window_actions.on_tabs.append([this, i] {
+ m_tab_widget->set_tab_index(i);
+ });
+ }
+ m_window_actions.on_tabs.append([this] {
+ m_tab_widget->activate_last_tab();
+ });
+
m_window_actions.on_about = [this] {
auto app_icon = GUI::Icon::default_icon("app-browser");
GUI::AboutDialog::show("Browser", app_icon.bitmap_for_size(32), this);
diff --git a/Userland/Applications/Browser/WindowActions.cpp b/Userland/Applications/Browser/WindowActions.cpp
index dc65b0ea94..d6bd24ad11 100644
--- a/Userland/Applications/Browser/WindowActions.cpp
+++ b/Userland/Applications/Browser/WindowActions.cpp
@@ -48,6 +48,23 @@ WindowActions::WindowActions(GUI::Window& window)
&window);
m_previous_tab_action->set_status_tip("Switch to the previous tab");
+ for (auto i = 0; i <= 7; ++i) {
+ m_tab_actions.append(GUI::Action::create(
+ String::formatted("Tab {}", i + 1), { Mod_Ctrl, static_cast<KeyCode>(Key_1 + i) }, [this, i](auto&) {
+ if (on_tabs[i])
+ on_tabs[i]();
+ },
+ &window));
+ m_tab_actions.last().set_status_tip(String::formatted("Switch to tab {}", i + 1));
+ }
+ m_tab_actions.append(GUI::Action::create(
+ "Last tab", { Mod_Ctrl, Key_9 }, [this](auto&) {
+ if (on_tabs[8])
+ on_tabs[8]();
+ },
+ &window));
+ m_tab_actions.last().set_status_tip("Switch to last tab");
+
m_about_action = GUI::Action::create(
"&About Browser", GUI::Icon::default_icon("app-browser").bitmap_for_size(16), [this](const GUI::Action&) {
if (on_about)
diff --git a/Userland/Applications/Browser/WindowActions.h b/Userland/Applications/Browser/WindowActions.h
index b2f7a60db3..923c8f705c 100644
--- a/Userland/Applications/Browser/WindowActions.h
+++ b/Userland/Applications/Browser/WindowActions.h
@@ -19,6 +19,7 @@ public:
Function<void()> on_create_new_tab;
Function<void()> on_next_tab;
Function<void()> on_previous_tab;
+ Vector<Function<void()>> on_tabs;
Function<void()> on_about;
Function<void(GUI::Action&)> on_show_bookmarks_bar;
@@ -32,6 +33,7 @@ private:
RefPtr<GUI::Action> m_create_new_tab_action;
RefPtr<GUI::Action> m_next_tab_action;
RefPtr<GUI::Action> m_previous_tab_action;
+ NonnullRefPtrVector<GUI::Action> m_tab_actions;
RefPtr<GUI::Action> m_about_action;
RefPtr<GUI::Action> m_show_bookmarks_bar_action;
};