From c670d8c56d14c48e5641819458695c607531501c Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 8 May 2021 21:18:51 +0200 Subject: [PATCH] LibGUI: Add UndoStack::{undo,redo}_action_text() These return the action_text() for the current undo and redo commands, if available. --- Userland/Libraries/LibGUI/UndoStack.cpp | 14 ++++++++++++++ Userland/Libraries/LibGUI/UndoStack.h | 3 +++ 2 files changed, 17 insertions(+) diff --git a/Userland/Libraries/LibGUI/UndoStack.cpp b/Userland/Libraries/LibGUI/UndoStack.cpp index 759b97b5f4..ea7aa2a125 100644 --- a/Userland/Libraries/LibGUI/UndoStack.cpp +++ b/Userland/Libraries/LibGUI/UndoStack.cpp @@ -109,4 +109,18 @@ void UndoStack::clear() on_state_change(); } +Optional UndoStack::undo_action_text() const +{ + if (!can_undo()) + return {}; + return m_stack[m_stack_index - 1].action_text(); +} + +Optional UndoStack::redo_action_text() const +{ + if (!can_redo()) + return {}; + return m_stack[m_stack_index].action_text(); +} + } diff --git a/Userland/Libraries/LibGUI/UndoStack.h b/Userland/Libraries/LibGUI/UndoStack.h index 2957ca0b97..44dd9ca0bf 100644 --- a/Userland/Libraries/LibGUI/UndoStack.h +++ b/Userland/Libraries/LibGUI/UndoStack.h @@ -30,6 +30,9 @@ public: void clear(); + Optional undo_action_text() const; + Optional redo_action_text() const; + Function on_state_change; private: