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

LibGUI: Add UndoStack::{undo,redo}_action_text()

These return the action_text() for the current undo and redo commands,
if available.
Andreas Kling преди 4 години
родител
ревизия
c670d8c56d
променени са 2 файла, в които са добавени 17 реда и са изтрити 0 реда
  1. 14 0
      Userland/Libraries/LibGUI/UndoStack.cpp
  2. 3 0
      Userland/Libraries/LibGUI/UndoStack.h

+ 14 - 0
Userland/Libraries/LibGUI/UndoStack.cpp

@@ -109,4 +109,18 @@ void UndoStack::clear()
         on_state_change();
 }
 
+Optional<String> UndoStack::undo_action_text() const
+{
+    if (!can_undo())
+        return {};
+    return m_stack[m_stack_index - 1].action_text();
+}
+
+Optional<String> UndoStack::redo_action_text() const
+{
+    if (!can_redo())
+        return {};
+    return m_stack[m_stack_index].action_text();
+}
+
 }

+ 3 - 0
Userland/Libraries/LibGUI/UndoStack.h

@@ -30,6 +30,9 @@ public:
 
     void clear();
 
+    Optional<String> undo_action_text() const;
+    Optional<String> redo_action_text() const;
+
     Function<void()> on_state_change;
 
 private: