mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:47:34 +00:00
LibGUI: Add fallible try_push() variant to UndoStack
This commit is contained in:
parent
ae333fad98
commit
510551bb4f
2 changed files with 11 additions and 3 deletions
|
@ -46,7 +46,7 @@ void UndoStack::redo()
|
||||||
on_state_change();
|
on_state_change();
|
||||||
}
|
}
|
||||||
|
|
||||||
void UndoStack::push(NonnullOwnPtr<Command> command)
|
ErrorOr<void> UndoStack::try_push(NonnullOwnPtr<Command> command)
|
||||||
{
|
{
|
||||||
// If the stack cursor is behind the top of the stack, nuke everything from here to the top.
|
// If the stack cursor is behind the top of the stack, nuke everything from here to the top.
|
||||||
while (m_stack.size() != m_stack_index)
|
while (m_stack.size() != m_stack_index)
|
||||||
|
@ -57,14 +57,21 @@ void UndoStack::push(NonnullOwnPtr<Command> command)
|
||||||
|
|
||||||
if (!m_stack.is_empty() && is_current_modified()) {
|
if (!m_stack.is_empty() && is_current_modified()) {
|
||||||
if (m_stack.last().merge_with(*command))
|
if (m_stack.last().merge_with(*command))
|
||||||
return;
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
m_stack.append(move(command));
|
TRY(m_stack.try_append(move(command)));
|
||||||
m_stack_index = m_stack.size();
|
m_stack_index = m_stack.size();
|
||||||
|
|
||||||
if (on_state_change)
|
if (on_state_change)
|
||||||
on_state_change();
|
on_state_change();
|
||||||
|
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
void UndoStack::push(NonnullOwnPtr<Command> command)
|
||||||
|
{
|
||||||
|
MUST(try_push(move(command)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void UndoStack::set_current_unmodified()
|
void UndoStack::set_current_unmodified()
|
||||||
|
|
|
@ -20,6 +20,7 @@ public:
|
||||||
~UndoStack() = default;
|
~UndoStack() = default;
|
||||||
|
|
||||||
void push(NonnullOwnPtr<Command>);
|
void push(NonnullOwnPtr<Command>);
|
||||||
|
ErrorOr<void> try_push(NonnullOwnPtr<Command>);
|
||||||
|
|
||||||
bool can_undo() const;
|
bool can_undo() const;
|
||||||
bool can_redo() const;
|
bool can_redo() const;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue