From fe977ec07087b103de8c809597fdaea8dd629837 Mon Sep 17 00:00:00 2001 From: Muhammet Kara Date: Fri, 31 May 2019 18:02:58 +0300 Subject: Auto redaction dialog second iteration * Add the Add handler * Add SfxAddTargetDialog dialog * Add the Delete handler Change-Id: I9c466754f6b593ffe3c8a1cc8034bbe47674f591 Reviewed-on: https://gerrit.libreoffice.org/73285 Tested-by: Jenkins Reviewed-by: Muhammet Kara --- sfx2/UIConfig_sfx.mk | 1 + sfx2/inc/autoredactdialog.hxx | 146 ++++++++++++++++++++++ sfx2/source/doc/autoredactdialog.cxx | 190 ++++++++++++++++++++++++---- sfx2/source/doc/objserv.cxx | 2 +- sfx2/uiconfig/ui/addtargetdialog.ui | 235 +++++++++++++++++++++++++++++++++++ sfx2/uiconfig/ui/autoredactdialog.ui | 10 +- 6 files changed, 557 insertions(+), 27 deletions(-) create mode 100644 sfx2/inc/autoredactdialog.hxx create mode 100644 sfx2/uiconfig/ui/addtargetdialog.ui (limited to 'sfx2') diff --git a/sfx2/UIConfig_sfx.mk b/sfx2/UIConfig_sfx.mk index a7154213d128..0eb097b7fffd 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/addtargetdialog \ sfx2/uiconfig/ui/autoredactdialog \ sfx2/uiconfig/ui/bookmarkdialog \ sfx2/uiconfig/ui/bookmarkmenu \ diff --git a/sfx2/inc/autoredactdialog.hxx b/sfx2/inc/autoredactdialog.hxx new file mode 100644 index 000000000000..26b29bf10cf5 --- /dev/null +++ b/sfx2/inc/autoredactdialog.hxx @@ -0,0 +1,146 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef INCLUDED_SFX2_INC_AUTOREDACTDIALOG_HXX +#define INCLUDED_SFX2_INC_AUTOREDACTDIALOG_HXX + +#include +#include +#include +#include +#include + +#include +#include + +namespace weld +{ +class Button; +} +namespace weld +{ +class ComboBox; +} +namespace weld +{ +class Label; +} +namespace weld +{ +class Window; +} +namespace weld +{ +class TreeView; +} + +enum RedactionTargetType +{ + REDACTION_TARGET_TEXT, + REDACTION_TARGET_REGEX, + REDACTION_TARGET_PREDEFINED, + REDACTION_TARGET_UNKNOWN +}; + +/// Keeps information for a single redaction target +struct RedactionTarget +{ + OUString sName; + RedactionTargetType sType; + OUString sContent; + bool bCaseSensitive; + bool bWholeWords; + sal_uInt32 nID; +}; + +/// Used to display the targets list +class TargetsTable +{ + std::unique_ptr m_xControl; + int GetRowByTargetName(const OUString& sName); + +public: + TargetsTable(std::unique_ptr xControl); + void InsertTarget(RedactionTarget* pTarget); + void SelectByName(const OUString& sName); + RedactionTarget* GetTargetByName(const OUString& sName); + OUString GetNameProposal(); + + void unselect_all() { m_xControl->unselect_all(); } + bool has_focus() const { return m_xControl->has_focus(); } + int n_children() const { return m_xControl->n_children(); } + int get_selected_index() const { return m_xControl->get_selected_index(); } + std::vector get_selected_rows() const { return m_xControl->get_selected_rows(); } + void clear() { m_xControl->clear(); } + void remove(int nRow) { m_xControl->remove(nRow); } + void select(int nRow) { m_xControl->select(nRow); } + OUString get_id(int nRow) const { return m_xControl->get_id(nRow); } + + //void connect_changed(const Link& rLink) { m_xControl->connect_changed(rLink); } + //void connect_row_activated(const Link& rLink) { m_xControl->connect_row_activated(rLink); } +}; + +class SFX2_DLLPUBLIC SfxAutoRedactDialog : public SfxDialogController +{ + SfxObjectShellLock m_xDocShell; + std::vector> m_aTableTargets; + + std::unique_ptr m_xRedactionTargetsLabel; + std::unique_ptr m_xTargetsBox; + std::unique_ptr m_xLoadBtn; + std::unique_ptr m_xSaveBtn; + std::unique_ptr m_xAddBtn; + std::unique_ptr m_xEditBtn; + std::unique_ptr m_xDeleteBtn; + + /*DECL_LINK(LoadHdl, weld::Button&, void); + DECL_LINK(SaveHdl, weld::Button&, void);*/ + DECL_LINK(AddHdl, weld::Button&, void); + //DECL_LINK(EditHdl, weld::Button&, void); + DECL_LINK(DeleteHdl, weld::Button&, void); + +public: + SfxAutoRedactDialog(weld::Window* pParent); + virtual ~SfxAutoRedactDialog() override; + + /* + * Check if the dialog has any valid redaction targets. + */ + bool hasTargets() const; + + // TODO: Some method(s) to check emptiness/validity + // TODO: Some method(s) to get the search params/objects + // TODO: Some method(s) to load/save redaction target sets +}; + +class SfxAddTargetDialog : public weld::GenericDialogController +{ +private: + std::unique_ptr m_xName; + std::unique_ptr m_xType; + std::unique_ptr m_xContent; + std::unique_ptr m_xCaseSensitive; + std::unique_ptr m_xWholeWords; + +public: + SfxAddTargetDialog(weld::Window* pWindow, const OUString& rName); + + OUString getName() const { return m_xName->get_text(); } + RedactionTargetType getType() const; + OUString getContent() const { return m_xContent->get_text(); } + bool isCaseSensitive() const + { + return m_xCaseSensitive->get_state() == TriState::TRISTATE_TRUE; + } + bool isWholeWords() const { return m_xWholeWords->get_state() == TriState::TRISTATE_TRUE; } +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sfx2/source/doc/autoredactdialog.cxx b/sfx2/source/doc/autoredactdialog.cxx index 0974a4f03b27..5d94906e9ba8 100644 --- a/sfx2/source/doc/autoredactdialog.cxx +++ b/sfx2/source/doc/autoredactdialog.cxx @@ -8,7 +8,7 @@ */ #include -#include +#include #include #include #include @@ -50,17 +50,43 @@ int TargetsTable::GetRowByTargetName(const OUString& sName) TargetsTable::TargetsTable(std::unique_ptr xControl) : m_xControl(std::move(xControl)) { - m_xControl->set_size_request(550, 250); + m_xControl->set_size_request(555, 250); std::vector aWidths; aWidths.push_back(100); - aWidths.push_back(45); - aWidths.push_back(110); + aWidths.push_back(50); + aWidths.push_back(200); + aWidths.push_back(105); aWidths.push_back(105); - aWidths.push_back(150); m_xControl->set_column_fixed_widths(aWidths); m_xControl->set_selection_mode(SelectionMode::Multiple); } +namespace +{ +OUString getTypeName(RedactionTargetType nType) +{ + OUString sTypeName("Unknown"); + + switch (nType) + { + case RedactionTargetType::REDACTION_TARGET_TEXT: + sTypeName = "Text"; + break; + case RedactionTargetType::REDACTION_TARGET_REGEX: + sTypeName = "Regex"; + break; + case RedactionTargetType::REDACTION_TARGET_PREDEFINED: + sTypeName = "Predefined"; + break; + case RedactionTargetType::REDACTION_TARGET_UNKNOWN: + sTypeName = "Unknown"; + break; + } + + return sTypeName; +} +} + void TargetsTable::InsertTarget(RedactionTarget* pTarget) { if (!pTarget) @@ -78,10 +104,10 @@ void TargetsTable::InsertTarget(RedactionTarget* pTarget) // 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); + m_xControl->set_text(nRow, getTypeName(pTarget->sType), 1); + m_xControl->set_text(nRow, pTarget->sContent, 2); + m_xControl->set_text(nRow, pTarget->bCaseSensitive ? OUString("Yes") : OUString("No"), 3); + m_xControl->set_text(nRow, pTarget->bWholeWords ? OUString("Yes") : OUString("No"), 4); } void TargetsTable::SelectByName(const OUString& sName) @@ -121,6 +147,107 @@ OUString TargetsTable::GetNameProposal() return sDefaultTargetName + " " + OUString::number(nHighestTargetId + 1); } +/*IMPL_LINK_NOARG(SfxAutoRedactDialog, LoadHdl, weld::Button&, void) +{ + //TODO: Implement + //Load a targets list from a previously saved file (a json file in the user profile dir?) +} + +IMPL_LINK_NOARG(SfxAutoRedactDialog, SaveHdl, weld::Button&, void) +{ + //TODO: Implement + //Allow saving the targets into a file +}*/ + +IMPL_LINK_NOARG(SfxAutoRedactDialog, AddHdl, weld::Button&, void) +{ + // Open the Add Target dialog, craete a new target and insert into the targets vector and the listbox + SfxAddTargetDialog aAddTargetDialog(getDialog(), m_xTargetsBox->GetNameProposal()); + + bool bIncomplete; + do + { + bIncomplete = false; + + if (aAddTargetDialog.run() != RET_OK) + return; + + if (aAddTargetDialog.getName().isEmpty() + || aAddTargetDialog.getType() == RedactionTargetType::REDACTION_TARGET_UNKNOWN + || aAddTargetDialog.getContent().isEmpty()) + { + bIncomplete = true; + std::unique_ptr xBox( + Application::CreateMessageDialog(getDialog(), VclMessageType::Warning, + VclButtonsType::Ok, "All fields are required")); + xBox->run(); + } + else if (m_xTargetsBox->GetTargetByName(aAddTargetDialog.getName())) + { + bIncomplete = true; + std::unique_ptr xBox(Application::CreateMessageDialog( + getDialog(), VclMessageType::Warning, VclButtonsType::Ok, + "There is already a target with this name")); + xBox->run(); + } + + } while (bIncomplete); + + //Alright, we now have everything we need to construct a new target + RedactionTarget* redactiontarget = new RedactionTarget( + { aAddTargetDialog.getName(), aAddTargetDialog.getType(), aAddTargetDialog.getContent(), + aAddTargetDialog.isCaseSensitive(), aAddTargetDialog.isWholeWords(), 0 }); + + // Only the visual/display part + m_xTargetsBox->InsertTarget(redactiontarget); + + // Actually add to the targets vector + if (m_xTargetsBox->GetTargetByName(redactiontarget->sName)) + m_aTableTargets.emplace_back(redactiontarget, redactiontarget->sName); + else + { + std::unique_ptr xBox(Application::CreateMessageDialog( + getDialog(), VclMessageType::Warning, VclButtonsType::Ok, + "An error occured while adding new target. Please report this incidence.")); + xBox->run(); + delete redactiontarget; + } +} + +/*IMPL_LINK_NOARG(SfxAutoRedactDialog, EditHdl, weld::Button&, void) +{ + //TODO: Implement + //Reuse the Add Target dialog +}*/ + +IMPL_LINK_NOARG(SfxAutoRedactDialog, DeleteHdl, weld::Button&, void) +{ + std::vector aSelectedRows = m_xTargetsBox->get_selected_rows(); + + //No selection, so nothing to delete + if (aSelectedRows.empty()) + return; + + if (aSelectedRows.size() > 1) + { + OUString sMsg("Are you sure you would like to delete " + + OUString::number(aSelectedRows.size()) + " targets at once?"); + //Warn the user about multiple deletions + std::unique_ptr xBox(Application::CreateMessageDialog( + getDialog(), VclMessageType::Question, VclButtonsType::OkCancel, sMsg)); + if (xBox->run() == RET_CANCEL) + return; + } + + // After each delete, the indexes of the following items decrease by one. + int delta = 0; + for (const auto& i : aSelectedRows) + { + m_aTableTargets.erase(m_aTableTargets.begin() + (i - delta)); + m_xTargetsBox->remove(i - delta++); + } +} + SfxAutoRedactDialog::SfxAutoRedactDialog(weld::Window* pParent) : SfxDialogController(pParent, "sfx/ui/autoredactdialog.ui", "AutoRedactDialog") , m_xRedactionTargetsLabel(m_xBuilder->weld_label("labelRedactionTargets")) @@ -147,19 +274,14 @@ SfxAutoRedactDialog::SfxAutoRedactDialog(weld::Window* pParent) //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" }); + // TODO: fill the targets box - m_xTargetsBox->InsertTarget(redactiontarget);*/ + // Handler connections + //m_xLoadBtn->connect_clicked(LINK(this, SfxAutoRedactDialog, LoadHdl)); + //m_xSaveBtn->connect_clicked(LINK(this, SfxAutoRedactDialog, SaveHdl)); + m_xAddBtn->connect_clicked(LINK(this, SfxAutoRedactDialog, AddHdl)); + //m_xEditBtn->connect_clicked(LINK(this, SfxAutoRedactDialog, EditHdl)); + m_xDeleteBtn->connect_clicked(LINK(this, SfxAutoRedactDialog, DeleteHdl)); } SfxAutoRedactDialog::~SfxAutoRedactDialog() @@ -178,4 +300,30 @@ bool SfxAutoRedactDialog::hasTargets() const return true; } +SfxAddTargetDialog::SfxAddTargetDialog(weld::Window* pParent, const OUString& rName) + : GenericDialogController(pParent, "sfx/ui/addtargetdialog.ui", "AddTargetDialog") + , m_xName(m_xBuilder->weld_entry("name")) + , m_xType(m_xBuilder->weld_combo_box("type")) + , m_xContent(m_xBuilder->weld_entry("content")) + , m_xCaseSensitive(m_xBuilder->weld_check_button("checkboxCaseSensitive")) + , m_xWholeWords(m_xBuilder->weld_check_button("checkboxWholeWords")) +{ + m_xName->set_text(rName); + m_xName->select_region(0, rName.getLength()); +} + +RedactionTargetType SfxAddTargetDialog::getType() const +{ + OUString sTypeID = m_xType->get_active_id(); + + if (sTypeID == "text") + return RedactionTargetType::REDACTION_TARGET_TEXT; + else if (sTypeID == "regex") + return RedactionTargetType::REDACTION_TARGET_REGEX; + else if (sTypeID == "predefined") + return RedactionTargetType::REDACTION_TARGET_PREDEFINED; + else + return RedactionTargetType::REDACTION_TARGET_UNKNOWN; +} + /* 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 feb8952f4c23..f4c941cba5f5 100644 --- a/sfx2/source/doc/objserv.cxx +++ b/sfx2/source/doc/objserv.cxx @@ -125,7 +125,7 @@ #include #include -#include +#include using namespace ::com::sun::star; using namespace ::com::sun::star::lang; diff --git a/sfx2/uiconfig/ui/addtargetdialog.ui b/sfx2/uiconfig/ui/addtargetdialog.ui new file mode 100644 index 000000000000..3d45c7a240bd --- /dev/null +++ b/sfx2/uiconfig/ui/addtargetdialog.ui @@ -0,0 +1,235 @@ + + + + + + False + 6 + Add Target + True + 0 + 0 + dialog + + + + + + False + True + True + vertical + 12 + + + False + + + gtk-cancel + True + True + True + True + + + False + True + end + 0 + + + + + gtk-ok + True + True + True + True + + + False + True + end + 0 + + + + + gtk-help + True + True + True + True + + + False + True + 1 + True + + + + + True + True + 5 + + + + + True + False + + + True + False + Name: + True + + + + + + 0 + 0 + + + + + True + True + 2 + 2 + True + + + + + + 1 + 0 + + + + + True + False + Type: + True + + + + + + 0 + 1 + + + + + True + False + Content: + True + + + + + + 0 + 2 + + + + + True + True + 2 + True + + + + + + 1 + 2 + + + + + True + False + + Text + Regex + Predefined + + + + + + + 1 + 1 + + + + + False + True + 0 + + + + + True + False + + + Case Sensitive + True + True + False + start + True + True + + + False + True + 0 + + + + + Whole Words Only + True + True + False + start + True + True + + + False + True + end + 1 + + + + + False + True + 2 + + + + + + cancel + close + help + + + diff --git a/sfx2/uiconfig/ui/autoredactdialog.ui b/sfx2/uiconfig/ui/autoredactdialog.ui index 01c0dc6e9592..113002775125 100644 --- a/sfx2/uiconfig/ui/autoredactdialog.ui +++ b/sfx2/uiconfig/ui/autoredactdialog.ui @@ -8,12 +8,12 @@ + + - - @@ -143,7 +143,7 @@ True 6 - Case Sensitive + Content @@ -156,7 +156,7 @@ True 6 - Whole Words + Case Sensitive @@ -169,7 +169,7 @@ True 6 - Description + Whole Words -- cgit