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/dllapi.h>
16 #include <sfx2/basedlgs.hxx>
17 #include <sfx2/objsh.hxx>
19 #include <vcl/idle.hxx>
20 #include <o3tl/typed_flags_set.hxx>
43 enum RedactionTargetType
45 REDACTION_TARGET_TEXT
,
46 REDACTION_TARGET_REGEX
,
47 REDACTION_TARGET_PREDEFINED
,
48 REDACTION_TARGET_UNKNOWN
51 /// Keeps information for a single redaction target
52 struct RedactionTarget
55 RedactionTargetType sType
;
62 /// Used to display the targets list
65 std::unique_ptr
<weld::TreeView
> m_xControl
;
66 int GetRowByTargetName(const OUString
& sName
);
69 TargetsTable(std::unique_ptr
<weld::TreeView
> xControl
);
70 void InsertTarget(RedactionTarget
* pTarget
);
71 void SelectByName(const OUString
& sName
);
72 RedactionTarget
* GetTargetByName(const OUString
& sName
);
73 OUString
GetNameProposal() const;
75 void unselect_all() { m_xControl
->unselect_all(); }
76 bool has_focus() const { return m_xControl
->has_focus(); }
77 int n_children() const { return m_xControl
->n_children(); }
78 int get_selected_index() const { return m_xControl
->get_selected_index(); }
79 std::vector
<int> get_selected_rows() const { return m_xControl
->get_selected_rows(); }
80 void clear() { m_xControl
->clear(); }
81 void remove(int nRow
) { m_xControl
->remove(nRow
); }
82 void select(int nRow
) { m_xControl
->select(nRow
); }
83 OUString
get_id(int nRow
) const { return m_xControl
->get_id(nRow
); }
85 // Sync data on the targets box with the data on the target
86 void setRowData(int nRowIndex
, const RedactionTarget
* pTarget
);
88 //void connect_changed(const Link<weld::TreeView&, void>& rLink) { m_xControl->connect_changed(rLink); }
89 //void connect_row_activated(const Link<weld::TreeView&, void>& rLink) { m_xControl->connect_row_activated(rLink); }
94 class FileDialogHelper
;
97 enum class StartFileDialogType
103 class SfxAutoRedactDialog
: public SfxDialogController
105 SfxObjectShellLock m_xDocShell
;
106 std::vector
<std::pair
<RedactionTarget
*, OUString
>> m_aTableTargets
;
107 std::unique_ptr
<sfx2::FileDialogHelper
> m_pFileDlg
;
108 bool m_bIsValidState
;
109 bool m_bTargetsCopied
;
111 std::unique_ptr
<weld::Label
> m_xRedactionTargetsLabel
;
112 std::unique_ptr
<TargetsTable
> m_xTargetsBox
;
113 std::unique_ptr
<weld::Button
> m_xLoadBtn
;
114 std::unique_ptr
<weld::Button
> m_xSaveBtn
;
115 std::unique_ptr
<weld::Button
> m_xAddBtn
;
116 std::unique_ptr
<weld::Button
> m_xEditBtn
;
117 std::unique_ptr
<weld::Button
> m_xDeleteBtn
;
119 DECL_LINK(Load
, weld::Button
&, void);
120 DECL_LINK(Save
, weld::Button
&, void);
121 DECL_LINK(AddHdl
, weld::Button
&, void);
122 DECL_LINK(EditHdl
, weld::Button
&, void);
123 DECL_LINK(DeleteHdl
, weld::Button
&, void);
125 DECL_LINK(LoadHdl
, sfx2::FileDialogHelper
*, void);
126 DECL_LINK(SaveHdl
, sfx2::FileDialogHelper
*, void);
128 void StartFileDialog(StartFileDialogType nType
, const OUString
& rTitle
);
129 /// Carry out proper addition both to the targets box, and to the tabletargets vector.
130 void addTarget(RedactionTarget
* pTarget
);
131 /// Clear all targets both visually and from the targets vector
135 SfxAutoRedactDialog(weld::Window
* pParent
);
136 virtual ~SfxAutoRedactDialog() override
;
138 /// Check if the dialog has any valid redaction targets.
139 bool hasTargets() const;
140 /// Check if the dialog is in a valid state.
141 bool isValidState() const { return m_bIsValidState
; }
142 /** Copies targets vector
143 * Does a shallow copy.
144 * Returns true if successful.
146 bool getTargets(std::vector
<std::pair
<RedactionTarget
*, OUString
>>& r_aTargets
);
149 class SfxAddTargetDialog
: public weld::GenericDialogController
152 std::unique_ptr
<weld::Entry
> m_xName
;
153 std::unique_ptr
<weld::ComboBox
> m_xType
;
154 std::unique_ptr
<weld::Label
> m_xLabelContent
;
155 std::unique_ptr
<weld::Entry
> m_xContent
;
156 std::unique_ptr
<weld::Label
> m_xLabelPredefContent
;
157 std::unique_ptr
<weld::ComboBox
> m_xPredefContent
;
158 std::unique_ptr
<weld::CheckButton
> m_xCaseSensitive
;
159 std::unique_ptr
<weld::CheckButton
> m_xWholeWords
;
161 DECL_LINK(SelectTypeHdl
, weld::ComboBox
&, void);
164 SfxAddTargetDialog(weld::Window
* pWindow
, const OUString
& rName
);
165 SfxAddTargetDialog(weld::Window
* pWindow
, const OUString
& sName
,
166 const RedactionTargetType
& eTargetType
, const OUString
& sContent
,
167 bool bCaseSensitive
, bool bWholeWords
);
169 OUString
getName() const { return m_xName
->get_text(); }
170 RedactionTargetType
getType() const;
171 OUString
getContent() const;
172 bool isCaseSensitive() const
174 return m_xCaseSensitive
->get_state() == TriState::TRISTATE_TRUE
;
176 bool isWholeWords() const { return m_xWholeWords
->get_state() == TriState::TRISTATE_TRUE
; }
181 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */