diff options
Diffstat (limited to 'sfx2/source/doc/autoredactdialog.cxx')
-rw-r--r-- | sfx2/source/doc/autoredactdialog.cxx | 190 |
1 files changed, 169 insertions, 21 deletions
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 <osl/file.hxx> -#include <sfx2/autoredactdialog.hxx> +#include <autoredactdialog.hxx> #include <vcl/layout.hxx> #include <vcl/idle.hxx> #include <vcl/gdimtf.hxx> @@ -50,17 +50,43 @@ int TargetsTable::GetRowByTargetName(const OUString& sName) TargetsTable::TargetsTable(std::unique_ptr<weld::TreeView> xControl) : m_xControl(std::move(xControl)) { - m_xControl->set_size_request(550, 250); + m_xControl->set_size_request(555, 250); std::vector<int> 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<sal_Int64>(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<weld::MessageDialog> 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<weld::MessageDialog> 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<weld::MessageDialog> 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<int> 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<weld::MessageDialog> 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: */ |