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 /svl | |
parent | e50a95b829b327b07ba35e831ae10fb8c40a71ee (diff) |
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 'svl')
-rw-r--r-- | svl/source/undo/undo.cxx | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/svl/source/undo/undo.cxx b/svl/source/undo/undo.cxx index 7ccafe3638ae..3c6d6515a93c 100644 --- a/svl/source/undo/undo.cxx +++ b/svl/source/undo/undo.cxx @@ -26,6 +26,7 @@ #include <comphelper/flagguard.hxx> #include <tools/diagnose_ex.h> #include <libxml/xmlwriter.h> +#include <boost/property_tree/json_parser.hpp> #include <unotools/datetime.hxx> #include <vector> @@ -1300,6 +1301,51 @@ void SfxUndoManager::dumpAsXml(xmlTextWriterPtr pWriter) const } } +/// Returns a JSON representation of pAction. +boost::property_tree::ptree lcl_ActionToJson(size_t nIndex, SfxUndoAction* pAction) +{ + boost::property_tree::ptree aRet; + aRet.put("index", nIndex); + aRet.put("comment", pAction->GetComment().toUtf8().getStr()); + aRet.put("viewId", pAction->GetViewShellId()); + aRet.put("dateTime", utl::toISO8601(pAction->GetDateTime().GetUNODateTime()).toUtf8().getStr()); + return aRet; +} + +OUString SfxUndoManager::GetUndoActionsInfo() const +{ + boost::property_tree::ptree aActions; + const SfxUndoArray* pUndoArray = m_xData->pActUndoArray; + for (size_t i = 0; i < GetUndoActionCount(); ++i) + { + boost::property_tree::ptree aAction = lcl_ActionToJson(i, pUndoArray->aUndoActions[pUndoArray->nCurUndoAction - 1 - i].pAction); + aActions.push_back(std::make_pair("", aAction)); + } + + boost::property_tree::ptree aTree; + aTree.add_child("actions", aActions); + std::stringstream aStream; + boost::property_tree::write_json(aStream, aTree); + return OUString::fromUtf8(aStream.str().c_str()); +} + +OUString SfxUndoManager::GetRedoActionsInfo() const +{ + boost::property_tree::ptree aActions; + const SfxUndoArray* pUndoArray = m_xData->pActUndoArray; + for (size_t i = 0; i < GetRedoActionCount(); ++i) + { + boost::property_tree::ptree aAction = lcl_ActionToJson(i, pUndoArray->aUndoActions[pUndoArray->nCurUndoAction + i].pAction); + aActions.push_back(std::make_pair("", aAction)); + } + + boost::property_tree::ptree aTree; + aTree.add_child("actions", aActions); + std::stringstream aStream; + boost::property_tree::write_json(aStream, aTree); + return OUString::fromUtf8(aStream.str().c_str()); +} + struct SfxListUndoAction::Impl { sal_uInt16 mnId; |