[nostalgia/studio] Add UndoCommand::mergeWith
This commit is contained in:
parent
10d2f2c064
commit
dd12857ba8
@ -6,16 +6,24 @@
|
||||
|
||||
namespace nostalgia::studio {
|
||||
|
||||
bool UndoCommand::mergeWith(const UndoCommand*) noexcept {
|
||||
return false;
|
||||
}
|
||||
|
||||
void UndoStack::push(UndoCommand *cmd) noexcept {
|
||||
for (const auto i = m_stackIdx; i < m_stack.size();) {
|
||||
oxIgnoreError(m_stack.erase(i));
|
||||
}
|
||||
m_stack.emplace_back(cmd);
|
||||
++m_stackIdx;
|
||||
auto cmdId = cmd->commandId();
|
||||
cmd->redo();
|
||||
redoTriggered.emit(cmdId);
|
||||
changeTriggered.emit(cmdId);
|
||||
if (!m_stack.size() || !m_stack.back().value->mergeWith(cmd)) {
|
||||
m_stack.emplace_back(cmd);
|
||||
++m_stackIdx;
|
||||
} else {
|
||||
delete cmd;
|
||||
}
|
||||
}
|
||||
|
||||
void UndoStack::redo() noexcept {
|
||||
|
@ -18,6 +18,7 @@ class UndoCommand {
|
||||
virtual void undo() noexcept = 0;
|
||||
[[nodiscard]]
|
||||
virtual int commandId() const noexcept = 0;
|
||||
virtual bool mergeWith(const UndoCommand *cmd) noexcept;
|
||||
};
|
||||
|
||||
class UndoStack {
|
||||
|
Loading…
Reference in New Issue
Block a user