mirror of
https://github.com/obsproject/obs-studio.git
synced 2024-07-14 15:24:07 +00:00
UI: Add disable push/pop to undo/redo stack
This allows disabling and re-enabling in certain situations where these actions doing so might end up being used in recursion.
This commit is contained in:
parent
edc82eb7cf
commit
1afe092c6e
|
@ -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();
|
||||
|
|
|
@ -29,11 +29,16 @@ class undo_stack : public QObject {
|
|||
ui_ptr ui;
|
||||
std::deque<undo_redo_t> undo_items;
|
||||
std::deque<undo_redo_t> 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,
|
||||
|
|
Loading…
Reference in a new issue