PixelPaint: Don't crash when cancel is pressed when saving a file

Previously, we were attempting to add an empty string to the most
recently open files list when no file was saved.
This commit is contained in:
Tim Ledbetter 2024-02-09 05:55:02 +00:00 committed by Jelle Raaijmakers
parent ecf41e13ad
commit ad62e433f0
3 changed files with 9 additions and 2 deletions

View file

@ -763,6 +763,8 @@ void ImageEditor::save_project()
return;
}
set_unmodified();
if (on_file_saved)
on_file_saved(path());
}
void ImageEditor::save_project_as()
@ -779,6 +781,8 @@ void ImageEditor::save_project_as()
set_path(file.filename());
set_loaded_from_image(false);
set_unmodified();
if (on_file_saved)
on_file_saved(path());
}
ErrorOr<void> ImageEditor::save_project_to_file(NonnullOwnPtr<Core::File> file) const

View file

@ -90,6 +90,8 @@ public:
Function<void(void)> on_leave;
Function<void(bool modified)> on_modified_change;
Function<void(ByteString const& filename)> on_file_saved;
bool request_close();
void save_project_as();

View file

@ -208,14 +208,12 @@ ErrorOr<void> MainWidget::initialize_menubar(GUI::Window& window)
auto* editor = current_image_editor();
VERIFY(editor);
editor->save_project_as();
GUI::Application::the()->set_most_recently_open_file(editor->path());
});
m_save_image_action = GUI::CommonActions::make_save_action([&](auto&) {
auto* editor = current_image_editor();
VERIFY(editor);
editor->save_project();
GUI::Application::the()->set_most_recently_open_file(editor->path());
});
file_menu->add_action(*m_new_image_action);
@ -1441,6 +1439,9 @@ ImageEditor& MainWidget::create_new_editor(NonnullRefPtr<Image> image)
if (image_editor.active_tool())
image_editor.active_tool()->on_secondary_color_change(color);
};
image_editor.on_file_saved = [](ByteString const& filename) {
GUI::Application::the()->set_most_recently_open_file(filename);
};
if (image->layer_count())
image_editor.set_active_layer(&image->layer(0));