| 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ |
| 2 | /* |
| 3 | * This file is part of the LibreOffice project. |
| 4 | * |
| 5 | * This Source Code Form is subject to the terms of the Mozilla Public |
| 6 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 7 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 8 | */ |
| 9 | |
| 10 | #ifndef INCLUDED_SFX2_INC_AUTOREDACTDIALOG_HXX |
| 11 | #define INCLUDED_SFX2_INC_AUTOREDACTDIALOG_HXX |
| 12 | |
| 13 | #include <memory> |
| 14 | #include <sal/config.h> |
| 15 | #include <sfx2/basedlgs.hxx> |
| 16 | #include <sfx2/objsh.hxx> |
| 17 | |
| 18 | enum RedactionTargetType |
| 19 | { |
| 20 | REDACTION_TARGET_TEXT, |
| 21 | REDACTION_TARGET_REGEX, |
| 22 | REDACTION_TARGET_PREDEFINED, |
| 23 | REDACTION_TARGET_IMAGE, |
| 24 | REDACTION_TARGET_UNKNOWN |
| 25 | }; |
| 26 | |
| 27 | /// Keeps information for a single redaction target |
| 28 | struct RedactionTarget |
| 29 | { |
| 30 | OUString sName; |
| 31 | RedactionTargetType sType; |
| 32 | OUString sContent; |
| 33 | bool bCaseSensitive; |
| 34 | bool bWholeWords; |
| 35 | sal_uInt32 nID; |
| 36 | }; |
| 37 | |
| 38 | /// Used to display the targets list |
| 39 | class TargetsTable |
| 40 | { |
| 41 | std::unique_ptr<weld::TreeView> m_xControl; |
| 42 | int GetRowByTargetName(std::u16string_view sName); |
| 43 | |
| 44 | public: |
| 45 | TargetsTable(std::unique_ptr<weld::TreeView> xControl); |
| 46 | void InsertTarget(RedactionTarget* pTarget); |
| 47 | bool HasTargetType(RedactionTargetType aTargetType); |
| 48 | RedactionTarget* GetTargetByName(std::u16string_view sName); |
| 49 | OUString GetNameProposal() const; |
| 50 | |
| 51 | int get_selected_index() const { return m_xControl->get_selected_index(); } |
| 52 | std::vector<int> get_selected_rows() const { return m_xControl->get_selected_rows(); } |
| 53 | void clear() { m_xControl->clear(); } |
| 54 | void remove(int nRow) { m_xControl->remove(nRow); } |
| 55 | void select(int nRow) { m_xControl->select(nRow); } |
| 56 | OUString get_id(int nRow) const { return m_xControl->get_id(nRow); } |
| 57 | |
| 58 | // Sync data on the targets box with the data on the target |
| 59 | void setRowData(int nRowIndex, const RedactionTarget* pTarget); |
| 60 | |
| 61 | void connect_row_activated(const Link<weld::TreeView&, bool>& rLink) |
| 62 | { |
| 63 | m_xControl->connect_row_activated(rLink); |
| 64 | }; |
| 65 | }; |
| 66 | |
| 67 | namespace sfx2 |
| 68 | { |
| 69 | class FileDialogHelper; |
| 70 | } |
| 71 | |
| 72 | enum class StartFileDialogType |
| 73 | { |
| 74 | Open, |
| 75 | SaveAs |
| 76 | }; |
| 77 | |
| 78 | class SfxAutoRedactDialog final : public SfxDialogController |
| 79 | { |
| 80 | SfxObjectShellLock m_xDocShell; |
| 81 | std::vector<std::pair<std::unique_ptr<RedactionTarget>, OUString>> m_aTableTargets; |
| 82 | std::unique_ptr<sfx2::FileDialogHelper> m_pFileDlg; |
| 83 | bool m_bIsValidState; |
| 84 | bool m_bTargetsCopied; |
| 85 | |
| 86 | TargetsTable m_aTargetsBox; |
| 87 | std::unique_ptr<weld::Button> m_xLoadBtn; |
| 88 | std::unique_ptr<weld::Button> m_xSaveBtn; |
| 89 | std::unique_ptr<weld::Button> m_xAddBtn; |
| 90 | std::unique_ptr<weld::Button> m_xEditBtn; |
| 91 | std::unique_ptr<weld::Button> m_xDeleteBtn; |
| 92 | |
| 93 | DECL_LINK(Load, weld::Button&, void); |
| 94 | DECL_LINK(Save, weld::Button&, void); |
| 95 | DECL_LINK(AddHdl, weld::Button&, void); |
| 96 | DECL_LINK(EditHdl, weld::Button&, void); |
| 97 | DECL_LINK(DeleteHdl, weld::Button&, void); |
| 98 | DECL_LINK(DoubleClickEditHdl, weld::TreeView&, bool); |
| 99 | DECL_LINK(LoadHdl, sfx2::FileDialogHelper*, void); |
| 100 | DECL_LINK(SaveHdl, sfx2::FileDialogHelper*, void); |
| 101 | |
| 102 | void StartFileDialog(StartFileDialogType nType, const OUString& rTitle); |
| 103 | /// Carry out proper addition both to the targets box, and to the tabletargets vector. |
| 104 | void addTarget(std::unique_ptr<RedactionTarget> pTarget); |
| 105 | /// Clear all targets both visually and from the targets vector |
| 106 | void clearTargets(); |
| 107 | |
| 108 | void ImplDestroy(); |
| 109 | |
| 110 | public: |
| 111 | SfxAutoRedactDialog(weld::Window* pParent); |
| 112 | virtual ~SfxAutoRedactDialog() override; |
| 113 | |
| 114 | /// Check if the dialog has any valid redaction targets. |
| 115 | bool hasTargets() const; |
| 116 | /// Check if the dialog is in a valid state. |
| 117 | bool isValidState() const { return m_bIsValidState; } |
| 118 | /** Copies targets vector |
| 119 | * Does a shallow copy. |
| 120 | * Returns true if successful. |
| 121 | */ |
| 122 | bool getTargets(std::vector<std::pair<RedactionTarget, OUString>>& r_aTargets); |
| 123 | }; |
| 124 | |
| 125 | class SfxAddTargetDialog final : public weld::GenericDialogController |
| 126 | { |
| 127 | private: |
| 128 | std::unique_ptr<weld::Entry> m_xName; |
| 129 | std::unique_ptr<weld::ComboBox> m_xType; |
| 130 | std::unique_ptr<weld::Label> m_xLabelContent; |
| 131 | std::unique_ptr<weld::Entry> m_xContent; |
| 132 | std::unique_ptr<weld::Label> m_xLabelPredefContent; |
| 133 | std::unique_ptr<weld::ComboBox> m_xPredefContent; |
| 134 | std::unique_ptr<weld::CheckButton> m_xCaseSensitive; |
| 135 | std::unique_ptr<weld::CheckButton> m_xWholeWords; |
| 136 | |
| 137 | DECL_LINK(SelectTypeHdl, weld::ComboBox&, void); |
| 138 | |
| 139 | public: |
| 140 | SfxAddTargetDialog(weld::Window* pWindow, const OUString& rName); |
| 141 | SfxAddTargetDialog(weld::Window* pWindow, const OUString& sName, |
| 142 | const RedactionTargetType& eTargetType, const OUString& sContent, |
| 143 | bool bCaseSensitive, bool bWholeWords); |
| 144 | |
| 145 | OUString getName() const { return m_xName->get_text(); } |
| 146 | RedactionTargetType getType() const; |
| 147 | OUString getContent() const; |
| 148 | bool isCaseSensitive() const |
| 149 | { |
| 150 | return m_xCaseSensitive->get_state() == TriState::TRISTATE_TRUE; |
| 151 | } |
| 152 | bool isWholeWords() const { return m_xWholeWords->get_state() == TriState::TRISTATE_TRUE; } |
| 153 | }; |
| 154 | |
| 155 | #endif |
| 156 | |
| 157 | /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ |