LibreOffice Module sfx2 (master) 1
templatedlg.cxx
Go to the documentation of this file.
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
10#include <sfx2/templatedlg.hxx>
11
12#include <sfx2/inputdlg.hxx>
13#include <sfx2/module.hxx>
14
17#include <comphelper/string.hxx>
19#include <sfx2/app.hxx>
20#include <sfx2/docfac.hxx>
21#include <sfx2/docfilt.hxx>
22#include <sfx2/fcontnr.hxx>
24#include <sfx2/objsh.hxx>
25#include <sfx2/sfxresid.hxx>
28#include <templateviewitem.hxx>
30#include <sot/storage.hxx>
31#include <tools/urlobj.hxx>
35#include <vcl/event.hxx>
36#include <vcl/svapp.hxx>
37#include <vcl/weld.hxx>
38
39#include <com/sun/star/beans/NamedValue.hpp>
40#include <com/sun/star/beans/PropertyValue.hpp>
41#include <com/sun/star/document/MacroExecMode.hpp>
42#include <com/sun/star/document/UpdateDocMode.hpp>
43#include <com/sun/star/embed/XStorage.hpp>
44#include <com/sun/star/embed/ElementModes.hpp>
45#include <com/sun/star/frame/Desktop.hpp>
46#include <com/sun/star/frame/XStorable.hpp>
47#include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
48#include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
49#include <com/sun/star/ui/dialogs/XFolderPicker2.hpp>
50#include <com/sun/star/task/InteractionHandler.hpp>
52
53#include <sfx2/strings.hrc>
54#include <bitmaps.hlst>
55
56constexpr OUStringLiteral TM_SETTING_MANAGER = u"TemplateManager";
57constexpr OUStringLiteral TM_SETTING_LASTFOLDER = u"LastFolder";
58constexpr OUStringLiteral TM_SETTING_LASTAPPLICATION = u"LastApplication";
59constexpr OUStringLiteral TM_SETTING_VIEWMODE = u"ViewMode";
60
61constexpr OUStringLiteral MNI_ACTION_NEW_FOLDER = u"new";
62constexpr OUStringLiteral MNI_ACTION_RENAME_FOLDER = u"rename";
63constexpr OUStringLiteral MNI_ACTION_DELETE_FOLDER = u"delete";
64constexpr OUStringLiteral MNI_ACTION_DEFAULT = u"default";
65constexpr OUStringLiteral MNI_ACTION_DEFAULT_WRITER = u"default_writer";
66constexpr OUStringLiteral MNI_ACTION_DEFAULT_CALC = u"default_calc";
67constexpr OUStringLiteral MNI_ACTION_DEFAULT_IMPRESS = u"default_impress";
68constexpr OUStringLiteral MNI_ACTION_DEFAULT_DRAW = u"default_draw";
69constexpr OUStringLiteral MNI_ACTION_IMPORT = u"import_template";
70constexpr OUStringLiteral MNI_ACTION_EXTENSIONS = u"extensions";
71#define MNI_ALL_APPLICATIONS 0
72#define MNI_WRITER 1
73#define MNI_CALC 2
74#define MNI_IMPRESS 3
75#define MNI_DRAW 4
76
77using namespace ::com::sun::star;
78using namespace ::com::sun::star::beans;
79using namespace ::com::sun::star::embed;
80using namespace ::com::sun::star::frame;
81using namespace ::com::sun::star::lang;
82using namespace ::com::sun::star::uno;
83using namespace ::com::sun::star::ui::dialogs;
84using namespace ::com::sun::star::document;
85
86static bool lcl_getServiceName (const OUString &rFileURL, OUString &rName );
87
88static std::vector<OUString> lcl_getAllFactoryURLs ();
89
90namespace {
91
92class SearchView_Keyword
93{
94public:
95
96 SearchView_Keyword (const OUString &rKeyword, FILTER_APPLICATION App)
97 : maKeyword(rKeyword.toAsciiLowerCase()), meApp(App)
98 {}
99
100 bool operator() (const TemplateItemProperties &rItem)
101 {
102 bool bRet = true;
103
104 INetURLObject aUrl(rItem.aPath);
105 OUString aExt = aUrl.getExtension();
106
107 if (meApp == FILTER_APPLICATION::WRITER)
108 {
109 bRet = aExt == "ott" || aExt == "stw" || aExt == "oth" || aExt == "dot" || aExt == "dotx";
110 }
111 else if (meApp == FILTER_APPLICATION::CALC)
112 {
113 bRet = aExt == "ots" || aExt == "stc" || aExt == "xlt" || aExt == "xltm" || aExt == "xltx";
114 }
115 else if (meApp == FILTER_APPLICATION::IMPRESS)
116 {
117 bRet = aExt == "otp" || aExt == "sti" || aExt == "pot" || aExt == "potm" || aExt == "potx";
118 }
119 else if (meApp == FILTER_APPLICATION::DRAW)
120 {
121 bRet = aExt == "otg" || aExt == "std";
122 }
123
124 return bRet && MatchSubstring(rItem.aName);
125 }
126
127 bool MatchSubstring( OUString const & sItemName )
128 {
129 if(maKeyword.isEmpty())
130 return false;
131 return sItemName.toAsciiLowerCase().indexOf(maKeyword) >= 0;
132 }
133
134private:
135
136 OUString maKeyword;
137 FILTER_APPLICATION meApp;
138};
139
140}
141
142/***
143 *
144 * Order items in ascending order (useful for the selection sets and move/copy operations since the associated ids
145 * change when processed by the SfxDocumentTemplates class so we want to process to ones with higher id first)
146 *
147 ***/
148
149static bool cmpSelectionItems (const ThumbnailViewItem *pItem1, const ThumbnailViewItem *pItem2)
150{
151 return pItem1->mnId > pItem2->mnId;
152}
153
155 : GenericDialogController(pParent, "sfx/ui/templatedlg.ui", "TemplateDialog")
156 , maSelTemplates(cmpSelectionItems)
157 , mxDesktop(Desktop::create(comphelper::getProcessComponentContext()))
158 , m_aUpdateDataTimer( "SfxTemplateManagerDlg UpdateDataTimer" )
159 , mxSearchFilter(m_xBuilder->weld_entry("search_filter"))
160 , mxCBApp(m_xBuilder->weld_combo_box("filter_application"))
161 , mxCBFolder(m_xBuilder->weld_combo_box("filter_folder"))
162 , mxOKButton(m_xBuilder->weld_button("ok"))
163 , mxCBXHideDlg(m_xBuilder->weld_check_button("hidedialogcb"))
164 , mxActionBar(m_xBuilder->weld_menu_button("action_menu"))
165 , mxLocalView(new TemplateDlgLocalView(m_xBuilder->weld_scrolled_window("scrolllocal", true),
166 m_xBuilder->weld_menu("contextmenu"),
167 m_xBuilder->weld_tree_view("tree_list")))
168 , mxLocalViewWeld(new weld::CustomWeld(*m_xBuilder, "template_view", *mxLocalView))
169 , mxListViewButton(m_xBuilder->weld_toggle_button("list_view_btn"))
170 , mxThumbnailViewButton(m_xBuilder->weld_toggle_button("thumbnail_view_btn"))
171 , mViewMode(TemplateViewMode::eThumbnailView)
172{
173 // Create popup menus
174 mxActionBar->append_item(MNI_ACTION_NEW_FOLDER, SfxResId(STR_CATEGORY_NEW), BMP_ACTION_NEW_CATEGORY);
175 mxActionBar->append_item(MNI_ACTION_RENAME_FOLDER, SfxResId(STR_CATEGORY_RENAME), BMP_ACTION_RENAME);
176 mxActionBar->append_item(MNI_ACTION_DELETE_FOLDER, SfxResId(STR_CATEGORY_DELETE), BMP_ACTION_DELETE_CATEGORY);
177 mxActionBar->append_separator("separator");
178 mxActionBar->append_item(MNI_ACTION_DEFAULT, SfxResId(STR_ACTION_RESET_ALL_DEFAULT_TEMPLATES));
179 mxActionBar->append_item(MNI_ACTION_DEFAULT_WRITER, SfxResId(STR_ACTION_RESET_WRITER_TEMPLATE), BMP_ACTION_DEFAULT_WRITER);
180 mxActionBar->append_item(MNI_ACTION_DEFAULT_CALC, SfxResId(STR_ACTION_RESET_CALC_TEMPLATE), BMP_ACTION_DEFAULT_CALC);
181 mxActionBar->append_item(MNI_ACTION_DEFAULT_IMPRESS, SfxResId(STR_ACTION_RESET_IMPRESS_TEMPLATE), BMP_ACTION_DEFAULT_IMPRESS);
182 mxActionBar->append_item(MNI_ACTION_DEFAULT_DRAW, SfxResId(STR_ACTION_RESET_DRAW_TEMPLATE), BMP_ACTION_DEFAULT_DRAW);
183 mxActionBar->append_separator("separator2");
184 mxActionBar->append_item(MNI_ACTION_IMPORT, SfxResId(STR_ACTION_IMPORT), BMP_ACTION_IMPORT);
185 mxActionBar->append_item(MNI_ACTION_EXTENSIONS, SfxResId(STR_ACTION_EXTENSIONS), BMP_ACTION_EXTENSIONS);
186
187 mxActionBar->connect_selected(LINK(this,SfxTemplateManagerDlg,MenuSelectHdl));
188
189 mxLocalView->setItemMaxTextLength(TEMPLATE_ITEM_MAX_TEXT_LENGTH);
193
194 mxLocalView->setItemStateHdl(LINK(this,SfxTemplateManagerDlg,TVItemStateHdl));
195 mxLocalView->setCreateContextMenuHdl(LINK(this,SfxTemplateManagerDlg, CreateContextMenuHdl));
196 mxLocalView->setOpenRegionHdl(LINK(this,SfxTemplateManagerDlg, OpenRegionHdl));
197 mxLocalView->setOpenTemplateHdl(LINK(this,SfxTemplateManagerDlg, OpenTemplateHdl));
198 mxLocalView->setEditTemplateHdl(LINK(this,SfxTemplateManagerDlg, EditTemplateHdl));
199 mxLocalView->setDeleteTemplateHdl(LINK(this,SfxTemplateManagerDlg, DeleteTemplateHdl));
200 mxLocalView->setDefaultTemplateHdl(LINK(this,SfxTemplateManagerDlg, DefaultTemplateHdl));
201 mxLocalView->setMoveTemplateHdl(LINK(this,SfxTemplateManagerDlg, MoveTemplateHdl));
202 mxLocalView->setExportTemplateHdl(LINK(this,SfxTemplateManagerDlg, ExportTemplateHdl));
203
204 mxLocalView->ShowTooltips(true);
205
206 // Set width and height of the templates thumbnail viewer to accommodate 3 rows and 4 columns of items
208
209 mxOKButton->connect_clicked(LINK(this, SfxTemplateManagerDlg, OkClickHdl));
210 // FIXME: rather than disabling make dispatchCommand(".uno:AdditionsDialog") work in start center
212 mxActionBar->set_item_sensitive(MNI_ACTION_EXTENSIONS, false);
213 else
214 mxActionBar->set_item_sensitive(MNI_ACTION_EXTENSIONS, true);
215 mxListViewButton->connect_toggled(LINK(this, SfxTemplateManagerDlg, ListViewHdl));
216 mxThumbnailViewButton->connect_toggled(LINK(this, SfxTemplateManagerDlg, ThumbnailViewHdl));
217
218 mxSearchFilter->connect_changed(LINK(this, SfxTemplateManagerDlg, SearchUpdateHdl));
219 mxSearchFilter->connect_focus_in(LINK( this, SfxTemplateManagerDlg, GetFocusHdl ));
220 mxSearchFilter->connect_focus_out(LINK( this, SfxTemplateManagerDlg, LoseFocusHdl ));
221 mxSearchFilter->connect_key_press(LINK( this, SfxTemplateManagerDlg, KeyInputHdl));
222
223 mxActionBar->show();
224
225 mxLocalView->Populate();
227
228 mxCBApp->set_active(0);
230
231 mxActionBar->set_item_visible(MNI_ACTION_EXTENSIONS, true);
232 mxActionBar->set_item_visible(MNI_ACTION_IMPORT, true);
233 mxActionBar->set_item_visible(MNI_ACTION_NEW_FOLDER, true);
234
235 mxOKButton->set_label(SfxResId(STR_OPEN));
236
237 mxCBApp->connect_changed(LINK(this, SfxTemplateManagerDlg, SelectApplicationHdl));
238 mxCBFolder->connect_changed(LINK(this, SfxTemplateManagerDlg, SelectRegionHdl));
239
240 mxLocalView->Show();
241
244
245 mxLocalView->connect_focus_rect(LINK(this, SfxTemplateManagerDlg, FocusRectLocalHdl));
246 bMakeSelItemVisible = false;
247}
248
250{
252
253 // Ignore view events since we are cleaning the object
255 mxLocalView->setOpenRegionHdl(Link<void*,void>());
256 mxLocalView->setOpenTemplateHdl(Link<ThumbnailViewItem*, void>());
257}
258
260{
261 //use application specific settings if there's no previous setting
263 readSettings();
265
267}
268
269IMPL_LINK(SfxTemplateManagerDlg, KeyInputHdl, const KeyEvent&, rKeyEvent, bool)
270{
271 if (mxSearchFilter != nullptr && !mxSearchFilter->get_text().isEmpty())
272 {
273 vcl::KeyCode aKeyCode = rKeyEvent.GetKeyCode();
274 sal_uInt16 nKeyCode = aKeyCode.GetCode();
275
276 if ( nKeyCode == KEY_ESCAPE )
277 {
278 mxSearchFilter->set_text("");
279 SearchUpdateHdl(*mxSearchFilter);
280 return true;
281 }
282 }
283 return false;
284}
285
286void SfxTemplateManagerDlg::setDocumentModel(const uno::Reference<frame::XModel> &rModel)
287{
288 m_xModel = rModel;
289}
290
292{
294 {
297 mxLocalView->ThumbnailView::GrabFocus();
298 mViewMode = eViewMode;
299 mxLocalView->setTemplateViewMode(eViewMode);
300 mxLocalView->Show();
301 }
303 {
306 mxLocalView->ListView::grab_focus();
307 mViewMode = eViewMode;
308 mxLocalView->setTemplateViewMode(eViewMode);
309 mxLocalView->Show();
310 }
311}
312
314{
315 return mViewMode;
316}
317
318
320{
321 const sal_Int16 nCurAppId = mxCBApp->get_active();
322
323 if (nCurAppId == MNI_WRITER)
325 else if (nCurAppId == MNI_IMPRESS)
327 else if (nCurAppId == MNI_CALC)
329 else if (nCurAppId == MNI_DRAW)
331
333}
334
336{
337 std::vector<OUString> aFolderNames = mxLocalView->getFolderNames();
338
339 for (size_t i = 0, n = aFolderNames.size(); i < n; ++i)
340 mxCBFolder->append_text(aFolderNames[i]);
341 mxCBFolder->set_active(0);
342 mxActionBar->set_item_sensitive(MNI_ACTION_RENAME_FOLDER, false);
343 mxActionBar->set_item_sensitive(MNI_ACTION_DELETE_FOLDER, false);
344}
345
347{
348 if ( ! m_xModel.is() )
349 {
350 mxCBApp->set_active(0);
351 mxCBFolder->set_active(0);
352 mxActionBar->set_item_sensitive(MNI_ACTION_RENAME_FOLDER, false);
353 mxActionBar->set_item_sensitive(MNI_ACTION_DELETE_FOLDER, false);
355 mxLocalView->showAllTemplates();
356 return;
357 }
358
360
361 switch(eFactory)
362 {
366 mxCBApp->set_active(MNI_WRITER);
367 break;
369 mxCBApp->set_active(MNI_CALC);
370 break;
372 mxCBApp->set_active(MNI_IMPRESS);
373 break;
375 mxCBApp->set_active(MNI_DRAW);
376 break;
377 default:
378 mxCBApp->set_active(0);
379 break;
380 }
381
383 mxCBFolder->set_active(0);
384 mxActionBar->set_item_sensitive(MNI_ACTION_RENAME_FOLDER, false);
385 mxActionBar->set_item_sensitive(MNI_ACTION_DELETE_FOLDER, false);
386 mxLocalView->showAllTemplates();
387}
388
390{
391 OUString aLastFolder;
392 SvtViewOptions aViewSettings( EViewType::Dialog, TM_SETTING_MANAGER );
393 sal_Int16 nViewMode = -1;
394
395 if ( aViewSettings.Exists() )
396 {
397 sal_uInt16 nTmp = 0;
398 aViewSettings.GetUserItem(TM_SETTING_LASTFOLDER) >>= aLastFolder;
399 aViewSettings.GetUserItem(TM_SETTING_LASTAPPLICATION) >>= nTmp;
400 aViewSettings.GetUserItem(TM_SETTING_VIEWMODE) >>= nViewMode;
401
402 //open last remembered application only when application model is not set
403 if(!m_xModel.is())
404 {
405 switch (nTmp)
406 {
407 case MNI_WRITER:
408 mxCBApp->set_active(MNI_WRITER);
409 break;
410 case MNI_CALC:
411 mxCBApp->set_active(MNI_CALC);
412 break;
413 case MNI_IMPRESS:
414 mxCBApp->set_active(MNI_IMPRESS);
415 break;
416 case MNI_DRAW:
417 mxCBApp->set_active(MNI_DRAW);
418 break;
419 default:
420 mxCBApp->set_active(0);
421 break;
422 }
423 }
424 }
425
427
428 if (aLastFolder.isEmpty())
429 {
430 //show all categories
431 mxCBFolder->set_active(0);
432 mxActionBar->set_item_sensitive(MNI_ACTION_RENAME_FOLDER, false);
433 mxActionBar->set_item_sensitive(MNI_ACTION_DELETE_FOLDER, false);
434 mxLocalView->showAllTemplates();
435 }
436 else
437 {
438 mxCBFolder->set_active_text(aLastFolder);
439 mxLocalView->showRegion(aLastFolder);
440 bool bIsBuiltInRegion = mxLocalView->IsBuiltInRegion(aLastFolder);
441 mxActionBar->set_item_sensitive(MNI_ACTION_RENAME_FOLDER, !bIsBuiltInRegion);
442 mxActionBar->set_item_sensitive(MNI_ACTION_DELETE_FOLDER, !bIsBuiltInRegion);
443 }
444
445 if(nViewMode == static_cast<sal_Int16>(TemplateViewMode::eListView) ||
446 nViewMode == static_cast<sal_Int16>(TemplateViewMode::eThumbnailView))
447 {
448 TemplateViewMode eViewMode = static_cast<TemplateViewMode>(nViewMode);
449 setTemplateViewMode(eViewMode);
450 }
451 else
452 {
453 //Default ViewMode
455 }
456}
457
459{
460 OUString aLastFolder;
461
462 if (mxLocalView->getCurRegionId())
463 aLastFolder = mxLocalView->getRegionName(mxLocalView->getCurRegionId()-1);
464
465 // last folder
466 Sequence< NamedValue > aSettings
467 {
468 { TM_SETTING_LASTFOLDER, css::uno::Any(aLastFolder) },
469 { TM_SETTING_LASTAPPLICATION, css::uno::Any(sal_uInt16(mxCBApp->get_active())) },
470 { TM_SETTING_VIEWMODE, css::uno::Any(static_cast<sal_Int16>(getTemplateViewMode()))}
471 };
472
473 // write
474 SvtViewOptions aViewSettings(EViewType::Dialog, TM_SETTING_MANAGER);
475 aViewSettings.SetUserData(aSettings);
476}
477
479{
480 mxLocalView->filterItems(ViewFilter_Application(getCurrentApplicationFilter()));
481 SelectRegionHdl(*mxCBFolder);
482 updateMenuItems();
483}
484
486{
487 const OUString sSelectedRegion = mxCBFolder->get_active_text();
488
489 if(mxCBFolder->get_active() == 0)
490 {
491 mxActionBar->set_item_sensitive(MNI_ACTION_RENAME_FOLDER, false);
492 mxActionBar->set_item_sensitive(MNI_ACTION_DELETE_FOLDER, false);
493 }
494 else
495 {
496 bool bIsBuiltInRegion = mxLocalView->IsBuiltInRegion(sSelectedRegion);
497 mxActionBar->set_item_sensitive(MNI_ACTION_RENAME_FOLDER, !bIsBuiltInRegion);
498 mxActionBar->set_item_sensitive(MNI_ACTION_DELETE_FOLDER, !bIsBuiltInRegion);
499 }
500 SearchUpdate();
501}
502
503IMPL_LINK(SfxTemplateManagerDlg, TVItemStateHdl, const ThumbnailViewItem*, pItem, void)
504{
505 const TemplateViewItem *pViewItem = dynamic_cast<const TemplateViewItem*>(pItem);
506
507 if (pViewItem)
508 OnTemplateState(pItem);
509}
510
511IMPL_LINK(SfxTemplateManagerDlg, MenuSelectHdl, const OUString&, rIdent, void)
512{
513 if (rIdent == MNI_ACTION_NEW_FOLDER)
514 OnCategoryNew();
515 else if (rIdent == MNI_ACTION_RENAME_FOLDER)
516 OnCategoryRename();
517 else if (rIdent == MNI_ACTION_DELETE_FOLDER)
518 OnCategoryDelete();
519 else if (rIdent == MNI_ACTION_DEFAULT)
520 {
521 DefaultTemplateMenuSelectHdl(MNI_ACTION_DEFAULT_WRITER);
522 DefaultTemplateMenuSelectHdl(MNI_ACTION_DEFAULT_CALC);
523 DefaultTemplateMenuSelectHdl(MNI_ACTION_DEFAULT_IMPRESS);
524 DefaultTemplateMenuSelectHdl(MNI_ACTION_DEFAULT_DRAW);
525 }
526 else if(rIdent == MNI_ACTION_DEFAULT_WRITER || rIdent == MNI_ACTION_DEFAULT_CALC ||
528 DefaultTemplateMenuSelectHdl(rIdent);
529 else if(rIdent == MNI_ACTION_IMPORT)
530 ImportActionHdl();
531 else if(rIdent == MNI_ACTION_EXTENSIONS)
532 ExtensionsActionHdl();
533}
534
536{
537 SvtModuleOptions aModOpt;
538 OUString aFactoryURL;
539 if (rIdent == MNI_ACTION_DEFAULT_WRITER)
541 else if (rIdent == MNI_ACTION_DEFAULT_CALC)
543 else if (rIdent == MNI_ACTION_DEFAULT_IMPRESS)
545 else if (rIdent == MNI_ACTION_DEFAULT_DRAW)
547 else
548 return;
549
550 OUString aServiceName = SfxObjectShell::GetServiceNameFromFactory(aFactoryURL);
551 OUString sPrevDefault = SfxObjectFactory::GetStandardTemplate( aServiceName );
552 if(!sPrevDefault.isEmpty())
553 {
554 mxLocalView->RemoveDefaultTemplateIcon(sPrevDefault);
555 }
556
557 SfxObjectFactory::SetStandardTemplate( aServiceName, OUString() );
558 mxLocalView->refreshDefaultColumn();
560}
561
563{
564 OnTemplateOpen();
565 m_xDialog->response(RET_OK);
566}
567
568IMPL_LINK_NOARG(SfxTemplateManagerDlg, MoveTemplateHdl, void*, void)
569{
570 // modal dialog to select templates category
572 aDlg.SetCategoryLBEntries(mxLocalView->getFolderNames());
573
574 size_t nItemId = 0;
575
576 if (aDlg.run() != RET_OK)
577 return;
578
579 const OUString& sCategory = aDlg.GetSelectedCategory();
580 bool bIsNewCategory = aDlg.IsNewCategoryCreated();
581 if(bIsNewCategory)
582 {
583 if (!sCategory.isEmpty())
584 {
585 nItemId = mxLocalView->createRegion(sCategory);
586 if(nItemId)
587 mxCBFolder->append_text(sCategory);
588 }
589 }
590 else
591 nItemId = mxLocalView->getRegionId(sCategory);
592
593 if(nItemId)
594 {
595 localMoveTo(nItemId);
596 }
597
598 mxLocalView->reload();
599 SearchUpdate();
600}
601IMPL_LINK_NOARG(SfxTemplateManagerDlg, ExportTemplateHdl, void*, void)
602{
603 OnTemplateExport();
604}
605
607{
608 if(mxCBFolder->get_active() == 0)
609 {
610 //Modal Dialog to select Category
612 aDlg.SetCategoryLBEntries(mxLocalView->getFolderNames());
613
614 if (aDlg.run() == RET_OK)
615 {
616 const OUString& sCategory = aDlg.GetSelectedCategory();
617 bool bIsNewCategory = aDlg.IsNewCategoryCreated();
618 if(bIsNewCategory)
619 {
620 if(mxLocalView->createRegion(sCategory))
621 {
622 mxCBFolder->append_text(sCategory);
623 OnTemplateImportCategory(sCategory);
624 }
625 else
626 {
627 OUString aMsg( SfxResId(STR_CREATE_ERROR) );
628 std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(m_xDialog.get(),
629 VclMessageType::Warning, VclButtonsType::Ok,
630 aMsg.replaceFirst("$1", sCategory)));
631 xBox->run();
632 return;
633 }
634 }
635 else
636 OnTemplateImportCategory(sCategory);
637 }
638 }
639 else
640 {
641 const auto sCategory = mxCBFolder->get_active_text();
642 OnTemplateImportCategory(sCategory);
643 }
644 mxLocalView->reload();
645 SearchUpdate();
646}
647
649{
650 uno::Sequence<beans::PropertyValue> aArgs{ comphelper::makePropertyValue(
651 "AdditionsTag", OUString("Templates")) };
652 comphelper::dispatchCommand(".uno:AdditionsDialog", aArgs);
653}
654
655IMPL_LINK_NOARG(SfxTemplateManagerDlg, OpenRegionHdl, void*, void)
656{
657 maSelTemplates.clear();
658 mxOKButton->set_sensitive(false);
659 mxActionBar->show();
660}
661
662IMPL_LINK(SfxTemplateManagerDlg, CreateContextMenuHdl, ThumbnailViewItem*, pItem, void)
663{
664 const TemplateViewItem *pViewItem = dynamic_cast<TemplateViewItem*>(pItem);
665 bool bIsDefault = false;
666 bool bIsInternal = false;
667 std::vector<const TemplateViewItem*> aSelTemplates;
668 for(const auto& aSelTmpl : maSelTemplates)
669 {
670 const TemplateViewItem *aItem = dynamic_cast<const TemplateViewItem*>(aSelTmpl);
671 aSelTemplates.push_back(aItem);
672 }
673
674 for(const auto& aSelTmpl : aSelTemplates)
675 {
676 if(aSelTmpl->IsDefaultTemplate())
677 bIsDefault = true;
678 if(TemplateLocalView::IsInternalTemplate(aSelTmpl->getPath()))
679 {
680 bIsInternal = true;
681 if(bIsDefault)
682 break;
683 }
684 }
685
686 if (!pViewItem)
687 return;
688
689 bool bIsSingleSel = maSelTemplates.size() == 1;
690 OUString aDefaultImg;
691 INetURLObject aUrl(pViewItem->getPath());
693 aDefaultImg = BMP_ACTION_DEFAULT_WRITER;
695 aDefaultImg = BMP_ACTION_DEFAULT_CALC;
697 aDefaultImg = BMP_ACTION_DEFAULT_IMPRESS;
699 aDefaultImg = BMP_ACTION_DEFAULT_DRAW;
700 mxLocalView->createContextMenu(bIsDefault, bIsInternal, bIsSingleSel, aDefaultImg);
701}
702
703IMPL_LINK(SfxTemplateManagerDlg, OpenTemplateHdl, ThumbnailViewItem*, pItem, void)
704{
705 uno::Sequence< PropertyValue > aArgs{
706 comphelper::makePropertyValue("AsTemplate", true),
707 comphelper::makePropertyValue("MacroExecutionMode", MacroExecMode::USE_CONFIG),
708 comphelper::makePropertyValue("UpdateDocMode", UpdateDocMode::ACCORDING_TO_CONFIG),
709 comphelper::makePropertyValue("InteractionHandler", task::InteractionHandler::createWithParent( ::comphelper::getProcessComponentContext(), nullptr )),
710 comphelper::makePropertyValue("ReadOnly", true)
711 };
712
713 TemplateViewItem *pTemplateItem = static_cast<TemplateViewItem*>(pItem);
714
715 try
716 {
717 mxDesktop->loadComponentFromURL(pTemplateItem->getPath(),"_default", 0, aArgs );
718 }
719 catch( const uno::Exception& )
720 {
721 }
722
723 m_xDialog->response(RET_OK);
724}
725
726IMPL_LINK(SfxTemplateManagerDlg, EditTemplateHdl, ThumbnailViewItem*, pItem, void)
727{
728 uno::Sequence< PropertyValue > aArgs{
729 comphelper::makePropertyValue("AsTemplate", false),
730 comphelper::makePropertyValue("MacroExecutionMode", MacroExecMode::USE_CONFIG),
731 comphelper::makePropertyValue("UpdateDocMode", UpdateDocMode::ACCORDING_TO_CONFIG)
732 };
733
734 uno::Reference< XStorable > xStorable;
735 TemplateViewItem *pViewItem = static_cast<TemplateViewItem*>(pItem);
736
737 try
738 {
739 xStorable.set( mxDesktop->loadComponentFromURL(pViewItem->getPath(),"_default", 0, aArgs ),
740 uno::UNO_QUERY );
741 }
742 catch( const uno::Exception& )
743 {
744 }
745
746 m_xDialog->response(RET_OK);
747}
748
749IMPL_LINK_NOARG(SfxTemplateManagerDlg, DeleteTemplateHdl, void*, void)
750{
751 std::set<const ThumbnailViewItem*,selection_cmp_fn> aSelTemplates = maSelTemplates;
752 OUString aDeletedTemplate;
753
754 for (auto const& pItem : aSelTemplates)
755 {
756 const TemplateViewItem *pViewItem = static_cast<const TemplateViewItem*>(pItem);
757 sal_uInt16 nRegionItemId = mxLocalView->getRegionId(pViewItem->mnRegionId);
758
759 if (!mxLocalView->removeTemplate(pViewItem->mnDocId + 1, nRegionItemId))//mnId w.r.t. region is mnDocId + 1;
760 {
761 aDeletedTemplate += pItem->maTitle+"\n";
762 }
763 }
764
765 if (!aDeletedTemplate.isEmpty())
766 {
767 OUString aMsg( SfxResId(STR_MSG_ERROR_DELETE_TEMPLATE) );
768 std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(m_xDialog.get(),
769 VclMessageType::Warning, VclButtonsType::Ok,
770 aMsg.replaceFirst("$1",aDeletedTemplate)));
771 xBox->run();
772 }
773}
774
775IMPL_LINK(SfxTemplateManagerDlg, DefaultTemplateHdl, ThumbnailViewItem*, pItem, void)
776{
777 TemplateViewItem *pViewItem = static_cast<TemplateViewItem*>(pItem);
778 OUString aServiceName;
779
780 if(!pViewItem->IsDefaultTemplate())
781 {
782 if (lcl_getServiceName(pViewItem->getPath(),aServiceName))
783 {
784 OUString sPrevDefault = SfxObjectFactory::GetStandardTemplate( aServiceName );
785 if(!sPrevDefault.isEmpty())
786 {
787 mxLocalView->RemoveDefaultTemplateIcon(sPrevDefault);
788 }
789 SfxObjectFactory::SetStandardTemplate(aServiceName,pViewItem->getPath());
790 pViewItem->showDefaultIcon(true);
791 }
792 }
793 else
794 {
795 if(lcl_getServiceName(pViewItem->getPath(),aServiceName))
796 {
797 SfxObjectFactory::SetStandardTemplate( aServiceName, OUString() );
798 pViewItem->showDefaultIcon(false);
799 }
800 }
801
802 updateMenuItems();
803}
804
806{
807 m_aUpdateDataTimer.Start();
808}
809
810IMPL_LINK_NOARG(SfxTemplateManagerDlg, ImplUpdateDataHdl, Timer*, void)
811{
812 SearchUpdate();
813}
814
816{
817 if (m_aUpdateDataTimer.IsActive())
818 {
819 m_aUpdateDataTimer.Stop();
820 m_aUpdateDataTimer.Invoke();
821 }
822}
823
825{
826 setTemplateViewMode(TemplateViewMode::eListView);
827}
828
830{
831 setTemplateViewMode(TemplateViewMode::eThumbnailView);
832 bMakeSelItemVisible = true;
833}
834
836{
837 if(bMakeSelItemVisible && !maSelTemplates.empty())
838 mxLocalView->MakeItemVisible((*maSelTemplates.begin())->mnId);
839 bMakeSelItemVisible = false;
840 return tools::Rectangle();
841}
842
844{
845 const OUString sSelectedRegion = mxCBFolder->get_active_text();
846 mxLocalView->setCurRegionId(mxLocalView->getRegionId(sSelectedRegion));
847 OUString aKeyword = mxSearchFilter->get_text();
848 mxLocalView->Clear();
849 std::function<bool(const TemplateItemProperties &)> aFunc =
850 [&](const TemplateItemProperties &rItem)->bool
851 {
852 return aKeyword.isEmpty() || SearchView_Keyword(aKeyword, getCurrentApplicationFilter())(rItem);
853 };
854
855 std::vector<TemplateItemProperties> aItems = mxLocalView->getFilteredItems(aFunc);
856 mxLocalView->insertItems(aItems, mxCBFolder->get_active()!=0, true);
857 mxLocalView->Invalidate();
858}
859
861{
862 mxLocalView->deselectItems();
863 maSelTemplates.clear();
864}
865
867{
868 bool bInSelection = maSelTemplates.find(pItem) != maSelTemplates.end();
869
870 if (pItem->isSelected())
871 {
872 if (maSelTemplates.empty())
873 {
874 mxOKButton->set_sensitive(true);
875 }
876 else if (maSelTemplates.size() != 1 || !bInSelection)
877 {
878 mxOKButton->set_sensitive(false);
879 }
880
881 if (!bInSelection)
882 maSelTemplates.insert(pItem);
883 }
884 else
885 {
886 if (bInSelection)
887 {
888 maSelTemplates.erase(pItem);
889
890 if (maSelTemplates.empty())
891 {
892 mxOKButton->set_sensitive(false);
893 }
894 else if (maSelTemplates.size() == 1)
895 {
896 mxOKButton->set_sensitive(true);
897 }
898 }
899 }
900
901}
902
903void SfxTemplateManagerDlg::OnTemplateImportCategory(std::u16string_view sCategory)
904{
905 sfx2::FileDialogHelper aFileDlg(css::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE,
908
909 // add "All" filter
910 aFileDlg.AddFilter( SfxResId(STR_SFX_FILTERNAME_ALL),
912
913 // add template filter
914 OUString sFilterExt;
915 OUString sFilterName( SfxResId( STR_TEMPLATE_FILTER ) );
916
917 // add filters of modules which are installed
918 SvtModuleOptions aModuleOpt;
920 sFilterExt += "*.ott;*.stw;*.oth;*.dotx;*.dot";
921
923 {
924 if ( !sFilterExt.isEmpty() )
925 sFilterExt += ";";
926
927 sFilterExt += "*.ots;*.stc;*.xltx;*.xlt";
928 }
929
931 {
932 if ( !sFilterExt.isEmpty() )
933 sFilterExt += ";";
934
935 sFilterExt += "*.otp;*.sti;*.pot;*.potx";
936 }
937
939 {
940 if ( !sFilterExt.isEmpty() )
941 sFilterExt += ";";
942
943 sFilterExt += "*.otg;*.std";
944 }
945
946 if ( !sFilterExt.isEmpty() )
947 sFilterExt += ";";
948
949 sFilterExt += "*.vor";
950
951 sFilterName += " (" + sFilterExt + ")";
952
953 aFileDlg.AddFilter( sFilterName, sFilterExt );
954 aFileDlg.SetCurrentFilter( sFilterName );
955
956 ErrCode nCode = aFileDlg.Execute();
957
958 if ( nCode != ERRCODE_NONE )
959 return;
960
961 const css::uno::Sequence<OUString> aFiles = aFileDlg.GetSelectedFiles();
962
963 if (!aFiles.hasElements())
964 return;
965
966 //Import to the selected regions
967 TemplateContainerItem* pContItem = mxLocalView->getRegion(sCategory);
968 if(!pContItem)
969 return;
970
971 OUString aTemplateList;
972
973 for (const auto& rFile : aFiles)
974 {
975 if(!mxLocalView->copyFrom(pContItem, rFile))
976 {
977 if (aTemplateList.isEmpty())
978 aTemplateList = rFile;
979 else
980 aTemplateList += "\n" + rFile;
981 }
982 }
983
984 if (!aTemplateList.isEmpty())
985 {
986 OUString aMsg(SfxResId(STR_MSG_ERROR_IMPORT));
987 aMsg = aMsg.replaceFirst("$1",pContItem->maTitle);
988 std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(m_xDialog.get(),
989 VclMessageType::Warning, VclButtonsType::Ok,
990 aMsg.replaceFirst("$2",aTemplateList)));
991 xBox->run();
992 }
993}
994
996{
997 uno::Reference<XComponentContext> xContext(comphelper::getProcessComponentContext());
998 uno::Reference<XFolderPicker2> xFolderPicker = sfx2::createFolderPicker(xContext, m_xDialog.get());
999
1000 xFolderPicker->setDisplayDirectory(SvtPathOptions().GetWorkPath());
1001
1002 sal_Int16 nResult = xFolderPicker->execute();
1003 sal_Int16 nCount = maSelTemplates.size();
1004
1005 if( nResult != ExecutableDialogResults::OK )
1006 return;
1007
1008 OUString aTemplateList;
1009 INetURLObject aPathObj(xFolderPicker->getDirectory());
1010 aPathObj.setFinalSlash();
1011
1012 // export templates from the current view
1013
1014 sal_uInt16 i = 1;
1015 auto aSelTemplates = maSelTemplates;
1016 for (auto const& selTemplate : aSelTemplates)
1017 {
1018 const TemplateViewItem *pItem = static_cast<const TemplateViewItem*>(selTemplate);
1019
1020 INetURLObject aItemPath(pItem->getPath());
1021
1022 if ( 1 == i )
1023 aPathObj.Append(aItemPath.getName());
1024 else
1025 aPathObj.setName(aItemPath.getName());
1026
1027 OUString aPath = aPathObj.GetMainURL( INetURLObject::DecodeMechanism::NONE );
1028
1029 if (!mxLocalView->exportTo(pItem->mnDocId + 1, //mnId w.r.t. region = mDocId + 1
1030 mxLocalView->getRegionId(pItem->mnRegionId), //pItem->mnRegionId does not store actual region Id
1031 aPath))
1032 {
1033 if (aTemplateList.isEmpty())
1034 aTemplateList = pItem->maTitle;
1035 else
1036 aTemplateList += "\n" + pItem->maTitle;
1037 }
1038 ++i;
1039 mxLocalView->deselectItems();
1040 }
1041
1042 if (!aTemplateList.isEmpty())
1043 {
1044 OUString aText( SfxResId(STR_MSG_ERROR_EXPORT) );
1045 std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(m_xDialog.get(),
1046 VclMessageType::Warning, VclButtonsType::Ok,
1047 aText.replaceFirst("$1",aTemplateList)));
1048 xBox->run();
1049 }
1050 else
1051 {
1052 OUString sText( SfxResId(STR_MSG_EXPORT_SUCCESS) );
1053 std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(m_xDialog.get(),
1054 VclMessageType::Info, VclButtonsType::Ok,
1055 sText.replaceFirst("$1", OUString::number(nCount))));
1056 xBox->run();
1057 }
1058}
1059
1061{
1062 ThumbnailViewItem *pItem = const_cast<ThumbnailViewItem*>(*maSelTemplates.begin());
1063
1064 OpenTemplateHdl(pItem);
1065}
1066
1068{
1069 InputDialog dlg(m_xDialog.get(), SfxResId(STR_INPUT_NEW));
1070 dlg.set_title(SfxResId(STR_WINDOW_TITLE_RENAME_NEW_CATEGORY));
1071 int ret = dlg.run();
1072
1073 if (!ret)
1074 return;
1075
1076 OUString aName = dlg.GetEntryText();
1077
1078 if(mxLocalView->createRegion(aName))
1079 mxCBFolder->append_text(aName);
1080 else
1081 {
1082 OUString aMsg( SfxResId(STR_CREATE_ERROR) );
1083 std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(m_xDialog.get(),
1084 VclMessageType::Warning, VclButtonsType::Ok,
1085 aMsg.replaceFirst("$1", aName)));
1086 xBox->run();
1087 }
1088}
1089
1091{
1092 OUString sCategory = mxCBFolder->get_active_text();
1093 InputDialog dlg(m_xDialog.get(), SfxResId(STR_INPUT_NEW));
1094 dlg.set_title(SfxResId(STR_WINDOW_TITLE_RENAME_CATEGORY));
1095 dlg.SetEntryText(sCategory);
1096 int ret = dlg.run();
1097
1098 if (!ret)
1099 return;
1100
1101 OUString aName = dlg.GetEntryText();
1102
1103 if(mxLocalView->renameRegion(sCategory, aName))
1104 {
1105 sal_Int32 nPos = mxCBFolder->find_text(sCategory);
1106 mxCBFolder->remove(nPos);
1107 mxCBFolder->insert_text(nPos, aName);
1108 mxCBFolder->set_active(nPos);
1109
1110 mxLocalView->reload();
1111 SearchUpdate();
1112 }
1113 else
1114 {
1115 OUString aMsg( SfxResId(STR_CREATE_ERROR) );
1116 std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(m_xDialog.get(),
1117 VclMessageType::Warning, VclButtonsType::Ok,
1118 aMsg.replaceFirst("$1", aName)));
1119 xBox->run();
1120 }
1121}
1122
1124{
1125 const auto sCategory = mxCBFolder->get_active_text();
1126 std::unique_ptr<weld::MessageDialog> popupDlg(Application::CreateMessageDialog(m_xDialog.get(),
1127 VclMessageType::Question, VclButtonsType::YesNo,
1128 SfxResId(STR_QMSG_SEL_FOLDER_DELETE).replaceFirst("$1",sCategory)));
1129 if (popupDlg->run() != RET_YES)
1130 return;
1131
1132 sal_Int16 nItemId = mxLocalView->getRegionId(sCategory);
1133
1134 if (!mxLocalView->removeRegion(nItemId))
1135 {
1136 OUString sMsg( SfxResId(STR_MSG_ERROR_DELETE_FOLDER) );
1137 std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(m_xDialog.get(),
1138 VclMessageType::Warning, VclButtonsType::Ok,
1139 sMsg.replaceFirst("$1",sCategory)));
1140 xBox->run();
1141 }
1142 else
1143 {
1144 mxCBFolder->remove_text(sCategory);
1145 }
1146
1147 mxLocalView->reload();
1148 mxLocalView->showAllTemplates();
1149 mxCBApp->set_active(0);
1150 mxCBFolder->set_active(0);
1151 SearchUpdate();
1152 mxActionBar->set_item_sensitive(MNI_ACTION_RENAME_FOLDER, false);
1153 mxActionBar->set_item_sensitive(MNI_ACTION_DELETE_FOLDER, false);
1155}
1156
1158{
1159
1160 mxActionBar->set_item_visible(MNI_ACTION_DEFAULT, false);
1161 mxActionBar->set_item_visible(MNI_ACTION_DEFAULT_WRITER, false);
1162 mxActionBar->set_item_visible(MNI_ACTION_DEFAULT_CALC, false);
1163 mxActionBar->set_item_visible(MNI_ACTION_DEFAULT_IMPRESS, false);
1164 mxActionBar->set_item_visible(MNI_ACTION_DEFAULT_DRAW, false);
1165 mxActionBar->set_item_sensitive(MNI_ACTION_DEFAULT, false);
1166 mxActionBar->set_item_sensitive(MNI_ACTION_DEFAULT_WRITER, false);
1167 mxActionBar->set_item_sensitive(MNI_ACTION_DEFAULT_CALC, false);
1168 mxActionBar->set_item_sensitive(MNI_ACTION_DEFAULT_IMPRESS, false);
1169 mxActionBar->set_item_sensitive(MNI_ACTION_DEFAULT_DRAW, false);
1170
1171 SvtModuleOptions aModOpt;
1172 if( mxCBApp->get_active() == MNI_WRITER)
1173 {
1174 mxActionBar->set_item_visible(MNI_ACTION_DEFAULT_WRITER, true);
1176 mxActionBar->set_item_sensitive(MNI_ACTION_DEFAULT_WRITER, true);
1177 }
1178 else if( mxCBApp->get_active() == MNI_CALC )
1179 {
1180 mxActionBar->set_item_visible(MNI_ACTION_DEFAULT_CALC, true);
1182 mxActionBar->set_item_sensitive(MNI_ACTION_DEFAULT_CALC, true);
1183 }
1184 else if(mxCBApp->get_active() == MNI_IMPRESS)
1185 {
1186 mxActionBar->set_item_visible(MNI_ACTION_DEFAULT_IMPRESS, true);
1188 mxActionBar->set_item_sensitive(MNI_ACTION_DEFAULT_IMPRESS, true);
1189 }
1190 else if(mxCBApp->get_active() == MNI_DRAW)
1191 {
1192 mxActionBar->set_item_visible(MNI_ACTION_DEFAULT_DRAW, true);
1194 mxActionBar->set_item_sensitive(MNI_ACTION_DEFAULT_DRAW, true);
1195 }
1196 else if(mxCBApp->get_active() == MNI_ALL_APPLICATIONS)
1197 {
1198 mxActionBar->set_item_visible(MNI_ACTION_DEFAULT, true);
1199 if(!lcl_getAllFactoryURLs().empty())
1200 mxActionBar->set_item_sensitive(MNI_ACTION_DEFAULT, true);
1201 }
1202}
1203
1205{
1206 if (nItemId)
1207 {
1208 // Move templates to desired folder if for some reason move fails
1209 // try copying them.
1210 mxLocalView->moveTemplates(maSelTemplates,nItemId);
1211 }
1212}
1213
1214static bool lcl_getServiceName ( const OUString &rFileURL, OUString &rName )
1215{
1216 bool bRet = false;
1217
1218 if ( !rFileURL.isEmpty() )
1219 {
1220 try
1221 {
1222 uno::Reference< embed::XStorage > xStorage =
1223 comphelper::OStorageHelper::GetStorageFromURL( rFileURL, embed::ElementModes::READ );
1224
1225 SotClipboardFormatId nFormat = SotStorage::GetFormatID( xStorage );
1226
1227 std::shared_ptr<const SfxFilter> pFilter = SfxGetpApp()->GetFilterMatcher().GetFilter4ClipBoardId( nFormat );
1228
1229 if ( pFilter )
1230 {
1231 rName = pFilter->GetServiceName();
1232 bRet = true;
1233 }
1234 }
1235 catch( uno::Exception& )
1236 {}
1237 }
1238
1239 return bRet;
1240}
1241
1242static std::vector<OUString> lcl_getAllFactoryURLs ()
1243{
1244 SvtModuleOptions aModOpt;
1245 std::vector<OUString> aList;
1246 const css::uno::Sequence<OUString> &aServiceNames = aModOpt.GetAllServiceNames();
1247
1248 for( const auto& rServiceName : aServiceNames )
1249 {
1250 if ( ! SfxObjectFactory::GetStandardTemplate( rServiceName ).isEmpty() )
1251 {
1253 SvtModuleOptions::ClassifyFactoryByName( rServiceName, eFac );
1254 aList.push_back(aModOpt.GetFactoryEmptyDocumentURL(eFac));
1255 }
1256 }
1257
1258 return aList;
1259}
1260
1261
1262// Class SfxTemplateCategoryDialog --------------------------------------------------
1263
1265 : GenericDialogController(pParent, "sfx/ui/templatecategorydlg.ui", "TemplatesCategoryDialog")
1266 , mbIsNewCategory(false)
1267 , mxLBCategory(m_xBuilder->weld_tree_view("categorylb"))
1268 , mxNewCategoryEdit(m_xBuilder->weld_entry("category_entry"))
1269 , mxOKButton(m_xBuilder->weld_button("ok"))
1270{
1271 mxLBCategory->append_text(SfxResId(STR_CATEGORY_NONE));
1272 mxNewCategoryEdit->connect_changed(LINK(this, SfxTemplateCategoryDialog, NewCategoryEditHdl));
1273 mxLBCategory->set_size_request(mxLBCategory->get_approximate_digit_width() * 32,
1274 mxLBCategory->get_height_rows(8));
1275 mxLBCategory->connect_changed(LINK(this, SfxTemplateCategoryDialog, SelectCategoryHdl));
1276 mxOKButton->set_sensitive(false);
1277}
1278
1280{
1281}
1282
1284{
1285 OUString sParam = comphelper::string::strip(mxNewCategoryEdit->get_text(), ' ');
1286 mxLBCategory->set_sensitive(sParam.isEmpty());
1287 if(!sParam.isEmpty())
1288 {
1289 msSelectedCategory = sParam;
1290 mbIsNewCategory = true;
1291 mxOKButton->set_sensitive(true);
1292 }
1293 else
1294 {
1295 SelectCategoryHdl(*mxLBCategory);
1296 mbIsNewCategory = false;
1297 }
1298}
1299
1301{
1302 if (mxLBCategory->get_selected_index() == 0)
1303 {
1304 msSelectedCategory = OUString();
1305 mxOKButton->set_sensitive(false);
1306 mxNewCategoryEdit->set_sensitive(true);
1307 }
1308 else
1309 {
1310 msSelectedCategory = mxLBCategory->get_selected_text();
1311 mxNewCategoryEdit->set_sensitive(false);
1312 mxOKButton->set_sensitive(true);
1313 }
1314
1315 mbIsNewCategory = false;
1316}
1317
1318void SfxTemplateCategoryDialog::SetCategoryLBEntries(std::vector<OUString> aFolderNames)
1319{
1320 for (size_t i = 0, n = aFolderNames.size(); i < n; ++i)
1321 mxLBCategory->append_text(aFolderNames[i]);
1322 mxLBCategory->select(0);
1323}
1324
1325// SfxTemplateSelectionDialog -----------------------------------------------------------------
1326
1328 : SfxTemplateManagerDlg(pParent)
1329 , maIdle("sfx2 SfxTemplateManagerDlg maIdle")
1330{
1331 mxCBApp->set_active(MNI_IMPRESS);
1332 mxCBFolder->set_active(0);
1333 m_xDialog->set_title(SfxResId(STR_TEMPLATE_SELECTION));
1334
1335 if (mxLocalView->IsVisible())
1336 {
1338 mxLocalView->showAllTemplates();
1339 }
1340
1341 mxCBApp->set_sensitive(false);
1342 mxActionBar->show();
1343 mxCBXHideDlg->show();
1344 mxCBXHideDlg->set_active(true);
1345
1346 mxLocalView->setOpenTemplateHdl(LINK(this,SfxTemplateSelectionDlg, OpenTemplateHdl));
1347 mxOKButton->connect_clicked(LINK(this, SfxTemplateSelectionDlg, OkClickHdl));
1349}
1350
1352{
1353 maIdle.Stop();
1354}
1355
1357{
1358 // tdf#124597 at startup this dialog is launched before its parent window
1359 // has taken its final size. The parent size request is processed during
1360 // the dialogs event loop so configure this dialog to center to
1361 // the parents pending geometry request
1362 m_xDialog->set_centered_on_parent(true);
1363
1364 // tdf#125079 toggle off the size tracking at some future idle point
1365 maIdle.SetPriority(TaskPriority::LOWEST);
1367 maIdle.Start();
1369
1371}
1372
1374{
1375 m_xDialog->set_centered_on_parent(false);
1376}
1377
1379{
1380 TemplateViewItem *pViewItem = static_cast<TemplateViewItem*>(pItem);
1381 msTemplatePath = pViewItem->getPath();
1382
1383 m_xDialog->response(RET_OK);
1384}
1385
1387{
1388 TemplateViewItem *pViewItem = static_cast<TemplateViewItem*>(const_cast<ThumbnailViewItem*>(*maSelTemplates.begin()));
1389 msTemplatePath = pViewItem->getPath();
1390
1391 m_xDialog->response(RET_OK);
1392}
1393
1394/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SfxApplication * SfxGetpApp()
Definition: app.hxx:231
Reference< XExecutableDialog > m_xDialog
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, const ILibreOfficeKitNotifier *pNotifier=nullptr)
OUString getName(sal_Int32 nIndex=LAST_SEGMENT, bool bIgnoreFinalSlash=true, DecodeMechanism eMechanism=DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
OUString GetMainURL(DecodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
OUString getExtension(sal_Int32 nIndex=LAST_SEGMENT, bool bIgnoreFinalSlash=true, DecodeMechanism eMechanism=DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
bool setFinalSlash()
bool setName(std::u16string_view rTheName, EncodeMechanism eMechanism=EncodeMechanism::WasEncoded, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)
bool Append(std::u16string_view rTheSegment, EncodeMechanism eMechanism=EncodeMechanism::WasEncoded, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)
virtual void Start(bool bStartTimer=true) override
OUString GetEntryText() const
Definition: inputdlg.cxx:24
void SetEntryText(const OUString &rStr)
Definition: inputdlg.cxx:26
SfxFilterMatcher & GetFilterMatcher()
Definition: appmain.cxx:27
std::shared_ptr< const SfxFilter > GetFilter4ClipBoardId(SotClipboardFormatId nId, SfxFilterFlags nMust=SfxFilterFlags::IMPORT, SfxFilterFlags nDont=SFX_FILTER_NOTINSTALLED) const
Definition: fltfnc.cxx:699
static SfxModule * GetActiveModule(SfxViewFrame *pFrame=nullptr)
Definition: module.cxx:208
static void SetStandardTemplate(const OUString &rServiceName, const OUString &rTemplateName)
Definition: docfac.cxx:239
static OUString GetStandardTemplate(std::u16string_view rServiceName)
Definition: docfac.cxx:251
static OUString GetServiceNameFromFactory(const OUString &rFact)
Definition: objxtor.cxx:921
std::unique_ptr< weld::TreeView > mxLBCategory
std::unique_ptr< weld::Entry > mxNewCategoryEdit
virtual ~SfxTemplateCategoryDialog() override
const OUString & GetSelectedCategory() const
bool IsNewCategoryCreated() const
void SetCategoryLBEntries(std::vector< OUString > names)
SfxTemplateCategoryDialog(weld::Window *pParent)
std::unique_ptr< weld::Button > mxOKButton
FILTER_APPLICATION getCurrentApplicationFilter() const
Return filter according to the currently selected application filter.
SfxTemplateManagerDlg(weld::Window *parent)
TemplateViewMode getTemplateViewMode() const
void OnTemplateImportCategory(std::u16string_view sCategory)
std::unique_ptr< weld::Entry > mxSearchFilter
TemplateViewMode mViewMode
std::unique_ptr< weld::MenuButton > mxActionBar
void getApplicationSpecificSettings()
void DefaultTemplateMenuSelectHdl(std::u16string_view rIdent)
void OnTemplateState(const ThumbnailViewItem *pItem)
virtual short run() override
static void ExtensionsActionHdl()
std::set< const ThumbnailViewItem *, selection_cmp_fn > maSelTemplates
std::unique_ptr< weld::CheckButton > mxCBXHideDlg
std::unique_ptr< weld::Toggleable > mxThumbnailViewButton
std::unique_ptr< weld::CustomWeld > mxLocalViewWeld
virtual ~SfxTemplateManagerDlg() override
void setTemplateViewMode(TemplateViewMode eViewMode)
void localMoveTo(sal_uInt16 nMenuId)
Move templates stored in the filesystem to another folder.
css::uno::Reference< css::frame::XModel > m_xModel
std::unique_ptr< weld::ComboBox > mxCBApp
std::unique_ptr< weld::Button > mxOKButton
std::unique_ptr< TemplateDlgLocalView > mxLocalView
void setDocumentModel(const css::uno::Reference< css::frame::XModel > &rModel)
std::unique_ptr< weld::Toggleable > mxListViewButton
std::unique_ptr< weld::ComboBox > mxCBFolder
virtual ~SfxTemplateSelectionDlg() override
SfxTemplateSelectionDlg(weld::Window *parent)
virtual short run() override
static SotClipboardFormatId GetFormatID(css::uno::Reference< css::embed::XStorage > const &xStorage)
bool IsModuleInstalled(EModule eModule) const
OUString GetFactoryEmptyDocumentURL(EFactory eFactory) const
OUString GetFactoryStandardTemplate(EFactory eFactory) const
css::uno::Sequence< OUString > GetAllServiceNames()
static EFactory ClassifyFactoryByModel(const css::uno::Reference< css::frame::XModel > &xModel)
static bool ClassifyFactoryByName(std::u16string_view sName, EFactory &eFactory)
css::uno::Any GetUserItem(const OUString &sName) const
void SetUserData(const css::uno::Sequence< css::beans::NamedValue > &lData)
bool Exists() const
void SetPriority(TaskPriority ePriority)
void Stop()
static bool IsInternalTemplate(const OUString &rPath)
bool IsDefaultTemplate() const
const OUString & getPath() const
void showDefaultIcon(bool bVal)
void SetTimeout(sal_uInt64 nTimeoutMs)
void SetInvokeHandler(const Link< Timer *, void > &rLink)
static bool isFilteredExtension(FILTER_APPLICATION filter, std::u16string_view rExt)
static css::uno::Reference< css::embed::XStorage > GetStorageFromURL(const OUString &aURL, sal_Int32 nStorageMode, const css::uno::Reference< css::uno::XComponentContext > &rxContext=css::uno::Reference< css::uno::XComponentContext >())
void AddFilter(const OUString &rFilterName, const OUString &rExtension)
css::uno::Sequence< OUString > GetSelectedFiles() const
Provides the selected files with full path information.
void SetCurrentFilter(const OUString &rFilter)
void SetContext(Context _eNewContext)
sets the context of the dialog and trigger necessary actions e.g.
sal_uInt16 GetCode() const
virtual short run()
void set_title(const OUString &rTitle)
std::shared_ptr< weld::Dialog > m_xDialog
int nCount
float u
#define ERRCODE_NONE
Sequence< OUString > aServiceNames
constexpr OUStringLiteral FILEDIALOG_FILTER_ALL
SotClipboardFormatId
TRISTATE_FALSE
TRISTATE_TRUE
OUString aName
sal_Int64 n
constexpr sal_uInt16 KEY_ESCAPE
sal_uInt16 nPos
Definition: linksrc.cxx:118
TemplateViewMode
Definition: listview.hxx:15
@ eThumbnailView
Definition: listview.hxx:17
@ eListView
Definition: listview.hxx:16
Implementation of the interface com.sun.star.rdf.XDocumentMetadataAccess.
OString strip(const OString &rIn, char c)
bool dispatchCommand(const OUString &rCommand, const uno::Reference< css::frame::XFrame > &rFrame, const css::uno::Sequence< css::beans::PropertyValue > &rArguments, const uno::Reference< css::frame::XDispatchResultListener > &rListener)
Reference< XComponentContext > getProcessComponentContext()
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
css::uno::Reference< css::deployment::XPackageRegistry > create(css::uno::Reference< css::deployment::XPackageRegistry > const &xRootRegistry, OUString const &context, OUString const &cachePath, css::uno::Reference< css::uno::XComponentContext > const &xComponentContext)
int i
css::uno::Reference< css::ui::dialogs::XFolderPicker2 > createFolderPicker(const css::uno::Reference< css::uno::XComponentContext > &rContext, weld::Window *pPreferredParent)
OUString SfxResId(TranslateId aId)
Definition: sfxresid.cxx:22
static bool cmpSelectionItems(const ThumbnailViewItem *pItem1, const ThumbnailViewItem *pItem2)
constexpr OUStringLiteral MNI_ACTION_DELETE_FOLDER
Definition: templatedlg.cxx:63
constexpr OUStringLiteral MNI_ACTION_DEFAULT_WRITER
Definition: templatedlg.cxx:65
#define MNI_CALC
Definition: templatedlg.cxx:73
IMPL_LINK(SfxTemplateManagerDlg, KeyInputHdl, const KeyEvent &, rKeyEvent, bool)
constexpr OUStringLiteral MNI_ACTION_IMPORT
Definition: templatedlg.cxx:69
constexpr OUStringLiteral MNI_ACTION_DEFAULT_CALC
Definition: templatedlg.cxx:66
#define MNI_DRAW
Definition: templatedlg.cxx:75
constexpr OUStringLiteral MNI_ACTION_DEFAULT_DRAW
Definition: templatedlg.cxx:68
constexpr OUStringLiteral MNI_ACTION_NEW_FOLDER
Definition: templatedlg.cxx:61
constexpr OUStringLiteral MNI_ACTION_RENAME_FOLDER
Definition: templatedlg.cxx:62
constexpr OUStringLiteral MNI_ACTION_DEFAULT_IMPRESS
Definition: templatedlg.cxx:67
IMPL_LINK_NOARG(SfxTemplateManagerDlg, SelectApplicationHdl, weld::ComboBox &, void)
#define MNI_WRITER
Definition: templatedlg.cxx:72
constexpr OUStringLiteral TM_SETTING_LASTFOLDER
Definition: templatedlg.cxx:57
constexpr OUStringLiteral TM_SETTING_LASTAPPLICATION
Definition: templatedlg.cxx:58
constexpr OUStringLiteral TM_SETTING_VIEWMODE
Definition: templatedlg.cxx:59
static std::vector< OUString > lcl_getAllFactoryURLs()
constexpr OUStringLiteral TM_SETTING_MANAGER
Definition: templatedlg.cxx:56
#define MNI_IMPRESS
Definition: templatedlg.cxx:74
static bool lcl_getServiceName(const OUString &rFileURL, OUString &rName)
constexpr OUStringLiteral MNI_ACTION_EXTENSIONS
Definition: templatedlg.cxx:70
#define MNI_ALL_APPLICATIONS
Definition: templatedlg.cxx:71
constexpr OUStringLiteral MNI_ACTION_DEFAULT
Definition: templatedlg.cxx:64
FILTER_APPLICATION
#define TEMPLATE_ITEM_MAX_HEIGHT_SUB
#define TEMPLATE_ITEM_PADDING
#define TEMPLATE_ITEM_MAX_HEIGHT
#define TEMPLATE_ITEM_MAX_WIDTH
#define TEMPLATE_ITEM_MAX_TEXT_LENGTH
#define TEMPLATE_ITEM_THUMBNAIL_MAX_HEIGHT
#define EDIT_UPDATEDATA_TIMEOUT
RET_OK
RET_YES