Serenity Operating System
at master 223 lines 12 kB view raw
1/* 2 * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> 3 * 4 * SPDX-License-Identifier: BSD-2-Clause 5 */ 6 7#include <AK/DeprecatedString.h> 8#include <AK/Function.h> 9#include <AK/WeakPtr.h> 10#include <LibCore/Version.h> 11#include <LibGUI/AboutDialog.h> 12#include <LibGUI/Action.h> 13#include <LibGUI/CommandPalette.h> 14#include <LibGUI/Icon.h> 15 16namespace GUI { 17 18namespace CommonActions { 19 20NonnullRefPtr<Action> make_about_action(DeprecatedString const& app_name, Icon const& app_icon, Window* parent) 21{ 22 auto weak_parent = AK::make_weak_ptr_if_nonnull<Window>(parent); 23 auto action = Action::create(DeprecatedString::formatted("&About {}", app_name), app_icon.bitmap_for_size(16), [=](auto&) { 24 AboutDialog::show( 25 String::from_utf8(app_name).release_value_but_fixme_should_propagate_errors(), 26 Core::Version::read_long_version_string().release_value_but_fixme_should_propagate_errors(), 27 app_icon.bitmap_for_size(32), 28 weak_parent) 29 .release_value_but_fixme_should_propagate_errors(); 30 }); 31 action->set_status_tip("Show application about box"); 32 return action; 33} 34 35NonnullRefPtr<Action> make_open_action(Function<void(Action&)> callback, Core::Object* parent) 36{ 37 auto action = Action::create("&Open...", { Mod_Ctrl, Key_O }, Gfx::Bitmap::load_from_file("/res/icons/16x16/open.png"sv).release_value_but_fixme_should_propagate_errors(), move(callback), parent); 38 action->set_status_tip("Open an existing file"); 39 return action; 40} 41 42NonnullRefPtr<Action> make_save_action(Function<void(Action&)> callback, Core::Object* parent) 43{ 44 auto action = Action::create("&Save", { Mod_Ctrl, Key_S }, Gfx::Bitmap::load_from_file("/res/icons/16x16/save.png"sv).release_value_but_fixme_should_propagate_errors(), move(callback), parent); 45 action->set_status_tip("Save the current file"); 46 return action; 47} 48 49NonnullRefPtr<Action> make_save_as_action(Function<void(Action&)> callback, Core::Object* parent) 50{ 51 auto action = Action::create("Save &As...", { Mod_Ctrl | Mod_Shift, Key_S }, Gfx::Bitmap::load_from_file("/res/icons/16x16/save-as.png"sv).release_value_but_fixme_should_propagate_errors(), move(callback), parent); 52 action->set_status_tip("Save the current file with a new name"); 53 return action; 54} 55 56NonnullRefPtr<Action> make_move_to_front_action(Function<void(Action&)> callback, Core::Object* parent) 57{ 58 auto action = Action::create("Move to &Front", { Mod_Ctrl | Mod_Shift, Key_Up }, Gfx::Bitmap::load_from_file("/res/icons/16x16/move-to-front.png"sv).release_value_but_fixme_should_propagate_errors(), move(callback), parent); 59 action->set_status_tip("Move to the top of the stack"); 60 return action; 61} 62 63NonnullRefPtr<Action> make_move_to_back_action(Function<void(Action&)> callback, Core::Object* parent) 64{ 65 auto action = Action::create("Move to &Back", { Mod_Ctrl | Mod_Shift, Key_Down }, Gfx::Bitmap::load_from_file("/res/icons/16x16/move-to-back.png"sv).release_value_but_fixme_should_propagate_errors(), move(callback), parent); 66 action->set_status_tip("Move to the bottom of the stack"); 67 return action; 68} 69 70NonnullRefPtr<Action> make_undo_action(Function<void(Action&)> callback, Core::Object* parent) 71{ 72 return Action::create("&Undo", { Mod_Ctrl, Key_Z }, Gfx::Bitmap::load_from_file("/res/icons/16x16/undo.png"sv).release_value_but_fixme_should_propagate_errors(), move(callback), parent); 73} 74 75NonnullRefPtr<Action> make_redo_action(Function<void(Action&)> callback, Core::Object* parent) 76{ 77 return Action::create("&Redo", { Mod_Ctrl | Mod_Shift, Key_Z }, { Mod_Ctrl, Key_Y }, Gfx::Bitmap::load_from_file("/res/icons/16x16/redo.png"sv).release_value_but_fixme_should_propagate_errors(), move(callback), parent); 78} 79 80NonnullRefPtr<Action> make_delete_action(Function<void(Action&)> callback, Core::Object* parent) 81{ 82 return Action::create("&Delete", { Mod_None, Key_Delete }, Gfx::Bitmap::load_from_file("/res/icons/16x16/delete.png"sv).release_value_but_fixme_should_propagate_errors(), move(callback), parent); 83} 84 85NonnullRefPtr<Action> make_cut_action(Function<void(Action&)> callback, Core::Object* parent) 86{ 87 auto action = Action::create("Cu&t", { Mod_Ctrl, Key_X }, Gfx::Bitmap::load_from_file("/res/icons/16x16/edit-cut.png"sv).release_value_but_fixme_should_propagate_errors(), move(callback), parent); 88 action->set_status_tip("Cut to clipboard"); 89 return action; 90} 91 92NonnullRefPtr<Action> make_copy_action(Function<void(Action&)> callback, Core::Object* parent) 93{ 94 auto action = Action::create("&Copy", { Mod_Ctrl, Key_C }, Gfx::Bitmap::load_from_file("/res/icons/16x16/edit-copy.png"sv).release_value_but_fixme_should_propagate_errors(), move(callback), parent); 95 action->set_status_tip("Copy to clipboard"); 96 return action; 97} 98 99NonnullRefPtr<Action> make_paste_action(Function<void(Action&)> callback, Core::Object* parent) 100{ 101 auto action = Action::create("&Paste", { Mod_Ctrl, Key_V }, Gfx::Bitmap::load_from_file("/res/icons/16x16/paste.png"sv).release_value_but_fixme_should_propagate_errors(), move(callback), parent); 102 action->set_status_tip("Paste from clipboard"); 103 return action; 104} 105 106NonnullRefPtr<Action> make_insert_emoji_action(Function<void(Action&)> callback, Core::Object* parent) 107{ 108 auto action = Action::create("&Insert Emoji...", { Mod_Ctrl | Mod_Alt, Key_Space }, Gfx::Bitmap::load_from_file("/res/icons/16x16/emoji.png"sv).release_value_but_fixme_should_propagate_errors(), move(callback), parent); 109 action->set_status_tip("Open the Emoji Picker"); 110 return action; 111} 112 113NonnullRefPtr<Action> make_fullscreen_action(Function<void(Action&)> callback, Core::Object* parent) 114{ 115 auto action = Action::create("&Fullscreen", { Mod_None, Key_F11 }, move(callback), parent); 116 action->set_status_tip("Enter fullscreen mode"); 117 action->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/fullscreen.png"sv).release_value_but_fixme_should_propagate_errors()); 118 return action; 119} 120 121NonnullRefPtr<Action> make_quit_action(Function<void(Action&)> callback) 122{ 123 auto action = Action::create("&Quit", { Mod_Alt, Key_F4 }, move(callback)); 124 action->set_status_tip("Quit the application"); 125 return action; 126} 127 128NonnullRefPtr<Action> make_help_action(Function<void(Action&)> callback, Core::Object* parent) 129{ 130 auto action = Action::create("&Manual", { Mod_None, Key_F1 }, Gfx::Bitmap::load_from_file("/res/icons/16x16/app-help.png"sv).release_value_but_fixme_should_propagate_errors(), move(callback), parent); 131 action->set_status_tip("Show help contents"); 132 return action; 133} 134 135NonnullRefPtr<Action> make_go_back_action(Function<void(Action&)> callback, Core::Object* parent) 136{ 137 auto action = Action::create("Go &Back", { Mod_Alt, Key_Left }, { MouseButton::Backward }, Gfx::Bitmap::load_from_file("/res/icons/16x16/go-back.png"sv).release_value_but_fixme_should_propagate_errors(), move(callback), parent); 138 action->set_status_tip("Move one step backward in history"); 139 return action; 140} 141 142NonnullRefPtr<Action> make_go_forward_action(Function<void(Action&)> callback, Core::Object* parent) 143{ 144 auto action = Action::create("Go &Forward", { Mod_Alt, Key_Right }, { MouseButton::Forward }, Gfx::Bitmap::load_from_file("/res/icons/16x16/go-forward.png"sv).release_value_but_fixme_should_propagate_errors(), move(callback), parent); 145 action->set_status_tip("Move one step forward in history"); 146 return action; 147} 148 149NonnullRefPtr<Action> make_go_home_action(Function<void(Action&)> callback, Core::Object* parent) 150{ 151 return Action::create("Go &Home", { Mod_Alt, Key_Home }, Gfx::Bitmap::load_from_file("/res/icons/16x16/go-home.png"sv).release_value_but_fixme_should_propagate_errors(), move(callback), parent); 152} 153 154NonnullRefPtr<Action> make_close_tab_action(Function<void(Action&)> callback, Core::Object* parent) 155{ 156 auto action = Action::create("&Close Tab", { Mod_Ctrl, Key_W }, Gfx::Bitmap::load_from_file("/res/icons/16x16/close-tab.png"sv).release_value_but_fixme_should_propagate_errors(), move(callback), parent); 157 action->set_status_tip("Close current tab"); 158 return action; 159} 160 161NonnullRefPtr<Action> make_reload_action(Function<void(Action&)> callback, Core::Object* parent) 162{ 163 return Action::create("&Reload", { Mod_Ctrl, Key_R }, Key_F5, Gfx::Bitmap::load_from_file("/res/icons/16x16/reload.png"sv).release_value_but_fixme_should_propagate_errors(), move(callback), parent); 164} 165 166NonnullRefPtr<Action> make_select_all_action(Function<void(Action&)> callback, Core::Object* parent) 167{ 168 return Action::create("Select &All", { Mod_Ctrl, Key_A }, Gfx::Bitmap::load_from_file("/res/icons/16x16/select-all.png"sv).release_value_but_fixme_should_propagate_errors(), move(callback), parent); 169} 170 171NonnullRefPtr<Action> make_rename_action(Function<void(Action&)> callback, Core::Object* parent) 172{ 173 return Action::create("Re&name", Key_F2, Gfx::Bitmap::load_from_file("/res/icons/16x16/rename.png"sv).release_value_but_fixme_should_propagate_errors(), move(callback), parent); 174} 175 176NonnullRefPtr<Action> make_properties_action(Function<void(Action&)> callback, Core::Object* parent) 177{ 178 return Action::create("P&roperties", { Mod_Alt, Key_Return }, Gfx::Bitmap::load_from_file("/res/icons/16x16/properties.png"sv).release_value_but_fixme_should_propagate_errors(), move(callback), parent); 179} 180 181NonnullRefPtr<Action> make_zoom_in_action(Function<void(Action&)> callback, Core::Object* parent) 182{ 183 return GUI::Action::create("Zoom &In", { Mod_Ctrl, Key_Equal }, Gfx::Bitmap::load_from_file("/res/icons/16x16/zoom-in.png"sv).release_value_but_fixme_should_propagate_errors(), move(callback), parent); 184} 185 186NonnullRefPtr<Action> make_reset_zoom_action(Function<void(Action&)> callback, Core::Object* parent) 187{ 188 return GUI::Action::create("&Reset Zoom", { Mod_Ctrl, Key_0 }, Gfx::Bitmap::load_from_file("/res/icons/16x16/zoom-reset.png"sv).release_value_but_fixme_should_propagate_errors(), move(callback), parent); 189} 190 191NonnullRefPtr<Action> make_zoom_out_action(Function<void(Action&)> callback, Core::Object* parent) 192{ 193 return GUI::Action::create("Zoom &Out", { Mod_Ctrl, Key_Minus }, Gfx::Bitmap::load_from_file("/res/icons/16x16/zoom-out.png"sv).release_value_but_fixme_should_propagate_errors(), move(callback), parent); 194} 195 196NonnullRefPtr<Action> make_rotate_clockwise_action(Function<void(Action&)> callback, Core::Object* parent) 197{ 198 return GUI::Action::create("Rotate Clock&wise", { Mod_Ctrl | Mod_Shift, Key_GreaterThan }, Gfx::Bitmap::load_from_file("/res/icons/16x16/edit-rotate-cw.png"sv).release_value_but_fixme_should_propagate_errors(), move(callback), parent); 199} 200 201NonnullRefPtr<Action> make_rotate_counterclockwise_action(Function<void(Action&)> callback, Core::Object* parent) 202{ 203 return GUI::Action::create("Rotate &Counterclockwise", { Mod_Ctrl | Mod_Shift, Key_LessThan }, Gfx::Bitmap::load_from_file("/res/icons/16x16/edit-rotate-ccw.png"sv).release_value_but_fixme_should_propagate_errors(), move(callback), parent); 204} 205 206NonnullRefPtr<Action> make_command_palette_action(Window* window) 207{ 208 auto action = Action::create("&Commands...", { Mod_Ctrl | Mod_Shift, Key_A }, MUST(Gfx::Bitmap::load_from_file("/res/icons/16x16/find.png"sv)), [=](auto&) { 209 auto command_palette = CommandPalette::construct(*window); 210 if (command_palette->exec() != GUI::Dialog::ExecResult::OK) 211 return; 212 auto* action = command_palette->selected_action(); 213 VERIFY(action); 214 action->flash_menubar_menu(*window); 215 action->activate(); 216 }); 217 action->set_status_tip("Open the command palette"); 218 return action; 219} 220 221} 222 223}