Browser: Add "next tab" and "previous tab" actions

Now you can switch between the open tabs with Ctrl+PgUp and Ctrl+PgDn
This commit is contained in:
Andreas Kling 2020-04-23 21:43:24 +02:00
parent 4087e3cfb9
commit 1b8b492258
3 changed files with 28 additions and 0 deletions

View file

@ -21,6 +21,20 @@ WindowActions::WindowActions(GUI::Window& window)
on_create_new_tab();
},
&window);
m_next_tab_action = GUI::Action::create(
"Next tab", { Mod_Ctrl, Key_PageDown }, [this](auto&) {
if (on_next_tab)
on_next_tab();
},
&window);
m_previous_tab_action = GUI::Action::create(
"Previous tab", { Mod_Ctrl, Key_PageUp }, [this](auto&) {
if (on_previous_tab)
on_previous_tab();
},
&window);
}
}

View file

@ -11,11 +11,17 @@ public:
WindowActions(GUI::Window&);
Function<void()> on_create_new_tab;
Function<void()> on_next_tab;
Function<void()> on_previous_tab;
GUI::Action& create_new_tab_action() { return *m_create_new_tab_action; }
GUI::Action& next_tab_action() { return *m_next_tab_action; }
GUI::Action& previous_tab_action() { return *m_previous_tab_action; }
private:
RefPtr<GUI::Action> m_create_new_tab_action;
RefPtr<GUI::Action> m_next_tab_action;
RefPtr<GUI::Action> m_previous_tab_action;
};
}

View file

@ -131,6 +131,14 @@ int main(int argc, char** argv)
create_new_tab();
};
window_actions.on_next_tab = [&] {
tab_widget.activate_next_tab();
};
window_actions.on_previous_tab = [&] {
tab_widget.activate_previous_tab();
};
create_new_tab();
return app.exec();