From 82bba7e4c044e54fc678ab108c662473d3a471a8 Mon Sep 17 00:00:00 2001 From: Muhammet Kara Date: Mon, 27 May 2019 17:44:10 +0300 Subject: Auto redaction dialog first iteration * Add the uno command .uno:AutoRedact with the name 'Auto-Redact' * Add the dialog SfxAutoRedactDialog * Implement the basic functionality to show up when clicked on the menu/toolbar item. * Add the class TargetsTable to control the weld::TreeView which is used to list the targets * Add the struct RedactionTarget to keep info for individual targets Change-Id: Ic02dfb009590c0928a2ea7b0f8b19b4febca221a Reviewed-on: https://gerrit.libreoffice.org/72254 Tested-by: Jenkins Reviewed-by: Muhammet Kara --- sfx2/Library_sfx.mk | 1 + sfx2/UIConfig_sfx.mk | 1 + sfx2/sdi/docslots.sdi | 5 + sfx2/sdi/sfx.sdi | 17 ++ sfx2/source/appl/appuno.cxx | 5 +- sfx2/source/doc/autoredactdialog.cxx | 181 +++++++++++++++++++ sfx2/source/doc/objserv.cxx | 19 ++ sfx2/uiconfig/ui/autoredactdialog.ui | 339 +++++++++++++++++++++++++++++++++++ 8 files changed, 566 insertions(+), 2 deletions(-) create mode 100644 sfx2/source/doc/autoredactdialog.cxx create mode 100644 sfx2/uiconfig/ui/autoredactdialog.ui (limited to 'sfx2') diff --git a/sfx2/Library_sfx.mk b/sfx2/Library_sfx.mk index 3f911e6b088d..6abba0617c7f 100644 --- a/sfx2/Library_sfx.mk +++ b/sfx2/Library_sfx.mk @@ -198,6 +198,7 @@ $(eval $(call gb_Library_add_exception_objects,sfx,\ sfx2/source/doc/Metadatable \ sfx2/source/doc/QuerySaveDocument \ sfx2/source/doc/SfxDocumentMetaData \ + sfx2/source/doc/autoredactdialog \ sfx2/source/doc/docfac \ sfx2/source/doc/docfile \ sfx2/source/doc/docfilt \ diff --git a/sfx2/UIConfig_sfx.mk b/sfx2/UIConfig_sfx.mk index f476c66ebe03..a7154213d128 100644 --- a/sfx2/UIConfig_sfx.mk +++ b/sfx2/UIConfig_sfx.mk @@ -11,6 +11,7 @@ $(eval $(call gb_UIConfig_UIConfig,sfx)) $(eval $(call gb_UIConfig_add_uifiles,sfx,\ sfx2/uiconfig/ui/alienwarndialog \ + sfx2/uiconfig/ui/autoredactdialog \ sfx2/uiconfig/ui/bookmarkdialog \ sfx2/uiconfig/ui/bookmarkmenu \ sfx2/uiconfig/ui/charmapcontrol \ diff --git a/sfx2/sdi/docslots.sdi b/sfx2/sdi/docslots.sdi index 5b878b8ff051..082baef0f5d5 100644 --- a/sfx2/sdi/docslots.sdi +++ b/sfx2/sdi/docslots.sdi @@ -253,6 +253,11 @@ shell SfxObjectShell ExecMethod = ExecFile_Impl ; StateMethod = GetState_Impl ; ] + SID_AUTOREDACTDOC + [ + ExecMethod = ExecFile_Impl ; + StateMethod = GetState_Impl ; + ] SID_SIGNATURE [ ExecMethod = ExecFile_Impl; diff --git a/sfx2/sdi/sfx.sdi b/sfx2/sdi/sfx.sdi index 3d8cade70309..29bef29d5f74 100644 --- a/sfx2/sdi/sfx.sdi +++ b/sfx2/sdi/sfx.sdi @@ -4832,6 +4832,23 @@ SfxVoidItem RedactDoc SID_REDACTDOC GroupId = SfxGroupId::Document; ] +SfxVoidItem AutoRedactDoc SID_AUTOREDACTDOC +(SfxStringItem URL SID_FILE_NAME, SfxStringItem FilterName SID_FILTER_NAME) +[ + AutoUpdate = FALSE, + FastCall = FALSE, + ReadOnlyDoc = TRUE, + Toggle = FALSE, + Container = TRUE, + RecordAbsolute = FALSE, + RecordPerSet; + + AccelConfig = TRUE, + MenuConfig = TRUE, + ToolBoxConfig = TRUE, + GroupId = SfxGroupId::Document; +] + SfxImageItem ImageOrientation SID_IMAGE_ORIENTATION [ diff --git a/sfx2/source/appl/appuno.cxx b/sfx2/source/appl/appuno.cxx index f272a938775d..1528f231ca39 100644 --- a/sfx2/source/appl/appuno.cxx +++ b/sfx2/source/appl/appuno.cxx @@ -177,7 +177,8 @@ static bool isMediaDescriptor( sal_uInt16 nSlotId ) nSlotId == SID_SAVETO || nSlotId == SID_SAVEACOPY || nSlotId == SID_EXPORTDOCASPDF || nSlotId == SID_DIRECTEXPORTDOCASPDF || nSlotId == SID_EXPORTDOCASEPUB || nSlotId == SID_DIRECTEXPORTDOCASEPUB || - nSlotId == SID_REDACTDOC || nSlotId == SID_SAVEACOPYITEM); + nSlotId == SID_REDACTDOC || nSlotId == SID_AUTOREDACTDOC || + nSlotId == SID_SAVEACOPYITEM); } void TransformParameters( sal_uInt16 nSlotId, const uno::Sequence& rArgs, SfxAllItemSet& rSet, const SfxSlot* pSlot ) @@ -1340,7 +1341,7 @@ void TransformItems( sal_uInt16 nSlotId, const SfxItemSet& rSet, uno::Sequence +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +int TargetsTable::GetRowByTargetName(const OUString& sName) +{ + for (int i = 0, nCount = m_xControl->n_children(); i < nCount; ++i) + { + RedactionTarget* pTarget + = reinterpret_cast(m_xControl->get_id(i).toInt64()); + if (pTarget->sName == sName) + { + return i; + } + } + return -1; +} + +TargetsTable::TargetsTable(std::unique_ptr xControl) + : m_xControl(std::move(xControl)) +{ + m_xControl->set_size_request(550, 250); + std::vector aWidths; + aWidths.push_back(100); + aWidths.push_back(45); + aWidths.push_back(110); + aWidths.push_back(105); + aWidths.push_back(150); + m_xControl->set_column_fixed_widths(aWidths); + m_xControl->set_selection_mode(SelectionMode::Multiple); +} + +void TargetsTable::InsertTarget(RedactionTarget* pTarget) +{ + if (!pTarget) + { + SAL_WARN("sfx.doc", "pTarget is null in TargetsTable::InsertTarget()"); + return; + } + + // Check if the name is empty or invalid (clashing with another entry's name) + if (pTarget->sName.isEmpty() || GetRowByTargetName(pTarget->sName) != -1) + { + pTarget->sName = GetNameProposal(); + } + + // Add to the end + int nRow = m_xControl->n_children(); + m_xControl->append(OUString::number(reinterpret_cast(pTarget)), pTarget->sName); + m_xControl->set_text(nRow, pTarget->sType, 1); + m_xControl->set_text(nRow, pTarget->bCaseSensitive ? OUString("Yes") : OUString("No"), 2); + m_xControl->set_text(nRow, pTarget->bWholeWords ? OUString("Yes") : OUString("No"), 3); + m_xControl->set_text(nRow, pTarget->sDescription, 4); +} + +void TargetsTable::SelectByName(const OUString& sName) +{ + int nEntry = GetRowByTargetName(sName); + if (nEntry == -1) + return; + select(nEntry); +} + +RedactionTarget* TargetsTable::GetTargetByName(const OUString& sName) +{ + int nEntry = GetRowByTargetName(sName); + if (nEntry == -1) + return nullptr; + + return reinterpret_cast(m_xControl->get_id(nEntry).toInt64()); +} + +OUString TargetsTable::GetNameProposal() +{ + //TODO: Define a translatable string + OUString sDefaultTargetName("Target"); + sal_Int32 nHighestTargetId = 0; + for (int i = 0, nCount = m_xControl->n_children(); i < nCount; ++i) + { + RedactionTarget* pTarget + = reinterpret_cast(m_xControl->get_id(i).toInt64()); + const OUString& sName = pTarget->sName; + sal_Int32 nIndex = 0; + if (sName.getToken(0, ' ', nIndex) == sDefaultTargetName) + { + sal_Int32 nCurrTargetId = sName.getToken(0, ' ', nIndex).toInt32(); + nHighestTargetId = std::max(nHighestTargetId, nCurrTargetId); + } + } + return sDefaultTargetName + " " + OUString::number(nHighestTargetId + 1); +} + +SfxAutoRedactDialog::SfxAutoRedactDialog(weld::Window* pParent) + : SfxDialogController(pParent, "sfx/ui/autoredactdialog.ui", "AutoRedactDialog") + , m_xRedactionTargetsLabel(m_xBuilder->weld_label("labelRedactionTargets")) + , m_xTargetsBox(new TargetsTable(m_xBuilder->weld_tree_view("targets"))) + , m_xLoadBtn(m_xBuilder->weld_button("btnLoadTargets")) + , m_xSaveBtn(m_xBuilder->weld_button("btnSaveTargets")) + , m_xAddBtn(m_xBuilder->weld_button("add")) + , m_xEditBtn(m_xBuilder->weld_button("edit")) + , m_xDeleteBtn(m_xBuilder->weld_button("delete")) +{ + // Can be used to remmeber the last set of redaction targets? + 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"); + aUserItem >>= sExtraData; + } + + // update the targets configuration if necessary + { + weld::WaitObject aWaitCursor(m_xDialog.get()); + //m_aTargets.Update(); + } + + // fill the targets box + /*const sal_uInt16 nCount = m_aTemplates.GetRegionCount(); + if (nCount) + { + for(sal_uInt16 i = 0; i < nCount; ++i) + m_xRegionLb->append_text(m_aTemplates.GetFullRegionName(i)); + m_xRegionLb->connect_changed(LINK(this, SfxNewFileDialog, RegionSelect)); + }*/ + + /*RedactionTarget* redactiontarget + = new RedactionTarget({ 0, "Target 1", "String", true, false, "Some description" }); + + m_xTargetsBox->InsertTarget(redactiontarget);*/ +} + +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")));*/ +} + +bool SfxAutoRedactDialog::hasTargets() const +{ + //TODO: Add also some validity checks? + if (m_aTableTargets.empty()) + return false; + + return true; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sfx2/source/doc/objserv.cxx b/sfx2/source/doc/objserv.cxx index 8df1c3e0fecf..feb8952f4c23 100644 --- a/sfx2/source/doc/objserv.cxx +++ b/sfx2/source/doc/objserv.cxx @@ -125,6 +125,8 @@ #include #include +#include + using namespace ::com::sun::star; using namespace ::com::sun::star::lang; using namespace ::com::sun::star::uno; @@ -542,6 +544,22 @@ void SfxObjectShell::ExecFile_Impl(SfxRequest &rReq) return; } + case SID_AUTOREDACTDOC: + { + //TODO: Implement + SfxAutoRedactDialog aDlg(pDialogParent); + sal_uInt16 nResult = aDlg.run(); + + if (nResult != RET_OK || !aDlg.hasTargets()) + { + //Do nothing + return; + } + + // else continue with normal redaction + [[fallthrough]]; + } + case SID_REDACTDOC: { css::uno::Reference xModel = GetModel(); @@ -1232,6 +1250,7 @@ void SfxObjectShell::GetState_Impl(SfxItemSet &rSet) case SID_EXPORTDOCASEPUB: case SID_DIRECTEXPORTDOCASEPUB: case SID_REDACTDOC: + case SID_AUTOREDACTDOC: { break; } diff --git a/sfx2/uiconfig/ui/autoredactdialog.ui b/sfx2/uiconfig/ui/autoredactdialog.ui new file mode 100644 index 000000000000..01c0dc6e9592 --- /dev/null +++ b/sfx2/uiconfig/ui/autoredactdialog.ui @@ -0,0 +1,339 @@ + + + + + + + + + + + + + + + + + + + + + + False + 6 + Automatic Redaction + True + dialog + + + + + + False + True + True + vertical + 12 + + + False + + + gtk-help + True + True + True + True + + + False + True + 0 + True + + + + + gtk-ok + True + True + True + True + + + False + True + 1 + + + + + gtk-cancel + True + True + True + True + + + False + True + 2 + + + + + False + False + 5 + + + + + True + False + + + True + True + True + True + in + + + True + True + True + 5 + 5 + True + True + liststore1 + 0 + False + + + + + + True + 6 + Target Name + + + + 0 + + + + + + + True + 6 + Type + + + + 1 + + + + + + + True + 6 + Case Sensitive + + + + 2 + + + + + + + True + 6 + Whole Words + + + + 3 + + + + + + + True + 6 + Description + + + + 4 + + + + + + + + + + + + 0 + 1 + + + + + True + False + start + center + 1 + 1 + _Redaction Targets + True + + + + + + 0 + 0 + + + + + True + False + vertical + start + + + Load Targets + True + True + True + 3 + + + True + True + 5 + 0 + + + + + Save Targets + True + True + True + 3 + + + True + True + 5 + 1 + + + + + 1 + 1 + + + + + + + + True + True + 3 + + + + + True + False + 6 + + + Add + True + True + True + + + False + False + 0 + + + + + Edit + True + True + True + + + False + False + 1 + + + + + Delete + True + True + True + + + False + False + 2 + + + + + False + False + 4 + + + + + + help + ok + cancel + + + + both + + + + + + + + + + + + + + + + -- cgit