diff options
author | meiskam <634802+meiskam@users.noreply.github.com> | 2022-12-11 04:12:37 -0500 |
---|---|---|
committer | Andrew Kaster <andrewdkaster@gmail.com> | 2022-12-15 00:14:35 -0700 |
commit | b33aa1bc9b0e853a2d7da028d079981b9b4a3ea7 (patch) | |
tree | 6c272c46d01ea2a65d1f2fc543edea59f68aac5c /Userland | |
parent | fb4315d121c14a61c50466949e6564139a6a87a1 (diff) | |
download | serenity-b33aa1bc9b0e853a2d7da028d079981b9b4a3ea7.zip |
PixelPaint: Update window `modified` to look at all tabs
This causes the corner X to correctly have dots when any of the open
tabs have unsaved changes. Event calls and undo stack modifications
have been collected to one spot.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Applications/PixelPaint/ImageEditor.cpp | 33 | ||||
-rw-r--r-- | Userland/Applications/PixelPaint/ImageEditor.h | 4 | ||||
-rw-r--r-- | Userland/Applications/PixelPaint/LevelsDialog.cpp | 4 | ||||
-rw-r--r-- | Userland/Applications/PixelPaint/MainWidget.cpp | 25 | ||||
-rw-r--r-- | Userland/Applications/PixelPaint/MainWidget.h | 2 |
5 files changed, 45 insertions, 23 deletions
diff --git a/Userland/Applications/PixelPaint/ImageEditor.cpp b/Userland/Applications/PixelPaint/ImageEditor.cpp index 66a4a9b447..e4212781a4 100644 --- a/Userland/Applications/PixelPaint/ImageEditor.cpp +++ b/Userland/Applications/PixelPaint/ImageEditor.cpp @@ -63,9 +63,7 @@ ImageEditor::~ImageEditor() void ImageEditor::did_complete_action(DeprecatedString action_text) { - if (on_modified_change) - on_modified_change(true); - m_undo_stack.push(make<ImageUndoCommand>(*m_image, move(action_text))); + set_modified(move(action_text)); } bool ImageEditor::is_modified() @@ -118,6 +116,24 @@ void ImageEditor::set_path(DeprecatedString path) set_title(LexicalPath::title(m_path)); } +void ImageEditor::set_modified(DeprecatedString action_text) +{ + m_undo_stack.push(make<ImageUndoCommand>(*m_image, move(action_text))); + update_modified(); +} + +void ImageEditor::set_unmodified() +{ + m_undo_stack.set_current_unmodified(); + update_modified(); +} + +void ImageEditor::update_modified() +{ + if (on_modified_change) + on_modified_change(is_modified()); +} + void ImageEditor::paint_event(GUI::PaintEvent& event) { GUI::Frame::paint_event(event); @@ -568,8 +584,7 @@ void ImageEditor::clear_guides() void ImageEditor::layers_did_change() { - if (on_modified_change) - on_modified_change(true); + update_modified(); update(); } @@ -687,9 +702,7 @@ void ImageEditor::save_project() GUI::MessageBox::show_error(window(), DeprecatedString::formatted("Could not save {}: {}", path(), result.error())); return; } - undo_stack().set_current_unmodified(); - if (on_modified_change) - on_modified_change(false); + set_unmodified(); } void ImageEditor::save_project_as() @@ -705,9 +718,7 @@ void ImageEditor::save_project_as() } set_path(file->filename()); set_loaded_from_image(false); - undo_stack().set_current_unmodified(); - if (on_modified_change) - on_modified_change(false); + set_unmodified(); } Result<void, DeprecatedString> ImageEditor::save_project_to_file(Core::File& file) const diff --git a/Userland/Applications/PixelPaint/ImageEditor.h b/Userland/Applications/PixelPaint/ImageEditor.h index 2db91de336..391b2f0b43 100644 --- a/Userland/Applications/PixelPaint/ImageEditor.h +++ b/Userland/Applications/PixelPaint/ImageEditor.h @@ -120,6 +120,10 @@ public: void set_editor_color_to_color_at_mouse_position(GUI::MouseEvent const& event, bool sample_all_layers); + void set_modified(DeprecatedString action_text); + void set_unmodified(); + void update_modified(); + private: explicit ImageEditor(NonnullRefPtr<Image>); diff --git a/Userland/Applications/PixelPaint/LevelsDialog.cpp b/Userland/Applications/PixelPaint/LevelsDialog.cpp index d38a989039..6babdbdd16 100644 --- a/Userland/Applications/PixelPaint/LevelsDialog.cpp +++ b/Userland/Applications/PixelPaint/LevelsDialog.cpp @@ -58,10 +58,8 @@ LevelsDialog::LevelsDialog(GUI::Window* parent_window, ImageEditor* editor) }; apply_button->on_click = [this](auto) { - if (m_did_change) { - m_editor->on_modified_change(true); + if (m_did_change) m_editor->did_complete_action("Levels"sv); - } cleanup_resources(); done(ExecResult::OK); diff --git a/Userland/Applications/PixelPaint/MainWidget.cpp b/Userland/Applications/PixelPaint/MainWidget.cpp index 76a918acda..fb09611a9e 100644 --- a/Userland/Applications/PixelPaint/MainWidget.cpp +++ b/Userland/Applications/PixelPaint/MainWidget.cpp @@ -95,12 +95,7 @@ MainWidget::MainWidget() m_vectorscope_widget->set_image(&image_editor.image()); m_layer_list_widget->set_image(&image_editor.image()); m_layer_properties_widget->set_layer(image_editor.active_layer()); - window()->set_modified(image_editor.is_modified()); - image_editor.on_modified_change = [this](bool modified) { - window()->set_modified(modified); - m_histogram_widget->image_changed(); - m_vectorscope_widget->image_changed(); - }; + update_window_modified(); if (auto* active_tool = m_toolbox->active_tool()) image_editor.set_active_tool(active_tool); m_show_guides_action->set_checked(image_editor.guide_visibility()); @@ -166,7 +161,7 @@ void MainWidget::initialize_menubar(GUI::Window& window) auto& editor = create_new_editor(*image); auto image_title = dialog->image_name().trim_whitespace(); editor.set_title(image_title.is_empty() ? "Untitled" : image_title); - editor.undo_stack().set_current_unmodified(); + editor.set_unmodified(); m_histogram_widget->set_image(image); m_vectorscope_widget->set_image(image); @@ -1005,7 +1000,7 @@ void MainWidget::open_image(Core::File& file) auto& editor = create_new_editor(image); editor.set_loaded_from_image(m_loader.is_raw_image()); editor.set_path(file.filename()); - editor.undo_stack().set_current_unmodified(); + editor.set_unmodified(); m_layer_list_widget->set_image(&image); } @@ -1022,7 +1017,7 @@ void MainWidget::create_default_image() auto& editor = create_new_editor(*image); editor.set_title("Untitled"); editor.set_active_layer(bg_layer); - editor.undo_stack().set_current_unmodified(); + editor.set_unmodified(); } void MainWidget::create_image_from_clipboard() @@ -1078,6 +1073,13 @@ ImageEditor& MainWidget::create_new_editor(NonnullRefPtr<Image> image) m_tab_widget->set_tab_title(image_editor, title); }; + image_editor.on_modified_change = [&](auto const modified) { + m_tab_widget->set_tab_modified(image_editor, modified); + update_window_modified(); + m_histogram_widget->image_changed(); + m_vectorscope_widget->image_changed(); + }; + image_editor.on_image_mouse_position_change = [&](auto const& mouse_position) { auto const& image_size = current_image_editor()->image().size(); auto image_rectangle = Gfx::IntRect { 0, 0, image_size.width(), image_size.height() }; @@ -1177,4 +1179,9 @@ void MainWidget::drop_event(GUI::DropEvent& event) open_image(response.value()); } } + +void MainWidget::update_window_modified() +{ + window()->set_modified(m_tab_widget->is_any_tab_modified()); +} } diff --git a/Userland/Applications/PixelPaint/MainWidget.h b/Userland/Applications/PixelPaint/MainWidget.h index 65b37093f5..5b46c1ebc0 100644 --- a/Userland/Applications/PixelPaint/MainWidget.h +++ b/Userland/Applications/PixelPaint/MainWidget.h @@ -59,6 +59,8 @@ private: virtual void drag_enter_event(GUI::DragEvent&) override; virtual void drop_event(GUI::DropEvent&) override; + void update_window_modified(); + ProjectLoader m_loader; RefPtr<ToolboxWidget> m_toolbox; |