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