diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2016-08-05 13:53:57 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2016-08-05 13:25:34 +0000 |
commit | 9dd8a0dcfdff21269f6423224d39d168519fb67e (patch) | |
tree | 50f908927005fcf5e7534b09fb38838ed50da212 /desktop/source | |
parent | tdf#88205 Adapt uses of css::uno::Sequence to use initializer_list ctor (diff) | |
download | core-9dd8a0dcfdff21269f6423224d39d168519fb67e.tar.gz core-9dd8a0dcfdff21269f6423224d39d168519fb67e.zip |
desktop: add undo/redo support to lok::Document::getCommandValues()
Expose the undo/redo stack and the metadata of each item.
Change-Id: I66b81e855a945c97be3d491ed709959f310d4b73
Reviewed-on: https://gerrit.libreoffice.org/27905
Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Tested-by: Jenkins <ci@libreoffice.org>
Diffstat (limited to 'desktop/source')
-rw-r--r-- | desktop/source/lib/init.cxx | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index 5972424ee4ba..0d4fb4f42f4a 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -78,6 +78,8 @@ #include <unotools/mediadescriptor.hxx> #include <osl/module.hxx> #include <comphelper/sequence.hxx> +#include <sfx2/sfxbasemodel.hxx> +#include <svl/undo.hxx> #include <app.hxx> @@ -85,7 +87,7 @@ // We also need to hackily be able to start the main libreoffice thread: #include "../app/sofficemain.h" #include "../app/officeipcthread.hxx" -#include "../../inc/lib/init.hxx" +#include <lib/init.hxx> #include "lokinteractionhandler.hxx" #include <lokclipboard.hxx> @@ -1776,6 +1778,38 @@ static char* getStyles(LibreOfficeKitDocument* pThis, const char* pCommand) return pJson; } +enum class UndoOrRedo +{ + UNDO, + REDO +}; + +/// Returns the JSON representation of either an undo or a redo stack. +static char* getUndoOrRedo(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; + + svl::IUndoManager* pUndoManager = pObjectShell->GetUndoManager(); + if (!pUndoManager) + return nullptr; + + OUString aString; + if (eCommand == UndoOrRedo::UNDO) + aString = pUndoManager->GetUndoActionsInfo(); + else + aString = pUndoManager->GetRedoActionsInfo(); + char* pJson = strdup(aString.toUtf8().getStr()); + return pJson; +} + static char* doc_getCommandValues(LibreOfficeKitDocument* pThis, const char* pCommand) { OString aCommand(pCommand); @@ -1790,6 +1824,14 @@ static char* doc_getCommandValues(LibreOfficeKitDocument* pThis, const char* pCo { return getStyles(pThis, pCommand); } + else if (aCommand == ".uno:Undo") + { + return getUndoOrRedo(pThis, UndoOrRedo::UNDO); + } + else if (aCommand == ".uno:Redo") + { + return getUndoOrRedo(pThis, UndoOrRedo::REDO); + } else if (aCommand.startsWith(aViewRowColumnHeaders)) { ITiledRenderable* pDoc = getTiledRenderable(pThis); |