From 295cc123c75def90e2ae2e8989d05082eb0e432c Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 7 May 2021 23:33:31 +0200 Subject: [PATCH] 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". --- Userland/Libraries/LibGUI/UndoStack.cpp | 21 ++++++++++----------- Userland/Libraries/LibGUI/UndoStack.h | 8 ++++---- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/Userland/Libraries/LibGUI/UndoStack.cpp b/Userland/Libraries/LibGUI/UndoStack.cpp index 90f0ae781e3..47e584bbb51 100644 --- a/Userland/Libraries/LibGUI/UndoStack.cpp +++ b/Userland/Libraries/LibGUI/UndoStack.cpp @@ -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) @@ -73,18 +73,17 @@ void UndoStack::push(NonnullOwnPtr&& 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(); + auto undo_commands_container = make(); 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; diff --git a/Userland/Libraries/LibGUI/UndoStack.h b/Userland/Libraries/LibGUI/UndoStack.h index faf4a9a45e8..51b5e004361 100644 --- a/Userland/Libraries/LibGUI/UndoStack.h +++ b/Userland/Libraries/LibGUI/UndoStack.h @@ -19,7 +19,7 @@ public: void push(NonnullOwnPtr&&); 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 m_undo_vector; + struct Combo { + NonnullOwnPtrVector commands; }; - NonnullOwnPtrVector m_stack; + NonnullOwnPtrVector m_stack; size_t m_stack_index { 0 }; Optional m_clean_index; };