mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 10:28:10 +00:00
LibGUI: Add GUndoStack and GCommand classes
This patch converts the undo stack from GTextDocument into GUndoStack, and GTextDocumentUndoCommand now inherits from GCommand. Let's turn this into a generic mechanism that can be used to implement undo/redo in any application. :^)
This commit is contained in:
parent
f8703d44cc
commit
f430da1d45
7 changed files with 156 additions and 73 deletions
31
Libraries/LibGUI/GUndoStack.h
Normal file
31
Libraries/LibGUI/GUndoStack.h
Normal file
|
@ -0,0 +1,31 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/NonnullOwnPtrVector.h>
|
||||
#include <LibGUI/GCommand.h>
|
||||
|
||||
class GCommand;
|
||||
|
||||
class GUndoStack {
|
||||
public:
|
||||
GUndoStack();
|
||||
~GUndoStack();
|
||||
|
||||
void push(NonnullOwnPtr<GCommand>&&);
|
||||
|
||||
bool can_undo() const { return m_stack_index < m_stack.size() && !m_stack.is_empty(); }
|
||||
bool can_redo() const { return m_stack_index > 0 && m_stack[m_stack_index - 1].m_undo_vector.size() > 0 && !m_stack.is_empty(); }
|
||||
|
||||
void undo();
|
||||
void redo();
|
||||
|
||||
void finalize_current_combo();
|
||||
|
||||
private:
|
||||
struct UndoCommandsContainer {
|
||||
NonnullOwnPtrVector<GCommand> m_undo_vector;
|
||||
};
|
||||
|
||||
NonnullOwnPtrVector<UndoCommandsContainer> m_stack;
|
||||
int m_stack_index { 0 };
|
||||
int m_last_updated_undo_vector_size { 0 };
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue