Centralize setting undo/redo action sensitivity

This fixes undo/redo action sensitivity for non-editor
history stack changes.

Notably recording was not undoable, because the butler
thread creates the reversible "capture" command.
This commit is contained in:
Robin Gareus 2023-06-02 18:07:02 +02:00
parent c56313cea0
commit 8794145c9d
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
2 changed files with 9 additions and 13 deletions

View File

@ -3796,8 +3796,6 @@ Editor::commit_reversible_command ()
if (_session) {
if (before.size() == 1) {
_session->add_command (new MementoCommand<SelectionMemento>(*(_selection_memento), before.front(), &_selection_memento->get_state ()));
redo_action->set_sensitive(false);
undo_action->set_sensitive(true);
begin_selection_op_history ();
}
@ -3815,18 +3813,24 @@ Editor::commit_reversible_command ()
void
Editor::history_changed ()
{
if (!_session) {
return;
}
string label;
if (undo_action && _session) {
if (undo_action) {
if (_session->undo_depth() == 0) {
label = S_("Command|Undo");
undo_action->set_sensitive(false);
} else {
label = string_compose(S_("Command|Undo (%1)"), _session->next_undo());
undo_action->set_sensitive(true);
}
undo_action->property_label() = label;
}
if (redo_action && _session) {
if (redo_action) {
if (_session->redo_depth() == 0) {
label = _("Redo");
redo_action->set_sensitive (false);

View File

@ -162,10 +162,6 @@ Editor::undo (uint32_t n)
if (_session) {
_session->undo (n);
if (_session->undo_depth() == 0) {
undo_action->set_sensitive(false);
}
redo_action->set_sensitive(true);
begin_selection_op_history ();
}
}
@ -186,11 +182,7 @@ Editor::redo (uint32_t n)
paste_count = 0;
if (_session) {
_session->redo (n);
if (_session->redo_depth() == 0) {
redo_action->set_sensitive(false);
}
undo_action->set_sensitive(true);
_session->redo (n);
begin_selection_op_history ();
}
}