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

New commits:
commit 6cdc42eeb3c031ae082df088a0a7e5db66694341
Author:     Attila Szűcs <attila.sz...@collabora.com>
AuthorDate: Wed Nov 13 05:39:27 2024 +0100
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Wed Nov 13 12:08:38 2024 +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/+/176515
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>

diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 27fccf945914..7ba3ebf9e977 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -6624,6 +6624,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)
 {
@@ -6738,6 +6766,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