Skip to content

Commit

Permalink
#5408: Re-implement IUndoSystem::cancel(). The pending operation is n…
Browse files Browse the repository at this point in the history
…o longer pushed to the stack only to be removed immediately afterwards.
  • Loading branch information
codereader committed Oct 29, 2021
1 parent d6612b8 commit 444b66e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
6 changes: 6 additions & 0 deletions radiantcore/undo/Stack.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ class UndoStack
_pending = std::make_shared<Operation>(command);
}

void cancel()
{
// discard the pending operation without storing it in the stack
_pending.reset();
}

// Finish the current undo operation
bool finish(const std::string& command)
{
Expand Down
11 changes: 5 additions & 6 deletions radiantcore/undo/UndoSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,11 @@ bool UndoSystem::operationStarted() const

void UndoSystem::cancel()
{
// Try to add the last operation as "temp"
if (finishUndo("$TEMPORARY"))
{
// Instantly remove the added operation
_undoStack.pop_back();
}
if (_activeUndoStack != nullptr)
{
_activeUndoStack->cancel();
setActiveUndoStack(nullptr);
}
}

void UndoSystem::finish(const std::string& command)
Expand Down
9 changes: 2 additions & 7 deletions radiantcore/undo/UndoSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,14 @@ class UndoSystem final :
~UndoSystem();

IUndoStateSaver* getStateSaver(IUndoable& undoable) override;

void releaseStateSaver(IUndoable& undoable) override;

void start() override;

bool operationStarted() const override;

// greebo: This finishes the current operation and
// instantly removes it from the stack
void cancel() override;

void finish(const std::string& command) override;

bool operationStarted() const override;

void undo() override;
void redo() override;

Expand Down

0 comments on commit 444b66e

Please sign in to comment.