Serenity Operating System
at master 99 lines 3.2 kB view raw
1/* 2 * Copyright (c) 2020, Andreas Kling <kling@serenityos.org> 3 * Copyright (c) 2022, the SerenityOS developers. 4 * 5 * SPDX-License-Identifier: BSD-2-Clause 6 */ 7 8#include "WindowActions.h" 9#include <Applications/Browser/Browser.h> 10#include <LibGUI/Icon.h> 11#include <LibGUI/Window.h> 12#include <LibGfx/Bitmap.h> 13 14namespace Browser { 15 16static WindowActions* s_the; 17 18WindowActions& WindowActions::the() 19{ 20 VERIFY(s_the); 21 return *s_the; 22} 23 24WindowActions::WindowActions(GUI::Window& window) 25{ 26 VERIFY(!s_the); 27 s_the = this; 28 m_create_new_tab_action = GUI::Action::create( 29 "&New Tab", { Mod_Ctrl, Key_T }, g_icon_bag.new_tab, [this](auto&) { 30 if (on_create_new_tab) 31 on_create_new_tab(); 32 }, 33 &window); 34 m_create_new_tab_action->set_status_tip("Open a new tab"); 35 36 m_create_new_window_action = GUI::Action::create( 37 "&New Window", { Mod_Ctrl, Key_N }, g_icon_bag.new_window, [this](auto&) { 38 if (on_create_new_window) { 39 on_create_new_window(); 40 } 41 }, 42 &window); 43 m_create_new_window_action->set_status_tip("Open a new browser window"); 44 45 m_next_tab_action = GUI::Action::create( 46 "&Next Tab", { Mod_Ctrl, Key_PageDown }, [this](auto&) { 47 if (on_next_tab) 48 on_next_tab(); 49 }, 50 &window); 51 m_next_tab_action->set_status_tip("Switch to the next tab"); 52 53 m_previous_tab_action = GUI::Action::create( 54 "&Previous Tab", { Mod_Ctrl, Key_PageUp }, [this](auto&) { 55 if (on_previous_tab) 56 on_previous_tab(); 57 }, 58 &window); 59 m_previous_tab_action->set_status_tip("Switch to the previous tab"); 60 61 for (auto i = 0; i <= 7; ++i) { 62 m_tab_actions.append(GUI::Action::create( 63 DeprecatedString::formatted("Tab {}", i + 1), { Mod_Ctrl, static_cast<KeyCode>(Key_1 + i) }, [this, i](auto&) { 64 if (on_tabs[i]) 65 on_tabs[i](); 66 }, 67 &window)); 68 m_tab_actions.last()->set_status_tip(DeprecatedString::formatted("Switch to tab {}", i + 1)); 69 } 70 m_tab_actions.append(GUI::Action::create( 71 "Last tab", { Mod_Ctrl, Key_9 }, [this](auto&) { 72 if (on_tabs[8]) 73 on_tabs[8](); 74 }, 75 &window)); 76 m_tab_actions.last()->set_status_tip("Switch to last tab"); 77 78 m_about_action = GUI::CommonActions::make_about_action("Browser", GUI::Icon::default_icon("app-browser"sv), &window); 79 80 m_show_bookmarks_bar_action = GUI::Action::create_checkable( 81 "&Bookmarks Bar", { Mod_Ctrl, Key_B }, 82 [this](auto& action) { 83 if (on_show_bookmarks_bar) 84 on_show_bookmarks_bar(action); 85 }, 86 &window); 87 m_show_bookmarks_bar_action->set_status_tip("Show/hide the bookmarks bar"); 88 89 m_vertical_tabs_action = GUI::Action::create_checkable( 90 "&Vertical Tabs", { Mod_Ctrl, Key_Comma }, 91 [this](auto& action) { 92 if (on_vertical_tabs) 93 on_vertical_tabs(action); 94 }, 95 &window); 96 m_vertical_tabs_action->set_status_tip("Enable/Disable vertical tabs"); 97} 98 99}