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.
This commit is contained in:
meiskam 2022-12-11 04:12:37 -05:00 committed by Andrew Kaster
parent fb4315d121
commit b33aa1bc9b
Notes: sideshowbarker 2024-07-17 03:11:06 +09:00
5 changed files with 45 additions and 23 deletions

View file

@ -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

View file

@ -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>);

View file

@ -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);

View file

@ -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());
}
}

View file

@ -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;