WindowActions.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. #include "WindowActions.h"
  8. #include <Applications/Browser/Browser.h>
  9. #include <LibGUI/Icon.h>
  10. #include <LibGUI/Window.h>
  11. #include <LibGfx/Bitmap.h>
  12. namespace Browser {
  13. static WindowActions* s_the;
  14. WindowActions& WindowActions::the()
  15. {
  16. VERIFY(s_the);
  17. return *s_the;
  18. }
  19. WindowActions::WindowActions(GUI::Window& window)
  20. {
  21. VERIFY(!s_the);
  22. s_the = this;
  23. m_create_new_tab_action = GUI::Action::create(
  24. "&New Tab", { Mod_Ctrl, Key_T }, g_icon_bag.new_tab, [this](auto&) {
  25. if (on_create_new_tab)
  26. on_create_new_tab();
  27. },
  28. &window);
  29. m_create_new_tab_action->set_status_tip("Open a new tab");
  30. m_create_new_window_action = GUI::Action::create(
  31. "&New Window", { Mod_Ctrl, Key_N }, g_icon_bag.new_window, [this](auto&) {
  32. if (on_create_new_window) {
  33. on_create_new_window();
  34. }
  35. },
  36. &window);
  37. m_create_new_window_action->set_status_tip("Open a new browser window");
  38. m_next_tab_action = GUI::Action::create(
  39. "&Next Tab", { Mod_Ctrl, Key_PageDown }, [this](auto&) {
  40. if (on_next_tab)
  41. on_next_tab();
  42. },
  43. &window);
  44. m_next_tab_action->set_status_tip("Switch to the next tab");
  45. m_previous_tab_action = GUI::Action::create(
  46. "&Previous Tab", { Mod_Ctrl, Key_PageUp }, [this](auto&) {
  47. if (on_previous_tab)
  48. on_previous_tab();
  49. },
  50. &window);
  51. m_previous_tab_action->set_status_tip("Switch to the previous tab");
  52. for (auto i = 0; i <= 7; ++i) {
  53. m_tab_actions.append(GUI::Action::create(
  54. String::formatted("Tab {}", i + 1), { Mod_Ctrl, static_cast<KeyCode>(Key_1 + i) }, [this, i](auto&) {
  55. if (on_tabs[i])
  56. on_tabs[i]();
  57. },
  58. &window));
  59. m_tab_actions.last().set_status_tip(String::formatted("Switch to tab {}", i + 1));
  60. }
  61. m_tab_actions.append(GUI::Action::create(
  62. "Last tab", { Mod_Ctrl, Key_9 }, [this](auto&) {
  63. if (on_tabs[8])
  64. on_tabs[8]();
  65. },
  66. &window));
  67. m_tab_actions.last().set_status_tip("Switch to last tab");
  68. m_about_action = GUI::Action::create(
  69. "&About Browser", GUI::Icon::default_icon("app-browser"sv).bitmap_for_size(16), [this](const GUI::Action&) {
  70. if (on_about)
  71. on_about();
  72. },
  73. &window);
  74. m_about_action->set_status_tip("Show application about box");
  75. m_show_bookmarks_bar_action = GUI::Action::create_checkable(
  76. "&Bookmarks Bar", { Mod_Ctrl, Key_B },
  77. [this](auto& action) {
  78. if (on_show_bookmarks_bar)
  79. on_show_bookmarks_bar(action);
  80. },
  81. &window);
  82. m_show_bookmarks_bar_action->set_status_tip("Show/hide the bookmarks bar");
  83. m_vertical_tabs_action = GUI::Action::create_checkable(
  84. "&Vertical Tabs", { Mod_Ctrl, Key_Comma },
  85. [this](auto& action) {
  86. if (on_vertical_tabs)
  87. on_vertical_tabs(action);
  88. },
  89. &window);
  90. m_vertical_tabs_action->set_status_tip("Enable/Disable vertical tabs");
  91. }
  92. }