diff --git a/Applications/Spreadsheet/SpreadsheetWidget.cpp b/Applications/Spreadsheet/SpreadsheetWidget.cpp index 4294462cfb..777062c9e1 100644 --- a/Applications/Spreadsheet/SpreadsheetWidget.cpp +++ b/Applications/Spreadsheet/SpreadsheetWidget.cpp @@ -137,6 +137,20 @@ SpreadsheetWidget::~SpreadsheetWidget() { } +void SpreadsheetWidget::set_filename(const String& filename) +{ + if (m_current_filename == filename) + return; + + m_current_filename = filename; + StringBuilder builder; + builder.append("Spreadsheet - "); + builder.append(m_current_filename); + + window()->set_title(builder.string_view()); + window()->update(); +} + void SpreadsheetWidget::load(const StringView& filename) { auto file_or_error = Core::File::open(filename, Core::IODevice::OpenMode::ReadOnly); @@ -195,6 +209,8 @@ void SpreadsheetWidget::load(const StringView& filename) } setup_tabs(); + + set_filename(filename); } void SpreadsheetWidget::save(const StringView& filename) @@ -230,6 +246,8 @@ void SpreadsheetWidget::save(const StringView& filename) GUI::MessageBox::show(window(), sb.to_string(), "Error", GUI::MessageBox::Type::Error); return; } + + set_filename(filename); } } diff --git a/Applications/Spreadsheet/SpreadsheetWidget.h b/Applications/Spreadsheet/SpreadsheetWidget.h index 0f4eaa19bf..6ade762440 100644 --- a/Applications/Spreadsheet/SpreadsheetWidget.h +++ b/Applications/Spreadsheet/SpreadsheetWidget.h @@ -41,6 +41,9 @@ public: void save(const StringView& filename); void load(const StringView& filename); + const String& current_filename() const { return m_current_filename; } + void set_filename(const String& filename); + private: explicit SpreadsheetWidget(NonnullRefPtrVector&& sheets = {}, bool should_add_sheet_if_empty = true); @@ -51,6 +54,8 @@ private: RefPtr m_tab_widget; RefPtr m_current_cell_label; RefPtr m_cell_value_editor; + + String m_current_filename; }; } diff --git a/Applications/Spreadsheet/main.cpp b/Applications/Spreadsheet/main.cpp index b0c7eaa393..d45f4c0ba6 100644 --- a/Applications/Spreadsheet/main.cpp +++ b/Applications/Spreadsheet/main.cpp @@ -107,13 +107,31 @@ int main(int argc, char* argv[]) spreadsheet_widget.load(load_path.value()); })); + file_menu.add_action(GUI::CommonActions::make_save_action([&](auto&) { + if (spreadsheet_widget.current_filename().is_empty()) { + String name = "sheet"; + Optional save_path = GUI::FilePicker::get_save_filepath(window, name, "json"); + if (!save_path.has_value()) + return; + + spreadsheet_widget.save(save_path.value()); + } else { + spreadsheet_widget.save(spreadsheet_widget.current_filename()); + } + })); + + file_menu.add_action(GUI::CommonActions::make_save_as_action([&](auto&) { + auto current_filename = spreadsheet_widget.current_filename(); String name = "sheet"; Optional save_path = GUI::FilePicker::get_save_filepath(window, name, "json"); if (!save_path.has_value()) return; spreadsheet_widget.save(save_path.value()); + + if (!current_filename.is_empty()) + spreadsheet_widget.set_filename(current_filename); })); app->set_menubar(move(menubar));