1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 12:37:44 +00:00

PixelPaint: Show more specific Undo/Redo action text

The Undo/Redo actions now tell you what kind of action will be
undone/redone. This is achieved by adding an "action text" field to the
ImageUndoCommand and having everyone who calls did_complete_action()
provide this text.
This commit is contained in:
Andreas Kling 2022-08-21 20:33:03 +02:00
parent 101eb53de5
commit bf25b0a0b5
15 changed files with 57 additions and 20 deletions

View file

@ -100,9 +100,41 @@ MainWidget::MainWidget()
m_show_guides_action->set_checked(image_editor.guide_visibility());
m_show_rulers_action->set_checked(image_editor.ruler_visibility());
image_editor.on_scale_change(image_editor.scale());
image_editor.undo_stack().on_state_change = [this] {
image_editor_did_update_undo_stack();
};
// Ensure that our undo/redo actions are in sync with the current editor.
image_editor_did_update_undo_stack();
};
}
void MainWidget::image_editor_did_update_undo_stack()
{
auto* image_editor = current_image_editor();
if (!image_editor) {
m_undo_action->set_enabled(false);
m_redo_action->set_enabled(false);
return;
}
auto make_action_text = [](auto prefix, auto suffix) {
StringBuilder builder;
builder.append(prefix);
if (suffix.has_value()) {
builder.append(' ');
builder.append(suffix.value());
}
return builder.to_string();
};
auto& undo_stack = image_editor->undo_stack();
m_undo_action->set_enabled(undo_stack.can_undo());
m_redo_action->set_enabled(undo_stack.can_redo());
m_undo_action->set_text(make_action_text("&Undo"sv, undo_stack.undo_action_text()));
m_redo_action->set_text(make_action_text("&Redo"sv, undo_stack.redo_action_text()));
}
// Note: Update these together! v
static Vector<String> const s_suggested_zoom_levels { "25%", "50%", "100%", "200%", "300%", "400%", "800%", "1600%", "Fit to width", "Fit to height", "Fit entire image" };
static constexpr int s_zoom_level_fit_width = 8;
@ -642,7 +674,7 @@ void MainWidget::initialize_menubar(GUI::Window& window)
auto* editor = current_image_editor();
VERIFY(editor);
editor->image().flatten_all_layers();
editor->did_complete_action();
editor->did_complete_action("Flatten Image"sv);
}));
m_layer_menu->add_action(GUI::Action::create(
@ -650,7 +682,7 @@ void MainWidget::initialize_menubar(GUI::Window& window)
auto* editor = current_image_editor();
VERIFY(editor);
editor->image().merge_visible_layers();
editor->did_complete_action();
editor->did_complete_action("Merge Visible"sv);
}));
m_layer_menu->add_action(GUI::Action::create(
@ -661,7 +693,7 @@ void MainWidget::initialize_menubar(GUI::Window& window)
if (!active_layer)
return;
editor->image().merge_active_layer_up(*active_layer);
editor->did_complete_action();
editor->did_complete_action("Merge Active Layer Up"sv);
}));
m_layer_menu->add_action(GUI::Action::create(
@ -672,7 +704,7 @@ void MainWidget::initialize_menubar(GUI::Window& window)
if (!active_layer)
return;
editor->image().merge_active_layer_down(*active_layer);
editor->did_complete_action();
editor->did_complete_action("Merge Active Layer Down"sv);
}));
m_filter_menu = window.add_menu("&Filter");
@ -694,7 +726,7 @@ void MainWidget::initialize_menubar(GUI::Window& window)
if (auto parameters = PixelPaint::FilterParameters<Gfx::GenericConvolutionFilter<5>>::get(&window)) {
filter.apply(layer->content_bitmap(), layer->rect(), layer->content_bitmap(), layer->rect(), *parameters);
layer->did_modify_bitmap(layer->rect());
editor->did_complete_action();
editor->did_complete_action("Generic 5x5 Convolution"sv);
}
}
}));