CommonActions.cpp 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <AK/Function.h>
  7. #include <AK/String.h>
  8. #include <AK/WeakPtr.h>
  9. #include <LibGUI/AboutDialog.h>
  10. #include <LibGUI/Action.h>
  11. #include <LibGUI/Icon.h>
  12. namespace GUI {
  13. namespace CommonActions {
  14. NonnullRefPtr<Action> make_about_action(const String& app_name, const Icon& app_icon, Window* parent)
  15. {
  16. auto weak_parent = AK::try_make_weak_ptr<Window>(parent);
  17. auto action = Action::create(String::formatted("&About {}", app_name), app_icon.bitmap_for_size(16), [=](auto&) {
  18. AboutDialog::show(app_name, app_icon.bitmap_for_size(32), weak_parent.ptr());
  19. });
  20. action->set_status_tip("Show application about box");
  21. return action;
  22. }
  23. NonnullRefPtr<Action> make_open_action(Function<void(Action&)> callback, Core::Object* parent)
  24. {
  25. auto action = Action::create("&Open...", { Mod_Ctrl, Key_O }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/open.png").release_value_but_fixme_should_propagate_errors(), move(callback), parent);
  26. action->set_status_tip("Open an existing file");
  27. return action;
  28. }
  29. NonnullRefPtr<Action> make_save_action(Function<void(Action&)> callback, Core::Object* parent)
  30. {
  31. auto action = Action::create("&Save", { Mod_Ctrl, Key_S }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/save.png").release_value_but_fixme_should_propagate_errors(), move(callback), parent);
  32. action->set_status_tip("Save the current file");
  33. return action;
  34. }
  35. NonnullRefPtr<Action> make_save_as_action(Function<void(Action&)> callback, Core::Object* parent)
  36. {
  37. auto action = Action::create("Save &As...", { Mod_Ctrl | Mod_Shift, Key_S }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/save-as.png").release_value_but_fixme_should_propagate_errors(), move(callback), parent);
  38. action->set_status_tip("Save the current file with a new name");
  39. return action;
  40. }
  41. NonnullRefPtr<Action> make_move_to_front_action(Function<void(Action&)> callback, Core::Object* parent)
  42. {
  43. auto action = Action::create("Move to &Front", { Mod_Ctrl | Mod_Shift, Key_Up }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/move-to-front.png").release_value_but_fixme_should_propagate_errors(), move(callback), parent);
  44. action->set_status_tip("Move to the top of the stack");
  45. return action;
  46. }
  47. NonnullRefPtr<Action> make_move_to_back_action(Function<void(Action&)> callback, Core::Object* parent)
  48. {
  49. auto action = Action::create("Move to &Back", { Mod_Ctrl | Mod_Shift, Key_Down }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/move-to-back.png").release_value_but_fixme_should_propagate_errors(), move(callback), parent);
  50. action->set_status_tip("Move to the bottom of the stack");
  51. return action;
  52. }
  53. NonnullRefPtr<Action> make_undo_action(Function<void(Action&)> callback, Core::Object* parent)
  54. {
  55. return Action::create("&Undo", { Mod_Ctrl, Key_Z }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/undo.png").release_value_but_fixme_should_propagate_errors(), move(callback), parent);
  56. }
  57. NonnullRefPtr<Action> make_redo_action(Function<void(Action&)> callback, Core::Object* parent)
  58. {
  59. return Action::create("&Redo", { Mod_Ctrl, Key_Y }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/redo.png").release_value_but_fixme_should_propagate_errors(), move(callback), parent);
  60. }
  61. NonnullRefPtr<Action> make_delete_action(Function<void(Action&)> callback, Core::Object* parent)
  62. {
  63. return Action::create("&Delete", { Mod_None, Key_Delete }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/delete.png").release_value_but_fixme_should_propagate_errors(), move(callback), parent);
  64. }
  65. NonnullRefPtr<Action> make_cut_action(Function<void(Action&)> callback, Core::Object* parent)
  66. {
  67. auto action = Action::create("Cu&t", { Mod_Ctrl, Key_X }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/edit-cut.png").release_value_but_fixme_should_propagate_errors(), move(callback), parent);
  68. action->set_status_tip("Cut to clipboard");
  69. return action;
  70. }
  71. NonnullRefPtr<Action> make_copy_action(Function<void(Action&)> callback, Core::Object* parent)
  72. {
  73. auto action = Action::create("&Copy", { Mod_Ctrl, Key_C }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/edit-copy.png").release_value_but_fixme_should_propagate_errors(), move(callback), parent);
  74. action->set_status_tip("Copy to clipboard");
  75. return action;
  76. }
  77. NonnullRefPtr<Action> make_paste_action(Function<void(Action&)> callback, Core::Object* parent)
  78. {
  79. auto action = Action::create("&Paste", { Mod_Ctrl, Key_V }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/paste.png").release_value_but_fixme_should_propagate_errors(), move(callback), parent);
  80. action->set_status_tip("Paste from clipboard");
  81. return action;
  82. }
  83. NonnullRefPtr<Action> make_fullscreen_action(Function<void(Action&)> callback, Core::Object* parent)
  84. {
  85. auto action = Action::create("&Fullscreen", { Mod_None, Key_F11 }, move(callback), parent);
  86. action->set_status_tip("Enter fullscreen mode");
  87. return action;
  88. }
  89. NonnullRefPtr<Action> make_quit_action(Function<void(Action&)> callback)
  90. {
  91. auto action = Action::create("&Quit", { Mod_Alt, Key_F4 }, move(callback));
  92. action->set_status_tip("Quit the application");
  93. return action;
  94. }
  95. NonnullRefPtr<Action> make_help_action(Function<void(Action&)> callback, Core::Object* parent)
  96. {
  97. auto action = Action::create("&Contents", { Mod_None, Key_F1 }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/app-help.png").release_value_but_fixme_should_propagate_errors(), move(callback), parent);
  98. action->set_status_tip("Show help contents");
  99. return action;
  100. }
  101. NonnullRefPtr<Action> make_go_back_action(Function<void(Action&)> callback, Core::Object* parent)
  102. {
  103. auto action = Action::create("Go &Back", { Mod_Alt, Key_Left }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/go-back.png").release_value_but_fixme_should_propagate_errors(), move(callback), parent);
  104. action->set_status_tip("Move one step backward in history");
  105. return action;
  106. }
  107. NonnullRefPtr<Action> make_go_forward_action(Function<void(Action&)> callback, Core::Object* parent)
  108. {
  109. auto action = Action::create("Go &Forward", { Mod_Alt, Key_Right }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/go-forward.png").release_value_but_fixme_should_propagate_errors(), move(callback), parent);
  110. action->set_status_tip("Move one step forward in history");
  111. return action;
  112. }
  113. NonnullRefPtr<Action> make_go_home_action(Function<void(Action&)> callback, Core::Object* parent)
  114. {
  115. return Action::create("Go &Home", { Mod_Alt, Key_Home }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/go-home.png").release_value_but_fixme_should_propagate_errors(), move(callback), parent);
  116. }
  117. NonnullRefPtr<Action> make_close_tab_action(Function<void(Action&)> callback, Core::Object* parent)
  118. {
  119. auto action = Action::create("&Close Tab", { Mod_Ctrl, Key_W }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/close-tab.png").release_value_but_fixme_should_propagate_errors(), move(callback), parent);
  120. action->set_status_tip("Close current tab");
  121. return action;
  122. }
  123. NonnullRefPtr<Action> make_reload_action(Function<void(Action&)> callback, Core::Object* parent)
  124. {
  125. return Action::create("&Reload", { Mod_Ctrl, Key_R }, Key_F5, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/reload.png").release_value_but_fixme_should_propagate_errors(), move(callback), parent);
  126. }
  127. NonnullRefPtr<Action> make_select_all_action(Function<void(Action&)> callback, Core::Object* parent)
  128. {
  129. return Action::create("Select &All", { Mod_Ctrl, Key_A }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/select-all.png").release_value_but_fixme_should_propagate_errors(), move(callback), parent);
  130. }
  131. NonnullRefPtr<Action> make_rename_action(Function<void(Action&)> callback, Core::Object* parent)
  132. {
  133. return Action::create("Re&name", Key_F2, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/rename.png").release_value_but_fixme_should_propagate_errors(), move(callback), parent);
  134. }
  135. NonnullRefPtr<Action> make_properties_action(Function<void(Action&)> callback, Core::Object* parent)
  136. {
  137. return Action::create("P&roperties", { Mod_Alt, Key_Return }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/properties.png").release_value_but_fixme_should_propagate_errors(), move(callback), parent);
  138. }
  139. NonnullRefPtr<Action> make_zoom_in_action(Function<void(Action&)> callback, Core::Object* parent)
  140. {
  141. return GUI::Action::create("Zoom &In", { Mod_Ctrl, Key_Equal }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/zoom-in.png").release_value_but_fixme_should_propagate_errors(), move(callback), parent);
  142. }
  143. NonnullRefPtr<Action> make_reset_zoom_action(Function<void(Action&)> callback, Core::Object* parent)
  144. {
  145. return GUI::Action::create("&Reset Zoom", { Mod_Ctrl, Key_0 }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/zoom-reset.png").release_value_but_fixme_should_propagate_errors(), move(callback), parent);
  146. }
  147. NonnullRefPtr<Action> make_zoom_out_action(Function<void(Action&)> callback, Core::Object* parent)
  148. {
  149. return GUI::Action::create("Zoom &Out", { Mod_Ctrl, Key_Minus }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/zoom-out.png").release_value_but_fixme_should_propagate_errors(), move(callback), parent);
  150. }
  151. NonnullRefPtr<Action> make_rotate_clockwise_action(Function<void(Action&)> callback, Core::Object* parent)
  152. {
  153. return GUI::Action::create("Rotate Clock&wise", { Mod_Ctrl | Mod_Shift, Key_X }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/edit-rotate-cw.png").release_value_but_fixme_should_propagate_errors(), move(callback), parent);
  154. }
  155. NonnullRefPtr<Action> make_rotate_counterclockwise_action(Function<void(Action&)> callback, Core::Object* parent)
  156. {
  157. return GUI::Action::create("Rotate &Counterclockwise", { Mod_Ctrl | Mod_Shift, Key_Z }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/edit-rotate-ccw.png").release_value_but_fixme_should_propagate_errors(), move(callback), parent);
  158. }
  159. }
  160. }