[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.2' - sfx2/source

Muhammet Kara (via logerrit) logerrit at kemper.freedesktop.org
Tue Jun 18 20:20:50 UTC 2019


 sfx2/source/doc/autoredactdialog.cxx |   73 ++++++++++++++++++++++++++++++++---
 1 file changed, 67 insertions(+), 6 deletions(-)

New commits:
commit 9c2043f649078c3b316415f174e6ec2840908d7e
Author:     Muhammet Kara <muhammet.kara at collabora.com>
AuthorDate: Mon Jun 17 15:33:37 2019 +0300
Commit:     Muhammet Kara <muhammet.kara at collabora.com>
CommitDate: Tue Jun 18 22:19:56 2019 +0200

    Let autoredact dialog remember last state
    
    * By storing the JSON string as SvtViewOptions
    
    Change-Id: I08e323005612cb0181d2176af659eb54267fbb3f
    Reviewed-on: https://gerrit.libreoffice.org/74169
    Tested-by: Jenkins
    Reviewed-by: Muhammet Kara <muhammet.kara at collabora.com>
    Reviewed-on: https://gerrit.libreoffice.org/74305
    Tested-by: Muhammet Kara <muhammet.kara at collabora.com>

diff --git a/sfx2/source/doc/autoredactdialog.cxx b/sfx2/source/doc/autoredactdialog.cxx
index 798ab965d831..c7248446f9f3 100644
--- a/sfx2/source/doc/autoredactdialog.cxx
+++ b/sfx2/source/doc/autoredactdialog.cxx
@@ -557,6 +557,7 @@ SfxAutoRedactDialog::SfxAutoRedactDialog(weld::Window* pParent)
     OUString sExtraData;
     SvtViewOptions aDlgOpt(EViewType::Dialog,
                            OStringToOUString(m_xDialog->get_help_id(), RTL_TEXTENCODING_UTF8));
+
     if (aDlgOpt.Exists())
     {
         css::uno::Any aUserItem = aDlgOpt.GetUserItem("UserItem");
@@ -564,12 +565,34 @@ SfxAutoRedactDialog::SfxAutoRedactDialog(weld::Window* pParent)
     }
 
     // update the targets configuration if necessary
+    if (!sExtraData.isEmpty())
     {
         weld::WaitObject aWaitCursor(m_xDialog.get());
-        //m_aTargets.Update();
-    }
 
-    // TODO: fill the targets box
+        try
+        {
+            // Create path string, and read JSON from file
+            boost::property_tree::ptree aTargetsJSON;
+            std::stringstream aStream(std::string(sExtraData.toUtf8().getStr()));
+
+            boost::property_tree::read_json(aStream, aTargetsJSON);
+
+            // Recreate & add the targets to the dialog
+            for (const boost::property_tree::ptree::value_type& rValue :
+                 aTargetsJSON.get_child("RedactionTargets"))
+            {
+                RedactionTarget* pTarget = JSONtoRedactionTarget(rValue);
+                addTarget(pTarget);
+            }
+        }
+        catch (css::uno::Exception& e)
+        {
+            SAL_WARN("sfx.doc",
+                     "Exception caught while trying to load the last dialog state: " << e.Message);
+            return;
+            //TODO: Warn the user with a message box
+        }
+    }
 
     // Handler connections
     m_xLoadBtn->connect_clicked(LINK(this, SfxAutoRedactDialog, Load));
@@ -581,9 +604,47 @@ SfxAutoRedactDialog::SfxAutoRedactDialog(weld::Window* pParent)
 
 SfxAutoRedactDialog::~SfxAutoRedactDialog()
 {
-    // Store the view options
-    /*SvtViewOptions aDlgOpt(EViewType::Dialog, OStringToOUString(m_xDialog->get_help_id(), RTL_TEXTENCODING_UTF8));
-    aDlgOpt.SetUserItem("UserItem", css::uno::makeAny(m_xMoreBt->get_expanded() ? OUString("Y") : OUString("N")));*/
+    if (m_aTableTargets.empty())
+    {
+        // Clear the dialog data
+        SvtViewOptions aDlgOpt(EViewType::Dialog,
+                               OStringToOUString(m_xDialog->get_help_id(), RTL_TEXTENCODING_UTF8));
+        aDlgOpt.Delete();
+        return;
+    }
+
+    try
+    {
+        // Put the targets into a JSON array
+        boost::property_tree::ptree aTargetsArray;
+        for (const auto& targetPair : m_aTableTargets)
+        {
+            aTargetsArray.push_back(std::make_pair("", redactionTargetToJSON(targetPair.first)));
+        }
+
+        // Build the JSON tree
+        boost::property_tree::ptree aTargetsTree;
+        aTargetsTree.add_child("RedactionTargets", aTargetsArray);
+        std::stringstream aStream;
+
+        boost::property_tree::write_json(aStream, aTargetsTree, false);
+
+        OUString sUserDataStr(OUString::fromUtf8(aStream.str().c_str()));
+
+        // Store the dialog data
+        SvtViewOptions aDlgOpt(EViewType::Dialog,
+                               OStringToOUString(m_xDialog->get_help_id(), RTL_TEXTENCODING_UTF8));
+        aDlgOpt.SetUserItem("UserItem", css::uno::makeAny(sUserDataStr));
+
+        clearTargets();
+    }
+    catch (css::uno::Exception& e)
+    {
+        SAL_WARN("sfx.doc",
+                 "Exception caught while trying to store the dialog state: " << e.Message);
+        return;
+        //TODO: Warn the user with a message box
+    }
 }
 
 bool SfxAutoRedactDialog::hasTargets() const


More information about the Libreoffice-commits mailing list