CommandStack.h header
#include <ew/core/CommandStack.h>
Namespace ew::core
CommandStack class
class ew::core::CommandStack
The undo/redo history. push() applies a command and records it as the newest undoable step; undo()/redo() move through the history. Pushing a new command after an undo discards the redo branch (standard linear undo).
Members
ew::core::CommandStack::CommandStack()
Constructs an empty command stack.
ew::core::CommandStack::~CommandStack()
Destroys the stack and its recorded commands.
ew::core::CommandStack::CommandStack(const CommandStack &)=delete
Not copyable.
ew::core::CommandStack::CommandStack(CommandStack &&)=delete
Not movable.
CommandStack & ew::core::CommandStack::operator=(const CommandStack &)=delete
Not copyable.
CommandStack & ew::core::CommandStack::operator=(CommandStack &&)=delete
Not movable.
void ew::core::CommandStack::push(std::unique_ptr< Command > command)
Applies command and records it as the newest undoable step. Null commands are ignored. Discards any redoable commands. While a group is open (see beginGroup) the command is applied immediately but collected into the group instead of the history.
void ew::core::CommandStack::beginGroup(QString description)
Opens a group: every push() until endGroup() applies immediately (so each step's effect is visible as it happens) but the whole run becomes ONE undoable entry described by description. Backs the AI assistant's act mode – one user request that writes = one Ctrl+Z (docs/AI_FOLDER_CONVERSION.md §4b). Nested begin/end pairs fold into the outer group (depth-counted, so an inner endGroup never truncates it). Undo/redo are unavailable while a group is open.
void ew::core::CommandStack::endGroup()
Closes the open group and records it as one undoable entry (nothing is recorded for an empty group). A no-op when no group is open.
bool ew::core::CommandStack::isGrouping() const
True while a group is collecting (between beginGroup and endGroup).
void ew::core::CommandStack::undo()
Undoes the most recent applied command; a no-op if canUndo() is false.
void ew::core::CommandStack::redo()
Re-applies the most recently undone command; a no-op if canRedo() is false.
bool ew::core::CommandStack::canUndo() const
Returns true if there is a command available to undo.
bool ew::core::CommandStack::canRedo() const
Returns true if there is a command available to redo.
int ew::core::CommandStack::undoCount() const
Returns the number of commands that can currently be undone.
void ew::core::CommandStack::setClean()
Marks the current position as the saved (clean) state – call after a successful save. isModified() then reports changes relative to this point.
void ew::core::CommandStack::markModified()
Marks the history as modified without pushing a command – for an edit made outside the command stack (e.g. prose typed straight into the text editor), so isModified() and the unsaved-changes prompt account for it. Cleared by setClean().
void ew::core::CommandStack::reset()
Discards all undo/redo history and returns to a clean (unmodified) state. Used when the project is reloaded from disk out from under the stack (e.g. the MCP server adopting a change the desktop app wrote): commands recorded against the now-replaced graph must never apply again, so the history is dropped rather than kept. Any open group is abandoned.
bool ew::core::CommandStack::isModified() const
Returns true if the current position differs from the last setClean() point (i.e. there are unsaved changes).