desktop/source/lib/init.cxx |   36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

New commits:
commit a02cbda34e8ea3d0e3d29e6e5dcafe0ec0c982d9
Author:     Attila Szűcs <attila.sz...@collabora.com>
AuthorDate: Wed Nov 13 05:39:27 2024 +0100
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Wed Jan 22 10:48:16 2025 +0100

    LOK: added .uno:UndoCount and .uno:RedoCount
    
    Added new commands for doc_getCommandValues
    to get actual undo and redo count.
    
    They get undo/redo count directly from SfxUndoManager.
    
    Change-Id: I2f7b7fc487eada7c5b1b161dfd4086c54094d747
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/180553
    Tested-by: Jenkins
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 26ce314ca98a..7bc0c16e5c53 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -6655,6 +6655,34 @@ static char* getUndoOrRedo(LibreOfficeKitDocument* 
pThis, UndoOrRedo eCommand)
     return pJson;
 }
 
+/// Returns only the number of the undo or redo elements
+static char* getUndoOrRedoCount(LibreOfficeKitDocument* pThis, UndoOrRedo 
eCommand)
+{
+    LibLODocument_Impl* pDocument = static_cast<LibLODocument_Impl*>(pThis);
+
+    auto pBaseModel = 
dynamic_cast<SfxBaseModel*>(pDocument->mxComponent.get());
+    if (!pBaseModel)
+        return nullptr;
+
+    SfxObjectShell* pObjectShell = pBaseModel->GetObjectShell();
+    if (!pObjectShell)
+        return nullptr;
+
+    SfxUndoManager* pUndoManager = pObjectShell->GetUndoManager();
+    if (!pUndoManager)
+        return nullptr;
+
+    size_t nCount;
+    if (eCommand == UndoOrRedo::UNDO)
+        nCount = pUndoManager->GetUndoActionCount();
+    else
+        nCount = pUndoManager->GetRedoActionCount();
+
+    OUString aString = OUString::number(nCount);
+    char* pCountStr = convertOUString(aString);
+    return pCountStr;
+}
+
 /// Returns the JSON representation of the redline stack.
 static char* getTrackedChanges(LibreOfficeKitDocument* pThis)
 {
@@ -6769,6 +6797,14 @@ static char* 
doc_getCommandValues(LibreOfficeKitDocument* pThis, const char* pCo
     {
         return getUndoOrRedo(pThis, UndoOrRedo::REDO);
     }
+    else if (aCommand == ".uno:UndoCount")
+    {
+        return getUndoOrRedoCount(pThis, UndoOrRedo::UNDO);
+    }
+    else if (aCommand == ".uno:RedoCount")
+    {
+        return getUndoOrRedoCount(pThis, UndoOrRedo::REDO);
+    }
     else if (aCommand == ".uno:AcceptTrackedChanges")
     {
         return getTrackedChanges(pThis);

Reply via email to