Skip to content

Commit

Permalink
PixelPaint: Call set_modified on window
Browse files Browse the repository at this point in the history
Call set_modified on window in order to reflect unsaved
changed in the titlebar's close button
  • Loading branch information
GeekFiftyFive authored and awesomekling committed Mar 24, 2022
1 parent 7eb672c commit ff8a6d8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Userland/Applications/PixelPaint/ImageEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,16 @@ ImageEditor::~ImageEditor()

void ImageEditor::did_complete_action()
{
if (on_modified_change)
on_modified_change(true);
m_undo_stack.push(make<ImageUndoCommand>(*m_image));
}

bool ImageEditor::is_modified()
{
return undo_stack().is_current_modified();
}

bool ImageEditor::undo()
{
if (!m_undo_stack.can_undo())
Expand Down Expand Up @@ -580,6 +587,8 @@ void ImageEditor::save_project()
return;
}
undo_stack().set_current_unmodified();
if (on_modified_change)
on_modified_change(false);
}

void ImageEditor::save_project_as()
Expand All @@ -596,6 +605,8 @@ 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);
}

Result<void, String> ImageEditor::save_project_to_file(Core::File& file) const
Expand Down
3 changes: 3 additions & 0 deletions Userland/Applications/PixelPaint/ImageEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class ImageEditor final
Function<void(Gfx::IntPoint const&)> on_image_mouse_position_change;

Function<void(void)> on_leave;
Function<void(bool modified)> on_modified_change;

bool request_close();

Expand All @@ -110,6 +111,8 @@ class ImageEditor final

void set_loaded_from_image(bool);

bool is_modified();

private:
explicit ImageEditor(NonnullRefPtr<Image>);

Expand Down
4 changes: 4 additions & 0 deletions Userland/Applications/PixelPaint/MainWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ MainWidget::MainWidget()
m_palette_widget->set_image_editor(&image_editor);
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);
};
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());
Expand Down

0 comments on commit ff8a6d8

Please sign in to comment.