remove assert looking for new compatibilityMode DOCX
[LibreOffice.git] / cui / source / inc / MacroManagerDialog.hxx
blob757728386e59dbdf8fcd088b2e99bcb847f6b1bc
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.
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 */
10 #pragma once
12 #include <sal/config.h>
14 #include <vector>
15 #include <basctl/scriptdocument.hxx>
16 #include <svx/passwd.hxx>
17 #include <svl/lstner.hxx>
19 #include <com/sun/star/beans/XPropertySet.hpp>
20 #include <com/sun/star/frame/DispatchInformation.hpp>
21 #include <com/sun/star/script/browse/XBrowseNode.hpp>
22 #include <com/sun/star/task/InteractionHandler.hpp>
24 struct ScriptContainerInfo
26 css::script::browse::XBrowseNode* pBrowseNode;
28 ScriptContainerInfo(css::script::browse::XBrowseNode* pObj)
29 : pBrowseNode(pObj)
34 struct ScriptInfo
36 css::script::browse::XBrowseNode* pBrowseNode;
37 OUString sURL;
38 OUString sDescription;
40 ScriptInfo(css::script::browse::XBrowseNode* pObj, const OUString& rsUrl,
41 const OUString& rsDesc)
42 : pBrowseNode(pObj)
43 , sURL(rsUrl)
44 , sDescription(rsDesc)
49 typedef std::vector<std::unique_ptr<ScriptInfo>> ScriptInfoArr;
51 // inspired by class CuiConfigFunctionListBox
52 // cui/source/inc/cfgutil.hxx
53 class ScriptsListBox
55 friend class ScriptContainersListBox; // for access to aArr
57 ScriptInfoArr aArr;
59 std::unique_ptr<weld::TreeView> m_xTreeView;
60 std::unique_ptr<weld::TreeIter> m_xScratchIter;
62 DECL_LINK(QueryTooltip, const weld::TreeIter& rIter, OUString);
64 public:
65 ScriptsListBox(std::unique_ptr<weld::TreeView> xTreeView);
66 ~ScriptsListBox();
68 void ClearAll();
69 static OUString GetDescriptionText(const OUString& rId);
70 OUString GetSelectedScriptName();
72 void connect_changed(const Link<weld::TreeView&, void>& rLink)
74 m_xTreeView->connect_selection_changed(rLink);
76 void connect_popup_menu(const Link<const CommandEvent&, bool>& rLink)
78 m_xTreeView->connect_popup_menu(rLink);
80 void connect_row_activated(const Link<weld::TreeView&, bool>& rLink)
82 m_xTreeView->connect_row_activated(rLink);
84 void freeze() { m_xTreeView->freeze(); }
85 void thaw() { m_xTreeView->thaw(); }
86 void append(const OUString& rId, const OUString& rStr, const OUString& rImage,
87 const weld::TreeIter* pParent = nullptr)
89 m_xTreeView->insert(pParent, -1, &rStr, &rId, nullptr, nullptr, false,
90 m_xScratchIter.get());
91 m_xTreeView->set_image(*m_xScratchIter, rImage);
93 int n_children() const { return m_xTreeView->n_children(); }
94 std::unique_ptr<weld::TreeIter> make_iterator(const weld::TreeIter* pOrig = nullptr) const
96 return m_xTreeView->make_iterator(pOrig);
98 OUString get_id(const weld::TreeIter& rIter) const { return m_xTreeView->get_id(rIter); }
99 bool get_selected(weld::TreeIter* pIter) const { return m_xTreeView->get_selected(pIter); }
100 OUString get_selected_id() const
102 if (!m_xTreeView->get_selected(m_xScratchIter.get()))
103 return OUString();
104 return m_xTreeView->get_id(*m_xScratchIter);
106 void select(int pos) { m_xTreeView->select(pos); }
107 weld::TreeView& get_widget() { return *m_xTreeView; }
109 void Remove(const weld::TreeIter& rEntry);
112 enum class ScriptContainerType
114 LOCATION,
115 LANGUAGE,
116 LIBRARY,
117 MODULEORDIALOG
120 class MacroManagerDialog;
122 // locations, libraries, modules, and dialogs
123 class ScriptContainersListBox
125 friend class MacroManagerDialog;
127 ScriptsListBox* m_pScriptsListBox;
129 css::uno::Reference<css::uno::XComponentContext> m_xContext;
130 css::uno::Reference<css::frame::XFrame> m_xFrame;
132 std::unique_ptr<weld::TreeView> m_xTreeView;
134 void Remove(const weld::TreeIter* pEntryIter, bool bRemoveEntryIter);
135 void Fill(const weld::TreeIter* pEntryIter);
136 basctl::ScriptDocument GetScriptDocument(const weld::TreeIter* pIter = nullptr);
138 DECL_LINK(ExpandingHdl, const weld::TreeIter&, bool);
139 DECL_LINK(QueryTooltip, const weld::TreeIter& rIter, OUString);
141 // for weld::WaitObject which seems not to always behave as expected without the
142 // dialog window as a parent
143 MacroManagerDialog* m_pMacroManagerDialog;
145 public:
146 ScriptContainersListBox(std::unique_ptr<weld::TreeView> xTreeView,
147 MacroManagerDialog* pMacroManagerDialog);
148 ~ScriptContainersListBox();
150 void connect_changed(const Link<weld::TreeView&, void>& rLink)
152 m_xTreeView->connect_selection_changed(rLink);
154 weld::TreeView& get_widget() { return *m_xTreeView; }
155 void ClearAll();
157 void Init(const css::uno::Reference<css::uno::XComponentContext>& xContext,
158 const css::uno::Reference<css::frame::XFrame>& xFrame);
159 void SetScriptsListBox(ScriptsListBox* pBox) { m_pScriptsListBox = pBox; }
160 void ScriptContainerSelected();
162 void Insert(const css::uno::Reference<css::script::browse::XBrowseNode>& xInsertNode,
163 const weld::TreeIter* pParentEntry, const OUString& rsUiName,
164 const OUString& rsImage, bool bChildOnDemand = false, int nPos = -1,
165 weld::TreeIter* pRet = nullptr);
167 OUString GetContainerName(const weld::TreeIter& rIter,
168 const ScriptContainerType eScriptContainerType);
169 OUString GetSelectedEntryContainerName(ScriptContainerType eScriptContainerType);
172 enum class InputDialogMode;
174 class MacroManagerDialog : public weld::GenericDialogController, public SfxListener
176 OUString m_aScriptsListBoxLabelBaseStr;
178 // For forwarding to Assign dialog
179 css::uno::Reference<css::frame::XFrame> m_xDocumentFrame;
181 std::unique_ptr<weld::Label> m_xDialogDescription;
182 std::unique_ptr<ScriptContainersListBox> m_xScriptContainersListBox;
183 std::unique_ptr<ScriptsListBox> m_xScriptsListBox;
184 std::unique_ptr<weld::Label> m_xScriptContainersListBoxLabel;
185 std::unique_ptr<weld::Label> m_xScriptsListBoxLabel;
186 std::unique_ptr<weld::Button> m_xRunButton;
187 std::unique_ptr<weld::Button> m_xCloseButton;
188 std::unique_ptr<weld::TextView> m_xDescriptionText;
189 std::unique_ptr<weld::Frame> m_xDescriptionFrame;
190 std::unique_ptr<weld::Button> m_xNewLibraryButton;
191 std::unique_ptr<weld::Button> m_xNewModuleButton;
192 std::unique_ptr<weld::Button> m_xNewDialogButton;
193 std::unique_ptr<weld::Button> m_xLibraryModuleDialogEditButton;
194 std::unique_ptr<weld::Button> m_xLibraryModuleDialogRenameButton;
195 std::unique_ptr<weld::Button> m_xLibraryModuleDialogDeleteButton;
196 std::unique_ptr<weld::Button> m_xLibraryPasswordButton;
197 std::unique_ptr<weld::Button> m_xLibraryImportButton;
198 std::unique_ptr<weld::Button> m_xLibraryExportButton;
199 std::unique_ptr<weld::Button> m_xMacroEditButton;
200 std::unique_ptr<weld::Button> m_xMacroDeleteButton;
201 std::unique_ptr<weld::Button> m_xMacroCreateButton;
202 std::unique_ptr<weld::Button> m_xMacroRenameButton;
203 std::unique_ptr<weld::Button> m_xAssignButton;
205 DECL_LINK(ClickHdl, weld::Button&, void);
206 DECL_LINK(SelectHdl, weld::TreeView&, void);
207 DECL_LINK(FunctionDoubleClickHdl, weld::TreeView&, bool);
208 DECL_LINK(ContextMenuHdl, const CommandEvent&, bool);
209 DECL_LINK(CheckPasswordHdl, SvxPasswordDialog*, bool);
211 void BasicScriptsCreateLibrary(const basctl::ScriptDocument& rDocument);
212 void BasicScriptsCreateModule(const basctl::ScriptDocument& rDocument);
213 void BasicScriptsCreateDialog(const basctl::ScriptDocument& rDocument);
214 void BasicScriptsLibraryModuleDialogEdit(const basctl::ScriptDocument& rDocument);
215 void BasicScriptsLibraryModuleDialogRename(const basctl::ScriptDocument& rDocument);
216 void BasicScriptsLibraryModuleDialogDelete(const basctl::ScriptDocument& rDocument);
217 void BasicScriptsLibraryPassword(const basctl::ScriptDocument& rDocument);
218 void BasicScriptsMacroEdit(const basctl::ScriptDocument& rDocument);
219 bool IsLibraryReadOnlyOrFailedPasswordQuery(const basctl::ScriptDocument& rDocument,
220 weld::TreeIter* pIter);
222 void ScriptingFrameworkScriptsCreateEntry(InputDialogMode eInputDialogMode);
223 void ScriptingFrameworkScriptsRenameEntry(weld::TreeView& rTreeView,
224 const weld::TreeIter& rEntry);
225 void ScriptingFrameworkScriptsDeleteEntry(weld::TreeView& rTreeView,
226 const weld::TreeIter& rEntry);
227 static bool getBoolProperty(css::uno::Reference<css::beans::XPropertySet> const& xProps,
228 OUString const& propName);
229 OUString getListOfChildren(const css::uno::Reference<css::script::browse::XBrowseNode>& node,
230 int depth);
232 css::uno::Reference<css::script::browse::XBrowseNode>
233 getBrowseNode(const weld::TreeView& rTreeView, const weld::TreeIter& rTreeIter);
235 void UpdateUI();
236 void CheckButtons();
238 virtual void Notify(SfxBroadcaster&, const SfxHint& rHint) override;
240 public:
241 MacroManagerDialog(weld::Window* pParent,
242 const css::uno::Reference<css::frame::XFrame>& xFrame);
243 virtual ~MacroManagerDialog() override;
245 OUString GetScriptURL() const;
247 void SaveLastUsedMacro();
248 void LoadLastUsedMacro();
251 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */