summaryrefslogtreecommitdiff
path: root/Userland/Applications/Spreadsheet
diff options
context:
space:
mode:
authorKarol Kosek <krkk@serenityos.org>2022-02-26 18:20:38 +0100
committerAli Mohammad Pur <Ali.mpfard@gmail.com>2022-03-28 22:28:40 +0430
commit3b352e46d6123c78e68e3393b941f55a0ccaa946 (patch)
treedfb2fd63bc72ce7e4b79348e4f2f24cd6ee423a3 /Userland/Applications/Spreadsheet
parentb23edd418c1f4bd347619aca5200e93990b1db7e (diff)
downloadserenity-3b352e46d6123c78e68e3393b941f55a0ccaa946.zip
Spreadsheet: Reuse save and rename actions
These parts of code were identical to their action counterparts.
Diffstat (limited to 'Userland/Applications/Spreadsheet')
-rw-r--r--Userland/Applications/Spreadsheet/SpreadsheetWidget.cpp39
1 files changed, 7 insertions, 32 deletions
diff --git a/Userland/Applications/Spreadsheet/SpreadsheetWidget.cpp b/Userland/Applications/Spreadsheet/SpreadsheetWidget.cpp
index f27a6501a6..2a20fbda5b 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<String> 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<SpreadsheetView&>(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<GUI::Widget&>(*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<String> 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)