mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 10:58:12 +00:00
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:
parent
b25eba10d2
commit
295cc123c7
2 changed files with 14 additions and 15 deletions
|
@ -27,10 +27,10 @@ void UndoStack::undo()
|
||||||
if (m_stack_index >= m_stack.size())
|
if (m_stack_index >= m_stack.size())
|
||||||
break;
|
break;
|
||||||
|
|
||||||
auto& container = m_stack[m_stack_index++];
|
auto& combo = m_stack[m_stack_index++];
|
||||||
if (container.m_undo_vector.size() == 0)
|
if (combo.commands.size() == 0)
|
||||||
continue;
|
continue;
|
||||||
for (auto& command : container.m_undo_vector)
|
for (auto& command : combo.commands)
|
||||||
command.undo();
|
command.undo();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -48,9 +48,9 @@ void UndoStack::redo()
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_stack_index -= 1;
|
m_stack_index -= 1;
|
||||||
auto& vector = m_stack[m_stack_index].m_undo_vector;
|
auto& commands = m_stack[m_stack_index].commands;
|
||||||
for (int i = vector.size() - 1; i >= 0; i--)
|
for (int i = commands.size() - 1; i >= 0; i--)
|
||||||
vector[i].redo();
|
commands[i].redo();
|
||||||
}
|
}
|
||||||
|
|
||||||
void UndoStack::push(NonnullOwnPtr<Command>&& command)
|
void UndoStack::push(NonnullOwnPtr<Command>&& command)
|
||||||
|
@ -73,18 +73,17 @@ void UndoStack::push(NonnullOwnPtr<Command>&& command)
|
||||||
finalize_current_combo();
|
finalize_current_combo();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto& current_vector = m_stack.first().m_undo_vector;
|
m_stack.first().commands.prepend(move(command));
|
||||||
current_vector.prepend(move(command));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void UndoStack::finalize_current_combo()
|
void UndoStack::finalize_current_combo()
|
||||||
{
|
{
|
||||||
if (m_stack_index > 0)
|
if (m_stack_index > 0)
|
||||||
return;
|
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;
|
return;
|
||||||
|
|
||||||
auto undo_commands_container = make<UndoCommandsContainer>();
|
auto undo_commands_container = make<Combo>();
|
||||||
m_stack.prepend(move(undo_commands_container));
|
m_stack.prepend(move(undo_commands_container));
|
||||||
|
|
||||||
if (m_clean_index.has_value())
|
if (m_clean_index.has_value())
|
||||||
|
@ -94,7 +93,7 @@ void UndoStack::finalize_current_combo()
|
||||||
void UndoStack::set_current_unmodified()
|
void UndoStack::set_current_unmodified()
|
||||||
{
|
{
|
||||||
// Skip empty container
|
// 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;
|
m_clean_index = m_stack_index + 1;
|
||||||
else
|
else
|
||||||
m_clean_index = m_stack_index;
|
m_clean_index = m_stack_index;
|
||||||
|
|
|
@ -19,7 +19,7 @@ public:
|
||||||
void push(NonnullOwnPtr<Command>&&);
|
void push(NonnullOwnPtr<Command>&&);
|
||||||
|
|
||||||
bool can_undo() const { return m_stack_index < m_stack.size() && !m_stack.is_empty(); }
|
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 undo();
|
||||||
void redo();
|
void redo();
|
||||||
|
@ -32,11 +32,11 @@ public:
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct UndoCommandsContainer {
|
struct Combo {
|
||||||
NonnullOwnPtrVector<Command> m_undo_vector;
|
NonnullOwnPtrVector<Command> commands;
|
||||||
};
|
};
|
||||||
|
|
||||||
NonnullOwnPtrVector<UndoCommandsContainer> m_stack;
|
NonnullOwnPtrVector<Combo> m_stack;
|
||||||
size_t m_stack_index { 0 };
|
size_t m_stack_index { 0 };
|
||||||
Optional<size_t> m_clean_index;
|
Optional<size_t> m_clean_index;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue