LibGUI: Rename UndoStack internals

Since we keep a stack of command combos, let's call entries on the
stack "Combo" instead of "UndoCommandsContainer".

And since it has a vector of commands, let's call it "commands"
instead of "m_undo_vector".
This commit is contained in:
Andreas Kling 2021-05-07 23:33:31 +02:00
parent b25eba10d2
commit 295cc123c7
2 changed files with 14 additions and 15 deletions

View file

@ -27,10 +27,10 @@ void UndoStack::undo()
if (m_stack_index >= m_stack.size())
break;
auto& container = m_stack[m_stack_index++];
if (container.m_undo_vector.size() == 0)
auto& combo = m_stack[m_stack_index++];
if (combo.commands.size() == 0)
continue;
for (auto& command : container.m_undo_vector)
for (auto& command : combo.commands)
command.undo();
break;
}
@ -48,9 +48,9 @@ void UndoStack::redo()
return;
m_stack_index -= 1;
auto& vector = m_stack[m_stack_index].m_undo_vector;
for (int i = vector.size() - 1; i >= 0; i--)
vector[i].redo();
auto& commands = m_stack[m_stack_index].commands;
for (int i = commands.size() - 1; i >= 0; i--)
commands[i].redo();
}
void UndoStack::push(NonnullOwnPtr<Command>&& command)
@ -73,18 +73,17 @@ void UndoStack::push(NonnullOwnPtr<Command>&& command)
finalize_current_combo();
}
auto& current_vector = m_stack.first().m_undo_vector;
current_vector.prepend(move(command));
m_stack.first().commands.prepend(move(command));
}
void UndoStack::finalize_current_combo()
{
if (m_stack_index > 0)
return;
if (m_stack.size() != 0 && m_stack.first().m_undo_vector.size() == 0)
if (m_stack.size() != 0 && m_stack.first().commands.size() == 0)
return;
auto undo_commands_container = make<UndoCommandsContainer>();
auto undo_commands_container = make<Combo>();
m_stack.prepend(move(undo_commands_container));
if (m_clean_index.has_value())
@ -94,7 +93,7 @@ void UndoStack::finalize_current_combo()
void UndoStack::set_current_unmodified()
{
// Skip empty container
if (can_undo() && m_stack[m_stack_index].m_undo_vector.is_empty())
if (can_undo() && m_stack[m_stack_index].commands.is_empty())
m_clean_index = m_stack_index + 1;
else
m_clean_index = m_stack_index;

View file

@ -19,7 +19,7 @@ public:
void push(NonnullOwnPtr<Command>&&);
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.is_empty() && m_stack[m_stack_index - 1].m_undo_vector.size() > 0; }
bool can_redo() const { return m_stack_index > 0 && !m_stack.is_empty() && m_stack[m_stack_index - 1].commands.size() > 0; }
void undo();
void redo();
@ -32,11 +32,11 @@ public:
void clear();
private:
struct UndoCommandsContainer {
NonnullOwnPtrVector<Command> m_undo_vector;
struct Combo {
NonnullOwnPtrVector<Command> commands;
};
NonnullOwnPtrVector<UndoCommandsContainer> m_stack;
NonnullOwnPtrVector<Combo> m_stack;
size_t m_stack_index { 0 };
Optional<size_t> m_clean_index;
};