From e8ff7c895ba991f9d9a5ef2b5c276c7b8674ce1b Mon Sep 17 00:00:00 2001 From: Brendan Coles Date: Sun, 1 Nov 2020 21:32:27 +0000 Subject: [PATCH] Applications: Use GUI::CommonActions for save and save as menu options --- Applications/FontEditor/main.cpp | 4 ++-- Applications/HexEditor/HexEditorWidget.cpp | 4 ++-- Applications/KeyboardMapper/main.cpp | 15 +++++++-------- Applications/TextEditor/TextEditorWidget.cpp | 4 ++-- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/Applications/FontEditor/main.cpp b/Applications/FontEditor/main.cpp index 77b10456a4..10481c8f5a 100644 --- a/Applications/FontEditor/main.cpp +++ b/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(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(window->main_widget()); LexicalPath lexical_path(editor->path()); Optional save_path = GUI::FilePicker::get_save_filepath(window, lexical_path.title(), lexical_path.extension()); diff --git a/Applications/HexEditor/HexEditorWidget.cpp b/Applications/HexEditor/HexEditorWidget.cpp index 37d09a671c..e61566afbb 100644 --- a/Applications/HexEditor/HexEditorWidget.cpp +++ b/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 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; diff --git a/Applications/KeyboardMapper/main.cpp b/Applications/KeyboardMapper/main.cpp index 65a99beccc..bbc5dbf18a 100644 --- a/Applications/KeyboardMapper/main.cpp +++ b/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 save_path = GUI::FilePicker::get_save_filepath(window, m_name, "json"); - if (!save_path.has_value()) - return; + auto save_as_action = GUI::CommonActions::make_save_as_action([&](auto&) { + String m_name = "Unnamed"; + Optional 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()); - }); + keyboard_mapper_widget->save_to_file(save_path.value()); + }); auto quit_action = GUI::CommonActions::make_quit_action( [&](auto&) { diff --git a/Applications/TextEditor/TextEditorWidget.cpp b/Applications/TextEditor/TextEditorWidget.cpp index 43dde1c685..09099ebe3d 100644 --- a/Applications/TextEditor/TextEditorWidget.cpp +++ b/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 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);