Quellcode durchsuchen

Applications: Use GUI::CommonActions for save and save as menu options

Brendan Coles vor 4 Jahren
Ursprung
Commit
e8ff7c895b

+ 2 - 2
Applications/FontEditor/main.cpp

@@ -105,11 +105,11 @@ int main(int argc, char** argv)
 
         set_edited_font(open_path.value(), move(new_font), window->position());
     }));
-    app_menu.add_action(GUI::Action::create("Save", { Mod_Ctrl, Key_S }, Gfx::Bitmap::load_from_file("/res/icons/16x16/save.png"), [&](auto&) {
+    app_menu.add_action(GUI::CommonActions::make_save_action([&](auto&) {
         FontEditorWidget* editor = static_cast<FontEditorWidget*>(window->main_widget());
         editor->save_as(editor->path());
     }));
-    app_menu.add_action(GUI::Action::create("Save as...", { Mod_Ctrl | Mod_Shift, Key_S }, Gfx::Bitmap::load_from_file("/res/icons/16x16/save.png"), [&](auto&) {
+    app_menu.add_action(GUI::CommonActions::make_save_as_action([&](auto&) {
         FontEditorWidget* editor = static_cast<FontEditorWidget*>(window->main_widget());
         LexicalPath lexical_path(editor->path());
         Optional<String> save_path = GUI::FilePicker::get_save_filepath(window, lexical_path.title(), lexical_path.extension());

+ 2 - 2
Applications/HexEditor/HexEditorWidget.cpp

@@ -99,7 +99,7 @@ HexEditorWidget::HexEditorWidget()
         open_file(open_path.value());
     });
 
-    m_save_action = GUI::Action::create("Save", { Mod_Ctrl, Key_S }, Gfx::Bitmap::load_from_file("/res/icons/16x16/save.png"), [&](const GUI::Action&) {
+    m_save_action = GUI::CommonActions::make_save_action([&](auto&) {
         if (!m_path.is_empty()) {
             if (!m_editor->write_to_file(m_path)) {
                 GUI::MessageBox::show(window(), "Unable to save file.\n", "Error", GUI::MessageBox::Type::Error);
@@ -113,7 +113,7 @@ HexEditorWidget::HexEditorWidget()
         m_save_as_action->activate();
     });
 
-    m_save_as_action = GUI::Action::create("Save as...", { Mod_Ctrl | Mod_Shift, Key_S }, Gfx::Bitmap::load_from_file("/res/icons/16x16/save.png"), [this](const GUI::Action&) {
+    m_save_as_action = GUI::CommonActions::make_save_as_action([&](auto&) {
         Optional<String> save_path = GUI::FilePicker::get_save_filepath(window(), m_name.is_null() ? "Untitled" : m_name, m_extension.is_null() ? "bin" : m_extension);
         if (!save_path.has_value())
             return;

+ 8 - 9
Applications/KeyboardMapper/main.cpp

@@ -74,15 +74,14 @@ int main(int argc, char** argv)
             keyboard_mapper_widget->save();
         });
 
-    auto save_as_action = GUI::Action::create("Save as...", { Mod_Ctrl | Mod_Shift, Key_S }, Gfx::Bitmap::load_from_file("/res/icons/16x16/save.png"),
-        [&](auto&) {
-            String m_name = "Unnamed";
-            Optional<String> save_path = GUI::FilePicker::get_save_filepath(window, m_name, "json");
-            if (!save_path.has_value())
-                return;
-
-            keyboard_mapper_widget->save_to_file(save_path.value());
-        });
+    auto save_as_action = GUI::CommonActions::make_save_as_action([&](auto&) {
+        String m_name = "Unnamed";
+        Optional<String> save_path = GUI::FilePicker::get_save_filepath(window, m_name, "json");
+        if (!save_path.has_value())
+            return;
+
+        keyboard_mapper_widget->save_to_file(save_path.value());
+    });
 
     auto quit_action = GUI::CommonActions::make_quit_action(
         [&](auto&) {

+ 2 - 2
Applications/TextEditor/TextEditorWidget.cpp

@@ -300,7 +300,7 @@ TextEditorWidget::TextEditorWidget()
         open_sesame(open_path.value());
     });
 
-    m_save_as_action = GUI::Action::create("Save as...", { Mod_Ctrl | Mod_Shift, Key_S }, Gfx::Bitmap::load_from_file("/res/icons/16x16/save.png"), [this](const GUI::Action&) {
+    m_save_as_action = GUI::CommonActions::make_save_as_action([&](auto&) {
         Optional<String> save_path = GUI::FilePicker::get_save_filepath(window(), m_name.is_null() ? "Untitled" : m_name, m_extension.is_null() ? "txt" : m_extension);
         if (!save_path.has_value())
             return;
@@ -315,7 +315,7 @@ TextEditorWidget::TextEditorWidget()
         dbgln("Wrote document to {}", save_path.value());
     });
 
-    m_save_action = GUI::Action::create("Save", { Mod_Ctrl, Key_S }, Gfx::Bitmap::load_from_file("/res/icons/16x16/save.png"), [&](const GUI::Action&) {
+    m_save_action = GUI::CommonActions::make_save_action([&](auto&) {
         if (!m_path.is_empty()) {
             if (!m_editor->write_to_file(m_path)) {
                 GUI::MessageBox::show(window(), "Unable to save file.\n", "Error", GUI::MessageBox::Type::Error);