WindowActions.cpp 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include "WindowActions.h"
  7. #include <Applications/Browser/Browser.h>
  8. #include <LibGUI/Icon.h>
  9. #include <LibGUI/Window.h>
  10. #include <LibGfx/Bitmap.h>
  11. namespace Browser {
  12. static WindowActions* s_the;
  13. WindowActions& WindowActions::the()
  14. {
  15. VERIFY(s_the);
  16. return *s_the;
  17. }
  18. WindowActions::WindowActions(GUI::Window& window)
  19. {
  20. VERIFY(!s_the);
  21. s_the = this;
  22. m_create_new_tab_action = GUI::Action::create(
  23. "&New Tab", { Mod_Ctrl, Key_T }, g_icon_bag.new_tab, [this](auto&) {
  24. if (on_create_new_tab)
  25. on_create_new_tab();
  26. },
  27. &window);
  28. m_create_new_tab_action->set_status_tip("Open a new tab");
  29. m_next_tab_action = GUI::Action::create(
  30. "&Next Tab", { Mod_Ctrl, Key_PageDown }, [this](auto&) {
  31. if (on_next_tab)
  32. on_next_tab();
  33. },
  34. &window);
  35. m_next_tab_action->set_status_tip("Switch to the next tab");
  36. m_previous_tab_action = GUI::Action::create(
  37. "&Previous Tab", { Mod_Ctrl, Key_PageUp }, [this](auto&) {
  38. if (on_previous_tab)
  39. on_previous_tab();
  40. },
  41. &window);
  42. m_previous_tab_action->set_status_tip("Switch to the previous tab");
  43. for (auto i = 0; i <= 7; ++i) {
  44. m_tab_actions.append(GUI::Action::create(
  45. String::formatted("Tab {}", i + 1), { Mod_Ctrl, static_cast<KeyCode>(Key_1 + i) }, [this, i](auto&) {
  46. if (on_tabs[i])
  47. on_tabs[i]();
  48. },
  49. &window));
  50. m_tab_actions.last().set_status_tip(String::formatted("Switch to tab {}", i + 1));
  51. }
  52. m_tab_actions.append(GUI::Action::create(
  53. "Last tab", { Mod_Ctrl, Key_9 }, [this](auto&) {
  54. if (on_tabs[8])
  55. on_tabs[8]();
  56. },
  57. &window));
  58. m_tab_actions.last().set_status_tip("Switch to last tab");
  59. m_about_action = GUI::Action::create(
  60. "&About Browser", GUI::Icon::default_icon("app-browser").bitmap_for_size(16), [this](const GUI::Action&) {
  61. if (on_about)
  62. on_about();
  63. },
  64. &window);
  65. m_about_action->set_status_tip("Show application about box");
  66. m_show_bookmarks_bar_action = GUI::Action::create_checkable(
  67. "&Bookmarks Bar", { Mod_Ctrl, Key_B },
  68. [this](auto& action) {
  69. if (on_show_bookmarks_bar)
  70. on_show_bookmarks_bar(action);
  71. },
  72. &window);
  73. m_show_bookmarks_bar_action->set_status_tip("Show/hide the bookmarks bar");
  74. }
  75. }