diff --git a/UI/undo-stack-obs.cpp b/UI/undo-stack-obs.cpp index ab358d610..eed29cbb2 100644 --- a/UI/undo-stack-obs.cpp +++ b/UI/undo-stack-obs.cpp @@ -64,7 +64,7 @@ void undo_stack::add_action(const QString &name, undo_redo_cb undo, void undo_stack::undo() { - if (undo_items.size() == 0 || !enabled) + if (undo_items.size() == 0 || !is_enabled()) return; last_is_repeatable = false; @@ -88,7 +88,7 @@ void undo_stack::undo() void undo_stack::redo() { - if (redo_items.size() == 0 || !enabled) + if (redo_items.size() == 0 || !is_enabled()) return; last_is_repeatable = false; @@ -110,9 +110,8 @@ void undo_stack::redo() } } -void undo_stack::enable() +void undo_stack::enable_internal() { - enabled = true; last_is_repeatable = false; ui->actionMainUndo->setDisabled(false); @@ -120,15 +119,42 @@ void undo_stack::enable() ui->actionMainRedo->setDisabled(false); } -void undo_stack::disable() +void undo_stack::disable_internal() { - enabled = false; last_is_repeatable = false; ui->actionMainUndo->setDisabled(true); ui->actionMainRedo->setDisabled(true); } +void undo_stack::enable() +{ + enabled = true; + if (is_enabled()) + enable_internal(); +} + +void undo_stack::disable() +{ + if (is_enabled()) + disable_internal(); + enabled = false; +} + +void undo_stack::push_disabled() +{ + if (is_enabled()) + disable_internal(); + disable_refs++; +} + +void undo_stack::pop_disabled() +{ + disable_refs--; + if (is_enabled()) + enable_internal(); +} + void undo_stack::clear_redo() { redo_items.clear(); diff --git a/UI/undo-stack-obs.hpp b/UI/undo-stack-obs.hpp index 2ab1f4893..e8e4992d5 100644 --- a/UI/undo-stack-obs.hpp +++ b/UI/undo-stack-obs.hpp @@ -29,11 +29,16 @@ class undo_stack : public QObject { ui_ptr ui; std::deque undo_items; std::deque redo_items; + int disable_refs = 0; bool enabled = true; bool last_is_repeatable = false; QTimer repeat_reset_timer; + inline bool is_enabled() const { return !disable_refs && enabled; } + + void enable_internal(); + void disable_internal(); void clear_redo(); private slots: @@ -44,6 +49,8 @@ public: void enable(); void disable(); + void push_disabled(); + void pop_disabled(); void clear(); void add_action(const QString &name, undo_redo_cb undo,