From 3b352e46d6123c78e68e3393b941f55a0ccaa946 Mon Sep 17 00:00:00 2001 From: Karol Kosek Date: Sat, 26 Feb 2022 18:20:38 +0100 Subject: [PATCH] Spreadsheet: Reuse save and rename actions These parts of code were identical to their action counterparts. --- .../Spreadsheet/SpreadsheetWidget.cpp | 39 ++++--------------- 1 file changed, 7 insertions(+), 32 deletions(-) diff --git a/Userland/Applications/Spreadsheet/SpreadsheetWidget.cpp b/Userland/Applications/Spreadsheet/SpreadsheetWidget.cpp index f27a6501a6b..2a20fbda5bc 100644 --- a/Userland/Applications/Spreadsheet/SpreadsheetWidget.cpp +++ b/Userland/Applications/Spreadsheet/SpreadsheetWidget.cpp @@ -137,16 +137,11 @@ SpreadsheetWidget::SpreadsheetWidget(GUI::Window& parent_window, NonnullRefPtrVe m_save_action = GUI::CommonActions::make_save_action([&](auto&) { if (current_filename().is_empty()) { - String name = "workbook"; - Optional save_path = GUI::FilePicker::get_save_filepath(window(), name, "sheets"); - if (!save_path.has_value()) - return; - - save(save_path.value()); - update_window_title(); - } else { - save(current_filename()); + m_save_as_action->activate(); + return; } + + save(current_filename()); }); m_save_as_action = GUI::CommonActions::make_save_as_action([&](auto&) { @@ -258,17 +253,7 @@ SpreadsheetWidget::SpreadsheetWidget(GUI::Window& parent_window, NonnullRefPtrVe m_tab_widget->on_double_click = [&](auto& widget) { m_tab_context_menu_sheet_view = static_cast(widget); - VERIFY(m_tab_context_menu_sheet_view); - - auto* sheet_ptr = m_tab_context_menu_sheet_view->sheet_if_available(); - VERIFY(sheet_ptr); // How did we get here without a sheet? - auto& sheet = *sheet_ptr; - String new_name; - if (GUI::InputBox::show(window(), new_name, String::formatted("New name for '{}'", sheet.name()), "Rename sheet") == GUI::Dialog::ExecOK) { - sheet.set_name(new_name); - sheet.update(); - m_tab_widget->set_tab_title(static_cast(*m_tab_context_menu_sheet_view), new_name); - } + m_rename_action->activate(); }; } @@ -454,18 +439,8 @@ bool SpreadsheetWidget::request_close() auto result = GUI::MessageBox::ask_about_unsaved_changes(window(), current_filename()); if (result == GUI::MessageBox::ExecYes) { - if (current_filename().is_empty()) { - String name = "workbook"; - Optional save_path = GUI::FilePicker::get_save_filepath(window(), name, "sheets"); - if (!save_path.has_value()) - return false; - - save(save_path.value()); - update_window_title(); - } else { - save(current_filename()); - } - return true; + m_save_action->activate(); + return !m_workbook->dirty(); } if (result == GUI::MessageBox::ExecNo)