[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.0' - sfx2/inc sfx2/source
Muhammet Kara (via logerrit)
logerrit at kemper.freedesktop.org
Sat Aug 17 14:39:10 UTC 2019
sfx2/inc/autoredactdialog.hxx | 8 +-
sfx2/source/doc/autoredactdialog.cxx | 131 +++++++++++++++++++++++++++++++++--
2 files changed, 133 insertions(+), 6 deletions(-)
New commits:
commit ec442c00bc1236bbd27010bdcf7b114c796712d8
Author: Muhammet Kara <muhammet.kara at collabora.com>
AuthorDate: Sat Jun 8 16:37:04 2019 +0300
Commit: Muhammet Kara <muhammet.kara at collabora.com>
CommitDate: Sat Aug 17 16:38:26 2019 +0200
Auto redaction dialog 3rd iteration
* Add the Edit handler
Change-Id: Id900d2aab6fa6795455012aaf2bcaf755ccca139
Reviewed-on: https://gerrit.libreoffice.org/73705
Tested-by: Jenkins
Reviewed-by: Muhammet Kara <muhammet.kara at collabora.com>
Reviewed-on: https://gerrit.libreoffice.org/77160
Tested-by: Muhammet Kara <muhammet.kara at collabora.com>
diff --git a/sfx2/inc/autoredactdialog.hxx b/sfx2/inc/autoredactdialog.hxx
index 26b29bf10cf5..267427c90b21 100644
--- a/sfx2/inc/autoredactdialog.hxx
+++ b/sfx2/inc/autoredactdialog.hxx
@@ -82,6 +82,9 @@ public:
void select(int nRow) { m_xControl->select(nRow); }
OUString get_id(int nRow) const { return m_xControl->get_id(nRow); }
+ // Sync data on the targets box with the data on the target
+ void setRowData(const int& nRowIndex, const RedactionTarget* pTarget);
+
//void connect_changed(const Link<weld::TreeView&, void>& rLink) { m_xControl->connect_changed(rLink); }
//void connect_row_activated(const Link<weld::TreeView&, void>& rLink) { m_xControl->connect_row_activated(rLink); }
};
@@ -102,7 +105,7 @@ class SFX2_DLLPUBLIC SfxAutoRedactDialog : public SfxDialogController
/*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(EditHdl, weld::Button&, void);
DECL_LINK(DeleteHdl, weld::Button&, void);
public:
@@ -130,6 +133,9 @@ private:
public:
SfxAddTargetDialog(weld::Window* pWindow, const OUString& rName);
+ SfxAddTargetDialog(weld::Window* pWindow, const OUString& sName,
+ const RedactionTargetType& eTargetType, const OUString& sContent,
+ const bool& bCaseSensitive, const bool& bWholeWords);
OUString getName() const { return m_xName->get_text(); }
RedactionTargetType getType() const;
diff --git a/sfx2/source/doc/autoredactdialog.cxx b/sfx2/source/doc/autoredactdialog.cxx
index 5d94906e9ba8..266859a129ec 100644
--- a/sfx2/source/doc/autoredactdialog.cxx
+++ b/sfx2/source/doc/autoredactdialog.cxx
@@ -85,6 +85,30 @@ OUString getTypeName(RedactionTargetType nType)
return sTypeName;
}
+
+/// Returns TypeID to be used in the add/edit target dialog
+OUString getTypeID(RedactionTargetType nType)
+{
+ OUString sTypeID("unknown");
+
+ switch (nType)
+ {
+ case RedactionTargetType::REDACTION_TARGET_TEXT:
+ sTypeID = "text";
+ break;
+ case RedactionTargetType::REDACTION_TARGET_REGEX:
+ sTypeID = "regex";
+ break;
+ case RedactionTargetType::REDACTION_TARGET_PREDEFINED:
+ sTypeID = "predefined";
+ break;
+ case RedactionTargetType::REDACTION_TARGET_UNKNOWN:
+ sTypeID = "unknown";
+ break;
+ }
+
+ return sTypeID;
+}
}
void TargetsTable::InsertTarget(RedactionTarget* pTarget)
@@ -147,6 +171,15 @@ OUString TargetsTable::GetNameProposal()
return sDefaultTargetName + " " + OUString::number(nHighestTargetId + 1);
}
+void TargetsTable::setRowData(const int& nRowIndex, const RedactionTarget* pTarget)
+{
+ m_xControl->set_text(nRowIndex, pTarget->sName, 0);
+ m_xControl->set_text(nRowIndex, getTypeName(pTarget->sType), 1);
+ m_xControl->set_text(nRowIndex, pTarget->sContent, 2);
+ m_xControl->set_text(nRowIndex, pTarget->bCaseSensitive ? OUString("Yes") : OUString("No"), 3);
+ m_xControl->set_text(nRowIndex, pTarget->bWholeWords ? OUString("Yes") : OUString("No"), 4);
+}
+
/*IMPL_LINK_NOARG(SfxAutoRedactDialog, LoadHdl, weld::Button&, void)
{
//TODO: Implement
@@ -214,11 +247,75 @@ IMPL_LINK_NOARG(SfxAutoRedactDialog, AddHdl, weld::Button&, void)
}
}
-/*IMPL_LINK_NOARG(SfxAutoRedactDialog, EditHdl, weld::Button&, void)
+IMPL_LINK_NOARG(SfxAutoRedactDialog, EditHdl, weld::Button&, void)
{
- //TODO: Implement
- //Reuse the Add Target dialog
-}*/
+ sal_Int32 nSelectedRow = m_xTargetsBox->get_selected_index();
+
+ // No selection, nothing to edit
+ if (nSelectedRow < 0)
+ return;
+
+ // Only one entry should be selected for editing
+ if (m_xTargetsBox->get_selected_rows().size() > 1)
+ {
+ OUString sMsg(
+ "You have selected multiple targets, but only one target can be edited at once.");
+ //Warn the user about multiple selections
+ std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(
+ getDialog(), VclMessageType::Error, VclButtonsType::Ok, sMsg));
+ xBox->run();
+ return;
+ }
+
+ // Get the redaction target to be edited
+ RedactionTarget* pTarget
+ = reinterpret_cast<RedactionTarget*>(m_xTargetsBox->get_id(nSelectedRow).toInt64());
+
+ // Construct and run the edit target dialog
+ SfxAddTargetDialog aEditTargetDialog(getDialog(), pTarget->sName, pTarget->sType,
+ pTarget->sContent, pTarget->bCaseSensitive,
+ pTarget->bWholeWords);
+
+ bool bIncomplete;
+ do
+ {
+ bIncomplete = false;
+
+ if (aEditTargetDialog.run() != RET_OK)
+ return;
+
+ if (aEditTargetDialog.getName().isEmpty()
+ || aEditTargetDialog.getType() == RedactionTargetType::REDACTION_TARGET_UNKNOWN
+ || aEditTargetDialog.getContent().isEmpty())
+ {
+ bIncomplete = true;
+ std::unique_ptr<weld::MessageDialog> xBox(
+ Application::CreateMessageDialog(getDialog(), VclMessageType::Warning,
+ VclButtonsType::Ok, "All fields are required"));
+ xBox->run();
+ }
+ else if (aEditTargetDialog.getName() != pTarget->sName
+ && m_xTargetsBox->GetTargetByName(aEditTargetDialog.getName()))
+ {
+ bIncomplete = true;
+ std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(
+ getDialog(), VclMessageType::Warning, VclButtonsType::Ok,
+ "There is already a target with this name"));
+ xBox->run();
+ }
+
+ } while (bIncomplete);
+
+ // Update the redaction target
+ pTarget->sName = aEditTargetDialog.getName();
+ pTarget->sType = aEditTargetDialog.getType();
+ pTarget->sContent = aEditTargetDialog.getContent();
+ pTarget->bCaseSensitive = aEditTargetDialog.isCaseSensitive();
+ pTarget->bWholeWords = aEditTargetDialog.isWholeWords();
+
+ // And sync the targets box row with the actual target data
+ m_xTargetsBox->setRowData(nSelectedRow, pTarget);
+}
IMPL_LINK_NOARG(SfxAutoRedactDialog, DeleteHdl, weld::Button&, void)
{
@@ -280,7 +377,7 @@ SfxAutoRedactDialog::SfxAutoRedactDialog(weld::Window* pParent)
//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_xEditBtn->connect_clicked(LINK(this, SfxAutoRedactDialog, EditHdl));
m_xDeleteBtn->connect_clicked(LINK(this, SfxAutoRedactDialog, DeleteHdl));
}
@@ -312,6 +409,30 @@ SfxAddTargetDialog::SfxAddTargetDialog(weld::Window* pParent, const OUString& rN
m_xName->select_region(0, rName.getLength());
}
+SfxAddTargetDialog::SfxAddTargetDialog(weld::Window* pParent, const OUString& sName,
+ const RedactionTargetType& eTargetType,
+ const OUString& sContent, const bool& bCaseSensitive,
+ const bool& bWholeWords)
+ : 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(sName);
+ m_xName->select_region(0, sName.getLength());
+
+ m_xType->set_active_id(getTypeID(eTargetType));
+
+ m_xContent->set_text(sContent);
+
+ m_xCaseSensitive->set_active(bCaseSensitive);
+ m_xWholeWords->set_active(bWholeWords);
+
+ set_title("Edit Target");
+}
+
RedactionTargetType SfxAddTargetDialog::getType() const
{
OUString sTypeID = m_xType->get_active_id();
More information about the Libreoffice-commits
mailing list