[nostalgia/studio] Make UndoCommand undo/redo return ox::Error
All checks were successful
Build / build (push) Successful in 2m29s
All checks were successful
Build / build (push) Successful in 2m29s
This commit is contained in:
@ -19,8 +19,8 @@ class NoChangesException: public ox::Exception {
|
||||
class UndoCommand {
|
||||
public:
|
||||
virtual ~UndoCommand() noexcept = default;
|
||||
virtual void redo() noexcept = 0;
|
||||
virtual void undo() noexcept = 0;
|
||||
virtual ox::Error redo() noexcept = 0;
|
||||
virtual ox::Error undo() noexcept = 0;
|
||||
[[nodiscard]]
|
||||
virtual int commandId() const noexcept = 0;
|
||||
virtual bool mergeWith(UndoCommand const&cmd) noexcept;
|
||||
|
@ -10,7 +10,9 @@ void UndoStack::push(ox::UPtr<UndoCommand> &&cmd) noexcept {
|
||||
for (auto const i = m_stackIdx; i < m_stack.size();) {
|
||||
std::ignore = m_stack.erase(i);
|
||||
}
|
||||
cmd->redo();
|
||||
if (cmd->redo()) {
|
||||
return;
|
||||
}
|
||||
redoTriggered.emit(cmd.get());
|
||||
changeTriggered.emit(cmd.get());
|
||||
if (m_stack.empty() || !(*m_stack.back().value)->mergeWith(*cmd)) {
|
||||
@ -21,8 +23,11 @@ void UndoStack::push(ox::UPtr<UndoCommand> &&cmd) noexcept {
|
||||
|
||||
void UndoStack::redo() noexcept {
|
||||
if (m_stackIdx < m_stack.size()) {
|
||||
auto &c = m_stack[m_stackIdx++];
|
||||
c->redo();
|
||||
auto &c = m_stack[m_stackIdx];
|
||||
if (c->redo()) {
|
||||
return;
|
||||
}
|
||||
++m_stackIdx;
|
||||
redoTriggered.emit(c.get());
|
||||
changeTriggered.emit(c.get());
|
||||
}
|
||||
@ -31,7 +36,9 @@ void UndoStack::redo() noexcept {
|
||||
void UndoStack::undo() noexcept {
|
||||
if (m_stackIdx) {
|
||||
auto &c = m_stack[--m_stackIdx];
|
||||
c->undo();
|
||||
if (c->undo()) {
|
||||
return;
|
||||
}
|
||||
undoTriggered.emit(c.get());
|
||||
changeTriggered.emit(c.get());
|
||||
}
|
||||
|
Reference in New Issue
Block a user