/src/libreoffice/svx/source/form/datanavi.cxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
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 | | * This file incorporates work covered by the following license notice: |
10 | | * |
11 | | * Licensed to the Apache Software Foundation (ASF) under one or more |
12 | | * contributor license agreements. See the NOTICE file distributed |
13 | | * with this work for additional information regarding copyright |
14 | | * ownership. The ASF licenses this file to you under the Apache |
15 | | * License, Version 2.0 (the "License"); you may not use this file |
16 | | * except in compliance with the License. You may obtain a copy of |
17 | | * the License at http://www.apache.org/licenses/LICENSE-2.0 . |
18 | | */ |
19 | | |
20 | | #include <sal/config.h> |
21 | | |
22 | | #include <memory> |
23 | | |
24 | | #include <sal/log.hxx> |
25 | | #include <datanavi.hxx> |
26 | | #include <fmservs.hxx> |
27 | | |
28 | | #include <bitmaps.hlst> |
29 | | #include <fpicker/strings.hrc> |
30 | | #include <o3tl/safeint.hxx> |
31 | | #include <o3tl/string_view.hxx> |
32 | | #include <svx/svxids.hrc> |
33 | | #include <comphelper/diagnose_ex.hxx> |
34 | | #include <unotools/resmgr.hxx> |
35 | | #include <svx/xmlexchg.hxx> |
36 | | #include <unotools/viewoptions.hxx> |
37 | | #include <sfx2/filedlghelper.hxx> |
38 | | #include <sfx2/viewfrm.hxx> |
39 | | #include <sfx2/objsh.hxx> |
40 | | #include <sfx2/bindings.hxx> |
41 | | #include <sfx2/dispatch.hxx> |
42 | | #include <utility> |
43 | | #include <vcl/commandevent.hxx> |
44 | | #include <vcl/event.hxx> |
45 | | #include <vcl/weld/weld.hxx> |
46 | | #include <com/sun/star/beans/PropertyAttribute.hpp> |
47 | | #include <com/sun/star/container/XSet.hpp> |
48 | | #include <com/sun/star/frame/XController.hpp> |
49 | | #include <com/sun/star/ui/dialogs/TemplateDescription.hpp> |
50 | | #include <com/sun/star/xforms/XFormsSupplier.hpp> |
51 | | #include <com/sun/star/xml/dom/XDocument.hpp> |
52 | | #include <comphelper/string.hxx> |
53 | | |
54 | | using namespace ::com::sun::star::beans; |
55 | | using namespace ::com::sun::star::container; |
56 | | using namespace ::com::sun::star::datatransfer; |
57 | | using namespace ::com::sun::star::frame; |
58 | | using namespace ::com::sun::star::uno; |
59 | | using namespace ::com::sun::star::xml::dom::events; |
60 | | using namespace ::svx; |
61 | | |
62 | | constexpr OUString CFGNAME_DATANAVIGATOR = u"DataNavigator"_ustr; |
63 | | constexpr OUString CFGNAME_SHOWDETAILS = u"ShowDetails"_ustr; |
64 | | constexpr OUString MSG_VARIABLE = u"%1"_ustr; |
65 | | constexpr OUStringLiteral MODELNAME = u"$MODELNAME"; |
66 | | constexpr OUStringLiteral INSTANCENAME = u"$INSTANCENAME"; |
67 | | constexpr OUStringLiteral ELEMENTNAME = u"$ELEMENTNAME"; |
68 | | constexpr OUStringLiteral ATTRIBUTENAME = u"$ATTRIBUTENAME"; |
69 | | constexpr OUStringLiteral SUBMISSIONNAME = u"$SUBMISSIONNAME"; |
70 | | constexpr OUStringLiteral BINDINGNAME = u"$BINDINGNAME"; |
71 | | |
72 | | |
73 | | namespace svxform |
74 | | { |
75 | | |
76 | | // properties of instance |
77 | | constexpr OUStringLiteral PN_INSTANCE_MODEL = u"Instance"; |
78 | | constexpr OUString PN_INSTANCE_ID = u"ID"_ustr; |
79 | | constexpr OUStringLiteral PN_INSTANCE_URL = u"URL"; |
80 | | |
81 | | // properties of binding |
82 | | constexpr OUString PN_BINDING_ID = u"BindingID"_ustr; |
83 | | constexpr OUString PN_BINDING_EXPR = u"BindingExpression"_ustr; |
84 | | constexpr OUStringLiteral PN_BINDING_MODEL = u"Model"; |
85 | | constexpr OUString PN_BINDING_NAMESPACES = u"ModelNamespaces"_ustr; |
86 | | constexpr OUString PN_READONLY_EXPR = u"ReadonlyExpression"_ustr; |
87 | | constexpr OUString PN_RELEVANT_EXPR = u"RelevantExpression"_ustr; |
88 | | constexpr OUString PN_REQUIRED_EXPR = u"RequiredExpression"_ustr; |
89 | | constexpr OUString PN_CONSTRAINT_EXPR = u"ConstraintExpression"_ustr; |
90 | | constexpr OUString PN_CALCULATE_EXPR = u"CalculateExpression"_ustr; |
91 | | constexpr OUString PN_BINDING_TYPE = u"Type"_ustr; |
92 | | |
93 | | // properties of submission |
94 | | constexpr OUString PN_SUBMISSION_ID = u"ID"_ustr; |
95 | | constexpr OUString PN_SUBMISSION_BIND = u"Bind"_ustr; |
96 | | constexpr OUString PN_SUBMISSION_REF = u"Ref"_ustr; |
97 | | constexpr OUString PN_SUBMISSION_ACTION = u"Action"_ustr; |
98 | | constexpr OUString PN_SUBMISSION_METHOD = u"Method"_ustr; |
99 | | constexpr OUString PN_SUBMISSION_REPLACE = u"Replace"_ustr; |
100 | | |
101 | | // other const strings |
102 | | constexpr OUString TRUE_VALUE = u"true()"_ustr; |
103 | | constexpr OUStringLiteral NEW_ELEMENT = u"newElement"; |
104 | | constexpr OUStringLiteral NEW_ATTRIBUTE = u"newAttribute"; |
105 | | constexpr OUString EVENTTYPE_CHARDATA = u"DOMCharacterDataModified"_ustr; |
106 | | constexpr OUString EVENTTYPE_ATTR = u"DOMAttrModified"_ustr; |
107 | | |
108 | 0 | #define MIN_PAGE_COUNT 3 // at least one instance, one submission and one binding page |
109 | | |
110 | | struct ItemNode |
111 | | { |
112 | | Reference< css::xml::dom::XNode > m_xNode; |
113 | | Reference< XPropertySet > m_xPropSet; |
114 | | |
115 | | explicit ItemNode( const Reference< css::xml::dom::XNode >& _rxNode ) : |
116 | 0 | m_xNode( _rxNode ) {} |
117 | | explicit ItemNode( const Reference< XPropertySet >& _rxSet ) : |
118 | 0 | m_xPropSet( _rxSet ) {} |
119 | | }; |
120 | | |
121 | | DataTreeDropTarget::DataTreeDropTarget(weld::TreeView& rWidget) |
122 | 0 | : DropTargetHelper(rWidget.get_drop_target()) |
123 | 0 | { |
124 | 0 | } |
125 | | |
126 | | sal_Int8 DataTreeDropTarget::AcceptDrop( const AcceptDropEvent& /*rEvt*/ ) |
127 | 0 | { |
128 | 0 | return DND_ACTION_NONE; |
129 | 0 | } |
130 | | |
131 | | sal_Int8 DataTreeDropTarget::ExecuteDrop( const ExecuteDropEvent& /*rEvt*/ ) |
132 | 0 | { |
133 | 0 | return DND_ACTION_NONE; |
134 | 0 | } |
135 | | |
136 | | IMPL_LINK(XFormsPage, PopupMenuHdl, const CommandEvent&, rCEvt, bool) |
137 | 0 | { |
138 | 0 | if (rCEvt.GetCommand() != CommandEventId::ContextMenu) |
139 | 0 | return false; |
140 | | |
141 | 0 | Point aPos(rCEvt.GetMousePosPixel()); |
142 | |
|
143 | 0 | if (m_xItemList->get_dest_row_at_pos(aPos, m_xScratchIter.get(), false) && !m_xItemList->is_selected(*m_xScratchIter)) |
144 | 0 | { |
145 | 0 | m_xItemList->select(*m_xScratchIter); |
146 | 0 | ItemSelectHdl(*m_xItemList); |
147 | 0 | } |
148 | |
|
149 | 0 | std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(m_xItemList.get(), u"svx/ui/formdatamenu.ui"_ustr)); |
150 | 0 | m_xMenu = xBuilder->weld_menu(u"menu"_ustr); |
151 | 0 | m_aRemovedMenuEntries.clear(); |
152 | |
|
153 | 0 | if (DGTInstance == m_eGroup) |
154 | 0 | m_aRemovedMenuEntries.insert(u"additem"_ustr); |
155 | 0 | else |
156 | 0 | { |
157 | 0 | m_aRemovedMenuEntries.insert(u"addelement"_ustr); |
158 | 0 | m_aRemovedMenuEntries.insert(u"addattribute"_ustr); |
159 | |
|
160 | 0 | if (DGTSubmission == m_eGroup) |
161 | 0 | { |
162 | 0 | m_xMenu->set_label(u"additem"_ustr, SvxResId(RID_STR_DATANAV_ADD_SUBMISSION)); |
163 | 0 | m_xMenu->set_label(u"edit"_ustr, SvxResId(RID_STR_DATANAV_EDIT_SUBMISSION)); |
164 | 0 | m_xMenu->set_label(u"delete"_ustr, SvxResId(RID_STR_DATANAV_REMOVE_SUBMISSION)); |
165 | 0 | } |
166 | 0 | else |
167 | 0 | { |
168 | 0 | m_xMenu->set_label(u"additem"_ustr, SvxResId(RID_STR_DATANAV_ADD_BINDING)); |
169 | 0 | m_xMenu->set_label(u"edit"_ustr, SvxResId(RID_STR_DATANAV_EDIT_BINDING)); |
170 | 0 | m_xMenu->set_label(u"delete"_ustr, SvxResId(RID_STR_DATANAV_REMOVE_BINDING)); |
171 | 0 | } |
172 | 0 | } |
173 | 0 | for (const auto& rRemove : m_aRemovedMenuEntries) |
174 | 0 | m_xMenu->remove(rRemove); |
175 | 0 | EnableMenuItems(); |
176 | 0 | OUString sCommand = m_xMenu->popup_at_rect(m_xItemList.get(), tools::Rectangle(aPos, Size(1,1))); |
177 | 0 | if (!sCommand.isEmpty()) |
178 | 0 | DoMenuAction(sCommand); |
179 | 0 | m_xMenu.reset(); |
180 | 0 | return true; |
181 | 0 | } |
182 | | |
183 | | void XFormsPage::DeleteAndClearTree() |
184 | 0 | { |
185 | 0 | m_xItemList->all_foreach([this](weld::TreeIter& rEntry) { |
186 | 0 | delete weld::fromId<ItemNode*>(m_xItemList->get_id(rEntry)); |
187 | 0 | return false; |
188 | 0 | }); |
189 | 0 | m_xItemList->clear(); |
190 | 0 | } |
191 | | |
192 | | void XFormsPage::SelectFirstEntry() |
193 | 0 | { |
194 | 0 | if (m_xItemList->get_iter_first(*m_xScratchIter)) |
195 | 0 | { |
196 | 0 | m_xItemList->select(*m_xScratchIter); |
197 | 0 | ItemSelectHdl(*m_xItemList); |
198 | 0 | } |
199 | 0 | } |
200 | | |
201 | | XFormsPage::XFormsPage(weld::Container* pPage, DataNavigatorWindow* _pNaviWin, DataGroupType _eGroup) |
202 | 0 | : BuilderPage(pPage, nullptr, u"svx/ui/xformspage.ui"_ustr, u"XFormsPage"_ustr) |
203 | 0 | , m_pParent(pPage) |
204 | 0 | , m_xToolBox(m_xBuilder->weld_toolbar(u"toolbar"_ustr)) |
205 | 0 | , m_xItemList(m_xBuilder->weld_tree_view(u"items"_ustr)) |
206 | 0 | , m_xScratchIter(m_xItemList->make_iterator()) |
207 | 0 | , m_aDropHelper(*m_xItemList) |
208 | 0 | , m_pNaviWin(_pNaviWin) |
209 | 0 | , m_bHasModel(false) |
210 | 0 | , m_eGroup(_eGroup) |
211 | 0 | , m_bLinkOnce(false) |
212 | 0 | { |
213 | 0 | m_xItemList->set_show_expanders(DGTInstance == m_eGroup || DGTSubmission == m_eGroup); |
214 | |
|
215 | 0 | if ( DGTInstance == m_eGroup ) |
216 | 0 | m_xToolBox->set_item_visible(u"additem"_ustr, false); |
217 | 0 | else |
218 | 0 | { |
219 | 0 | m_xToolBox->set_item_visible(u"addelement"_ustr, false); |
220 | 0 | m_xToolBox->set_item_visible(u"addattribute"_ustr, false); |
221 | |
|
222 | 0 | if ( DGTSubmission == m_eGroup ) |
223 | 0 | { |
224 | 0 | m_xToolBox->set_item_label(u"additem"_ustr, SvxResId(RID_STR_DATANAV_ADD_SUBMISSION)); |
225 | 0 | m_xToolBox->set_item_label(u"edit"_ustr, SvxResId(RID_STR_DATANAV_EDIT_SUBMISSION)); |
226 | 0 | m_xToolBox->set_item_label(u"delete"_ustr, SvxResId(RID_STR_DATANAV_REMOVE_SUBMISSION)); |
227 | 0 | } |
228 | 0 | else |
229 | 0 | { |
230 | 0 | m_xToolBox->set_item_label(u"additem"_ustr, SvxResId(RID_STR_DATANAV_ADD_BINDING)); |
231 | 0 | m_xToolBox->set_item_label(u"edit"_ustr, SvxResId(RID_STR_DATANAV_EDIT_BINDING)); |
232 | 0 | m_xToolBox->set_item_label(u"delete"_ustr, SvxResId(RID_STR_DATANAV_REMOVE_BINDING)); |
233 | 0 | } |
234 | 0 | } |
235 | |
|
236 | 0 | m_xToolBox->connect_clicked(LINK(this, XFormsPage, TbxSelectHdl)); |
237 | |
|
238 | 0 | m_xItemList->connect_selection_changed(LINK(this, XFormsPage, ItemSelectHdl)); |
239 | 0 | m_xItemList->connect_key_press(LINK(this, XFormsPage, KeyInputHdl)); |
240 | 0 | m_xItemList->connect_command(LINK(this, XFormsPage, PopupMenuHdl)); |
241 | 0 | ItemSelectHdl(*m_xItemList); |
242 | 0 | } |
243 | | |
244 | | XFormsPage::~XFormsPage() |
245 | 0 | { |
246 | 0 | DeleteAndClearTree(); |
247 | 0 | m_pNaviWin = nullptr; |
248 | 0 | m_pParent->move(m_xContainer.get(), nullptr); |
249 | 0 | } |
250 | | |
251 | | IMPL_LINK(XFormsPage, TbxSelectHdl, const OUString&, rIdent, void) |
252 | 0 | { |
253 | 0 | DoToolBoxAction(rIdent); |
254 | 0 | } |
255 | | |
256 | | IMPL_LINK_NOARG(XFormsPage, ItemSelectHdl, weld::TreeView&, void) |
257 | 0 | { |
258 | 0 | EnableMenuItems(); |
259 | 0 | PrepDnD(); |
260 | 0 | } |
261 | | |
262 | | void XFormsPage::PrepDnD() |
263 | 0 | { |
264 | 0 | rtl::Reference<TransferDataContainer> xTransferable(new TransferDataContainer); |
265 | 0 | m_xItemList->enable_drag_source(xTransferable, DND_ACTION_NONE); |
266 | |
|
267 | 0 | std::unique_ptr<weld::TreeIter> pIter = m_xItemList->get_selected(); |
268 | 0 | if (!pIter) |
269 | 0 | { |
270 | | // no drag without an entry |
271 | 0 | return; |
272 | 0 | } |
273 | | |
274 | 0 | if ( m_eGroup == DGTBinding ) |
275 | 0 | { |
276 | | // for the moment, bindings cannot be dragged. |
277 | | // #i59395# / 2005-12-15 / frank.schoenheit@sun.com |
278 | 0 | return; |
279 | 0 | } |
280 | | |
281 | | // GetServiceNameForNode() requires a datatype repository which |
282 | | // will be automatically build if requested??? |
283 | 0 | Reference< css::xforms::XModel > xModel( GetXFormsHelper(), UNO_QUERY ); |
284 | 0 | Reference< css::xforms::XDataTypeRepository > xDataTypes = |
285 | 0 | xModel->getDataTypeRepository(); |
286 | 0 | if(!xDataTypes.is()) |
287 | 0 | return; |
288 | | |
289 | 0 | ItemNode *pItemNode = weld::fromId<ItemNode*>(m_xItemList->get_id(*pIter)); |
290 | 0 | if (!pItemNode) |
291 | 0 | { |
292 | | // the only known (and allowed?) case where this happens are sub-entries of a submission |
293 | | // entry |
294 | 0 | DBG_ASSERT( DGTSubmission == m_eGroup, "DataTreeListBox::StartDrag: how this?" ); |
295 | 0 | bool bSelected = m_xItemList->iter_parent(*pIter); |
296 | 0 | DBG_ASSERT(bSelected && !m_xItemList->get_iter_depth(*pIter), "DataTreeListBox::StartDrag: what kind of entry *is* this?"); |
297 | | // on the submission page, we have only top-level entries (the submission themself) |
298 | | // plus direct children of those (facets of a submission) |
299 | 0 | pItemNode = bSelected ? weld::fromId<ItemNode*>(m_xItemList->get_id(*pIter)) : nullptr; |
300 | 0 | if (!pItemNode) |
301 | 0 | return; |
302 | 0 | } |
303 | | |
304 | 0 | OUString szName = m_xItemList->get_text(*pIter); |
305 | 0 | Reference<css::xml::dom::XNode> xNode(pItemNode->m_xNode); |
306 | 0 | Reference<XPropertySet> xPropSet(pItemNode->m_xPropSet); |
307 | | |
308 | | // tdf#154535 create the OXFormsDescriptor on-demand so we don't cause an unwanted |
309 | | // Binding to be created unless we are forced to. |
310 | 0 | auto fnCreateFormsDescriptor = [this, szName=std::move(szName), xNode=std::move(xNode), xPropSet=std::move(xPropSet)](){ |
311 | 0 | OXFormsDescriptor desc; |
312 | 0 | desc.szName = szName; |
313 | 0 | if (xNode) { |
314 | | // a valid node interface tells us that we need to create a control from a binding |
315 | 0 | desc.szServiceName = GetServiceNameForNode(xNode); |
316 | 0 | desc.xPropSet = GetBindingForNode(xNode); |
317 | 0 | DBG_ASSERT( desc.xPropSet.is(), "DataTreeListBox::StartDrag(): invalid node binding" ); |
318 | 0 | } |
319 | 0 | else { |
320 | 0 | desc.szServiceName = FM_COMPONENT_COMMANDBUTTON; |
321 | 0 | desc.xPropSet = xPropSet; |
322 | 0 | } |
323 | 0 | return desc; |
324 | 0 | }; |
325 | |
|
326 | 0 | xTransferable = rtl::Reference<TransferDataContainer>(new OXFormsTransferable(fnCreateFormsDescriptor)); |
327 | 0 | m_xItemList->enable_drag_source(xTransferable, DND_ACTION_COPY); |
328 | 0 | } |
329 | | |
330 | | void XFormsPage::AddChildren(const weld::TreeIter* _pParent, |
331 | | const Reference< css::xml::dom::XNode >& _xNode) |
332 | 0 | { |
333 | 0 | DBG_ASSERT( m_xUIHelper.is(), "XFormsPage::AddChildren(): invalid UIHelper" ); |
334 | |
|
335 | 0 | try |
336 | 0 | { |
337 | 0 | Reference< css::xml::dom::XNodeList > xNodeList = _xNode->getChildNodes(); |
338 | 0 | if ( xNodeList.is() ) |
339 | 0 | { |
340 | 0 | bool bShowDetails = m_pNaviWin->IsShowDetails(); |
341 | 0 | sal_Int32 i, nNodeCount = xNodeList->getLength(); |
342 | 0 | for ( i = 0; i < nNodeCount; ++i ) |
343 | 0 | { |
344 | 0 | Reference< css::xml::dom::XNode > xChild = xNodeList->item(i); |
345 | 0 | css::xml::dom::NodeType eChildType = xChild->getNodeType(); |
346 | 0 | OUString aExpImg; |
347 | 0 | switch ( eChildType ) |
348 | 0 | { |
349 | 0 | case css::xml::dom::NodeType_ATTRIBUTE_NODE: |
350 | 0 | aExpImg = RID_SVXBMP_ATTRIBUTE; |
351 | 0 | break; |
352 | 0 | case css::xml::dom::NodeType_ELEMENT_NODE: |
353 | 0 | aExpImg = RID_SVXBMP_ELEMENT; |
354 | 0 | break; |
355 | 0 | case css::xml::dom::NodeType_TEXT_NODE: |
356 | 0 | aExpImg = RID_SVXBMP_TEXT; |
357 | 0 | break; |
358 | 0 | default: |
359 | 0 | aExpImg = RID_SVXBMP_OTHER; |
360 | 0 | } |
361 | | |
362 | 0 | OUString sName = m_xUIHelper->getNodeDisplayName( xChild, bShowDetails ); |
363 | 0 | if ( !sName.isEmpty() ) |
364 | 0 | { |
365 | 0 | ItemNode* pNode = new ItemNode( xChild ); |
366 | 0 | OUString sId(weld::toId(pNode)); |
367 | 0 | std::unique_ptr<weld::TreeIter> xEntry = m_xItemList->make_iterator(); |
368 | 0 | m_xItemList->insert(_pParent, -1, &sName, &sId, nullptr, nullptr, false, xEntry.get()); |
369 | 0 | m_xItemList->set_image(*xEntry, aExpImg); |
370 | |
|
371 | 0 | if ( xChild->hasAttributes() ) |
372 | 0 | { |
373 | 0 | Reference< css::xml::dom::XNamedNodeMap > xMap = xChild->getAttributes(); |
374 | 0 | if ( xMap.is() ) |
375 | 0 | { |
376 | 0 | aExpImg = RID_SVXBMP_ATTRIBUTE; |
377 | 0 | sal_Int32 j, nMapLen = xMap->getLength(); |
378 | 0 | for ( j = 0; j < nMapLen; ++j ) |
379 | 0 | { |
380 | 0 | Reference< css::xml::dom::XNode > xAttr = xMap->item(j); |
381 | 0 | pNode = new ItemNode( xAttr ); |
382 | 0 | OUString sSubId(weld::toId(pNode)); |
383 | 0 | OUString sAttrName = m_xUIHelper->getNodeDisplayName( xAttr, bShowDetails ); |
384 | 0 | m_xItemList->insert(xEntry.get(), -1, &sAttrName, &sSubId, nullptr, nullptr, false, m_xScratchIter.get()); |
385 | 0 | m_xItemList->set_image(*m_xScratchIter, aExpImg); |
386 | 0 | } |
387 | 0 | } |
388 | 0 | } |
389 | 0 | if ( xChild->hasChildNodes() ) |
390 | 0 | AddChildren(xEntry.get(), xChild); |
391 | 0 | } |
392 | 0 | } |
393 | 0 | } |
394 | 0 | } |
395 | 0 | catch( Exception& ) |
396 | 0 | { |
397 | 0 | DBG_UNHANDLED_EXCEPTION("svx"); |
398 | 0 | } |
399 | 0 | } |
400 | | |
401 | | bool XFormsPage::DoToolBoxAction(std::u16string_view rToolBoxID) |
402 | 0 | { |
403 | 0 | bool bHandled = false; |
404 | 0 | bool bIsDocModified = false; |
405 | 0 | m_pNaviWin->DisableNotify( true ); |
406 | |
|
407 | 0 | if (rToolBoxID == u"additem" || rToolBoxID == u"addelement" || rToolBoxID == u"addattribute") |
408 | 0 | { |
409 | 0 | bHandled = true; |
410 | 0 | Reference< css::xforms::XModel > xModel( m_xUIHelper, UNO_QUERY ); |
411 | 0 | DBG_ASSERT( xModel.is(), "XFormsPage::DoToolBoxAction(): Action without model" ); |
412 | 0 | if ( DGTSubmission == m_eGroup ) |
413 | 0 | { |
414 | 0 | AddSubmissionDialog aDlg(m_pNaviWin->GetFrameWeld(), nullptr, m_xUIHelper); |
415 | 0 | if ( aDlg.run() == RET_OK && aDlg.GetNewSubmission().is() ) |
416 | 0 | { |
417 | 0 | try |
418 | 0 | { |
419 | 0 | const Reference< css::xforms::XSubmission >& xNewSubmission = aDlg.GetNewSubmission(); |
420 | 0 | Reference< XSet > xSubmissions = xModel->getSubmissions(); |
421 | 0 | xSubmissions->insert( Any( xNewSubmission ) ); |
422 | 0 | AddEntry(xNewSubmission, m_xScratchIter.get()); |
423 | 0 | m_xItemList->select(*m_xScratchIter); |
424 | 0 | bIsDocModified = true; |
425 | 0 | } |
426 | 0 | catch ( Exception const & ) |
427 | 0 | { |
428 | 0 | TOOLS_WARN_EXCEPTION( "svx.form", "XFormsPage::DoToolBoxAction()" ); |
429 | 0 | } |
430 | 0 | } |
431 | 0 | } |
432 | 0 | else |
433 | 0 | { |
434 | 0 | DataItemType eType = DITElement; |
435 | |
|
436 | 0 | std::unique_ptr<weld::TreeIter> xEntry = m_xItemList->get_selected(); |
437 | |
|
438 | 0 | std::unique_ptr<ItemNode> pNode; |
439 | 0 | Reference< css::xml::dom::XNode > xParentNode; |
440 | 0 | Reference< XPropertySet > xNewBinding; |
441 | 0 | TranslateId pResId; |
442 | 0 | bool bIsElement = true; |
443 | 0 | if ( DGTInstance == m_eGroup ) |
444 | 0 | { |
445 | 0 | if ( !m_sInstanceURL.isEmpty() ) |
446 | 0 | { |
447 | 0 | LinkedInstanceWarningBox aMsgBox(m_pNaviWin->GetFrameWeld()); |
448 | 0 | if (aMsgBox.run() != RET_OK) |
449 | 0 | return bHandled; |
450 | 0 | } |
451 | 0 | assert(xEntry && "XFormsPage::DoToolBoxAction(): no entry"); |
452 | 0 | ItemNode* pParentNode = weld::fromId<ItemNode*>(m_xItemList->get_id(*xEntry)); |
453 | 0 | assert(pParentNode && "XFormsPage::DoToolBoxAction(): no parent node"); |
454 | 0 | xParentNode = pParentNode->m_xNode; |
455 | 0 | Reference< css::xml::dom::XNode > xNewNode; |
456 | 0 | if (rToolBoxID == u"addelement") |
457 | 0 | { |
458 | 0 | try |
459 | 0 | { |
460 | 0 | pResId = RID_STR_DATANAV_ADD_ELEMENT; |
461 | 0 | xNewNode = m_xUIHelper->createElement( xParentNode, NEW_ELEMENT ); |
462 | 0 | } |
463 | 0 | catch ( Exception const & ) |
464 | 0 | { |
465 | 0 | TOOLS_WARN_EXCEPTION( "svx.form", "XFormsPage::DoToolBoxAction(): exception while create element" ); |
466 | 0 | } |
467 | 0 | } |
468 | 0 | else |
469 | 0 | { |
470 | 0 | pResId = RID_STR_DATANAV_ADD_ATTRIBUTE; |
471 | 0 | bIsElement = false; |
472 | 0 | eType = DITAttribute; |
473 | 0 | try |
474 | 0 | { |
475 | 0 | xNewNode = m_xUIHelper->createAttribute( xParentNode, NEW_ATTRIBUTE ); |
476 | 0 | } |
477 | 0 | catch ( Exception const & ) |
478 | 0 | { |
479 | 0 | TOOLS_WARN_EXCEPTION( "svx.form", "XFormsPage::DoToolBoxAction(): exception while create attribute" ); |
480 | 0 | } |
481 | 0 | } |
482 | | |
483 | 0 | try |
484 | 0 | { |
485 | 0 | xNewNode = xParentNode->appendChild( xNewNode ); |
486 | 0 | } |
487 | 0 | catch ( Exception const & ) |
488 | 0 | { |
489 | 0 | TOOLS_WARN_EXCEPTION( "svx.form", "XFormsPage::DoToolBoxAction(): exception while append child" ); |
490 | 0 | } |
491 | | |
492 | 0 | try |
493 | 0 | { |
494 | 0 | Reference< css::xml::dom::XNode > xPNode; |
495 | 0 | if ( xNewNode.is() ) |
496 | 0 | xPNode = xNewNode->getParentNode(); |
497 | | // attributes don't have parents in the DOM model |
498 | 0 | DBG_ASSERT( rToolBoxID == u"addattribute" |
499 | 0 | || xPNode.is(), "XFormsPage::DoToolboxAction(): node not added" ); |
500 | 0 | } |
501 | 0 | catch ( Exception const & ) |
502 | 0 | { |
503 | 0 | TOOLS_WARN_EXCEPTION( "svx.form", "XFormsPage::DoToolboxAction()" ); |
504 | 0 | } |
505 | | |
506 | 0 | try |
507 | 0 | { |
508 | 0 | m_xUIHelper->getBindingForNode( xNewNode, true ); |
509 | 0 | } |
510 | 0 | catch ( Exception const & ) |
511 | 0 | { |
512 | 0 | TOOLS_WARN_EXCEPTION( "svx.form", "XFormsPage::DoToolBoxAction(): exception while get binding for node" ); |
513 | 0 | } |
514 | 0 | pNode.reset(new ItemNode( xNewNode )); |
515 | 0 | } |
516 | 0 | else |
517 | 0 | { |
518 | 0 | try |
519 | 0 | { |
520 | 0 | pResId = RID_STR_DATANAV_ADD_BINDING; |
521 | 0 | xNewBinding = xModel->createBinding(); |
522 | 0 | Reference< XSet > xBindings = xModel->getBindings(); |
523 | 0 | xBindings->insert( Any( xNewBinding ) ); |
524 | 0 | pNode.reset(new ItemNode( xNewBinding )); |
525 | 0 | eType = DITBinding; |
526 | 0 | } |
527 | 0 | catch ( Exception const & ) |
528 | 0 | { |
529 | 0 | TOOLS_WARN_EXCEPTION( "svx.form", "XFormsPage::DoToolBoxAction(): exception while adding binding" ); |
530 | 0 | } |
531 | 0 | } |
532 | | |
533 | 0 | AddDataItemDialog aDlg(m_pNaviWin->GetFrameWeld(), pNode.get(), m_xUIHelper); |
534 | 0 | aDlg.set_title(SvxResId(pResId)); |
535 | 0 | aDlg.InitText( eType ); |
536 | 0 | short nReturn = aDlg.run(); |
537 | 0 | if ( DGTInstance == m_eGroup ) |
538 | 0 | { |
539 | 0 | if ( RET_OK == nReturn ) |
540 | 0 | { |
541 | 0 | AddEntry( std::move(pNode), bIsElement, m_xScratchIter.get()); |
542 | 0 | m_xItemList->scroll_to_row(*m_xScratchIter); |
543 | 0 | m_xItemList->select(*m_xScratchIter); |
544 | 0 | bIsDocModified = true; |
545 | 0 | } |
546 | 0 | else |
547 | 0 | { |
548 | 0 | try |
549 | 0 | { |
550 | 0 | Reference< css::xml::dom::XNode > xPNode; |
551 | 0 | Reference< css::xml::dom::XNode > xNode = |
552 | 0 | xParentNode->removeChild( pNode->m_xNode ); |
553 | 0 | if ( xNode.is() ) |
554 | 0 | xPNode = xNode->getParentNode(); |
555 | 0 | DBG_ASSERT( !xPNode.is(), "XFormsPage::RemoveEntry(): node not removed" ); |
556 | 0 | } |
557 | 0 | catch ( Exception const & ) |
558 | 0 | { |
559 | 0 | TOOLS_WARN_EXCEPTION( "svx.form", "XFormsPage::DoToolboxAction()" ); |
560 | 0 | } |
561 | 0 | } |
562 | 0 | } |
563 | 0 | else |
564 | 0 | { |
565 | 0 | if ( RET_OK == nReturn ) |
566 | 0 | { |
567 | 0 | AddEntry(xNewBinding, m_xScratchIter.get()); |
568 | 0 | m_xItemList->select(*m_xScratchIter); |
569 | 0 | bIsDocModified = true; |
570 | 0 | } |
571 | 0 | else |
572 | 0 | { |
573 | 0 | try |
574 | 0 | { |
575 | 0 | Reference< XSet > xBindings = xModel->getBindings(); |
576 | 0 | xBindings->remove( Any( xNewBinding ) ); |
577 | 0 | } |
578 | 0 | catch ( Exception const & ) |
579 | 0 | { |
580 | 0 | TOOLS_WARN_EXCEPTION( "svx.form", "XFormsPage::DoToolboxAction()" ); |
581 | 0 | } |
582 | 0 | } |
583 | 0 | } |
584 | 0 | } |
585 | 0 | } |
586 | 0 | else if (rToolBoxID == u"edit") |
587 | 0 | { |
588 | 0 | bHandled = true; |
589 | |
|
590 | 0 | if (std::unique_ptr<weld::TreeIter> xEntry = m_xItemList->get_selected()) |
591 | 0 | { |
592 | 0 | if ( DGTSubmission == m_eGroup && m_xItemList->get_iter_depth(*xEntry) ) |
593 | 0 | { |
594 | 0 | m_xItemList->iter_parent(*xEntry); |
595 | 0 | } |
596 | 0 | ItemNode* pNode = weld::fromId<ItemNode*>(m_xItemList->get_id(*xEntry)); |
597 | 0 | if ( DGTInstance == m_eGroup || DGTBinding == m_eGroup ) |
598 | 0 | { |
599 | 0 | if ( DGTInstance == m_eGroup && !m_sInstanceURL.isEmpty() ) |
600 | 0 | { |
601 | 0 | LinkedInstanceWarningBox aMsgBox(m_pNaviWin->GetFrameWeld()); |
602 | 0 | if (aMsgBox.run() != RET_OK) |
603 | 0 | return bHandled; |
604 | 0 | } |
605 | | |
606 | 0 | AddDataItemDialog aDlg(m_pNaviWin->GetFrameWeld(), pNode, m_xUIHelper); |
607 | 0 | DataItemType eType = DITElement; |
608 | 0 | TranslateId pResId = RID_STR_DATANAV_EDIT_ELEMENT; |
609 | 0 | if ( pNode && pNode->m_xNode.is() ) |
610 | 0 | { |
611 | 0 | try |
612 | 0 | { |
613 | 0 | css::xml::dom::NodeType eChildType = pNode->m_xNode->getNodeType(); |
614 | 0 | if ( eChildType == css::xml::dom::NodeType_ATTRIBUTE_NODE ) |
615 | 0 | { |
616 | 0 | pResId = RID_STR_DATANAV_EDIT_ATTRIBUTE; |
617 | 0 | eType = DITAttribute; |
618 | 0 | } |
619 | 0 | } |
620 | 0 | catch ( Exception const & ) |
621 | 0 | { |
622 | 0 | TOOLS_WARN_EXCEPTION( "svx.form", "XFormsPage::DoToolboxAction()" ); |
623 | 0 | } |
624 | 0 | } |
625 | 0 | else if ( DGTBinding == m_eGroup ) |
626 | 0 | { |
627 | 0 | pResId = RID_STR_DATANAV_EDIT_BINDING; |
628 | 0 | eType = DITBinding; |
629 | 0 | } |
630 | 0 | aDlg.set_title(SvxResId(pResId)); |
631 | 0 | aDlg.InitText( eType ); |
632 | 0 | if (aDlg.run() == RET_OK) |
633 | 0 | { |
634 | | // Set the new name |
635 | 0 | OUString sNewName; |
636 | 0 | if (pNode) |
637 | 0 | { |
638 | 0 | if ( DGTInstance == m_eGroup ) |
639 | 0 | { |
640 | 0 | try |
641 | 0 | { |
642 | 0 | sNewName = m_xUIHelper->getNodeDisplayName( |
643 | 0 | pNode->m_xNode, m_pNaviWin->IsShowDetails() ); |
644 | 0 | } |
645 | 0 | catch ( Exception const & ) |
646 | 0 | { |
647 | 0 | TOOLS_WARN_EXCEPTION( "svx.form", "XFormsPage::DoToolboxAction()" ); |
648 | 0 | } |
649 | 0 | } |
650 | 0 | else |
651 | 0 | { |
652 | 0 | try |
653 | 0 | { |
654 | 0 | OUString sTemp; |
655 | 0 | pNode->m_xPropSet->getPropertyValue( PN_BINDING_ID ) >>= sTemp; |
656 | 0 | sNewName += sTemp + ": "; |
657 | 0 | pNode->m_xPropSet->getPropertyValue( PN_BINDING_EXPR ) >>= sTemp; |
658 | 0 | sNewName += sTemp; |
659 | 0 | } |
660 | 0 | catch ( Exception const & ) |
661 | 0 | { |
662 | 0 | TOOLS_WARN_EXCEPTION( "svx.form", "XFormsPage::DoToolboxAction()" ); |
663 | 0 | } |
664 | 0 | } |
665 | 0 | } |
666 | | |
667 | 0 | m_xItemList->set_text(*xEntry, sNewName); |
668 | 0 | bIsDocModified = true; |
669 | 0 | } |
670 | 0 | } |
671 | 0 | else |
672 | 0 | { |
673 | 0 | AddSubmissionDialog aDlg(m_pNaviWin->GetFrameWeld(), pNode, m_xUIHelper); |
674 | 0 | aDlg.set_title(SvxResId(RID_STR_DATANAV_EDIT_SUBMISSION)); |
675 | 0 | if (aDlg.run() == RET_OK) |
676 | 0 | { |
677 | 0 | EditEntry( pNode->m_xPropSet ); |
678 | 0 | bIsDocModified = true; |
679 | 0 | } |
680 | 0 | } |
681 | 0 | } |
682 | 0 | } |
683 | 0 | else if (rToolBoxID == u"delete") |
684 | 0 | { |
685 | 0 | bHandled = true; |
686 | 0 | if ( DGTInstance == m_eGroup && !m_sInstanceURL.isEmpty() ) |
687 | 0 | { |
688 | 0 | LinkedInstanceWarningBox aMsgBox(m_pNaviWin->GetFrameWeld()); |
689 | 0 | if (aMsgBox.run() != RET_OK) |
690 | 0 | return bHandled; |
691 | 0 | } |
692 | 0 | bIsDocModified = RemoveEntry(); |
693 | 0 | } |
694 | 0 | else |
695 | 0 | { |
696 | 0 | OSL_FAIL( "XFormsPage::DoToolboxAction: unknown ID!" ); |
697 | 0 | } |
698 | | |
699 | 0 | m_pNaviWin->DisableNotify( false ); |
700 | 0 | EnableMenuItems(); |
701 | 0 | if ( bIsDocModified ) |
702 | 0 | svxform::DataNavigatorWindow::SetDocModified(); |
703 | 0 | return bHandled; |
704 | 0 | } |
705 | | |
706 | | void XFormsPage::AddEntry(std::unique_ptr<ItemNode> _pNewNode, bool _bIsElement, weld::TreeIter* pRet) |
707 | 0 | { |
708 | 0 | if (!pRet) |
709 | 0 | pRet = m_xScratchIter.get(); |
710 | |
|
711 | 0 | std::unique_ptr<weld::TreeIter> xParent = m_xItemList->get_selected(); |
712 | 0 | OUString aImage(_bIsElement ? RID_SVXBMP_ELEMENT : RID_SVXBMP_ATTRIBUTE); |
713 | 0 | OUString sName; |
714 | 0 | try |
715 | 0 | { |
716 | 0 | sName = m_xUIHelper->getNodeDisplayName( |
717 | 0 | _pNewNode->m_xNode, m_pNaviWin->IsShowDetails() ); |
718 | 0 | } |
719 | 0 | catch ( Exception& ) |
720 | 0 | { |
721 | 0 | DBG_UNHANDLED_EXCEPTION("svx"); |
722 | 0 | } |
723 | 0 | OUString sId(weld::toId(_pNewNode.release())); |
724 | 0 | m_xItemList->insert(xParent.get(), -1, &sName, &sId, nullptr, nullptr, false, pRet); |
725 | 0 | m_xItemList->set_image(*pRet, aImage); |
726 | 0 | if (xParent && !m_xItemList->get_row_expanded(*xParent) && m_xItemList->iter_has_child(*xParent)) |
727 | 0 | m_xItemList->expand_row(*xParent); |
728 | 0 | } |
729 | | |
730 | | void XFormsPage::AddEntry(const Reference< XPropertySet >& _rEntry, weld::TreeIter* pRet) |
731 | 0 | { |
732 | 0 | if (!pRet) |
733 | 0 | pRet = m_xScratchIter.get(); |
734 | |
|
735 | 0 | OUString aImage(RID_SVXBMP_ELEMENT); |
736 | |
|
737 | 0 | ItemNode* pNode = new ItemNode( _rEntry ); |
738 | 0 | OUString sTemp; |
739 | |
|
740 | 0 | if ( DGTSubmission == m_eGroup ) |
741 | 0 | { |
742 | 0 | try |
743 | 0 | { |
744 | | // ID |
745 | 0 | _rEntry->getPropertyValue( PN_SUBMISSION_ID ) >>= sTemp; |
746 | 0 | OUString sId(weld::toId(pNode)); |
747 | 0 | m_xItemList->insert(nullptr, -1, &sTemp, &sId, nullptr, nullptr, false, pRet); |
748 | 0 | m_xItemList->set_image(*pRet, aImage); |
749 | 0 | std::unique_ptr<weld::TreeIter> xRes(m_xItemList->make_iterator()); |
750 | | // Action |
751 | 0 | _rEntry->getPropertyValue( PN_SUBMISSION_ACTION ) >>= sTemp; |
752 | 0 | OUString sEntry = SvxResId( RID_STR_DATANAV_SUBM_ACTION ) + sTemp; |
753 | 0 | m_xItemList->insert(pRet, -1, &sEntry, nullptr, nullptr, nullptr, false, xRes.get()); |
754 | 0 | m_xItemList->set_image(*xRes, aImage); |
755 | | // Method |
756 | 0 | _rEntry->getPropertyValue( PN_SUBMISSION_METHOD ) >>= sTemp; |
757 | 0 | sEntry = SvxResId( RID_STR_DATANAV_SUBM_METHOD ) + |
758 | 0 | m_aMethodString.toUI( sTemp ); |
759 | 0 | m_xItemList->insert(pRet, -1, &sEntry, nullptr, nullptr, nullptr, false, xRes.get()); |
760 | 0 | m_xItemList->set_image(*xRes, aImage); |
761 | | // Ref |
762 | 0 | _rEntry->getPropertyValue( PN_SUBMISSION_REF ) >>= sTemp; |
763 | 0 | sEntry = SvxResId( RID_STR_DATANAV_SUBM_REF ) + sTemp; |
764 | 0 | m_xItemList->insert(pRet, -1, &sEntry, nullptr, nullptr, nullptr, false, xRes.get()); |
765 | 0 | m_xItemList->set_image(*xRes, aImage); |
766 | | // Bind |
767 | 0 | _rEntry->getPropertyValue( PN_SUBMISSION_BIND ) >>= sTemp; |
768 | 0 | sEntry = SvxResId( RID_STR_DATANAV_SUBM_BIND ) + sTemp; |
769 | 0 | m_xItemList->insert(pRet, -1, &sEntry, nullptr, nullptr, nullptr, false, xRes.get()); |
770 | 0 | m_xItemList->set_image(*xRes, aImage); |
771 | | // Replace |
772 | 0 | _rEntry->getPropertyValue( PN_SUBMISSION_REPLACE ) >>= sTemp; |
773 | 0 | sEntry = SvxResId( RID_STR_DATANAV_SUBM_REPLACE ) + |
774 | 0 | m_aReplaceString.toUI( sTemp ); |
775 | 0 | m_xItemList->insert(pRet, -1, &sEntry, nullptr, nullptr, nullptr, false, xRes.get()); |
776 | 0 | m_xItemList->set_image(*xRes, aImage); |
777 | 0 | } |
778 | 0 | catch ( Exception const & ) |
779 | 0 | { |
780 | 0 | TOOLS_WARN_EXCEPTION( "svx.form", "XFormsPage::AddEntry(Ref)" ); |
781 | 0 | } |
782 | 0 | } |
783 | 0 | else // then Binding Page |
784 | 0 | { |
785 | 0 | try |
786 | 0 | { |
787 | 0 | OUString sName; |
788 | 0 | _rEntry->getPropertyValue( PN_BINDING_ID ) >>= sTemp; |
789 | 0 | sName += sTemp + ": "; |
790 | 0 | _rEntry->getPropertyValue( PN_BINDING_EXPR ) >>= sTemp; |
791 | 0 | sName += sTemp; |
792 | |
|
793 | 0 | OUString sId(weld::toId(pNode)); |
794 | 0 | m_xItemList->insert(nullptr, -1, &sName, &sId, nullptr, nullptr, false, pRet); |
795 | 0 | m_xItemList->set_image(*pRet, aImage); |
796 | 0 | } |
797 | 0 | catch ( Exception const & ) |
798 | 0 | { |
799 | 0 | TOOLS_WARN_EXCEPTION( "svx.form", "XFormsPage::AddEntry(Ref)" ); |
800 | 0 | } |
801 | 0 | } |
802 | 0 | } |
803 | | |
804 | | void XFormsPage::EditEntry( const Reference< XPropertySet >& _rEntry ) |
805 | 0 | { |
806 | 0 | if ( DGTSubmission != m_eGroup ) |
807 | 0 | return; |
808 | | |
809 | 0 | try |
810 | 0 | { |
811 | 0 | std::unique_ptr<weld::TreeIter> xEntry = m_xItemList->get_selected(); |
812 | 0 | if (!xEntry) |
813 | 0 | { |
814 | 0 | SAL_WARN( "svx.form", "corrupt tree" ); |
815 | 0 | return; |
816 | 0 | } |
817 | | |
818 | | // #i36262# may be called for submission entry *or* for |
819 | | // submission children. If we don't have any children, we |
820 | | // assume the latter case and use the parent |
821 | 0 | if (!m_xItemList->iter_has_child(*xEntry)) |
822 | 0 | m_xItemList->iter_parent(*xEntry); |
823 | |
|
824 | 0 | OUString sTemp; |
825 | 0 | _rEntry->getPropertyValue( PN_SUBMISSION_ID ) >>= sTemp; |
826 | 0 | m_xItemList->set_text(*xEntry, sTemp); |
827 | |
|
828 | 0 | _rEntry->getPropertyValue( PN_SUBMISSION_BIND ) >>= sTemp; |
829 | 0 | OUString sEntry = SvxResId( RID_STR_DATANAV_SUBM_BIND ) + sTemp; |
830 | 0 | if (!m_xItemList->iter_children(*xEntry)) |
831 | 0 | { |
832 | 0 | SAL_WARN( "svx.form", "corrupt tree" ); |
833 | 0 | return; |
834 | 0 | } |
835 | 0 | m_xItemList->set_text(*xEntry, sEntry); |
836 | 0 | _rEntry->getPropertyValue( PN_SUBMISSION_REF ) >>= sTemp; |
837 | 0 | sEntry = SvxResId( RID_STR_DATANAV_SUBM_REF ) + sTemp; |
838 | 0 | if (!m_xItemList->iter_next_sibling(*xEntry)) |
839 | 0 | { |
840 | 0 | SAL_WARN( "svx.form", "corrupt tree" ); |
841 | 0 | return; |
842 | 0 | } |
843 | 0 | m_xItemList->set_text(*xEntry, sEntry); |
844 | 0 | _rEntry->getPropertyValue( PN_SUBMISSION_ACTION ) >>= sTemp; |
845 | 0 | sEntry = SvxResId( RID_STR_DATANAV_SUBM_ACTION ) + sTemp; |
846 | 0 | if (!m_xItemList->iter_next_sibling(*xEntry)) |
847 | 0 | { |
848 | 0 | SAL_WARN( "svx.form", "corrupt tree" ); |
849 | 0 | return; |
850 | 0 | } |
851 | 0 | _rEntry->getPropertyValue( PN_SUBMISSION_METHOD ) >>= sTemp; |
852 | 0 | sEntry = SvxResId( RID_STR_DATANAV_SUBM_METHOD ) + |
853 | 0 | m_aMethodString.toUI( sTemp ); |
854 | 0 | if (!m_xItemList->iter_next_sibling(*xEntry)) |
855 | 0 | { |
856 | 0 | SAL_WARN( "svx.form", "corrupt tree" ); |
857 | 0 | return; |
858 | 0 | } |
859 | 0 | m_xItemList->set_text(*xEntry, sEntry); |
860 | 0 | _rEntry->getPropertyValue( PN_SUBMISSION_REPLACE ) >>= sTemp; |
861 | 0 | sEntry = SvxResId( RID_STR_DATANAV_SUBM_REPLACE ) + |
862 | 0 | m_aReplaceString.toUI( sTemp ); |
863 | 0 | if (!m_xItemList->iter_next_sibling(*xEntry)) |
864 | 0 | { |
865 | 0 | SAL_WARN( "svx.form", "corrupt tree" ); |
866 | 0 | return; |
867 | 0 | } |
868 | 0 | m_xItemList->set_text(*xEntry, sEntry); |
869 | 0 | } |
870 | 0 | catch ( Exception const & ) |
871 | 0 | { |
872 | 0 | TOOLS_WARN_EXCEPTION( "svx.form", "XFormsPage::EditEntry()" ); |
873 | 0 | } |
874 | 0 | } |
875 | | |
876 | | bool XFormsPage::RemoveEntry() |
877 | 0 | { |
878 | 0 | bool bRet = false; |
879 | |
|
880 | 0 | std::unique_ptr<weld::TreeIter> xEntry = m_xItemList->get_selected(); |
881 | 0 | if ( xEntry && |
882 | 0 | ( DGTInstance != m_eGroup || m_xItemList->get_iter_depth(*xEntry) ) ) |
883 | 0 | { |
884 | 0 | Reference< css::xforms::XModel > xModel( m_xUIHelper, UNO_QUERY ); |
885 | 0 | DBG_ASSERT( xModel.is(), "XFormsPage::RemoveEntry(): no model" ); |
886 | 0 | ItemNode* pNode = weld::fromId<ItemNode*>(m_xItemList->get_id(*xEntry)); |
887 | 0 | assert(pNode && "XFormsPage::RemoveEntry(): no node"); |
888 | |
|
889 | 0 | if ( DGTInstance == m_eGroup ) |
890 | 0 | { |
891 | 0 | try |
892 | 0 | { |
893 | 0 | DBG_ASSERT( pNode->m_xNode.is(), "XFormsPage::RemoveEntry(): no XNode" ); |
894 | 0 | css::xml::dom::NodeType eChildType = pNode->m_xNode->getNodeType(); |
895 | 0 | bool bIsElement = ( eChildType == css::xml::dom::NodeType_ELEMENT_NODE ); |
896 | 0 | TranslateId pResId = bIsElement ? RID_STR_QRY_REMOVE_ELEMENT : RID_STR_QRY_REMOVE_ATTRIBUTE; |
897 | 0 | OUString sVar = bIsElement ? OUString(ELEMENTNAME) : OUString(ATTRIBUTENAME); |
898 | 0 | std::unique_ptr<weld::MessageDialog> xQBox(Application::CreateMessageDialog(m_pNaviWin->GetFrameWeld(), |
899 | 0 | VclMessageType::Question, VclButtonsType::YesNo, |
900 | 0 | SvxResId(pResId))); |
901 | 0 | OUString sMessText = xQBox->get_primary_text(); |
902 | 0 | sMessText = sMessText.replaceFirst( |
903 | 0 | sVar, m_xUIHelper->getNodeDisplayName( pNode->m_xNode, false ) ); |
904 | 0 | xQBox->set_primary_text(sMessText); |
905 | 0 | if (xQBox->run() == RET_YES) |
906 | 0 | { |
907 | 0 | std::unique_ptr<weld::TreeIter> xParent(m_xItemList->make_iterator(xEntry.get())); |
908 | 0 | bool bParent = m_xItemList->iter_parent(*xParent); (void)bParent; |
909 | 0 | assert(bParent && "XFormsPage::RemoveEntry(): no parent entry"); |
910 | 0 | ItemNode* pParentNode = weld::fromId<ItemNode*>(m_xItemList->get_id(*xParent)); |
911 | 0 | assert(pParentNode && pParentNode->m_xNode.is() && "XFormsPage::RemoveEntry(): no parent XNode"); |
912 | |
|
913 | 0 | Reference< css::xml::dom::XNode > xPNode; |
914 | 0 | Reference< css::xml::dom::XNode > xNode = |
915 | 0 | pParentNode->m_xNode->removeChild( pNode->m_xNode ); |
916 | 0 | if ( xNode.is() ) |
917 | 0 | xPNode = xNode->getParentNode(); |
918 | 0 | DBG_ASSERT( !xPNode.is(), "XFormsPage::RemoveEntry(): node not removed" ); |
919 | 0 | bRet = true; |
920 | 0 | } |
921 | 0 | } |
922 | 0 | catch ( Exception const & ) |
923 | 0 | { |
924 | 0 | TOOLS_WARN_EXCEPTION( "svx.form", "XFormsPage::RemoveEntry()" ); |
925 | 0 | } |
926 | 0 | } |
927 | 0 | else |
928 | 0 | { |
929 | 0 | DBG_ASSERT( pNode->m_xPropSet.is(), "XFormsPage::RemoveEntry(): no propset" ); |
930 | 0 | bool bSubmission = ( DGTSubmission == m_eGroup ); |
931 | 0 | TranslateId pResId = bSubmission ? RID_STR_QRY_REMOVE_SUBMISSION : RID_STR_QRY_REMOVE_BINDING; |
932 | 0 | OUString sProperty = bSubmission ? PN_SUBMISSION_ID : PN_BINDING_ID; |
933 | 0 | OUString sSearch = bSubmission ? OUString(SUBMISSIONNAME) : OUString(BINDINGNAME); |
934 | 0 | OUString sName; |
935 | 0 | try |
936 | 0 | { |
937 | 0 | pNode->m_xPropSet->getPropertyValue( sProperty ) >>= sName; |
938 | 0 | } |
939 | 0 | catch ( Exception const & ) |
940 | 0 | { |
941 | 0 | TOOLS_WARN_EXCEPTION( "svx.form", "XFormsPage::RemoveEntry()" ); |
942 | 0 | } |
943 | 0 | std::unique_ptr<weld::MessageDialog> xQBox(Application::CreateMessageDialog(m_pNaviWin->GetFrameWeld(), |
944 | 0 | VclMessageType::Question, VclButtonsType::YesNo, |
945 | 0 | SvxResId(pResId))); |
946 | 0 | OUString sMessText = xQBox->get_primary_text(); |
947 | 0 | sMessText = sMessText.replaceFirst( sSearch, sName); |
948 | 0 | xQBox->set_primary_text(sMessText); |
949 | 0 | if (xQBox->run() == RET_YES) |
950 | 0 | { |
951 | 0 | try |
952 | 0 | { |
953 | 0 | if ( bSubmission ) |
954 | 0 | xModel->getSubmissions()->remove( Any( pNode->m_xPropSet ) ); |
955 | 0 | else // then Binding Page |
956 | 0 | xModel->getBindings()->remove( Any( pNode->m_xPropSet ) ); |
957 | 0 | bRet = true; |
958 | 0 | } |
959 | 0 | catch ( Exception const & ) |
960 | 0 | { |
961 | 0 | TOOLS_WARN_EXCEPTION( "svx.form", "XFormsPage::RemoveEntry()" ); |
962 | 0 | } |
963 | 0 | } |
964 | 0 | } |
965 | | |
966 | 0 | if (bRet) |
967 | 0 | { |
968 | 0 | m_xItemList->remove(*xEntry); |
969 | 0 | delete pNode; |
970 | 0 | } |
971 | 0 | } |
972 | | |
973 | 0 | return bRet; |
974 | 0 | } |
975 | | |
976 | | IMPL_LINK(XFormsPage, KeyInputHdl, const KeyEvent&, rKEvt, bool) |
977 | 0 | { |
978 | 0 | bool bHandled = false; |
979 | |
|
980 | 0 | sal_uInt16 nCode = rKEvt.GetKeyCode().GetCode(); |
981 | 0 | if (nCode == KEY_DELETE) |
982 | 0 | bHandled = DoMenuAction(u"delete"); |
983 | |
|
984 | 0 | return bHandled; |
985 | 0 | } |
986 | | |
987 | | OUString XFormsPage::SetModel( const Reference< css::xforms::XModel >& _xModel, int _nPagePos ) |
988 | 0 | { |
989 | 0 | DBG_ASSERT( _xModel.is(), "XFormsPage::SetModel(): invalid model" ); |
990 | |
|
991 | 0 | m_xUIHelper.set( _xModel, UNO_QUERY ); |
992 | 0 | OUString sRet; |
993 | 0 | m_bHasModel = true; |
994 | |
|
995 | 0 | switch ( m_eGroup ) |
996 | 0 | { |
997 | 0 | case DGTInstance : |
998 | 0 | { |
999 | 0 | DBG_ASSERT( _nPagePos != -1, "XFormsPage::SetModel(): invalid page position" ); |
1000 | 0 | try |
1001 | 0 | { |
1002 | 0 | Reference< XContainer > xContainer( _xModel->getInstances(), UNO_QUERY ); |
1003 | 0 | if ( xContainer.is() ) |
1004 | 0 | m_pNaviWin->AddContainerBroadcaster( xContainer ); |
1005 | |
|
1006 | 0 | Reference< XEnumerationAccess > xNumAccess = _xModel->getInstances(); |
1007 | 0 | if ( xNumAccess.is() ) |
1008 | 0 | { |
1009 | 0 | Reference < XEnumeration > xNum = xNumAccess->createEnumeration(); |
1010 | 0 | if ( xNum.is() && xNum->hasMoreElements() ) |
1011 | 0 | { |
1012 | 0 | int nIter = 0; |
1013 | 0 | while ( xNum->hasMoreElements() ) |
1014 | 0 | { |
1015 | 0 | if ( nIter == _nPagePos ) |
1016 | 0 | { |
1017 | 0 | Sequence< PropertyValue > xPropSeq; |
1018 | 0 | Any aAny = xNum->nextElement(); |
1019 | 0 | if ( aAny >>= xPropSeq ) |
1020 | 0 | sRet = LoadInstance(xPropSeq); |
1021 | 0 | else |
1022 | 0 | { |
1023 | 0 | SAL_WARN( "svx.form", "XFormsPage::SetModel(): invalid instance" ); |
1024 | 0 | } |
1025 | 0 | break; |
1026 | 0 | } |
1027 | 0 | else |
1028 | 0 | { |
1029 | 0 | xNum->nextElement(); |
1030 | 0 | ++nIter; |
1031 | 0 | } |
1032 | 0 | } |
1033 | 0 | } |
1034 | 0 | } |
1035 | 0 | } |
1036 | 0 | catch( Exception const & ) |
1037 | 0 | { |
1038 | 0 | TOOLS_WARN_EXCEPTION( "svx.form", "XFormsPage::SetModel()" ); |
1039 | 0 | } |
1040 | 0 | break; |
1041 | 0 | } |
1042 | | |
1043 | 0 | case DGTSubmission : |
1044 | 0 | { |
1045 | 0 | DBG_ASSERT( _nPagePos == -1, "XFormsPage::SetModel(): invalid page position" ); |
1046 | 0 | try |
1047 | 0 | { |
1048 | 0 | Reference< XContainer > xContainer( _xModel->getSubmissions(), UNO_QUERY ); |
1049 | 0 | if ( xContainer.is() ) |
1050 | 0 | m_pNaviWin->AddContainerBroadcaster( xContainer ); |
1051 | |
|
1052 | 0 | Reference< XEnumerationAccess > xNumAccess = _xModel->getSubmissions(); |
1053 | 0 | if ( xNumAccess.is() ) |
1054 | 0 | { |
1055 | 0 | Reference < XEnumeration > xNum = xNumAccess->createEnumeration(); |
1056 | 0 | if ( xNum.is() && xNum->hasMoreElements() ) |
1057 | 0 | { |
1058 | 0 | while ( xNum->hasMoreElements() ) |
1059 | 0 | { |
1060 | 0 | Reference< XPropertySet > xPropSet; |
1061 | 0 | Any aAny = xNum->nextElement(); |
1062 | 0 | if ( aAny >>= xPropSet ) |
1063 | 0 | AddEntry( xPropSet ); |
1064 | 0 | } |
1065 | 0 | } |
1066 | 0 | } |
1067 | 0 | } |
1068 | 0 | catch( Exception const & ) |
1069 | 0 | { |
1070 | 0 | TOOLS_WARN_EXCEPTION( "svx.form", "XFormsPage::SetModel()" ); |
1071 | 0 | } |
1072 | 0 | break; |
1073 | 0 | } |
1074 | | |
1075 | 0 | case DGTBinding : |
1076 | 0 | { |
1077 | 0 | DBG_ASSERT( _nPagePos == -1, "XFormsPage::SetModel(): invalid page position" ); |
1078 | 0 | try |
1079 | 0 | { |
1080 | 0 | Reference< XContainer > xContainer( _xModel->getBindings(), UNO_QUERY ); |
1081 | 0 | if ( xContainer.is() ) |
1082 | 0 | m_pNaviWin->AddContainerBroadcaster( xContainer ); |
1083 | |
|
1084 | 0 | Reference< XEnumerationAccess > xNumAccess = _xModel->getBindings(); |
1085 | 0 | if ( xNumAccess.is() ) |
1086 | 0 | { |
1087 | 0 | Reference < XEnumeration > xNum = xNumAccess->createEnumeration(); |
1088 | 0 | if ( xNum.is() && xNum->hasMoreElements() ) |
1089 | 0 | { |
1090 | 0 | OUString aImage(RID_SVXBMP_ELEMENT); |
1091 | 0 | std::unique_ptr<weld::TreeIter> xRes(m_xItemList->make_iterator()); |
1092 | 0 | while ( xNum->hasMoreElements() ) |
1093 | 0 | { |
1094 | 0 | Reference< XPropertySet > xPropSet; |
1095 | 0 | Any aAny = xNum->nextElement(); |
1096 | 0 | if ( aAny >>= xPropSet ) |
1097 | 0 | { |
1098 | 0 | OUString sEntry; |
1099 | 0 | OUString sTemp; |
1100 | 0 | xPropSet->getPropertyValue( PN_BINDING_ID ) >>= sTemp; |
1101 | 0 | sEntry += sTemp + ": "; |
1102 | 0 | xPropSet->getPropertyValue( PN_BINDING_EXPR ) >>= sTemp; |
1103 | 0 | sEntry += sTemp; |
1104 | |
|
1105 | 0 | ItemNode* pNode = new ItemNode( xPropSet ); |
1106 | |
|
1107 | 0 | OUString sId(weld::toId(pNode)); |
1108 | 0 | m_xItemList->insert(nullptr, -1, &sEntry, &sId, nullptr, nullptr, false, xRes.get()); |
1109 | 0 | m_xItemList->set_image(*xRes, aImage); |
1110 | 0 | } |
1111 | 0 | } |
1112 | 0 | } |
1113 | 0 | } |
1114 | 0 | } |
1115 | 0 | catch( Exception const & ) |
1116 | 0 | { |
1117 | 0 | TOOLS_WARN_EXCEPTION( "svx.form", "XFormsPage::SetModel()" ); |
1118 | 0 | } |
1119 | 0 | break; |
1120 | 0 | } |
1121 | 0 | default: |
1122 | 0 | OSL_FAIL( "XFormsPage::SetModel: unknown group!" ); |
1123 | 0 | break; |
1124 | 0 | } |
1125 | | |
1126 | 0 | EnableMenuItems(); |
1127 | |
|
1128 | 0 | return sRet; |
1129 | 0 | } |
1130 | | |
1131 | | void XFormsPage::ClearModel() |
1132 | 0 | { |
1133 | 0 | m_bHasModel = false; |
1134 | 0 | DeleteAndClearTree(); |
1135 | 0 | } |
1136 | | |
1137 | | OUString XFormsPage::LoadInstance(const Sequence< PropertyValue >& _xPropSeq) |
1138 | 0 | { |
1139 | 0 | OUString sRet; |
1140 | 0 | OUString sTemp; |
1141 | 0 | OUString sInstModel = PN_INSTANCE_MODEL; |
1142 | 0 | OUString sInstName = PN_INSTANCE_ID; |
1143 | 0 | OUString sInstURL = PN_INSTANCE_URL; |
1144 | 0 | for ( const PropertyValue& rProp : _xPropSeq ) |
1145 | 0 | { |
1146 | 0 | if ( sInstModel == rProp.Name ) |
1147 | 0 | { |
1148 | 0 | Reference< css::xml::dom::XNode > xRoot; |
1149 | 0 | if ( rProp.Value >>= xRoot ) |
1150 | 0 | { |
1151 | 0 | try |
1152 | 0 | { |
1153 | 0 | Reference< XEventTarget > xTarget( xRoot, UNO_QUERY ); |
1154 | 0 | if ( xTarget.is() ) |
1155 | 0 | m_pNaviWin->AddEventBroadcaster( xTarget ); |
1156 | |
|
1157 | 0 | OUString sNodeName = |
1158 | 0 | m_xUIHelper->getNodeDisplayName( xRoot, m_pNaviWin->IsShowDetails() ); |
1159 | 0 | if ( sNodeName.isEmpty() ) |
1160 | 0 | sNodeName = xRoot->getNodeName(); |
1161 | 0 | if ( xRoot->hasChildNodes() ) |
1162 | 0 | AddChildren(nullptr, xRoot); |
1163 | 0 | } |
1164 | 0 | catch ( Exception const & ) |
1165 | 0 | { |
1166 | 0 | TOOLS_WARN_EXCEPTION( "svx.form", "XFormsPage::LoadInstance()" ); |
1167 | 0 | } |
1168 | 0 | } |
1169 | 0 | } |
1170 | 0 | else if ( sInstName == rProp.Name && ( rProp.Value >>= sTemp ) ) |
1171 | 0 | m_sInstanceName = sRet = sTemp; |
1172 | 0 | else if ( sInstURL == rProp.Name && ( rProp.Value >>= sTemp ) ) |
1173 | 0 | m_sInstanceURL = sTemp; |
1174 | 0 | } |
1175 | | |
1176 | 0 | return sRet; |
1177 | 0 | } |
1178 | | |
1179 | | bool XFormsPage::DoMenuAction(std::u16string_view rMenuID) |
1180 | 0 | { |
1181 | 0 | return DoToolBoxAction(rMenuID); |
1182 | 0 | } |
1183 | | |
1184 | | void XFormsPage::SetMenuEntrySensitive(const OUString& rIdent, bool bSensitive) |
1185 | 0 | { |
1186 | 0 | if (m_aRemovedMenuEntries.find(rIdent) != m_aRemovedMenuEntries.end()) |
1187 | 0 | return; |
1188 | 0 | m_xMenu->set_sensitive(rIdent, bSensitive); |
1189 | 0 | } |
1190 | | |
1191 | | void XFormsPage::EnableMenuItems() |
1192 | 0 | { |
1193 | 0 | bool bEnableAdd = false; |
1194 | 0 | bool bEnableEdit = false; |
1195 | 0 | bool bEnableRemove = false; |
1196 | |
|
1197 | 0 | std::unique_ptr<weld::TreeIter> xEntry = m_xItemList->get_selected(); |
1198 | 0 | bool bEntry = bool(xEntry); |
1199 | 0 | if (bEntry) |
1200 | 0 | { |
1201 | 0 | bEnableAdd = true; |
1202 | 0 | bool bSubmitChild = false; |
1203 | 0 | if (DGTSubmission == m_eGroup && m_xItemList->get_iter_depth(*xEntry)) |
1204 | 0 | { |
1205 | 0 | m_xItemList->iter_parent(*xEntry); |
1206 | 0 | bSubmitChild = true; |
1207 | 0 | } |
1208 | 0 | ItemNode* pNode = weld::fromId<ItemNode*>(m_xItemList->get_id(*xEntry)); |
1209 | 0 | if ( pNode && ( pNode->m_xNode.is() || pNode->m_xPropSet.is() ) ) |
1210 | 0 | { |
1211 | 0 | bEnableEdit = true; |
1212 | 0 | bEnableRemove = !bSubmitChild; |
1213 | 0 | if ( DGTInstance == m_eGroup && !m_xItemList->get_iter_depth(*xEntry) ) |
1214 | 0 | bEnableRemove = false; |
1215 | 0 | if ( pNode->m_xNode.is() ) |
1216 | 0 | { |
1217 | 0 | try |
1218 | 0 | { |
1219 | 0 | css::xml::dom::NodeType eChildType = pNode->m_xNode->getNodeType(); |
1220 | 0 | if ( eChildType != css::xml::dom::NodeType_ELEMENT_NODE |
1221 | 0 | && eChildType != css::xml::dom::NodeType_DOCUMENT_NODE ) |
1222 | 0 | { |
1223 | 0 | bEnableAdd = false; |
1224 | 0 | } |
1225 | 0 | } |
1226 | 0 | catch ( Exception const & ) |
1227 | 0 | { |
1228 | 0 | TOOLS_WARN_EXCEPTION( "svx.form", "XFormsPage::EnableMenuItems()" ); |
1229 | 0 | } |
1230 | 0 | } |
1231 | 0 | } |
1232 | 0 | } |
1233 | 0 | else if ( m_eGroup != DGTInstance ) |
1234 | 0 | bEnableAdd = true; |
1235 | | |
1236 | 0 | m_xToolBox->set_item_sensitive(u"additem"_ustr, bEnableAdd); |
1237 | 0 | m_xToolBox->set_item_sensitive(u"addelement"_ustr, bEnableAdd); |
1238 | 0 | m_xToolBox->set_item_sensitive(u"addattribute"_ustr, bEnableAdd); |
1239 | 0 | m_xToolBox->set_item_sensitive(u"edit"_ustr, bEnableEdit); |
1240 | 0 | m_xToolBox->set_item_sensitive(u"delete"_ustr, bEnableRemove); |
1241 | |
|
1242 | 0 | if (m_xMenu) |
1243 | 0 | { |
1244 | 0 | SetMenuEntrySensitive(u"additem"_ustr, bEnableAdd); |
1245 | 0 | SetMenuEntrySensitive(u"addelement"_ustr, bEnableAdd); |
1246 | 0 | SetMenuEntrySensitive(u"addattribute"_ustr, bEnableAdd); |
1247 | 0 | SetMenuEntrySensitive(u"edit"_ustr, bEnableEdit); |
1248 | 0 | SetMenuEntrySensitive(u"delete"_ustr, bEnableRemove); |
1249 | 0 | } |
1250 | 0 | if ( DGTInstance != m_eGroup ) |
1251 | 0 | return; |
1252 | | |
1253 | 0 | TranslateId pResId1 = RID_STR_DATANAV_EDIT_ELEMENT; |
1254 | 0 | TranslateId pResId2 = RID_STR_DATANAV_REMOVE_ELEMENT; |
1255 | 0 | if (bEntry) |
1256 | 0 | { |
1257 | 0 | ItemNode* pNode = weld::fromId<ItemNode*>(m_xItemList->get_id(*xEntry)); |
1258 | 0 | if ( pNode && pNode->m_xNode.is() ) |
1259 | 0 | { |
1260 | 0 | try |
1261 | 0 | { |
1262 | 0 | css::xml::dom::NodeType eChildType = pNode->m_xNode->getNodeType(); |
1263 | 0 | if ( eChildType == css::xml::dom::NodeType_ATTRIBUTE_NODE ) |
1264 | 0 | { |
1265 | 0 | pResId1 = RID_STR_DATANAV_EDIT_ATTRIBUTE; |
1266 | 0 | pResId2 = RID_STR_DATANAV_REMOVE_ATTRIBUTE; |
1267 | 0 | } |
1268 | 0 | } |
1269 | 0 | catch ( Exception const & ) |
1270 | 0 | { |
1271 | 0 | TOOLS_WARN_EXCEPTION( "svx.form", "XFormsPage::EnableMenuItems()" ); |
1272 | 0 | } |
1273 | 0 | } |
1274 | 0 | } |
1275 | 0 | m_xToolBox->set_item_label(u"edit"_ustr, SvxResId(pResId1)); |
1276 | 0 | m_xToolBox->set_item_label(u"delete"_ustr, SvxResId(pResId2)); |
1277 | 0 | if (m_xMenu) |
1278 | 0 | { |
1279 | 0 | m_xMenu->set_label(u"edit"_ustr, SvxResId( pResId1 ) ); |
1280 | 0 | m_xMenu->set_label(u"delete"_ustr, SvxResId( pResId2 ) ); |
1281 | 0 | } |
1282 | 0 | } |
1283 | | |
1284 | | DataNavigatorWindow::DataNavigatorWindow(vcl::Window* pParent, weld::Builder& rBuilder, SfxBindings const * pBindings) |
1285 | 0 | : m_xParent(pParent) |
1286 | 0 | , m_xModelsBox(rBuilder.weld_combo_box(u"modelslist"_ustr)) |
1287 | 0 | , m_xModelBtn(rBuilder.weld_menu_button(u"modelsbutton"_ustr)) |
1288 | 0 | , m_xTabCtrl(rBuilder.weld_notebook(u"tabcontrol"_ustr)) |
1289 | 0 | , m_xInstanceBtn(rBuilder.weld_menu_button(u"instances"_ustr)) |
1290 | 0 | , m_nLastSelectedPos(-1) |
1291 | 0 | , m_bShowDetails(false) |
1292 | 0 | , m_bIsNotifyDisabled(false) |
1293 | 0 | , m_aUpdateTimer("svx DataNavigatorWindow m_aUpdateTimer") |
1294 | 0 | , m_xDataListener(new DataListener(this)) |
1295 | 0 | { |
1296 | | // handler |
1297 | 0 | m_xModelsBox->connect_changed( LINK( this, DataNavigatorWindow, ModelSelectListBoxHdl ) ); |
1298 | 0 | Link<const OUString&, void> aLink1 = LINK( this, DataNavigatorWindow, MenuSelectHdl ); |
1299 | 0 | m_xModelBtn->connect_selected(aLink1); |
1300 | 0 | m_xInstanceBtn->connect_selected(aLink1); |
1301 | 0 | Link<weld::Toggleable&,void> aLink2 = LINK( this, DataNavigatorWindow, MenuActivateHdl ); |
1302 | 0 | m_xModelBtn->connect_toggled( aLink2 ); |
1303 | 0 | m_xInstanceBtn->connect_toggled( aLink2 ); |
1304 | 0 | m_xTabCtrl->connect_enter_page( LINK( this, DataNavigatorWindow, ActivatePageHdl ) ); |
1305 | 0 | m_aUpdateTimer.SetTimeout( 2000 ); |
1306 | 0 | m_aUpdateTimer.SetInvokeHandler( LINK( this, DataNavigatorWindow, UpdateHdl ) ); |
1307 | | |
1308 | | // init tabcontrol |
1309 | 0 | OUString sPageId(u"instance"_ustr); |
1310 | 0 | SvtViewOptions aViewOpt( EViewType::TabDialog, CFGNAME_DATANAVIGATOR ); |
1311 | 0 | if ( aViewOpt.Exists() ) |
1312 | 0 | { |
1313 | 0 | OUString sNewPageId = aViewOpt.GetPageID(); |
1314 | 0 | if (m_xTabCtrl->get_page_index(sNewPageId) != -1) |
1315 | 0 | sPageId = sNewPageId; |
1316 | 0 | aViewOpt.GetUserItem(CFGNAME_SHOWDETAILS) >>= m_bShowDetails; |
1317 | 0 | } |
1318 | |
|
1319 | 0 | m_xInstanceBtn->set_item_active(u"instancesdetails"_ustr, m_bShowDetails); |
1320 | | |
1321 | | // get our frame |
1322 | 0 | assert(pBindings != nullptr && |
1323 | 0 | "DataNavigatorWindow::LoadModels(): no SfxBindings; can't get frame"); |
1324 | 0 | m_xFrame = pBindings->GetDispatcher()->GetFrame()->GetFrame().GetFrameInterface(); |
1325 | 0 | DBG_ASSERT( m_xFrame.is(), "DataNavigatorWindow::LoadModels(): no frame" ); |
1326 | | // add frameaction listener |
1327 | 0 | m_xFrame->addFrameActionListener( Reference< XFrameActionListener >(m_xDataListener) ); |
1328 | | |
1329 | | // load xforms models of the current document |
1330 | 0 | LoadModels(); |
1331 | | |
1332 | | // tdf#154683 Select the current page after loading the Models, the default |
1333 | | // Instance page needs to be selected at LoadModel time in order to get its |
1334 | | // tab text updated automatically. |
1335 | 0 | m_xTabCtrl->set_current_page(sPageId); |
1336 | 0 | ActivatePageHdl(sPageId); |
1337 | | |
1338 | | // tdf#154322 select the first entry of the current page by default |
1339 | 0 | if (XFormsPage* pPage = GetPage(sPageId)) |
1340 | 0 | pPage->SelectFirstEntry(); |
1341 | 0 | } |
1342 | | |
1343 | | DataNavigatorWindow::~DataNavigatorWindow() |
1344 | 0 | { |
1345 | 0 | m_xFrame->removeFrameActionListener( Reference< XFrameActionListener >(m_xDataListener) ); |
1346 | |
|
1347 | 0 | SvtViewOptions aViewOpt( EViewType::TabDialog, CFGNAME_DATANAVIGATOR ); |
1348 | 0 | aViewOpt.SetPageID(m_xTabCtrl->get_current_page_ident()); |
1349 | 0 | aViewOpt.SetUserItem(CFGNAME_SHOWDETAILS, Any(m_bShowDetails)); |
1350 | |
|
1351 | 0 | m_xInstPage.reset(); |
1352 | 0 | m_xSubmissionPage.reset(); |
1353 | 0 | m_xBindingPage.reset(); |
1354 | |
|
1355 | 0 | sal_Int32 i, nCount = m_aPageList.size(); |
1356 | 0 | for ( i = 0; i < nCount; ++i ) |
1357 | 0 | m_aPageList[i].reset(); |
1358 | 0 | m_aPageList.clear(); |
1359 | |
|
1360 | 0 | RemoveBroadcaster(); |
1361 | 0 | m_xDataListener.clear(); |
1362 | 0 | } |
1363 | | |
1364 | | IMPL_LINK( DataNavigatorWindow, ModelSelectListBoxHdl, weld::ComboBox&, rBox, void ) |
1365 | 0 | { |
1366 | 0 | ModelSelectHdl(&rBox); |
1367 | 0 | } |
1368 | | |
1369 | | void DataNavigatorWindow::ModelSelectHdl(const weld::ComboBox* pBox) |
1370 | 0 | { |
1371 | 0 | sal_Int32 nPos = m_xModelsBox->get_active(); |
1372 | | // pBox == NULL, if you want to force a new fill. |
1373 | 0 | if ( nPos != m_nLastSelectedPos || !pBox ) |
1374 | 0 | { |
1375 | 0 | m_nLastSelectedPos = nPos; |
1376 | 0 | ClearAllPageModels( pBox != nullptr ); |
1377 | 0 | InitPages(); |
1378 | 0 | SetPageModel(GetCurrentPage()); |
1379 | 0 | } |
1380 | 0 | } |
1381 | | |
1382 | | IMPL_LINK(DataNavigatorWindow, MenuSelectHdl, const OUString&, rIdent, void) |
1383 | 0 | { |
1384 | 0 | bool bIsDocModified = false; |
1385 | 0 | Reference< css::xforms::XFormsUIHelper1 > xUIHelper; |
1386 | 0 | sal_Int32 nSelectedPos = m_xModelsBox->get_active(); |
1387 | 0 | OUString sSelectedModel(m_xModelsBox->get_text(nSelectedPos)); |
1388 | 0 | Reference< css::xforms::XModel > xModel; |
1389 | 0 | try |
1390 | 0 | { |
1391 | 0 | Any aAny = m_xDataContainer->getByName( sSelectedModel ); |
1392 | 0 | if ( aAny >>= xModel ) |
1393 | 0 | xUIHelper.set( xModel, UNO_QUERY ); |
1394 | 0 | } |
1395 | 0 | catch ( Exception const & ) |
1396 | 0 | { |
1397 | 0 | TOOLS_WARN_EXCEPTION( "svx.form", "DataNavigatorWindow::MenuSelectHdl()" ); |
1398 | 0 | } |
1399 | 0 | DBG_ASSERT( xUIHelper.is(), "DataNavigatorWindow::MenuSelectHdl(): no UIHelper" ); |
1400 | |
|
1401 | 0 | m_bIsNotifyDisabled = true; |
1402 | |
|
1403 | 0 | if (rIdent == "modelsadd") |
1404 | 0 | { |
1405 | 0 | AddModelDialog aDlg(GetFrameWeld(), false); |
1406 | 0 | bool bShowDialog = true; |
1407 | 0 | while ( bShowDialog ) |
1408 | 0 | { |
1409 | 0 | bShowDialog = false; |
1410 | 0 | if (aDlg.run() == RET_OK) |
1411 | 0 | { |
1412 | 0 | OUString sNewName = aDlg.GetName(); |
1413 | 0 | bool bDocumentData = aDlg.GetModifyDoc(); |
1414 | |
|
1415 | 0 | if (m_xModelsBox->find_text(sNewName) != -1) |
1416 | 0 | { |
1417 | | // error: model name already exists |
1418 | 0 | std::unique_ptr<weld::MessageDialog> xErrBox(Application::CreateMessageDialog(GetFrameWeld(), |
1419 | 0 | VclMessageType::Warning, VclButtonsType::Ok, |
1420 | 0 | SvxResId(RID_STR_DOUBLE_MODELNAME))); |
1421 | 0 | xErrBox->set_primary_text(xErrBox->get_primary_text().replaceFirst(MSG_VARIABLE, sNewName)); |
1422 | 0 | xErrBox->run(); |
1423 | 0 | bShowDialog = true; |
1424 | 0 | } |
1425 | 0 | else |
1426 | 0 | { |
1427 | 0 | try |
1428 | 0 | { |
1429 | | // add new model to frame model |
1430 | 0 | Reference< css::xforms::XModel > xNewModel( |
1431 | 0 | xUIHelper->newModel( m_xFrameModel, sNewName ), UNO_SET_THROW ); |
1432 | |
|
1433 | 0 | Reference< XPropertySet > xModelProps( xNewModel, UNO_QUERY_THROW ); |
1434 | 0 | xModelProps->setPropertyValue(u"ExternalData"_ustr, Any( !bDocumentData ) ); |
1435 | |
|
1436 | 0 | m_xModelsBox->append_text(sNewName); |
1437 | 0 | m_xModelsBox->set_active(m_xModelsBox->get_count() - 1); |
1438 | 0 | ModelSelectHdl(m_xModelsBox.get()); |
1439 | 0 | bIsDocModified = true; |
1440 | 0 | } |
1441 | 0 | catch ( Exception const & ) |
1442 | 0 | { |
1443 | 0 | TOOLS_WARN_EXCEPTION( "svx.form", "DataNavigatorWindow::MenuSelectHdl()" ); |
1444 | 0 | } |
1445 | 0 | } |
1446 | 0 | } |
1447 | 0 | } |
1448 | 0 | } |
1449 | 0 | else if (rIdent == "modelsedit") |
1450 | 0 | { |
1451 | 0 | AddModelDialog aDlg(GetFrameWeld(), true); |
1452 | 0 | aDlg.SetName( sSelectedModel ); |
1453 | |
|
1454 | 0 | bool bDocumentData( false ); |
1455 | 0 | try |
1456 | 0 | { |
1457 | 0 | Reference< css::xforms::XFormsSupplier > xFormsSupp( m_xFrameModel, UNO_QUERY_THROW ); |
1458 | 0 | Reference< XNameContainer > xXForms( xFormsSupp->getXForms(), UNO_SET_THROW ); |
1459 | 0 | Reference< XPropertySet > xModelProps( xXForms->getByName( sSelectedModel ), UNO_QUERY_THROW ); |
1460 | 0 | bool bExternalData = false; |
1461 | 0 | OSL_VERIFY( xModelProps->getPropertyValue( u"ExternalData"_ustr ) >>= bExternalData ); |
1462 | 0 | bDocumentData = !bExternalData; |
1463 | 0 | } |
1464 | 0 | catch( const Exception& ) |
1465 | 0 | { |
1466 | 0 | DBG_UNHANDLED_EXCEPTION("svx"); |
1467 | 0 | } |
1468 | 0 | aDlg.SetModifyDoc( bDocumentData ); |
1469 | |
|
1470 | 0 | if (aDlg.run() == RET_OK) |
1471 | 0 | { |
1472 | 0 | if ( aDlg.GetModifyDoc() != bDocumentData ) |
1473 | 0 | { |
1474 | 0 | bDocumentData = aDlg.GetModifyDoc(); |
1475 | 0 | try |
1476 | 0 | { |
1477 | 0 | Reference< css::xforms::XFormsSupplier > xFormsSupp( m_xFrameModel, UNO_QUERY_THROW ); |
1478 | 0 | Reference< XNameContainer > xXForms( xFormsSupp->getXForms(), UNO_SET_THROW ); |
1479 | 0 | Reference< XPropertySet > xModelProps( xXForms->getByName( sSelectedModel ), UNO_QUERY_THROW ); |
1480 | 0 | xModelProps->setPropertyValue( u"ExternalData"_ustr, Any( !bDocumentData ) ); |
1481 | 0 | bIsDocModified = true; |
1482 | 0 | } |
1483 | 0 | catch( const Exception& ) |
1484 | 0 | { |
1485 | 0 | DBG_UNHANDLED_EXCEPTION("svx"); |
1486 | 0 | } |
1487 | 0 | } |
1488 | |
|
1489 | 0 | OUString sNewName = aDlg.GetName(); |
1490 | 0 | if ( !sNewName.isEmpty() && ( sNewName != sSelectedModel ) ) |
1491 | 0 | { |
1492 | 0 | try |
1493 | 0 | { |
1494 | 0 | xUIHelper->renameModel( m_xFrameModel, sSelectedModel, sNewName ); |
1495 | |
|
1496 | 0 | m_xModelsBox->remove(nSelectedPos); |
1497 | 0 | m_xModelsBox->append_text(sNewName); |
1498 | 0 | m_xModelsBox->set_active(m_xModelsBox->get_count() - 1); |
1499 | 0 | bIsDocModified = true; |
1500 | 0 | } |
1501 | 0 | catch ( Exception const & ) |
1502 | 0 | { |
1503 | 0 | TOOLS_WARN_EXCEPTION( "svx.form", "DataNavigatorWindow::MenuSelectHdl()" ); |
1504 | 0 | } |
1505 | 0 | } |
1506 | 0 | } |
1507 | 0 | } |
1508 | 0 | else if (rIdent == "modelsremove") |
1509 | 0 | { |
1510 | 0 | std::unique_ptr<weld::MessageDialog> xQBox(Application::CreateMessageDialog(GetFrameWeld(), |
1511 | 0 | VclMessageType::Question, VclButtonsType::YesNo, |
1512 | 0 | SvxResId( RID_STR_QRY_REMOVE_MODEL))); |
1513 | 0 | OUString sText = xQBox->get_primary_text(); |
1514 | 0 | sText = sText.replaceFirst( MODELNAME, sSelectedModel ); |
1515 | 0 | xQBox->set_primary_text(sText); |
1516 | 0 | if (xQBox->run() == RET_YES) |
1517 | 0 | { |
1518 | 0 | try |
1519 | 0 | { |
1520 | 0 | xUIHelper->removeModel( m_xFrameModel, sSelectedModel ); |
1521 | 0 | } |
1522 | 0 | catch ( Exception const & ) |
1523 | 0 | { |
1524 | 0 | TOOLS_WARN_EXCEPTION( "svx.form", "DataNavigatorWindow::MenuSelectHdl()" ); |
1525 | 0 | } |
1526 | 0 | m_xModelsBox->remove(nSelectedPos); |
1527 | 0 | if (m_xModelsBox->get_count() <= nSelectedPos) |
1528 | 0 | nSelectedPos = m_xModelsBox->get_count() - 1; |
1529 | 0 | m_xModelsBox->set_active(nSelectedPos); |
1530 | 0 | ModelSelectHdl(m_xModelsBox.get()); |
1531 | 0 | bIsDocModified = true; |
1532 | 0 | } |
1533 | 0 | } |
1534 | 0 | else if (rIdent == "instancesadd") |
1535 | 0 | { |
1536 | 0 | AddInstanceDialog aDlg(GetFrameWeld(), false); |
1537 | 0 | if (aDlg.run() == RET_OK) |
1538 | 0 | { |
1539 | 0 | OUString sPageId = GetNewPageId(); // ModelSelectHdl will cause a page of this id to be created |
1540 | |
|
1541 | 0 | OUString sName = aDlg.GetName(); |
1542 | 0 | if (sName.isEmpty()) |
1543 | 0 | { |
1544 | 0 | SAL_WARN( "svx.form", "DataNavigatorWindow::CreateInstancePage(): instance without name" ); |
1545 | 0 | sName = "untitled"; |
1546 | 0 | } |
1547 | | |
1548 | 0 | OUString sURL = aDlg.GetURL(); |
1549 | 0 | bool bLinkOnce = aDlg.IsLinkInstance(); |
1550 | 0 | try |
1551 | 0 | { |
1552 | 0 | xUIHelper->newInstance( sName, sURL, !bLinkOnce ); |
1553 | 0 | } |
1554 | 0 | catch ( Exception const & ) |
1555 | 0 | { |
1556 | 0 | TOOLS_WARN_EXCEPTION( "svx.form", "DataNavigatorWindow::MenuSelectHdl()" ); |
1557 | 0 | } |
1558 | 0 | ModelSelectHdl( nullptr ); |
1559 | |
|
1560 | 0 | XFormsPage* pPage = GetPage(sPageId); |
1561 | 0 | pPage->SetInstanceName(sName); |
1562 | 0 | pPage->SetInstanceURL(sURL); |
1563 | 0 | pPage->SetLinkOnce(bLinkOnce); |
1564 | 0 | ActivatePageHdl(sPageId); |
1565 | |
|
1566 | 0 | bIsDocModified = true; |
1567 | 0 | } |
1568 | 0 | } |
1569 | 0 | else if (rIdent == "instancesedit") |
1570 | 0 | { |
1571 | 0 | OUString sIdent = GetCurrentPage(); |
1572 | 0 | XFormsPage* pPage = GetPage(sIdent); |
1573 | 0 | if ( pPage ) |
1574 | 0 | { |
1575 | 0 | AddInstanceDialog aDlg(GetFrameWeld(), true); |
1576 | 0 | aDlg.SetName( pPage->GetInstanceName() ); |
1577 | 0 | aDlg.SetURL( pPage->GetInstanceURL() ); |
1578 | 0 | aDlg.SetLinkInstance( pPage->GetLinkOnce() ); |
1579 | 0 | OUString sOldName = aDlg.GetName(); |
1580 | 0 | if (aDlg.run() == RET_OK) |
1581 | 0 | { |
1582 | 0 | OUString sNewName = aDlg.GetName(); |
1583 | 0 | OUString sURL = aDlg.GetURL(); |
1584 | 0 | bool bLinkOnce = aDlg.IsLinkInstance(); |
1585 | 0 | try |
1586 | 0 | { |
1587 | 0 | xUIHelper->renameInstance( sOldName, |
1588 | 0 | sNewName, |
1589 | 0 | sURL, |
1590 | 0 | !bLinkOnce ); |
1591 | 0 | } |
1592 | 0 | catch ( Exception const & ) |
1593 | 0 | { |
1594 | 0 | TOOLS_WARN_EXCEPTION( "svx.form", "DataNavigatorWindow::MenuSelectHdl()" ); |
1595 | 0 | } |
1596 | 0 | pPage->SetInstanceName(sNewName); |
1597 | 0 | pPage->SetInstanceURL(sURL); |
1598 | 0 | pPage->SetLinkOnce(bLinkOnce); |
1599 | 0 | m_xTabCtrl->set_tab_label_text(sIdent, sNewName); |
1600 | 0 | bIsDocModified = true; |
1601 | 0 | } |
1602 | 0 | } |
1603 | 0 | } |
1604 | 0 | else if (rIdent == "instancesremove") |
1605 | 0 | { |
1606 | 0 | OUString sIdent = GetCurrentPage(); |
1607 | 0 | XFormsPage* pPage = GetPage(sIdent); |
1608 | 0 | if (pPage) |
1609 | 0 | { |
1610 | 0 | OUString sInstName = pPage->GetInstanceName(); |
1611 | 0 | std::unique_ptr<weld::MessageDialog> xQBox(Application::CreateMessageDialog(GetFrameWeld(), |
1612 | 0 | VclMessageType::Question, VclButtonsType::YesNo, |
1613 | 0 | SvxResId(RID_STR_QRY_REMOVE_INSTANCE))); |
1614 | 0 | OUString sMessText = xQBox->get_primary_text(); |
1615 | 0 | sMessText = sMessText.replaceFirst( INSTANCENAME, sInstName ); |
1616 | 0 | xQBox->set_primary_text(sMessText); |
1617 | 0 | if (xQBox->run() == RET_YES) |
1618 | 0 | { |
1619 | 0 | bool bDoRemove = false; |
1620 | 0 | if (IsAdditionalPage(sIdent)) |
1621 | 0 | { |
1622 | 0 | auto aPageListEnd = m_aPageList.end(); |
1623 | 0 | auto aFoundPage = std::find_if(m_aPageList.begin(), aPageListEnd, |
1624 | 0 | [pPage](const auto&elem) { return elem.get() == pPage; }); |
1625 | 0 | if ( aFoundPage != aPageListEnd ) |
1626 | 0 | { |
1627 | 0 | m_aPageList.erase( aFoundPage ); |
1628 | 0 | bDoRemove = true; |
1629 | 0 | } |
1630 | 0 | } |
1631 | 0 | else |
1632 | 0 | { |
1633 | 0 | m_xInstPage.reset(); |
1634 | 0 | bDoRemove = true; |
1635 | 0 | } |
1636 | |
|
1637 | 0 | if ( bDoRemove ) |
1638 | 0 | { |
1639 | 0 | try |
1640 | 0 | { |
1641 | 0 | xUIHelper->removeInstance( sInstName ); |
1642 | 0 | } |
1643 | 0 | catch (const Exception&) |
1644 | 0 | { |
1645 | 0 | TOOLS_WARN_EXCEPTION( "svx.form", "DataNavigatorWindow::MenuSelectHdl()" ); |
1646 | 0 | } |
1647 | 0 | m_xTabCtrl->remove_page(sIdent); |
1648 | 0 | m_xTabCtrl->set_current_page(u"instance"_ustr); |
1649 | 0 | ModelSelectHdl( nullptr ); |
1650 | 0 | bIsDocModified = true; |
1651 | 0 | } |
1652 | 0 | } |
1653 | 0 | } |
1654 | 0 | } |
1655 | 0 | else if (rIdent == "instancesdetails") |
1656 | 0 | { |
1657 | 0 | m_bShowDetails = !m_bShowDetails; |
1658 | 0 | m_xInstanceBtn->set_item_active(u"instancesdetails"_ustr, m_bShowDetails); |
1659 | 0 | ModelSelectHdl(m_xModelsBox.get()); |
1660 | 0 | } |
1661 | 0 | else |
1662 | 0 | { |
1663 | 0 | SAL_WARN( "svx.form", "DataNavigatorWindow::MenuSelectHdl(): wrong menu item" ); |
1664 | 0 | } |
1665 | | |
1666 | 0 | m_bIsNotifyDisabled = false; |
1667 | |
|
1668 | 0 | if ( bIsDocModified ) |
1669 | 0 | SetDocModified(); |
1670 | 0 | } |
1671 | | |
1672 | | bool DataNavigatorWindow::IsAdditionalPage(std::u16string_view rIdent) |
1673 | 0 | { |
1674 | 0 | return o3tl::starts_with(rIdent, u"additional"); |
1675 | 0 | } |
1676 | | |
1677 | | IMPL_LINK( DataNavigatorWindow, MenuActivateHdl, weld::Toggleable&, rBtn, void ) |
1678 | 0 | { |
1679 | 0 | if (m_xInstanceBtn.get() == &rBtn) |
1680 | 0 | { |
1681 | 0 | OUString sIdent(m_xTabCtrl->get_current_page_ident()); |
1682 | 0 | bool bIsInstPage = (IsAdditionalPage(sIdent) || sIdent == "instance"); |
1683 | 0 | m_xInstanceBtn->set_item_sensitive( u"instancesedit"_ustr, bIsInstPage ); |
1684 | 0 | m_xInstanceBtn->set_item_sensitive( u"instancesremove"_ustr, |
1685 | 0 | bIsInstPage && m_xTabCtrl->get_n_pages() > MIN_PAGE_COUNT ); |
1686 | 0 | m_xInstanceBtn->set_item_sensitive( u"instancesdetails"_ustr, bIsInstPage ); |
1687 | 0 | } |
1688 | 0 | else if (m_xModelBtn.get() == &rBtn) |
1689 | 0 | { |
1690 | | // we need at least one model! |
1691 | 0 | m_xModelBtn->set_item_sensitive(u"modelsremove"_ustr, m_xModelsBox->get_count() > 1 ); |
1692 | 0 | } |
1693 | 0 | else |
1694 | 0 | { |
1695 | 0 | SAL_WARN( "svx.form", "DataNavigatorWindow::MenuActivateHdl(): wrong button" ); |
1696 | 0 | } |
1697 | 0 | } |
1698 | | |
1699 | | IMPL_LINK(DataNavigatorWindow, ActivatePageHdl, const OUString&, rIdent, void) |
1700 | 0 | { |
1701 | 0 | XFormsPage* pPage = GetPage(rIdent); |
1702 | 0 | if (!pPage) |
1703 | 0 | return; |
1704 | 0 | if (m_xDataContainer.is() && !pPage->HasModel()) |
1705 | 0 | SetPageModel(rIdent); |
1706 | 0 | } |
1707 | | |
1708 | | IMPL_LINK_NOARG(DataNavigatorWindow, UpdateHdl, Timer *, void) |
1709 | 0 | { |
1710 | 0 | ModelSelectHdl( nullptr ); |
1711 | 0 | } |
1712 | | |
1713 | | XFormsPage* DataNavigatorWindow::GetPage(const OUString& rCurId) |
1714 | 0 | { |
1715 | 0 | XFormsPage* pPage = nullptr; |
1716 | 0 | if (rCurId == "submissions") |
1717 | 0 | { |
1718 | 0 | if (!m_xSubmissionPage) |
1719 | 0 | m_xSubmissionPage.reset(new XFormsPage(m_xTabCtrl->get_page(rCurId), this, DGTSubmission)); |
1720 | 0 | pPage = m_xSubmissionPage.get(); |
1721 | 0 | } |
1722 | 0 | else if (rCurId == "bindings") |
1723 | 0 | { |
1724 | 0 | if (!m_xBindingPage) |
1725 | 0 | m_xBindingPage.reset(new XFormsPage(m_xTabCtrl->get_page(rCurId), this, DGTBinding)); |
1726 | 0 | pPage = m_xBindingPage.get(); |
1727 | 0 | } |
1728 | 0 | else if (rCurId == "instance") |
1729 | 0 | { |
1730 | 0 | if (!m_xInstPage) |
1731 | 0 | m_xInstPage.reset(new XFormsPage(m_xTabCtrl->get_page(rCurId), this, DGTInstance)); |
1732 | 0 | pPage = m_xInstPage.get(); |
1733 | 0 | } |
1734 | 0 | else |
1735 | 0 | { |
1736 | 0 | sal_uInt16 nPos = m_xTabCtrl->get_page_index(rCurId); |
1737 | 0 | if (HasFirstInstancePage() && nPos > 0) |
1738 | 0 | nPos--; |
1739 | 0 | if (m_aPageList.size() > nPos) |
1740 | 0 | pPage = m_aPageList[nPos].get(); |
1741 | 0 | else |
1742 | 0 | { |
1743 | 0 | m_aPageList.emplace_back(std::make_unique<XFormsPage>(m_xTabCtrl->get_page(rCurId), this, DGTInstance)); |
1744 | 0 | pPage = m_aPageList.back().get(); |
1745 | 0 | } |
1746 | 0 | } |
1747 | 0 | return pPage; |
1748 | 0 | } |
1749 | | |
1750 | | OUString DataNavigatorWindow::GetCurrentPage() const |
1751 | 0 | { |
1752 | 0 | return m_xTabCtrl->get_current_page_ident(); |
1753 | 0 | } |
1754 | | |
1755 | | void DataNavigatorWindow::LoadModels() |
1756 | 0 | { |
1757 | 0 | if ( !m_xFrameModel.is() ) |
1758 | 0 | { |
1759 | | // get model of active frame |
1760 | 0 | Reference< XController > xCtrl = m_xFrame->getController(); |
1761 | 0 | if ( xCtrl.is() ) |
1762 | 0 | { |
1763 | 0 | try |
1764 | 0 | { |
1765 | 0 | m_xFrameModel = xCtrl->getModel(); |
1766 | 0 | } |
1767 | 0 | catch ( Exception const & ) |
1768 | 0 | { |
1769 | 0 | TOOLS_WARN_EXCEPTION( "svx.form", "DataNavigatorWindow::LoadModels()" ); |
1770 | 0 | } |
1771 | 0 | } |
1772 | 0 | } |
1773 | | |
1774 | 0 | if ( m_xFrameModel.is() ) |
1775 | 0 | { |
1776 | 0 | try |
1777 | 0 | { |
1778 | 0 | Reference< css::xforms::XFormsSupplier > xFormsSupp( m_xFrameModel, UNO_QUERY ); |
1779 | 0 | if ( xFormsSupp.is() ) |
1780 | 0 | { |
1781 | 0 | Reference< XNameContainer > xContainer = xFormsSupp->getXForms(); |
1782 | 0 | if ( xContainer.is() ) |
1783 | 0 | { |
1784 | 0 | m_xDataContainer = std::move(xContainer); |
1785 | 0 | const Sequence< OUString > aNameList = m_xDataContainer->getElementNames(); |
1786 | 0 | for ( const OUString& rName : aNameList ) |
1787 | 0 | { |
1788 | 0 | Any aAny = m_xDataContainer->getByName( rName ); |
1789 | 0 | Reference< css::xforms::XModel > xFormsModel; |
1790 | 0 | if ( aAny >>= xFormsModel ) |
1791 | 0 | m_xModelsBox->append_text(xFormsModel->getID()); |
1792 | 0 | } |
1793 | 0 | } |
1794 | 0 | } |
1795 | 0 | } |
1796 | 0 | catch( Exception const & ) |
1797 | 0 | { |
1798 | 0 | TOOLS_WARN_EXCEPTION( "svx.form", "DataNavigatorWindow::LoadModels()" ); |
1799 | 0 | } |
1800 | 0 | } |
1801 | | |
1802 | 0 | if (m_xModelsBox->get_count() > 0) |
1803 | 0 | { |
1804 | 0 | m_xModelsBox->set_active(0); |
1805 | 0 | ModelSelectHdl(m_xModelsBox.get()); |
1806 | 0 | } |
1807 | 0 | } |
1808 | | |
1809 | | void DataNavigatorWindow::SetPageModel(const OUString& rIdent) |
1810 | 0 | { |
1811 | 0 | OUString sModel(m_xModelsBox->get_active_text()); |
1812 | 0 | try |
1813 | 0 | { |
1814 | 0 | Any aAny = m_xDataContainer->getByName( sModel ); |
1815 | 0 | Reference< css::xforms::XModel > xFormsModel; |
1816 | 0 | if ( aAny >>= xFormsModel ) |
1817 | 0 | { |
1818 | 0 | int nPagePos = -1; |
1819 | 0 | XFormsPage* pPage = GetPage(rIdent); |
1820 | 0 | DBG_ASSERT( pPage, "DataNavigatorWindow::SetPageModel(): no page" ); |
1821 | 0 | if (IsAdditionalPage(rIdent) || rIdent == "instance") |
1822 | 0 | { |
1823 | | // instance page |
1824 | 0 | nPagePos = m_xTabCtrl->get_page_index(rIdent); |
1825 | 0 | } |
1826 | 0 | m_bIsNotifyDisabled = true; |
1827 | 0 | OUString sText = pPage->SetModel( xFormsModel, nPagePos ); |
1828 | 0 | m_bIsNotifyDisabled = false; |
1829 | 0 | if (!sText.isEmpty()) |
1830 | 0 | m_xTabCtrl->set_tab_label_text(rIdent, sText); |
1831 | 0 | } |
1832 | 0 | } |
1833 | 0 | catch (const NoSuchElementException& ) |
1834 | 0 | { |
1835 | 0 | SAL_WARN( "svx.form", "DataNavigatorWindow::SetPageModel(): no such element" ); |
1836 | 0 | } |
1837 | 0 | catch( Exception const & ) |
1838 | 0 | { |
1839 | 0 | TOOLS_WARN_EXCEPTION( "svx.form", "DataNavigatorWindow::SetPageModel()" ); |
1840 | 0 | } |
1841 | 0 | } |
1842 | | |
1843 | | void DataNavigatorWindow::InitPages() |
1844 | 0 | { |
1845 | 0 | OUString sModel(m_xModelsBox->get_active_text()); |
1846 | 0 | try |
1847 | 0 | { |
1848 | 0 | Any aAny = m_xDataContainer->getByName( sModel ); |
1849 | 0 | Reference< css::xforms::XModel > xModel; |
1850 | 0 | if ( aAny >>= xModel ) |
1851 | 0 | { |
1852 | 0 | Reference< XEnumerationAccess > xNumAccess = xModel->getInstances(); |
1853 | 0 | if ( xNumAccess.is() ) |
1854 | 0 | { |
1855 | 0 | Reference < XEnumeration > xNum = xNumAccess->createEnumeration(); |
1856 | 0 | if ( xNum.is() && xNum->hasMoreElements() ) |
1857 | 0 | { |
1858 | 0 | sal_Int32 nAlreadyLoadedCount = m_aPageList.size(); |
1859 | 0 | if ( !HasFirstInstancePage() && nAlreadyLoadedCount > 0 ) |
1860 | 0 | nAlreadyLoadedCount--; |
1861 | 0 | sal_Int32 nIdx = 0; |
1862 | 0 | while ( xNum->hasMoreElements() ) |
1863 | 0 | { |
1864 | 0 | if ( nIdx > nAlreadyLoadedCount ) |
1865 | 0 | { |
1866 | 0 | Sequence< PropertyValue > xPropSeq; |
1867 | 0 | if ( xNum->nextElement() >>= xPropSeq ) |
1868 | 0 | CreateInstancePage( xPropSeq ); |
1869 | 0 | else |
1870 | 0 | { |
1871 | 0 | SAL_WARN( "svx.form", "DataNavigator::InitPages(): invalid instance" ); |
1872 | 0 | } |
1873 | 0 | } |
1874 | 0 | else |
1875 | 0 | xNum->nextElement(); |
1876 | 0 | nIdx++; |
1877 | 0 | } |
1878 | 0 | } |
1879 | 0 | } |
1880 | 0 | } |
1881 | 0 | } |
1882 | 0 | catch ( NoSuchElementException& ) |
1883 | 0 | { |
1884 | 0 | SAL_WARN( "svx.form", "DataNavigatorWindow::SetPageModel(): no such element" ); |
1885 | 0 | } |
1886 | 0 | catch( Exception const & ) |
1887 | 0 | { |
1888 | 0 | TOOLS_WARN_EXCEPTION( "svx.form", "DataNavigatorWindow::SetPageModel()" ); |
1889 | 0 | } |
1890 | 0 | } |
1891 | | |
1892 | | void DataNavigatorWindow::ClearAllPageModels( bool bClearPages ) |
1893 | 0 | { |
1894 | 0 | if ( m_xInstPage ) |
1895 | 0 | m_xInstPage->ClearModel(); |
1896 | 0 | if ( m_xSubmissionPage ) |
1897 | 0 | m_xSubmissionPage->ClearModel(); |
1898 | 0 | if ( m_xBindingPage ) |
1899 | 0 | m_xBindingPage->ClearModel(); |
1900 | |
|
1901 | 0 | sal_Int32 nCount = m_aPageList.size(); |
1902 | 0 | for (sal_Int32 i = 0; i < nCount; ++i) |
1903 | 0 | { |
1904 | 0 | XFormsPage* pPage = m_aPageList[i].get(); |
1905 | 0 | pPage->ClearModel(); |
1906 | 0 | } |
1907 | |
|
1908 | 0 | if ( bClearPages ) |
1909 | 0 | { |
1910 | 0 | m_aPageList.clear(); |
1911 | 0 | while ( m_xTabCtrl->get_n_pages() > MIN_PAGE_COUNT ) |
1912 | 0 | m_xTabCtrl->remove_page(m_xTabCtrl->get_page_ident(1)); |
1913 | 0 | } |
1914 | 0 | } |
1915 | | |
1916 | | void DataNavigatorWindow::CreateInstancePage( const Sequence< PropertyValue >& _xPropSeq ) |
1917 | 0 | { |
1918 | 0 | OUString sInstName; |
1919 | 0 | auto pProp = std::find_if(_xPropSeq.begin(), _xPropSeq.end(), |
1920 | 0 | [](const PropertyValue& rProp) { return PN_INSTANCE_ID == rProp.Name; }); |
1921 | 0 | if (pProp != _xPropSeq.end()) |
1922 | 0 | pProp->Value >>= sInstName; |
1923 | |
|
1924 | 0 | OUString sPageId = GetNewPageId(); |
1925 | 0 | if ( sInstName.isEmpty() ) |
1926 | 0 | { |
1927 | 0 | SAL_WARN( "svx.form", "DataNavigatorWindow::CreateInstancePage(): instance without name" ); |
1928 | 0 | sInstName = "untitled"; |
1929 | 0 | } |
1930 | 0 | m_xTabCtrl->insert_page(sPageId, sInstName, m_xTabCtrl->get_n_pages() - 2); |
1931 | 0 | } |
1932 | | |
1933 | | bool DataNavigatorWindow::HasFirstInstancePage() const |
1934 | 0 | { |
1935 | 0 | return m_xTabCtrl->get_page_ident(0) == "instance"; |
1936 | 0 | } |
1937 | | |
1938 | | OUString DataNavigatorWindow::GetNewPageId() const |
1939 | 0 | { |
1940 | 0 | int nMax = 0; |
1941 | |
|
1942 | 0 | int nCount = m_xTabCtrl->get_n_pages(); |
1943 | 0 | for (int i = 0; i < nCount; ++i) |
1944 | 0 | { |
1945 | 0 | OUString sIdent = m_xTabCtrl->get_page_ident(i); |
1946 | 0 | std::u16string_view sNumber; |
1947 | 0 | if (!sIdent.startsWith("additional", &sNumber)) |
1948 | 0 | continue; |
1949 | 0 | int nPageId = o3tl::toInt32(sNumber); |
1950 | 0 | if (nMax < nPageId) |
1951 | 0 | nMax = nPageId; |
1952 | 0 | } |
1953 | |
|
1954 | 0 | return "additional" + OUString::number(nMax + 1); |
1955 | 0 | } |
1956 | | |
1957 | | void DataNavigatorWindow::SetDocModified() |
1958 | 0 | { |
1959 | 0 | SfxObjectShell* pCurrentDoc = SfxObjectShell::Current(); |
1960 | 0 | DBG_ASSERT( pCurrentDoc, "DataNavigatorWindow::SetDocModified(): no objectshell" ); |
1961 | 0 | if (pCurrentDoc && !pCurrentDoc->IsModified() && pCurrentDoc->IsEnableSetModified()) |
1962 | 0 | pCurrentDoc->SetModified(); |
1963 | 0 | } |
1964 | | |
1965 | | void DataNavigatorWindow::NotifyChanges( bool _bLoadAll ) |
1966 | 0 | { |
1967 | 0 | if ( m_bIsNotifyDisabled ) |
1968 | 0 | return; |
1969 | | |
1970 | 0 | if ( _bLoadAll ) |
1971 | 0 | { |
1972 | | // reset all members |
1973 | 0 | RemoveBroadcaster(); |
1974 | 0 | m_xDataContainer.clear(); |
1975 | 0 | m_xFrameModel.clear(); |
1976 | 0 | m_xModelsBox->clear(); |
1977 | 0 | m_nLastSelectedPos = -1; |
1978 | | // for a reload |
1979 | 0 | LoadModels(); |
1980 | 0 | } |
1981 | 0 | else |
1982 | 0 | m_aUpdateTimer.Start(); |
1983 | 0 | } |
1984 | | |
1985 | | void DataNavigatorWindow::AddContainerBroadcaster( const css::uno::Reference< css::container::XContainer >& xContainer ) |
1986 | 0 | { |
1987 | 0 | xContainer->addContainerListener( Reference< XContainerListener >(m_xDataListener) ); |
1988 | 0 | m_aContainerList.push_back( xContainer ); |
1989 | 0 | } |
1990 | | |
1991 | | |
1992 | | void DataNavigatorWindow::AddEventBroadcaster( const css::uno::Reference< css::xml::dom::events::XEventTarget >& xTarget ) |
1993 | 0 | { |
1994 | 0 | Reference< XEventListener > xListener = m_xDataListener; |
1995 | 0 | xTarget->addEventListener( EVENTTYPE_CHARDATA, xListener, true ); |
1996 | 0 | xTarget->addEventListener( EVENTTYPE_CHARDATA, xListener, false ); |
1997 | 0 | xTarget->addEventListener( EVENTTYPE_ATTR, xListener, true ); |
1998 | 0 | xTarget->addEventListener( EVENTTYPE_ATTR, xListener, false ); |
1999 | 0 | m_aEventTargetList.push_back( xTarget ); |
2000 | 0 | } |
2001 | | |
2002 | | void DataNavigatorWindow::RemoveBroadcaster() |
2003 | 0 | { |
2004 | 0 | sal_Int32 i, nCount = m_aContainerList.size(); |
2005 | 0 | for ( i = 0; i < nCount; ++i ) |
2006 | 0 | m_aContainerList[i]->removeContainerListener( Reference< XContainerListener >(m_xDataListener) ); |
2007 | 0 | Reference< XEventListener > xEventListener = m_xDataListener; |
2008 | 0 | nCount = m_aEventTargetList.size(); |
2009 | 0 | for ( i = 0; i < nCount; ++i ) |
2010 | 0 | { |
2011 | 0 | m_aEventTargetList[i]->removeEventListener( EVENTTYPE_CHARDATA, xEventListener, true ); |
2012 | 0 | m_aEventTargetList[i]->removeEventListener( EVENTTYPE_CHARDATA, xEventListener, false ); |
2013 | 0 | m_aEventTargetList[i]->removeEventListener( EVENTTYPE_ATTR, xEventListener, true ); |
2014 | 0 | m_aEventTargetList[i]->removeEventListener( EVENTTYPE_ATTR, xEventListener, false ); |
2015 | 0 | } |
2016 | 0 | } |
2017 | | |
2018 | | DataNavigator::DataNavigator(SfxBindings* _pBindings, SfxChildWindow* _pMgr, vcl::Window* _pParent) |
2019 | 0 | : SfxDockingWindow(_pBindings, _pMgr, _pParent, u"DataNavigator"_ustr, u"svx/ui/datanavigator.ui"_ustr) |
2020 | 0 | , SfxControllerItem(SID_FM_DATANAVIGATOR_CONTROL, *_pBindings) |
2021 | 0 | , m_xDataWin(new DataNavigatorWindow(this, *m_xBuilder, _pBindings)) |
2022 | 0 | { |
2023 | 0 | SetText( SvxResId( RID_STR_DATANAVIGATOR ) ); |
2024 | |
|
2025 | 0 | Size aSize = GetOptimalSize(); |
2026 | 0 | Size aLogSize = PixelToLogic(aSize, MapMode(MapUnit::MapAppFont)); |
2027 | 0 | SfxDockingWindow::SetFloatingSize( aLogSize ); |
2028 | 0 | } Unexecuted instantiation: svxform::DataNavigator::DataNavigator(SfxBindings*, SfxChildWindow*, vcl::Window*) Unexecuted instantiation: svxform::DataNavigator::DataNavigator(SfxBindings*, SfxChildWindow*, vcl::Window*) |
2029 | | |
2030 | | DataNavigator::~DataNavigator() |
2031 | 0 | { |
2032 | 0 | disposeOnce(); |
2033 | 0 | } |
2034 | | |
2035 | | void DataNavigator::dispose() |
2036 | 0 | { |
2037 | 0 | m_xDataWin.reset(); |
2038 | 0 | ::SfxControllerItem::dispose(); |
2039 | 0 | SfxDockingWindow::dispose(); |
2040 | 0 | } |
2041 | | |
2042 | | void DataNavigator::StateChangedAtToolBoxControl( sal_uInt16 , SfxItemState , const SfxPoolItem* ) |
2043 | 0 | { |
2044 | 0 | } |
2045 | | |
2046 | | Size DataNavigator::CalcDockingSize( SfxChildAlignment eAlign ) |
2047 | 0 | { |
2048 | 0 | if ( ( eAlign == SfxChildAlignment::TOP ) || ( eAlign == SfxChildAlignment::BOTTOM ) ) |
2049 | 0 | return Size(); |
2050 | | |
2051 | 0 | return SfxDockingWindow::CalcDockingSize( eAlign ); |
2052 | 0 | } |
2053 | | |
2054 | | SfxChildAlignment DataNavigator::CheckAlignment( SfxChildAlignment eActAlign, SfxChildAlignment eAlign ) |
2055 | 0 | { |
2056 | 0 | switch ( eAlign ) |
2057 | 0 | { |
2058 | 0 | case SfxChildAlignment::LEFT: |
2059 | 0 | case SfxChildAlignment::RIGHT: |
2060 | 0 | case SfxChildAlignment::NOALIGNMENT: |
2061 | 0 | return eAlign; |
2062 | 0 | default: |
2063 | 0 | break; |
2064 | 0 | } |
2065 | 0 | return eActAlign; |
2066 | 0 | } |
2067 | | |
2068 | | SFX_IMPL_DOCKINGWINDOW( DataNavigatorManager, SID_FM_SHOW_DATANAVIGATOR ) |
2069 | | |
2070 | | DataNavigatorManager::DataNavigatorManager( |
2071 | | vcl::Window* _pParent, sal_uInt16 _nId, SfxBindings* _pBindings, SfxChildWinInfo* _pInfo ) : |
2072 | | |
2073 | 0 | SfxChildWindow( _pParent, _nId ) |
2074 | | |
2075 | 0 | { |
2076 | 0 | SetWindow( VclPtr<DataNavigator>::Create( _pBindings, this, _pParent ) ); |
2077 | 0 | SetAlignment(SfxChildAlignment::RIGHT); |
2078 | 0 | GetWindow()->SetSizePixel( Size( 250, 400 ) ); |
2079 | 0 | static_cast<SfxDockingWindow*>(GetWindow())->Initialize( _pInfo ); |
2080 | 0 | } |
2081 | | |
2082 | | AddDataItemDialog::AddDataItemDialog(weld::Window* pParent, ItemNode* _pNode, |
2083 | | const Reference< css::xforms::XFormsUIHelper1 >& _rUIHelper) |
2084 | 0 | : GenericDialogController(pParent, u"svx/ui/adddataitemdialog.ui"_ustr, u"AddDataItemDialog"_ustr) |
2085 | 0 | , m_xUIHelper(_rUIHelper) |
2086 | 0 | , m_pItemNode(_pNode) |
2087 | 0 | , m_eItemType(DITNone) |
2088 | 0 | , m_sFL_Element(SvxResId(RID_STR_ELEMENT)) |
2089 | 0 | , m_sFL_Attribute(SvxResId(RID_STR_ATTRIBUTE)) |
2090 | 0 | , m_sFL_Binding(SvxResId(RID_STR_BINDING)) |
2091 | 0 | , m_sFT_BindingExp(SvxResId(RID_STR_BINDING_EXPR)) |
2092 | 0 | , m_xItemFrame(m_xBuilder->weld_frame(u"itemframe"_ustr)) |
2093 | 0 | , m_xNameFT(m_xBuilder->weld_label(u"nameft"_ustr)) |
2094 | 0 | , m_xNameED(m_xBuilder->weld_entry(u"name"_ustr)) |
2095 | 0 | , m_xDefaultFT(m_xBuilder->weld_label(u"valueft"_ustr)) |
2096 | 0 | , m_xDefaultED(m_xBuilder->weld_entry(u"value"_ustr)) |
2097 | 0 | , m_xDefaultBtn(m_xBuilder->weld_button(u"browse"_ustr)) |
2098 | 0 | , m_xSettingsFrame(m_xBuilder->weld_widget(u"settingsframe"_ustr)) |
2099 | 0 | , m_xDataTypeLB(m_xBuilder->weld_combo_box(u"datatype"_ustr)) |
2100 | 0 | , m_xRequiredCB(m_xBuilder->weld_check_button(u"required"_ustr)) |
2101 | 0 | , m_xRequiredBtn(m_xBuilder->weld_button(u"requiredcond"_ustr)) |
2102 | 0 | , m_xRelevantCB(m_xBuilder->weld_check_button(u"relevant"_ustr)) |
2103 | 0 | , m_xRelevantBtn(m_xBuilder->weld_button(u"relevantcond"_ustr)) |
2104 | 0 | , m_xConstraintCB(m_xBuilder->weld_check_button(u"constraint"_ustr)) |
2105 | 0 | , m_xConstraintBtn(m_xBuilder->weld_button(u"constraintcond"_ustr)) |
2106 | 0 | , m_xReadonlyCB(m_xBuilder->weld_check_button(u"readonly"_ustr)) |
2107 | 0 | , m_xReadonlyBtn(m_xBuilder->weld_button(u"readonlycond"_ustr)) |
2108 | 0 | , m_xCalculateCB(m_xBuilder->weld_check_button(u"calculate"_ustr)) |
2109 | 0 | , m_xCalculateBtn(m_xBuilder->weld_button(u"calculatecond"_ustr)) |
2110 | 0 | , m_xOKBtn(m_xBuilder->weld_button(u"ok"_ustr)) |
2111 | 0 | { |
2112 | 0 | InitDialog(); |
2113 | 0 | InitFromNode(); |
2114 | 0 | InitDataTypeBox(); |
2115 | 0 | Check(nullptr); |
2116 | 0 | } |
2117 | | |
2118 | | AddDataItemDialog::~AddDataItemDialog() |
2119 | 0 | { |
2120 | 0 | if ( m_xTempBinding.is() ) |
2121 | 0 | { |
2122 | 0 | Reference< css::xforms::XModel > xModel( m_xUIHelper, UNO_QUERY ); |
2123 | 0 | if ( xModel.is() ) |
2124 | 0 | { |
2125 | 0 | try |
2126 | 0 | { |
2127 | 0 | Reference < XSet > xBindings = xModel->getBindings(); |
2128 | 0 | if ( xBindings.is() ) |
2129 | 0 | xBindings->remove( Any( m_xTempBinding ) ); |
2130 | 0 | } |
2131 | 0 | catch (const Exception&) |
2132 | 0 | { |
2133 | 0 | TOOLS_WARN_EXCEPTION( "svx.form", "AddDataItemDialog::Dtor()" ); |
2134 | 0 | } |
2135 | 0 | } |
2136 | 0 | } |
2137 | 0 | if( m_xUIHelper.is() && m_xBinding.is() ) |
2138 | 0 | { |
2139 | | // remove binding, if it does not convey 'useful' information |
2140 | 0 | m_xUIHelper->removeBindingIfUseless( m_xBinding ); |
2141 | 0 | } |
2142 | 0 | } |
2143 | | |
2144 | | IMPL_LINK(AddDataItemDialog, CheckHdl, weld::Toggleable&, rBox, void) |
2145 | 0 | { |
2146 | 0 | Check(&rBox); |
2147 | 0 | } |
2148 | | |
2149 | | void AddDataItemDialog::Check(const weld::Toggleable* pBox) |
2150 | 0 | { |
2151 | | // Condition buttons are only enable if their check box is checked |
2152 | 0 | m_xReadonlyBtn->set_sensitive( m_xReadonlyCB->get_active() ); |
2153 | 0 | m_xRequiredBtn->set_sensitive( m_xRequiredCB->get_active() ); |
2154 | 0 | m_xRelevantBtn->set_sensitive( m_xRelevantCB->get_active() ); |
2155 | 0 | m_xConstraintBtn->set_sensitive( m_xConstraintCB->get_active() ); |
2156 | 0 | m_xCalculateBtn->set_sensitive( m_xCalculateCB->get_active() ); |
2157 | |
|
2158 | 0 | if ( !(pBox && m_xTempBinding.is()) ) |
2159 | 0 | return; |
2160 | | |
2161 | 0 | OUString sTemp, sPropName; |
2162 | 0 | if ( m_xRequiredCB.get() == pBox ) |
2163 | 0 | sPropName = PN_REQUIRED_EXPR; |
2164 | 0 | else if ( m_xRelevantCB.get() == pBox ) |
2165 | 0 | sPropName = PN_RELEVANT_EXPR; |
2166 | 0 | else if ( m_xConstraintCB.get() == pBox ) |
2167 | 0 | sPropName = PN_CONSTRAINT_EXPR; |
2168 | 0 | else if ( m_xReadonlyCB.get() == pBox ) |
2169 | 0 | sPropName = PN_READONLY_EXPR; |
2170 | 0 | else if ( m_xCalculateCB.get() == pBox ) |
2171 | 0 | sPropName = PN_CALCULATE_EXPR; |
2172 | 0 | bool bIsChecked = pBox->get_active(); |
2173 | 0 | m_xTempBinding->getPropertyValue( sPropName ) >>= sTemp; |
2174 | 0 | if ( bIsChecked && sTemp.isEmpty() ) |
2175 | 0 | sTemp = TRUE_VALUE; |
2176 | 0 | else if ( !bIsChecked && !sTemp.isEmpty() ) |
2177 | 0 | sTemp.clear(); |
2178 | 0 | m_xTempBinding->setPropertyValue( sPropName, Any( sTemp ) ); |
2179 | 0 | } |
2180 | | |
2181 | | IMPL_LINK(AddDataItemDialog, ConditionHdl, weld::Button&, rBtn, void) |
2182 | 0 | { |
2183 | 0 | OUString sPropName; |
2184 | 0 | if ( m_xDefaultBtn.get() == &rBtn ) |
2185 | 0 | sPropName = PN_BINDING_EXPR; |
2186 | 0 | else if ( m_xRequiredBtn.get() == &rBtn ) |
2187 | 0 | sPropName = PN_REQUIRED_EXPR; |
2188 | 0 | else if ( m_xRelevantBtn.get() == &rBtn ) |
2189 | 0 | sPropName = PN_RELEVANT_EXPR; |
2190 | 0 | else if ( m_xConstraintBtn.get() == &rBtn ) |
2191 | 0 | sPropName = PN_CONSTRAINT_EXPR; |
2192 | 0 | else if (m_xReadonlyBtn.get() == &rBtn) |
2193 | 0 | sPropName = PN_READONLY_EXPR; |
2194 | 0 | else if (m_xCalculateBtn.get() == &rBtn) |
2195 | 0 | sPropName = PN_CALCULATE_EXPR; |
2196 | 0 | AddConditionDialog aDlg(m_xDialog.get(), sPropName, m_xTempBinding); |
2197 | 0 | bool bIsDefBtn = ( m_xDefaultBtn.get() == &rBtn ); |
2198 | 0 | OUString sCondition; |
2199 | 0 | if ( bIsDefBtn ) |
2200 | 0 | sCondition = m_xDefaultED->get_text(); |
2201 | 0 | else |
2202 | 0 | { |
2203 | 0 | OUString sTemp; |
2204 | 0 | m_xTempBinding->getPropertyValue( sPropName ) >>= sTemp; |
2205 | 0 | if ( sTemp.isEmpty() ) |
2206 | 0 | sTemp = TRUE_VALUE; |
2207 | 0 | sCondition = sTemp; |
2208 | 0 | } |
2209 | 0 | aDlg.SetCondition( sCondition ); |
2210 | |
|
2211 | 0 | if (aDlg.run() == RET_OK) |
2212 | 0 | { |
2213 | 0 | OUString sNewCondition = aDlg.GetCondition(); |
2214 | 0 | if ( bIsDefBtn ) |
2215 | 0 | m_xDefaultED->set_text(sNewCondition); |
2216 | 0 | else |
2217 | 0 | { |
2218 | |
|
2219 | 0 | m_xTempBinding->setPropertyValue( |
2220 | 0 | sPropName, Any( sNewCondition ) ); |
2221 | 0 | } |
2222 | 0 | } |
2223 | 0 | } |
2224 | | |
2225 | | static void copyPropSet( const Reference< XPropertySet >& xFrom, Reference< XPropertySet > const & xTo ) |
2226 | 0 | { |
2227 | 0 | DBG_ASSERT( xFrom.is(), "copyPropSet(): no source" ); |
2228 | 0 | DBG_ASSERT( xTo.is(), "copyPropSet(): no target" ); |
2229 | |
|
2230 | 0 | try |
2231 | 0 | { |
2232 | | // get property names & infos, and iterate over target properties |
2233 | 0 | const Sequence< Property > aProperties = xTo->getPropertySetInfo()->getProperties(); |
2234 | 0 | Reference< XPropertySetInfo > xFromInfo = xFrom->getPropertySetInfo(); |
2235 | 0 | for ( const Property& rProperty : aProperties ) |
2236 | 0 | { |
2237 | 0 | const OUString& rName = rProperty.Name; |
2238 | | |
2239 | | // if both set have the property, copy the value |
2240 | | // (catch and ignore exceptions, if any) |
2241 | 0 | if ( xFromInfo->hasPropertyByName( rName ) ) |
2242 | 0 | { |
2243 | | // don't set readonly properties |
2244 | 0 | Property aProperty = xFromInfo->getPropertyByName( rName ); |
2245 | 0 | if ( ( aProperty.Attributes & PropertyAttribute::READONLY ) == 0 ) |
2246 | 0 | xTo->setPropertyValue(rName, xFrom->getPropertyValue( rName )); |
2247 | 0 | } |
2248 | | // else: no property? then ignore. |
2249 | 0 | } |
2250 | 0 | } |
2251 | 0 | catch ( Exception const & ) |
2252 | 0 | { |
2253 | 0 | TOOLS_WARN_EXCEPTION( "svx.form", "copyPropSet()" ); |
2254 | 0 | } |
2255 | 0 | } |
2256 | | |
2257 | | IMPL_LINK_NOARG(AddDataItemDialog, OKHdl, weld::Button&, void) |
2258 | 0 | { |
2259 | 0 | bool bIsHandleBinding = ( DITBinding == m_eItemType ); |
2260 | 0 | bool bIsHandleText = ( DITText == m_eItemType ); |
2261 | 0 | OUString sNewName( m_xNameED->get_text() ); |
2262 | |
|
2263 | 0 | if ( ( !bIsHandleBinding && !bIsHandleText && !m_xUIHelper->isValidXMLName( sNewName ) ) || |
2264 | 0 | ( bIsHandleBinding && sNewName.isEmpty() ) ) |
2265 | 0 | { |
2266 | | // Error and don't close the dialog |
2267 | 0 | std::unique_ptr<weld::MessageDialog> xErrBox(Application::CreateMessageDialog(m_xDialog.get(), |
2268 | 0 | VclMessageType::Warning, VclButtonsType::Ok, |
2269 | 0 | SvxResId(RID_STR_INVALID_XMLNAME))); |
2270 | 0 | xErrBox->set_primary_text(xErrBox->get_primary_text().replaceFirst(MSG_VARIABLE, sNewName)); |
2271 | 0 | xErrBox->run(); |
2272 | 0 | return; |
2273 | 0 | } |
2274 | | |
2275 | 0 | OUString sDataType( m_xDataTypeLB->get_active_text() ); |
2276 | 0 | m_xTempBinding->setPropertyValue( PN_BINDING_TYPE, Any( sDataType ) ); |
2277 | |
|
2278 | 0 | if ( bIsHandleBinding ) |
2279 | 0 | { |
2280 | | // copy properties from temp binding to original binding |
2281 | 0 | copyPropSet( m_xTempBinding, m_pItemNode->m_xPropSet ); |
2282 | 0 | try |
2283 | 0 | { |
2284 | 0 | OUString sValue = m_xNameED->get_text(); |
2285 | 0 | m_pItemNode->m_xPropSet->setPropertyValue( PN_BINDING_ID, Any( sValue ) ); |
2286 | 0 | sValue = m_xDefaultED->get_text(); |
2287 | 0 | m_pItemNode->m_xPropSet->setPropertyValue( PN_BINDING_EXPR, Any( sValue ) ); |
2288 | 0 | } |
2289 | 0 | catch ( Exception const & ) |
2290 | 0 | { |
2291 | 0 | TOOLS_WARN_EXCEPTION( "svx.form", "AddDataDialog::OKHdl()" ); |
2292 | 0 | } |
2293 | 0 | } |
2294 | 0 | else |
2295 | 0 | { |
2296 | | // copy properties from temp binding to original binding |
2297 | 0 | copyPropSet( m_xTempBinding, m_xBinding ); |
2298 | 0 | try |
2299 | 0 | { |
2300 | 0 | if ( bIsHandleText ) |
2301 | 0 | m_xUIHelper->setNodeValue( m_pItemNode->m_xNode, m_xDefaultED->get_text() ); |
2302 | 0 | else |
2303 | 0 | { |
2304 | 0 | Reference< css::xml::dom::XNode > xNewNode = |
2305 | 0 | m_xUIHelper->renameNode( m_pItemNode->m_xNode, m_xNameED->get_text() ); |
2306 | 0 | m_xUIHelper->setNodeValue( xNewNode, m_xDefaultED->get_text() ); |
2307 | 0 | m_pItemNode->m_xNode = std::move(xNewNode); |
2308 | 0 | } |
2309 | 0 | } |
2310 | 0 | catch ( Exception const & ) |
2311 | 0 | { |
2312 | 0 | TOOLS_WARN_EXCEPTION( "svx.form", "AddDataDialog::OKHdl()" ); |
2313 | 0 | } |
2314 | 0 | } |
2315 | | // then close the dialog |
2316 | 0 | m_xDialog->response(RET_OK); |
2317 | 0 | } |
2318 | | |
2319 | | void AddDataItemDialog::InitDialog() |
2320 | 0 | { |
2321 | | // set handler |
2322 | 0 | Link<weld::Toggleable&,void> aLink = LINK( this, AddDataItemDialog, CheckHdl ); |
2323 | 0 | m_xRequiredCB->connect_toggled( aLink ); |
2324 | 0 | m_xRelevantCB->connect_toggled( aLink ); |
2325 | 0 | m_xConstraintCB->connect_toggled( aLink ); |
2326 | 0 | m_xReadonlyCB->connect_toggled( aLink ); |
2327 | 0 | m_xCalculateCB->connect_toggled( aLink ); |
2328 | |
|
2329 | 0 | Link<weld::Button&,void> aLink2 = LINK( this, AddDataItemDialog, ConditionHdl ); |
2330 | 0 | m_xDefaultBtn->connect_clicked( aLink2 ); |
2331 | 0 | m_xRequiredBtn->connect_clicked( aLink2 ); |
2332 | 0 | m_xRelevantBtn->connect_clicked( aLink2 ); |
2333 | 0 | m_xConstraintBtn->connect_clicked( aLink2 ); |
2334 | 0 | m_xReadonlyBtn->connect_clicked( aLink2 ); |
2335 | 0 | m_xCalculateBtn->connect_clicked( aLink2 ); |
2336 | |
|
2337 | 0 | m_xOKBtn->connect_clicked( LINK( this, AddDataItemDialog, OKHdl ) ); |
2338 | 0 | } |
2339 | | |
2340 | | void AddDataItemDialog::InitFromNode() |
2341 | 0 | { |
2342 | 0 | if ( m_pItemNode ) |
2343 | 0 | { |
2344 | 0 | if ( m_pItemNode->m_xNode.is() ) |
2345 | 0 | { |
2346 | 0 | try |
2347 | 0 | { |
2348 | | // detect type of the node |
2349 | 0 | css::xml::dom::NodeType eChildType = m_pItemNode->m_xNode->getNodeType(); |
2350 | 0 | switch ( eChildType ) |
2351 | 0 | { |
2352 | 0 | case css::xml::dom::NodeType_ATTRIBUTE_NODE: |
2353 | 0 | m_eItemType = DITAttribute; |
2354 | 0 | break; |
2355 | 0 | case css::xml::dom::NodeType_ELEMENT_NODE: |
2356 | 0 | m_eItemType = DITElement; |
2357 | 0 | break; |
2358 | 0 | case css::xml::dom::NodeType_TEXT_NODE: |
2359 | 0 | m_eItemType = DITText; |
2360 | 0 | break; |
2361 | 0 | default: |
2362 | 0 | OSL_FAIL( "AddDataItemDialog::InitFronNode: cannot handle this node type!" ); |
2363 | 0 | break; |
2364 | 0 | } |
2365 | | |
2366 | | /** Get binding of the node and clone it |
2367 | | Then use this temporary binding in the dialog. |
2368 | | When the user click OK the temporary binding will be copied |
2369 | | into the original binding. |
2370 | | */ |
2371 | | |
2372 | 0 | Reference< css::xml::dom::XNode > xNode = m_pItemNode->m_xNode; |
2373 | 0 | m_xBinding = m_xUIHelper->getBindingForNode( xNode, true ); |
2374 | 0 | if ( m_xBinding.is() ) |
2375 | 0 | { |
2376 | 0 | Reference< css::xforms::XModel > xModel( m_xUIHelper, UNO_QUERY ); |
2377 | 0 | if ( xModel.is() ) |
2378 | 0 | { |
2379 | 0 | m_xTempBinding = m_xUIHelper->cloneBindingAsGhost( m_xBinding ); |
2380 | 0 | Reference < XSet > xBindings = xModel->getBindings(); |
2381 | 0 | if ( xBindings.is() ) |
2382 | 0 | xBindings->insert( Any( m_xTempBinding ) ); |
2383 | 0 | } |
2384 | 0 | } |
2385 | |
|
2386 | 0 | if ( m_eItemType != DITText ) |
2387 | 0 | { |
2388 | 0 | OUString sName( m_xUIHelper->getNodeName( m_pItemNode->m_xNode ) ); |
2389 | 0 | m_xNameED->set_text( sName ); |
2390 | 0 | } |
2391 | 0 | m_xDefaultED->set_text( m_pItemNode->m_xNode->getNodeValue() ); |
2392 | 0 | } |
2393 | 0 | catch( Exception const & ) |
2394 | 0 | { |
2395 | 0 | TOOLS_WARN_EXCEPTION( "svx.form", "AddDataItemDialog::InitFromNode()" ); |
2396 | 0 | } |
2397 | 0 | } |
2398 | 0 | else if ( m_pItemNode->m_xPropSet.is() ) |
2399 | 0 | { |
2400 | 0 | m_eItemType = DITBinding; |
2401 | 0 | Reference< css::xforms::XModel > xModel( m_xUIHelper, UNO_QUERY ); |
2402 | 0 | if ( xModel.is() ) |
2403 | 0 | { |
2404 | 0 | try |
2405 | 0 | { |
2406 | 0 | m_xTempBinding = m_xUIHelper->cloneBindingAsGhost( m_pItemNode->m_xPropSet ); |
2407 | 0 | Reference < XSet > xBindings = xModel->getBindings(); |
2408 | 0 | if ( xBindings.is() ) |
2409 | 0 | xBindings->insert( Any( m_xTempBinding ) ); |
2410 | 0 | } |
2411 | 0 | catch ( Exception const & ) |
2412 | 0 | { |
2413 | 0 | TOOLS_WARN_EXCEPTION( "svx.form", "AddDataItemDialog::InitFromNode()" ); |
2414 | 0 | } |
2415 | 0 | } |
2416 | 0 | try |
2417 | 0 | { |
2418 | 0 | Reference< XPropertySetInfo > xInfo = m_pItemNode->m_xPropSet->getPropertySetInfo(); |
2419 | 0 | OUString sTemp; |
2420 | 0 | if ( xInfo->hasPropertyByName( PN_BINDING_ID ) ) |
2421 | 0 | { |
2422 | 0 | m_pItemNode->m_xPropSet->getPropertyValue( PN_BINDING_ID ) >>= sTemp; |
2423 | 0 | m_xNameED->set_text( sTemp ); |
2424 | 0 | m_pItemNode->m_xPropSet->getPropertyValue( PN_BINDING_EXPR ) >>= sTemp; |
2425 | 0 | m_xDefaultED->set_text( sTemp ); |
2426 | 0 | } |
2427 | 0 | else if ( xInfo->hasPropertyByName( PN_SUBMISSION_BIND ) ) |
2428 | 0 | { |
2429 | 0 | m_pItemNode->m_xPropSet->getPropertyValue( PN_SUBMISSION_ID ) >>= sTemp; |
2430 | 0 | m_xNameED->set_text( sTemp ); |
2431 | 0 | } |
2432 | 0 | } |
2433 | 0 | catch( Exception const & ) |
2434 | 0 | { |
2435 | 0 | TOOLS_WARN_EXCEPTION( "svx.form", "AddDataItemDialog::InitFromNode()" ); |
2436 | 0 | } |
2437 | | |
2438 | 0 | m_xDefaultBtn->show(); |
2439 | 0 | } |
2440 | | |
2441 | 0 | if ( m_xTempBinding.is() ) |
2442 | 0 | { |
2443 | 0 | try |
2444 | 0 | { |
2445 | 0 | OUString sTemp; |
2446 | 0 | if ( ( m_xTempBinding->getPropertyValue( PN_REQUIRED_EXPR ) >>= sTemp ) |
2447 | 0 | && !sTemp.isEmpty() ) |
2448 | 0 | m_xRequiredCB->set_active(true); |
2449 | 0 | if ( ( m_xTempBinding->getPropertyValue( PN_RELEVANT_EXPR ) >>= sTemp ) |
2450 | 0 | && !sTemp.isEmpty() ) |
2451 | 0 | m_xRelevantCB->set_active(true); |
2452 | 0 | if ( ( m_xTempBinding->getPropertyValue( PN_CONSTRAINT_EXPR ) >>= sTemp ) |
2453 | 0 | && !sTemp.isEmpty() ) |
2454 | 0 | m_xConstraintCB->set_active(true); |
2455 | 0 | if ( ( m_xTempBinding->getPropertyValue( PN_READONLY_EXPR ) >>= sTemp ) |
2456 | 0 | && !sTemp.isEmpty() ) |
2457 | 0 | m_xReadonlyCB->set_active(true); |
2458 | 0 | if ( ( m_xTempBinding->getPropertyValue( PN_CALCULATE_EXPR ) >>= sTemp ) |
2459 | 0 | && !sTemp.isEmpty() ) |
2460 | 0 | m_xCalculateCB->set_active(true); |
2461 | 0 | } |
2462 | 0 | catch (const Exception&) |
2463 | 0 | { |
2464 | 0 | TOOLS_WARN_EXCEPTION( "svx.form", "AddDataItemDialog::InitFromNode()" ); |
2465 | 0 | } |
2466 | 0 | } |
2467 | 0 | } |
2468 | | |
2469 | 0 | if ( DITText == m_eItemType ) |
2470 | 0 | { |
2471 | 0 | m_xSettingsFrame->hide(); |
2472 | 0 | m_xNameFT->set_sensitive(false); |
2473 | 0 | m_xNameED->set_sensitive(false); |
2474 | 0 | } |
2475 | 0 | } |
2476 | | |
2477 | | void AddDataItemDialog::InitDataTypeBox() |
2478 | 0 | { |
2479 | 0 | if ( m_eItemType == DITText ) |
2480 | 0 | return; |
2481 | | |
2482 | 0 | Reference< css::xforms::XModel > xModel( m_xUIHelper, UNO_QUERY ); |
2483 | 0 | if ( !xModel.is() ) |
2484 | 0 | return; |
2485 | | |
2486 | 0 | try |
2487 | 0 | { |
2488 | 0 | Reference< css::xforms::XDataTypeRepository > xDataTypes = |
2489 | 0 | xModel->getDataTypeRepository(); |
2490 | 0 | if ( xDataTypes.is() ) |
2491 | 0 | { |
2492 | 0 | const Sequence< OUString > aNameList = xDataTypes->getElementNames(); |
2493 | 0 | for ( const OUString& rName : aNameList ) |
2494 | 0 | m_xDataTypeLB->append_text(rName); |
2495 | 0 | } |
2496 | |
|
2497 | 0 | if ( m_xTempBinding.is() ) |
2498 | 0 | { |
2499 | 0 | OUString sTemp; |
2500 | 0 | if ( m_xTempBinding->getPropertyValue( PN_BINDING_TYPE ) >>= sTemp ) |
2501 | 0 | { |
2502 | 0 | int nPos = m_xDataTypeLB->find_text(sTemp); |
2503 | 0 | if (nPos == -1) |
2504 | 0 | { |
2505 | 0 | m_xDataTypeLB->append_text(sTemp); |
2506 | 0 | nPos = m_xDataTypeLB->get_count() - 1; |
2507 | 0 | } |
2508 | 0 | m_xDataTypeLB->set_active(nPos); |
2509 | 0 | } |
2510 | 0 | } |
2511 | 0 | } |
2512 | 0 | catch ( Exception const & ) |
2513 | 0 | { |
2514 | 0 | TOOLS_WARN_EXCEPTION( "svx.form", "AddDataItemDialog::InitDataTypeBox()" ); |
2515 | 0 | } |
2516 | 0 | } |
2517 | | |
2518 | | void AddDataItemDialog::InitText( DataItemType _eType ) |
2519 | 0 | { |
2520 | 0 | OUString sText; |
2521 | |
|
2522 | 0 | switch ( _eType ) |
2523 | 0 | { |
2524 | 0 | case DITAttribute : |
2525 | 0 | { |
2526 | 0 | sText = m_sFL_Attribute; |
2527 | 0 | break; |
2528 | 0 | } |
2529 | | |
2530 | 0 | case DITBinding : |
2531 | 0 | { |
2532 | 0 | sText = m_sFL_Binding; |
2533 | 0 | m_xDefaultFT->set_label(m_sFT_BindingExp); |
2534 | 0 | break; |
2535 | 0 | } |
2536 | | |
2537 | 0 | default: |
2538 | 0 | { |
2539 | 0 | sText = m_sFL_Element; |
2540 | 0 | } |
2541 | 0 | } |
2542 | | |
2543 | 0 | m_xItemFrame->set_label(sText); |
2544 | 0 | } |
2545 | | |
2546 | | AddConditionDialog::AddConditionDialog(weld::Window* pParent, |
2547 | | OUString _aPropertyName, |
2548 | | const Reference< XPropertySet >& _rPropSet) |
2549 | 0 | : GenericDialogController(pParent, u"svx/ui/addconditiondialog.ui"_ustr, u"AddConditionDialog"_ustr) |
2550 | 0 | , m_aResultIdle("svx AddConditionDialog m_aResultIdle") |
2551 | 0 | , m_sPropertyName(std::move(_aPropertyName)) |
2552 | 0 | , m_xBinding(_rPropSet) |
2553 | 0 | , m_xConditionED(m_xBuilder->weld_text_view(u"condition"_ustr)) |
2554 | 0 | , m_xResultWin(m_xBuilder->weld_text_view(u"result"_ustr)) |
2555 | 0 | , m_xEditNamespacesBtn(m_xBuilder->weld_button(u"edit"_ustr)) |
2556 | 0 | , m_xOKBtn(m_xBuilder->weld_button(u"ok"_ustr)) |
2557 | 0 | { |
2558 | 0 | DBG_ASSERT( m_xBinding.is(), "AddConditionDialog::Ctor(): no Binding" ); |
2559 | |
|
2560 | 0 | m_xConditionED->set_size_request(m_xConditionED->get_approximate_digit_width() * 52, |
2561 | 0 | m_xConditionED->get_height_rows(4)); |
2562 | 0 | m_xResultWin->set_size_request(m_xResultWin->get_approximate_digit_width() * 52, |
2563 | 0 | m_xResultWin->get_height_rows(4)); |
2564 | |
|
2565 | 0 | m_xConditionED->connect_changed( LINK( this, AddConditionDialog, ModifyHdl ) ); |
2566 | 0 | m_xEditNamespacesBtn->connect_clicked( LINK( this, AddConditionDialog, EditHdl ) ); |
2567 | 0 | m_xOKBtn->connect_clicked( LINK( this, AddConditionDialog, OKHdl ) ); |
2568 | 0 | m_aResultIdle.SetPriority( TaskPriority::LOWEST ); |
2569 | 0 | m_aResultIdle.SetInvokeHandler( LINK( this, AddConditionDialog, ResultHdl ) ); |
2570 | |
|
2571 | 0 | if ( !m_sPropertyName.isEmpty() ) |
2572 | 0 | { |
2573 | 0 | try |
2574 | 0 | { |
2575 | 0 | OUString sTemp; |
2576 | 0 | if ( ( m_xBinding->getPropertyValue( m_sPropertyName ) >>= sTemp ) |
2577 | 0 | && !sTemp.isEmpty() ) |
2578 | 0 | { |
2579 | 0 | m_xConditionED->set_text( sTemp ); |
2580 | 0 | } |
2581 | 0 | else |
2582 | 0 | { |
2583 | | //! m_xBinding->setPropertyValue( m_sPropertyName, makeAny( TRUE_VALUE ) ); |
2584 | 0 | m_xConditionED->set_text( TRUE_VALUE ); |
2585 | 0 | } |
2586 | |
|
2587 | 0 | Reference< css::xforms::XModel > xModel; |
2588 | 0 | if ( ( m_xBinding->getPropertyValue( PN_BINDING_MODEL ) >>= xModel ) && xModel.is() ) |
2589 | 0 | m_xUIHelper.set( xModel, UNO_QUERY ); |
2590 | 0 | } |
2591 | 0 | catch (const Exception&) |
2592 | 0 | { |
2593 | 0 | TOOLS_WARN_EXCEPTION( "svx.form", "AddConditionDialog::Ctor()" ); |
2594 | 0 | } |
2595 | 0 | } |
2596 | | |
2597 | 0 | DBG_ASSERT( m_xUIHelper.is(), "AddConditionDialog::Ctor(): no UIHelper" ); |
2598 | 0 | ResultHdl( &m_aResultIdle ); |
2599 | 0 | } |
2600 | | |
2601 | | AddConditionDialog::~AddConditionDialog() |
2602 | 0 | { |
2603 | 0 | } |
2604 | | |
2605 | | IMPL_LINK_NOARG(AddConditionDialog, EditHdl, weld::Button&, void) |
2606 | 0 | { |
2607 | 0 | Reference< XNameContainer > xNameContnr; |
2608 | 0 | try |
2609 | 0 | { |
2610 | 0 | m_xBinding->getPropertyValue( PN_BINDING_NAMESPACES ) >>= xNameContnr; |
2611 | 0 | } |
2612 | 0 | catch ( Exception const & ) |
2613 | 0 | { |
2614 | 0 | TOOLS_WARN_EXCEPTION( "svx.form", "AddDataItemDialog::EditHdl()" ); |
2615 | 0 | } |
2616 | 0 | NamespaceItemDialog aDlg(this, xNameContnr); |
2617 | 0 | aDlg.run(); |
2618 | 0 | try |
2619 | 0 | { |
2620 | 0 | m_xBinding->setPropertyValue( PN_BINDING_NAMESPACES, Any( xNameContnr ) ); |
2621 | 0 | } |
2622 | 0 | catch ( Exception const & ) |
2623 | 0 | { |
2624 | 0 | TOOLS_WARN_EXCEPTION( "svx.form", "AddDataItemDialog::EditHdl()" ); |
2625 | 0 | } |
2626 | 0 | } |
2627 | | |
2628 | | IMPL_LINK_NOARG(AddConditionDialog, OKHdl, weld::Button&, void) |
2629 | 0 | { |
2630 | 0 | m_xDialog->response(RET_OK); |
2631 | 0 | } |
2632 | | |
2633 | | IMPL_LINK_NOARG(AddConditionDialog, ModifyHdl, weld::TextView&, void) |
2634 | 0 | { |
2635 | 0 | m_aResultIdle.Start(); |
2636 | 0 | } |
2637 | | |
2638 | | IMPL_LINK_NOARG(AddConditionDialog, ResultHdl, Timer *, void) |
2639 | 0 | { |
2640 | 0 | OUString sCondition = comphelper::string::strip(m_xConditionED->get_text(), ' '); |
2641 | 0 | OUString sResult; |
2642 | 0 | if ( !sCondition.isEmpty() ) |
2643 | 0 | { |
2644 | 0 | try |
2645 | 0 | { |
2646 | 0 | sResult = m_xUIHelper->getResultForExpression( m_xBinding, ( m_sPropertyName == PN_BINDING_EXPR ), sCondition ); |
2647 | 0 | } |
2648 | 0 | catch ( Exception const & ) |
2649 | 0 | { |
2650 | 0 | TOOLS_WARN_EXCEPTION( "svx.form", "AddConditionDialog::ResultHdl()" ); |
2651 | 0 | } |
2652 | 0 | } |
2653 | 0 | m_xResultWin->set_text(sResult); |
2654 | 0 | } |
2655 | | |
2656 | | NamespaceItemDialog::NamespaceItemDialog(AddConditionDialog* pCondDlg, Reference<XNameContainer>& rContainer) |
2657 | 0 | : GenericDialogController(pCondDlg->getDialog(), u"svx/ui/namespacedialog.ui"_ustr, u"NamespaceDialog"_ustr) |
2658 | 0 | , m_pConditionDlg(pCondDlg) |
2659 | 0 | , m_rNamespaces(rContainer) |
2660 | 0 | , m_xNamespacesList(m_xBuilder->weld_tree_view(u"namespaces"_ustr)) |
2661 | 0 | , m_xAddNamespaceBtn(m_xBuilder->weld_button(u"add"_ustr)) |
2662 | 0 | , m_xEditNamespaceBtn(m_xBuilder->weld_button(u"edit"_ustr)) |
2663 | 0 | , m_xDeleteNamespaceBtn(m_xBuilder->weld_button(u"delete"_ustr)) |
2664 | 0 | , m_xOKBtn(m_xBuilder->weld_button(u"ok"_ustr)) |
2665 | 0 | { |
2666 | 0 | m_xNamespacesList->set_size_request(m_xNamespacesList->get_approximate_digit_width() * 80, |
2667 | 0 | m_xNamespacesList->get_height_rows(8)); |
2668 | |
|
2669 | 0 | std::vector<int> aWidths |
2670 | 0 | { |
2671 | 0 | o3tl::narrowing<int>(m_xNamespacesList->get_approximate_digit_width() * 20) |
2672 | 0 | }; |
2673 | 0 | m_xNamespacesList->set_column_fixed_widths(aWidths); |
2674 | |
|
2675 | 0 | m_xNamespacesList->connect_selection_changed(LINK(this, NamespaceItemDialog, SelectHdl)); |
2676 | 0 | Link<weld::Button&,void> aLink = LINK( this, NamespaceItemDialog, ClickHdl ); |
2677 | 0 | m_xAddNamespaceBtn->connect_clicked( aLink ); |
2678 | 0 | m_xEditNamespaceBtn->connect_clicked( aLink ); |
2679 | 0 | m_xDeleteNamespaceBtn->connect_clicked( aLink ); |
2680 | 0 | m_xOKBtn->connect_clicked( LINK( this, NamespaceItemDialog, OKHdl ) ); |
2681 | |
|
2682 | 0 | LoadNamespaces(); |
2683 | 0 | SelectHdl(*m_xNamespacesList); |
2684 | 0 | } |
2685 | | |
2686 | | NamespaceItemDialog::~NamespaceItemDialog() |
2687 | 0 | { |
2688 | 0 | } |
2689 | | |
2690 | | IMPL_LINK_NOARG( NamespaceItemDialog, SelectHdl, weld::TreeView&, void) |
2691 | 0 | { |
2692 | 0 | bool bEnable = m_xNamespacesList->get_selected_index() != -1; |
2693 | 0 | m_xEditNamespaceBtn->set_sensitive( bEnable ); |
2694 | 0 | m_xDeleteNamespaceBtn->set_sensitive( bEnable ); |
2695 | 0 | } |
2696 | | |
2697 | | IMPL_LINK( NamespaceItemDialog, ClickHdl, weld::Button&, rButton, void ) |
2698 | 0 | { |
2699 | 0 | if (m_xAddNamespaceBtn.get() == &rButton) |
2700 | 0 | { |
2701 | 0 | ManageNamespaceDialog aDlg(m_xDialog.get(), m_pConditionDlg, false); |
2702 | 0 | if (aDlg.run() == RET_OK) |
2703 | 0 | { |
2704 | 0 | m_xNamespacesList->append_text(aDlg.GetPrefix()); |
2705 | 0 | int nRow = m_xNamespacesList->n_children(); |
2706 | 0 | m_xNamespacesList->set_text(nRow - 1, aDlg.GetURL(), 1); |
2707 | 0 | } |
2708 | 0 | } |
2709 | 0 | else if (m_xEditNamespaceBtn.get() == &rButton) |
2710 | 0 | { |
2711 | 0 | ManageNamespaceDialog aDlg(m_xDialog.get(), m_pConditionDlg, true); |
2712 | 0 | int nEntry = m_xNamespacesList->get_selected_index(); |
2713 | 0 | DBG_ASSERT( nEntry != -1, "NamespaceItemDialog::ClickHdl(): no entry" ); |
2714 | 0 | OUString sPrefix(m_xNamespacesList->get_text(nEntry, 0)); |
2715 | 0 | aDlg.SetNamespace(sPrefix, m_xNamespacesList->get_text(nEntry, 1)); |
2716 | 0 | if (aDlg.run() == RET_OK) |
2717 | 0 | { |
2718 | | // if a prefix was changed, mark the old prefix as 'removed' |
2719 | 0 | if( sPrefix != aDlg.GetPrefix() ) |
2720 | 0 | m_aRemovedList.push_back( sPrefix ); |
2721 | |
|
2722 | 0 | m_xNamespacesList->set_text(nEntry, aDlg.GetPrefix(), 0); |
2723 | 0 | m_xNamespacesList->set_text(nEntry, aDlg.GetURL(), 1); |
2724 | 0 | } |
2725 | 0 | } |
2726 | 0 | else if (m_xDeleteNamespaceBtn.get() == &rButton) |
2727 | 0 | { |
2728 | 0 | int nEntry = m_xNamespacesList->get_selected_index(); |
2729 | 0 | DBG_ASSERT( nEntry != -1, "NamespaceItemDialog::ClickHdl(): no entry" ); |
2730 | 0 | OUString sPrefix(m_xNamespacesList->get_text(nEntry, 0)); |
2731 | 0 | m_aRemovedList.push_back( sPrefix ); |
2732 | 0 | m_xNamespacesList->remove(nEntry); |
2733 | 0 | } |
2734 | 0 | else |
2735 | 0 | { |
2736 | 0 | SAL_WARN( "svx.form", "NamespaceItemDialog::ClickHdl(): invalid button" ); |
2737 | 0 | } |
2738 | | |
2739 | 0 | SelectHdl(*m_xNamespacesList); |
2740 | 0 | } |
2741 | | |
2742 | | IMPL_LINK_NOARG(NamespaceItemDialog, OKHdl, weld::Button&, void) |
2743 | 0 | { |
2744 | 0 | try |
2745 | 0 | { |
2746 | | // update namespace container |
2747 | 0 | sal_Int32 i, nRemovedCount = m_aRemovedList.size(); |
2748 | 0 | for( i = 0; i < nRemovedCount; ++i ) |
2749 | 0 | m_rNamespaces->removeByName( m_aRemovedList[i] ); |
2750 | |
|
2751 | 0 | sal_Int32 nEntryCount = m_xNamespacesList->n_children(); |
2752 | 0 | for( i = 0; i < nEntryCount; ++i ) |
2753 | 0 | { |
2754 | 0 | OUString sPrefix(m_xNamespacesList->get_text(i, 0)); |
2755 | 0 | OUString sURL(m_xNamespacesList->get_text(i, 1)); |
2756 | |
|
2757 | 0 | if ( m_rNamespaces->hasByName( sPrefix ) ) |
2758 | 0 | m_rNamespaces->replaceByName( sPrefix, Any( sURL ) ); |
2759 | 0 | else |
2760 | 0 | m_rNamespaces->insertByName( sPrefix, Any( sURL ) ); |
2761 | 0 | } |
2762 | 0 | } |
2763 | 0 | catch ( Exception const & ) |
2764 | 0 | { |
2765 | 0 | TOOLS_WARN_EXCEPTION( "svx.form", "NamespaceItemDialog::OKHdl()" ); |
2766 | 0 | } |
2767 | | // and close the dialog |
2768 | 0 | m_xDialog->response(RET_OK); |
2769 | 0 | } |
2770 | | |
2771 | | void NamespaceItemDialog::LoadNamespaces() |
2772 | 0 | { |
2773 | 0 | try |
2774 | 0 | { |
2775 | 0 | int nRow = 0; |
2776 | 0 | const Sequence< OUString > aAllNames = m_rNamespaces->getElementNames(); |
2777 | 0 | for ( const OUString& sPrefix : aAllNames ) |
2778 | 0 | { |
2779 | 0 | if ( m_rNamespaces->hasByName( sPrefix ) ) |
2780 | 0 | { |
2781 | 0 | OUString sURL; |
2782 | 0 | Any aAny = m_rNamespaces->getByName( sPrefix ); |
2783 | 0 | if (aAny >>= sURL) |
2784 | 0 | { |
2785 | 0 | m_xNamespacesList->append_text(sPrefix); |
2786 | 0 | m_xNamespacesList->set_text(nRow, sURL, 1); |
2787 | 0 | ++nRow; |
2788 | 0 | } |
2789 | 0 | } |
2790 | 0 | } |
2791 | 0 | } |
2792 | 0 | catch ( Exception const & ) |
2793 | 0 | { |
2794 | 0 | TOOLS_WARN_EXCEPTION( "svx.form", "NamespaceItemDialog::LoadNamespaces()" ); |
2795 | 0 | } |
2796 | 0 | } |
2797 | | |
2798 | | ManageNamespaceDialog::ManageNamespaceDialog(weld::Window* pParent, AddConditionDialog* pCondDlg, bool bIsEdit) |
2799 | 0 | : GenericDialogController(pParent, u"svx/ui/addnamespacedialog.ui"_ustr, u"AddNamespaceDialog"_ustr) |
2800 | 0 | , m_pConditionDlg(pCondDlg) |
2801 | 0 | , m_xPrefixED(m_xBuilder->weld_entry(u"prefix"_ustr)) |
2802 | 0 | , m_xUrlED(m_xBuilder->weld_entry(u"url"_ustr)) |
2803 | 0 | , m_xOKBtn(m_xBuilder->weld_button(u"ok"_ustr)) |
2804 | 0 | , m_xAltTitle(m_xBuilder->weld_label(u"alttitle"_ustr)) |
2805 | 0 | { |
2806 | 0 | if (bIsEdit) |
2807 | 0 | m_xDialog->set_title(m_xAltTitle->get_label()); |
2808 | |
|
2809 | 0 | m_xOKBtn->connect_clicked(LINK(this, ManageNamespaceDialog, OKHdl)); |
2810 | 0 | } |
2811 | | |
2812 | | ManageNamespaceDialog::~ManageNamespaceDialog() |
2813 | 0 | { |
2814 | 0 | } |
2815 | | |
2816 | | IMPL_LINK_NOARG(ManageNamespaceDialog, OKHdl, weld::Button&, void) |
2817 | 0 | { |
2818 | 0 | OUString sPrefix = m_xPrefixED->get_text(); |
2819 | |
|
2820 | 0 | try |
2821 | 0 | { |
2822 | 0 | if (!m_pConditionDlg->GetUIHelper()->isValidPrefixName(sPrefix)) |
2823 | 0 | { |
2824 | 0 | std::unique_ptr<weld::MessageDialog> xErrBox(Application::CreateMessageDialog(m_xDialog.get(), |
2825 | 0 | VclMessageType::Warning, VclButtonsType::Ok, |
2826 | 0 | SvxResId(RID_STR_INVALID_XMLPREFIX))); |
2827 | 0 | xErrBox->set_primary_text(xErrBox->get_primary_text().replaceFirst(MSG_VARIABLE, sPrefix)); |
2828 | 0 | xErrBox->run(); |
2829 | 0 | return; |
2830 | 0 | } |
2831 | 0 | } |
2832 | 0 | catch ( Exception const & ) |
2833 | 0 | { |
2834 | 0 | TOOLS_WARN_EXCEPTION( "svx.form", "ManageNamespacesDialog::OKHdl()" ); |
2835 | 0 | } |
2836 | | |
2837 | | // no error so close the dialog |
2838 | 0 | m_xDialog->response(RET_OK); |
2839 | 0 | } |
2840 | | |
2841 | | AddSubmissionDialog::AddSubmissionDialog( |
2842 | | weld::Window* pParent, ItemNode* _pNode, |
2843 | | const Reference< css::xforms::XFormsUIHelper1 >& _rUIHelper) |
2844 | 0 | : GenericDialogController(pParent, u"svx/ui/addsubmissiondialog.ui"_ustr, u"AddSubmissionDialog"_ustr) |
2845 | 0 | , m_pItemNode(_pNode) |
2846 | 0 | , m_xUIHelper(_rUIHelper) |
2847 | 0 | , m_xNameED(m_xBuilder->weld_entry(u"name"_ustr)) |
2848 | 0 | , m_xActionED(m_xBuilder->weld_entry(u"action"_ustr)) |
2849 | 0 | , m_xMethodLB(m_xBuilder->weld_combo_box(u"method"_ustr)) |
2850 | 0 | , m_xRefED(m_xBuilder->weld_entry(u"expression"_ustr)) |
2851 | 0 | , m_xRefBtn(m_xBuilder->weld_button(u"browse"_ustr)) |
2852 | 0 | , m_xBindLB(m_xBuilder->weld_combo_box(u"binding"_ustr)) |
2853 | 0 | , m_xReplaceLB(m_xBuilder->weld_combo_box(u"replace"_ustr)) |
2854 | 0 | , m_xOKBtn(m_xBuilder->weld_button(u"ok"_ustr)) |
2855 | 0 | { |
2856 | 0 | FillAllBoxes(); |
2857 | |
|
2858 | 0 | m_xRefBtn->connect_clicked( LINK( this, AddSubmissionDialog, RefHdl ) ); |
2859 | 0 | m_xOKBtn->connect_clicked( LINK( this, AddSubmissionDialog, OKHdl ) ); |
2860 | 0 | } |
2861 | | |
2862 | | AddSubmissionDialog::~AddSubmissionDialog() |
2863 | 0 | { |
2864 | | // #i38991# if we have added a binding, we need to remove it as well. |
2865 | 0 | if( m_xCreatedBinding.is() && m_xUIHelper.is() ) |
2866 | 0 | m_xUIHelper->removeBindingIfUseless( m_xCreatedBinding ); |
2867 | 0 | } |
2868 | | |
2869 | | IMPL_LINK_NOARG(AddSubmissionDialog, RefHdl, weld::Button&, void) |
2870 | 0 | { |
2871 | 0 | AddConditionDialog aDlg(m_xDialog.get(), PN_BINDING_EXPR, m_xTempBinding ); |
2872 | 0 | aDlg.SetCondition( m_xRefED->get_text() ); |
2873 | 0 | if ( aDlg.run() == RET_OK ) |
2874 | 0 | m_xRefED->set_text(aDlg.GetCondition()); |
2875 | 0 | } |
2876 | | |
2877 | | IMPL_LINK_NOARG(AddSubmissionDialog, OKHdl, weld::Button&, void) |
2878 | 0 | { |
2879 | 0 | OUString sName(m_xNameED->get_text()); |
2880 | 0 | if(sName.isEmpty()) |
2881 | 0 | { |
2882 | 0 | std::unique_ptr<weld::MessageDialog> xErrorBox(Application::CreateMessageDialog(m_xDialog.get(), |
2883 | 0 | VclMessageType::Warning, VclButtonsType::Ok, |
2884 | 0 | SvxResId(RID_STR_EMPTY_SUBMISSIONNAME))); |
2885 | 0 | xErrorBox->run(); |
2886 | 0 | return; |
2887 | 0 | } |
2888 | | |
2889 | 0 | if ( !m_xSubmission.is() ) |
2890 | 0 | { |
2891 | 0 | DBG_ASSERT( !m_xNewSubmission.is(), |
2892 | 0 | "AddSubmissionDialog::OKHdl(): new submission already exists" ); |
2893 | | |
2894 | | // add a new submission |
2895 | 0 | Reference< css::xforms::XModel > xModel( m_xUIHelper, UNO_QUERY ); |
2896 | 0 | if ( xModel.is() ) |
2897 | 0 | { |
2898 | 0 | try |
2899 | 0 | { |
2900 | 0 | m_xNewSubmission = xModel->createSubmission(); |
2901 | 0 | m_xSubmission = m_xNewSubmission; |
2902 | 0 | } |
2903 | 0 | catch ( Exception const & ) |
2904 | 0 | { |
2905 | 0 | TOOLS_WARN_EXCEPTION( "svx.form", "AddSubmissionDialog::OKHdl()" ); |
2906 | 0 | } |
2907 | 0 | } |
2908 | 0 | } |
2909 | | |
2910 | 0 | if ( m_xSubmission.is() ) |
2911 | 0 | { |
2912 | 0 | OUString sTemp = m_xNameED->get_text(); |
2913 | 0 | try |
2914 | 0 | { |
2915 | 0 | m_xSubmission->setPropertyValue( PN_SUBMISSION_ID, Any( sTemp ) ); |
2916 | 0 | sTemp = m_xActionED->get_text(); |
2917 | 0 | m_xSubmission->setPropertyValue( PN_SUBMISSION_ACTION, Any( sTemp ) ); |
2918 | 0 | sTemp = m_aMethodString.toAPI( m_xMethodLB->get_active_text() ); |
2919 | 0 | m_xSubmission->setPropertyValue( PN_SUBMISSION_METHOD, Any( sTemp ) ); |
2920 | 0 | sTemp = m_xRefED->get_text(); |
2921 | 0 | m_xSubmission->setPropertyValue( PN_SUBMISSION_REF, Any( sTemp ) ); |
2922 | 0 | OUString sEntry = m_xBindLB->get_active_text(); |
2923 | 0 | sal_Int32 nColonIdx = sEntry.indexOf(':'); |
2924 | 0 | if (nColonIdx != -1) |
2925 | 0 | sEntry = sEntry.copy(0, nColonIdx); |
2926 | 0 | sTemp = sEntry; |
2927 | 0 | m_xSubmission->setPropertyValue( PN_SUBMISSION_BIND, Any( sTemp ) ); |
2928 | 0 | sTemp = m_aReplaceString.toAPI( m_xReplaceLB->get_active_text() ); |
2929 | 0 | m_xSubmission->setPropertyValue( PN_SUBMISSION_REPLACE, Any( sTemp ) ); |
2930 | 0 | } |
2931 | 0 | catch ( Exception const & ) |
2932 | 0 | { |
2933 | 0 | TOOLS_WARN_EXCEPTION( "svx.form", "AddSubmissionDialog::OKHdl()" ); |
2934 | 0 | } |
2935 | 0 | } |
2936 | | |
2937 | 0 | m_xDialog->response(RET_OK); |
2938 | 0 | } |
2939 | | |
2940 | | void AddSubmissionDialog::FillAllBoxes() |
2941 | 0 | { |
2942 | | // method box |
2943 | 0 | m_xMethodLB->append_text(SvxResId(RID_STR_METHOD_POST)); |
2944 | 0 | m_xMethodLB->append_text(SvxResId(RID_STR_METHOD_PUT)); |
2945 | 0 | m_xMethodLB->append_text(SvxResId(RID_STR_METHOD_GET)); |
2946 | 0 | m_xMethodLB->set_active(0); |
2947 | | |
2948 | | // binding box |
2949 | 0 | Reference< css::xforms::XModel > xModel( m_xUIHelper, UNO_QUERY ); |
2950 | 0 | if ( xModel.is() ) |
2951 | 0 | { |
2952 | 0 | try |
2953 | 0 | { |
2954 | 0 | Reference< XEnumerationAccess > xNumAccess = xModel->getBindings(); |
2955 | 0 | if ( xNumAccess.is() ) |
2956 | 0 | { |
2957 | 0 | Reference < XEnumeration > xNum = xNumAccess->createEnumeration(); |
2958 | 0 | if ( xNum.is() && xNum->hasMoreElements() ) |
2959 | 0 | { |
2960 | 0 | while ( xNum->hasMoreElements() ) |
2961 | 0 | { |
2962 | 0 | Reference< XPropertySet > xPropSet; |
2963 | 0 | Any aAny = xNum->nextElement(); |
2964 | 0 | if ( aAny >>= xPropSet ) |
2965 | 0 | { |
2966 | 0 | OUString sEntry; |
2967 | 0 | OUString sTemp; |
2968 | 0 | xPropSet->getPropertyValue( PN_BINDING_ID ) >>= sTemp; |
2969 | 0 | sEntry += sTemp + ": "; |
2970 | 0 | xPropSet->getPropertyValue( PN_BINDING_EXPR ) >>= sTemp; |
2971 | 0 | sEntry += sTemp; |
2972 | 0 | m_xBindLB->append_text(sEntry); |
2973 | |
|
2974 | 0 | if ( !m_xTempBinding.is() ) |
2975 | 0 | m_xTempBinding = std::move(xPropSet); |
2976 | 0 | } |
2977 | 0 | } |
2978 | 0 | } |
2979 | 0 | } |
2980 | 0 | } |
2981 | 0 | catch ( Exception const & ) |
2982 | 0 | { |
2983 | 0 | TOOLS_WARN_EXCEPTION( "svx.form", "AddSubmissionDialog::FillAllBoxes()" ); |
2984 | 0 | } |
2985 | 0 | } |
2986 | | |
2987 | | // #i36342# we need a temporary binding; create one if no existing binding |
2988 | | // is found |
2989 | 0 | if( !m_xTempBinding.is() ) |
2990 | 0 | { |
2991 | 0 | m_xCreatedBinding = m_xUIHelper->getBindingForNode( |
2992 | 0 | Reference<css::xml::dom::XNode>( |
2993 | 0 | xModel->getDefaultInstance()->getDocumentElement(), |
2994 | 0 | UNO_QUERY_THROW ), |
2995 | 0 | true ); |
2996 | 0 | m_xTempBinding = m_xCreatedBinding; |
2997 | 0 | } |
2998 | | |
2999 | | // replace box |
3000 | 0 | m_xReplaceLB->append_text(SvxResId(RID_STR_REPLACE_NONE)); |
3001 | 0 | m_xReplaceLB->append_text(SvxResId(RID_STR_REPLACE_INST)); |
3002 | 0 | m_xReplaceLB->append_text(SvxResId(RID_STR_REPLACE_DOC)); |
3003 | | |
3004 | | |
3005 | | // init the controls with the values of the submission |
3006 | 0 | if ( m_pItemNode && m_pItemNode->m_xPropSet.is() ) |
3007 | 0 | { |
3008 | 0 | m_xSubmission = m_pItemNode->m_xPropSet; |
3009 | 0 | try |
3010 | 0 | { |
3011 | 0 | OUString sTemp; |
3012 | 0 | m_xSubmission->getPropertyValue( PN_SUBMISSION_ID ) >>= sTemp; |
3013 | 0 | m_xNameED->set_text( sTemp ); |
3014 | 0 | m_xSubmission->getPropertyValue( PN_SUBMISSION_ACTION ) >>= sTemp; |
3015 | 0 | m_xActionED->set_text( sTemp ); |
3016 | 0 | m_xSubmission->getPropertyValue( PN_SUBMISSION_REF ) >>= sTemp; |
3017 | 0 | m_xRefED->set_text(sTemp); |
3018 | |
|
3019 | 0 | m_xSubmission->getPropertyValue( PN_SUBMISSION_METHOD ) >>= sTemp; |
3020 | 0 | sTemp = m_aMethodString.toUI( sTemp ); |
3021 | 0 | sal_Int32 nPos = m_xMethodLB->find_text( sTemp ); |
3022 | 0 | if (nPos == -1) |
3023 | 0 | { |
3024 | 0 | m_xMethodLB->append_text( sTemp ); |
3025 | 0 | nPos = m_xMethodLB->get_count() - 1; |
3026 | 0 | } |
3027 | 0 | m_xMethodLB->set_active( nPos ); |
3028 | |
|
3029 | 0 | m_xSubmission->getPropertyValue( PN_SUBMISSION_BIND ) >>= sTemp; |
3030 | 0 | nPos = m_xBindLB->find_text(sTemp); |
3031 | 0 | if (nPos == -1) |
3032 | 0 | { |
3033 | 0 | m_xBindLB->append_text(sTemp); |
3034 | 0 | nPos = m_xBindLB->get_count() - 1; |
3035 | 0 | } |
3036 | 0 | m_xBindLB->set_active(nPos); |
3037 | |
|
3038 | 0 | m_xSubmission->getPropertyValue( PN_SUBMISSION_REPLACE ) >>= sTemp; |
3039 | 0 | sTemp = m_aReplaceString.toUI( sTemp ); |
3040 | 0 | if ( sTemp.isEmpty() ) |
3041 | 0 | sTemp = m_xReplaceLB->get_text(0); // first entry == "none" |
3042 | 0 | nPos = m_xReplaceLB->find_text(sTemp); |
3043 | 0 | if (nPos == -1) |
3044 | 0 | { |
3045 | 0 | m_xReplaceLB->append_text(sTemp); |
3046 | 0 | nPos = m_xReplaceLB->get_count() - 1; |
3047 | 0 | } |
3048 | 0 | m_xReplaceLB->set_active(nPos); |
3049 | 0 | } |
3050 | 0 | catch ( Exception const & ) |
3051 | 0 | { |
3052 | 0 | TOOLS_WARN_EXCEPTION( "svx.form", "AddSubmissionDialog::FillAllBoxes()" ); |
3053 | 0 | } |
3054 | 0 | } |
3055 | | |
3056 | 0 | m_xRefBtn->set_sensitive(m_xTempBinding.is()); |
3057 | 0 | } |
3058 | | |
3059 | | AddModelDialog::AddModelDialog(weld::Window* pParent, bool bIsEdit) |
3060 | 0 | : GenericDialogController(pParent, u"svx/ui/addmodeldialog.ui"_ustr, u"AddModelDialog"_ustr) |
3061 | 0 | , m_xNameED(m_xBuilder->weld_entry(u"name"_ustr)) |
3062 | 0 | , m_xModifyCB(m_xBuilder->weld_check_button(u"modify"_ustr)) |
3063 | 0 | , m_xAltTitle(m_xBuilder->weld_label(u"alttitle"_ustr)) |
3064 | 0 | { |
3065 | 0 | if (bIsEdit) |
3066 | 0 | m_xDialog->set_title(m_xAltTitle->get_label()); |
3067 | 0 | } |
3068 | | |
3069 | | AddModelDialog::~AddModelDialog() |
3070 | 0 | { |
3071 | 0 | } |
3072 | | |
3073 | | AddInstanceDialog::AddInstanceDialog(weld::Window* pParent, bool _bEdit) |
3074 | 0 | : GenericDialogController(pParent, u"svx/ui/addinstancedialog.ui"_ustr, u"AddInstanceDialog"_ustr) |
3075 | 0 | , m_xNameED(m_xBuilder->weld_entry(u"name"_ustr)) |
3076 | 0 | , m_xURLED(new SvtURLBox(m_xBuilder->weld_combo_box(u"url"_ustr))) |
3077 | 0 | , m_xFilePickerBtn(m_xBuilder->weld_button(u"browse"_ustr)) |
3078 | 0 | , m_xLinkInstanceCB(m_xBuilder->weld_check_button(u"link"_ustr)) |
3079 | 0 | , m_xAltTitle(m_xBuilder->weld_label(u"alttitle"_ustr)) |
3080 | 0 | { |
3081 | 0 | if (_bEdit) |
3082 | 0 | m_xDialog->set_title(m_xAltTitle->get_label()); |
3083 | |
|
3084 | 0 | m_xURLED->DisableHistory(); |
3085 | 0 | m_xFilePickerBtn->connect_clicked(LINK(this, AddInstanceDialog, FilePickerHdl)); |
3086 | | |
3087 | | // load the filter name from fps resource |
3088 | 0 | m_sAllFilterName = Translate::get(STR_FILTERNAME_ALL, Translate::Create("fps")); |
3089 | 0 | } |
3090 | | |
3091 | | AddInstanceDialog::~AddInstanceDialog() |
3092 | 0 | { |
3093 | 0 | } |
3094 | | |
3095 | | IMPL_LINK_NOARG(AddInstanceDialog, FilePickerHdl, weld::Button&, void) |
3096 | 0 | { |
3097 | 0 | ::sfx2::FileDialogHelper aDlg( |
3098 | 0 | css::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE, |
3099 | 0 | FileDialogFlags::NONE, m_xDialog.get()); |
3100 | 0 | aDlg.SetContext(sfx2::FileDialogHelper::FormsAddInstance); |
3101 | |
|
3102 | 0 | aDlg.AddFilter( m_sAllFilterName, FILEDIALOG_FILTER_ALL ); |
3103 | 0 | OUString sFilterName( u"XML"_ustr ); |
3104 | 0 | aDlg.AddFilter( sFilterName, u"*.xml"_ustr ); |
3105 | 0 | aDlg.SetCurrentFilter( sFilterName ); |
3106 | |
|
3107 | 0 | if (aDlg.Execute() == ERRCODE_NONE) |
3108 | 0 | m_xURLED->set_entry_text(aDlg.GetPath()); |
3109 | 0 | } |
3110 | | |
3111 | | LinkedInstanceWarningBox::LinkedInstanceWarningBox(weld::Widget* pParent) |
3112 | 0 | : MessageDialogController(pParent, u"svx/ui/formlinkwarndialog.ui"_ustr, |
3113 | 0 | u"FormLinkWarnDialog"_ustr) |
3114 | 0 | { |
3115 | 0 | } |
3116 | | |
3117 | | } |
3118 | | |
3119 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |