Преглед на файлове

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".
Andreas Kling преди 4 години
родител
ревизия
295cc123c7
променени са 2 файла, в които са добавени 14 реда и са изтрити 15 реда
  1. 10 11
      Userland/Libraries/LibGUI/UndoStack.cpp
  2. 4 4
      Userland/Libraries/LibGUI/UndoStack.h

+ 10 - 11
Userland/Libraries/LibGUI/UndoStack.cpp

@@ -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++];
-            if (container.m_undo_vector.size() == 0)
+            auto& combo = m_stack[m_stack_index++];
+            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;
-    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)
 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;
-    current_vector.prepend(move(command));
+    m_stack.first().commands.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;

+ 4 - 4
Userland/Libraries/LibGUI/UndoStack.h

@@ -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 {
-        NonnullOwnPtrVector<Command> m_undo_vector;
+    struct Combo {
+        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;
 };
 };