1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
3 * This file is part of the LibreOffice project.
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/.
10 #ifndef INCLUDED_SFX2_INC_AUTOREDACTDIALOG_HXX
11 #define INCLUDED_SFX2_INC_AUTOREDACTDIALOG_HXX
14 #include <sal/config.h>
15 #include <sfx2/basedlgs.hxx>
16 #include <sfx2/objsh.hxx>
39 enum RedactionTargetType
41 REDACTION_TARGET_TEXT
,
42 REDACTION_TARGET_REGEX
,
43 REDACTION_TARGET_PREDEFINED
,
44 REDACTION_TARGET_UNKNOWN
47 /// Keeps information for a single redaction target
48 struct RedactionTarget
51 RedactionTargetType sType
;
58 /// Used to display the targets list
61 std::unique_ptr
<weld::TreeView
> m_xControl
;
62 int GetRowByTargetName(std::u16string_view sName
);
65 TargetsTable(std::unique_ptr
<weld::TreeView
> xControl
);
66 void InsertTarget(RedactionTarget
* pTarget
);
67 RedactionTarget
* GetTargetByName(std::u16string_view sName
);
68 OUString
GetNameProposal() const;
70 int get_selected_index() const { return m_xControl
->get_selected_index(); }
71 std::vector
<int> get_selected_rows() const { return m_xControl
->get_selected_rows(); }
72 void clear() { m_xControl
->clear(); }
73 void remove(int nRow
) { m_xControl
->remove(nRow
); }
74 void select(int nRow
) { m_xControl
->select(nRow
); }
75 OUString
get_id(int nRow
) const { return m_xControl
->get_id(nRow
); }
77 // Sync data on the targets box with the data on the target
78 void setRowData(int nRowIndex
, const RedactionTarget
* pTarget
);
83 class FileDialogHelper
;
86 enum class StartFileDialogType
92 class SfxAutoRedactDialog final
: public SfxDialogController
94 SfxObjectShellLock m_xDocShell
;
95 std::vector
<std::pair
<std::unique_ptr
<RedactionTarget
>, OUString
>> m_aTableTargets
;
96 std::unique_ptr
<sfx2::FileDialogHelper
> m_pFileDlg
;
98 bool m_bTargetsCopied
;
100 std::unique_ptr
<weld::Label
> m_xRedactionTargetsLabel
;
101 std::unique_ptr
<TargetsTable
> m_xTargetsBox
;
102 std::unique_ptr
<weld::Button
> m_xLoadBtn
;
103 std::unique_ptr
<weld::Button
> m_xSaveBtn
;
104 std::unique_ptr
<weld::Button
> m_xAddBtn
;
105 std::unique_ptr
<weld::Button
> m_xEditBtn
;
106 std::unique_ptr
<weld::Button
> m_xDeleteBtn
;
108 DECL_LINK(Load
, weld::Button
&, void);
109 DECL_LINK(Save
, weld::Button
&, void);
110 DECL_LINK(AddHdl
, weld::Button
&, void);
111 DECL_LINK(EditHdl
, weld::Button
&, void);
112 DECL_LINK(DeleteHdl
, weld::Button
&, void);
114 DECL_LINK(LoadHdl
, sfx2::FileDialogHelper
*, void);
115 DECL_LINK(SaveHdl
, sfx2::FileDialogHelper
*, void);
117 void StartFileDialog(StartFileDialogType nType
, const OUString
& rTitle
);
118 /// Carry out proper addition both to the targets box, and to the tabletargets vector.
119 void addTarget(std::unique_ptr
<RedactionTarget
> pTarget
);
120 /// Clear all targets both visually and from the targets vector
124 SfxAutoRedactDialog(weld::Window
* pParent
);
125 virtual ~SfxAutoRedactDialog() override
;
127 /// Check if the dialog has any valid redaction targets.
128 bool hasTargets() const;
129 /// Check if the dialog is in a valid state.
130 bool isValidState() const { return m_bIsValidState
; }
131 /** Copies targets vector
132 * Does a shallow copy.
133 * Returns true if successful.
135 bool getTargets(std::vector
<std::pair
<RedactionTarget
, OUString
>>& r_aTargets
);
138 class SfxAddTargetDialog final
: public weld::GenericDialogController
141 std::unique_ptr
<weld::Entry
> m_xName
;
142 std::unique_ptr
<weld::ComboBox
> m_xType
;
143 std::unique_ptr
<weld::Label
> m_xLabelContent
;
144 std::unique_ptr
<weld::Entry
> m_xContent
;
145 std::unique_ptr
<weld::Label
> m_xLabelPredefContent
;
146 std::unique_ptr
<weld::ComboBox
> m_xPredefContent
;
147 std::unique_ptr
<weld::CheckButton
> m_xCaseSensitive
;
148 std::unique_ptr
<weld::CheckButton
> m_xWholeWords
;
150 DECL_LINK(SelectTypeHdl
, weld::ComboBox
&, void);
153 SfxAddTargetDialog(weld::Window
* pWindow
, const OUString
& rName
);
154 SfxAddTargetDialog(weld::Window
* pWindow
, const OUString
& sName
,
155 const RedactionTargetType
& eTargetType
, const OUString
& sContent
,
156 bool bCaseSensitive
, bool bWholeWords
);
158 OUString
getName() const { return m_xName
->get_text(); }
159 RedactionTargetType
getType() const;
160 OUString
getContent() const;
161 bool isCaseSensitive() const
163 return m_xCaseSensitive
->get_state() == TriState::TRISTATE_TRUE
;
165 bool isWholeWords() const { return m_xWholeWords
->get_state() == TriState::TRISTATE_TRUE
; }
170 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */