8#include "gui/backend/backend/actions/undo_stack.h"
10#define UNDO_MANAGER (PROJECT->undo_manager_)
12namespace zrythm::gui::actions
18class UndoManager :
public QObject
21 Q_PROPERTY (
UndoStack * undoStack READ getUndoStack CONSTANT)
22 Q_PROPERTY (
UndoStack * redoStack READ getRedoStack CONSTANT)
26 UndoManager (QObject * parent =
nullptr);
27 Q_DISABLE_COPY_MOVE (UndoManager)
28 ~UndoManager ()
override =
default;
35 UndoStack * getUndoStack ()
const {
return undo_stack_; }
36 UndoStack * getRedoStack ()
const {
return redo_stack_; }
59 Q_INVOKABLE
void perform (QObject * action_qobject);
66 void get_plugins (std::vector<zrythm::plugins::Plugin *> &arr)
const;
79 friend void init_from (
81 const UndoManager &other,
85 static constexpr auto kUndoStackKey =
"undoStack"sv;
86 static constexpr auto kRedoStackKey =
"redoStack"sv;
87 friend void to_json (nlohmann::json &j,
const UndoManager &undo_manager)
89 j[kUndoStackKey] = undo_manager.undo_stack_;
91 friend void from_json (
const nlohmann::json &j,
UndoManager &undo_manager)
93 j.at (kUndoStackKey).get_to (*undo_manager.undo_stack_);
103 template <UndoableActionSub
class T>
105 do_or_undo_action (T * action, UndoStack &main_stack, UndoStack &opposite_stack);
111 void do_undo_redo (
bool is_undo);
114 UndoStack * undo_stack_ =
nullptr;
115 UndoStack * redo_stack_ =
nullptr;
129UndoManager::do_or_undo_action (
130 ArrangerSelectionsAction * action,
131 UndoStack &main_stack,
132 UndoStack &opposite_stack);
134UndoManager::do_or_undo_action (
135 ChannelSendAction * action,
136 UndoStack &main_stack,
137 UndoStack &opposite_stack);
139UndoManager::do_or_undo_action (
140 ChordAction * action,
141 UndoStack &main_stack,
142 UndoStack &opposite_stack);
144UndoManager::do_or_undo_action (
145 MidiMappingAction * action,
146 UndoStack &main_stack,
147 UndoStack &opposite_stack);
149UndoManager::do_or_undo_action (
150 MixerSelectionsAction * action,
151 UndoStack &main_stack,
152 UndoStack &opposite_stack);
154UndoManager::do_or_undo_action (
156 UndoStack &main_stack,
157 UndoStack &opposite_stack);
159UndoManager::do_or_undo_action (
160 PortConnectionAction * action,
161 UndoStack &main_stack,
162 UndoStack &opposite_stack);
164UndoManager::do_or_undo_action (
165 RangeAction * action,
166 UndoStack &main_stack,
167 UndoStack &opposite_stack);
169UndoManager::do_or_undo_action (
170 TracklistSelectionsAction * action,
171 UndoStack &main_stack,
172 UndoStack &opposite_stack);
174UndoManager::do_or_undo_action (
175 TransportAction * action,
176 UndoStack &main_stack,
177 UndoStack &opposite_stack);
void init_loaded(sample_rate_t engine_sample_rate)
Inits the undo manager by populating the undo/redo stacks.
std::optional< UndoableActionPtrVariant > get_last_action() const
Returns the last performed action, or NULL if the stack is empty.
void clear_stacks()
Clears the undo and redo stacks.
Q_INVOKABLE void perform(QObject *action_qobject)
Performs the action and pushes it to the undo stack.
std::binary_semaphore action_sem_
Semaphore for performing actions.
void get_plugins(std::vector< zrythm::plugins::Plugin * > &arr) const
Returns all plugins in the undo stacks.
Q_INVOKABLE void undo()
Undo last action.
bool redo_stack_locked_
Whether the redo stack is currently locked.
Q_INVOKABLE void redo()
Redo last undone action.
Serializable stack for undoable actions.