diff options
author | Muhammet Kara <muhammet.kara@collabora.com> | 2019-06-17 15:33:37 +0300 |
---|---|---|
committer | Muhammet Kara <muhammet.kara@collabora.com> | 2019-06-18 20:20:08 +0200 |
commit | 3cc152695af2117fecc0006ac2d34d43a9df0d86 (patch) | |
tree | e42dec98bc86e34e23855c39031f12ef560b1fdf /sfx2 | |
parent | 288e729ecfdb7dbb9a4ca00cbc03bcdfe9442a0d (diff) |
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@collabora.com>
Diffstat (limited to 'sfx2')
-rw-r--r-- | sfx2/source/doc/autoredactdialog.cxx | 73 |
1 files changed, 67 insertions, 6 deletions
diff --git a/sfx2/source/doc/autoredactdialog.cxx b/sfx2/source/doc/autoredactdialog.cxx index cc0aa1456db8..950684ac4d1c 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())); + + 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 |