Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * Copyright 2012 LibreOffice contributors.
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 "templatedlg.hxx"
11 :
12 : #include "inputdlg.hxx"
13 : #include "templatesearchview.hxx"
14 : #include "templatesearchviewitem.hxx"
15 :
16 : #include <comphelper/processfactory.hxx>
17 : #include <comphelper/storagehelper.hxx>
18 : #include <sfx2/app.hxx>
19 : #include <sfx2/docfac.hxx>
20 : #include <sfx2/fcontnr.hxx>
21 : #include <sfx2/filedlghelper.hxx>
22 : #include <sfx2/sfxresid.hxx>
23 : #include <sfx2/templateinfodlg.hxx>
24 : #include <sfx2/templatelocalview.hxx>
25 : #include <sfx2/templatelocalviewitem.hxx>
26 : #include <sfx2/templateremoteview.hxx>
27 : #include <sfx2/templateremoteviewitem.hxx>
28 : #include <sfx2/templateviewitem.hxx>
29 : #include <sfx2/thumbnailviewitem.hxx>
30 : #include <sot/storage.hxx>
31 : #include <svtools/imagemgr.hxx>
32 : #include <svtools/PlaceEditDialog.hxx>
33 : #include <tools/urlobj.hxx>
34 : #include <unotools/moduleoptions.hxx>
35 : #include <unotools/pathoptions.hxx>
36 : #include <vcl/edit.hxx>
37 : #include <vcl/msgbox.hxx>
38 : #include <vcl/toolbox.hxx>
39 :
40 : #include <com/sun/star/beans/PropertyValue.hpp>
41 : #include <com/sun/star/embed/XStorage.hpp>
42 : #include <com/sun/star/embed/ElementModes.hpp>
43 : #include <com/sun/star/frame/XComponentLoader.hpp>
44 : #include <com/sun/star/frame/XStorable.hpp>
45 : #include <com/sun/star/lang/XComponent.hpp>
46 : #include <com/sun/star/lang/XMultiServiceFactory.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/FolderPicker.hpp>
50 :
51 : #include "doc.hrc"
52 : #include "templatedlg.hrc"
53 :
54 : #define PADDING_DLG_BORDER 10
55 :
56 : using namespace ::com::sun::star;
57 : using namespace ::com::sun::star::beans;
58 : using namespace ::com::sun::star::embed;
59 : using namespace ::com::sun::star::frame;
60 : using namespace ::com::sun::star::lang;
61 : using namespace ::com::sun::star::uno;
62 : using namespace ::com::sun::star::ui::dialogs;
63 :
64 : static bool lcl_getServiceName (const OUString &rFileURL, OUString &rName );
65 :
66 : static std::vector<OUString> lcl_getAllFactoryURLs ();
67 :
68 : // Sort by name in ascending order
69 : class SortView_Name
70 : {
71 : public:
72 :
73 0 : bool operator() (const ThumbnailViewItem *pItem1, const ThumbnailViewItem *pItem2)
74 : {
75 0 : return (pItem1->maTitle.compareTo(pItem2->maTitle) < 0);
76 : }
77 : };
78 :
79 0 : class SearchView_Keyword
80 : {
81 : public:
82 :
83 0 : SearchView_Keyword (const OUString &rKeyword)
84 0 : : maKeyword(rKeyword)
85 0 : {}
86 :
87 0 : bool operator() (const TemplateItemProperties &rItem)
88 : {
89 0 : return rItem.aName.matchIgnoreAsciiCase(maKeyword);
90 : }
91 :
92 : private:
93 :
94 : OUString maKeyword;
95 : };
96 :
97 0 : SfxTemplateManagerDlg::SfxTemplateManagerDlg (Window *parent)
98 : : ModelessDialog(parent, SfxResId(DLG_TEMPLATE_MANAGER)),
99 : maTabControl(this,SfxResId(TAB_CONTROL)),
100 0 : mpToolbars( new Control(&maTabControl,SfxResId(TOOLBARS))),
101 0 : mpSearchEdit(new Edit(this,WB_HIDE | WB_BORDER)),
102 0 : mpViewBar( new ToolBox(mpToolbars, SfxResId(TBX_ACTION_VIEW))),
103 0 : mpActionBar( new ToolBox(mpToolbars, SfxResId(TBX_ACTION_ACTION))),
104 0 : mpTemplateBar( new ToolBox(mpToolbars, SfxResId(TBX_ACTION_TEMPLATES))),
105 0 : mpSearchView(new TemplateSearchView(this)),
106 0 : maView(new TemplateLocalView(this,SfxResId(TEMPLATE_VIEW))),
107 0 : mpOnlineView(new TemplateRemoteView(this, WB_VSCROLL,false)),
108 : mbIsSaveMode(false),
109 0 : mxDesktop(comphelper::getProcessServiceFactory()->createInstance( "com.sun.star.frame.Desktop" ),uno::UNO_QUERY )
110 : {
111 : // Create popup menus
112 0 : mpActionMenu = new PopupMenu;
113 0 : mpActionMenu->InsertItem(MNI_ACTION_SORT_NAME,SfxResId(STR_ACTION_SORT_NAME).toString(),SfxResId(IMG_ACTION_SORT));
114 0 : mpActionMenu->InsertItem(MNI_ACTION_REFRESH,SfxResId(STR_ACTION_REFRESH).toString(),SfxResId(IMG_ACTION_REFRESH));
115 0 : mpActionMenu->InsertItem(MNI_ACTION_DEFAULT,SfxResId(STR_ACTION_DEFAULT).toString());
116 0 : mpActionMenu->SetSelectHdl(LINK(this,SfxTemplateManagerDlg,MenuSelectHdl));
117 :
118 0 : mpRepositoryMenu = new PopupMenu;
119 0 : mpRepositoryMenu->SetSelectHdl(LINK(this,SfxTemplateManagerDlg,RepositoryMenuSelectHdl));
120 :
121 0 : mpTemplateDefaultMenu = new PopupMenu;
122 0 : mpTemplateDefaultMenu->SetSelectHdl(LINK(this,SfxTemplateManagerDlg,DefaultTemplateMenuSelectHdl));
123 0 : mpActionMenu->SetPopupMenu(MNI_ACTION_DEFAULT,mpTemplateDefaultMenu);
124 :
125 : // Set toolbox styles
126 0 : mpViewBar->SetButtonType(BUTTON_SYMBOLTEXT);
127 0 : mpTemplateBar->SetButtonType(BUTTON_SYMBOLTEXT);
128 :
129 : // Set toolbox button bits
130 0 : mpViewBar->SetItemBits(TBI_TEMPLATE_REPOSITORY, TIB_DROPDOWNONLY);
131 0 : mpActionBar->SetItemBits(TBI_TEMPLATE_ACTION, TIB_DROPDOWNONLY);
132 0 : mpTemplateBar->SetItemBits(TBI_TEMPLATE_MOVE,TIB_DROPDOWNONLY);
133 :
134 : // Set toolbox handlers
135 0 : mpViewBar->SetClickHdl(LINK(this,SfxTemplateManagerDlg,TBXViewHdl));
136 0 : mpViewBar->SetDropdownClickHdl(LINK(this,SfxTemplateManagerDlg,TBXDropdownHdl));
137 0 : mpActionBar->SetClickHdl(LINK(this,SfxTemplateManagerDlg,TBXActionHdl));
138 0 : mpActionBar->SetDropdownClickHdl(LINK(this,SfxTemplateManagerDlg,TBXDropdownHdl));
139 0 : mpTemplateBar->SetClickHdl(LINK(this,SfxTemplateManagerDlg,TBXTemplateHdl));
140 0 : mpTemplateBar->SetDropdownClickHdl(LINK(this,SfxTemplateManagerDlg,TBXDropdownHdl));
141 0 : mpSearchEdit->SetUpdateDataHdl(LINK(this,SfxTemplateManagerDlg,SearchUpdateHdl));
142 0 : mpSearchEdit->EnableUpdateData();
143 :
144 0 : maView->SetStyle(WB_VSCROLL);
145 0 : maView->setItemMaxTextLength(TEMPLATE_ITEM_MAX_TEXT_LENGTH);
146 :
147 : maView->setItemDimensions(TEMPLATE_ITEM_MAX_WIDTH,TEMPLATE_ITEM_THUMBNAIL_MAX_HEIGHT,
148 : TEMPLATE_ITEM_MAX_HEIGHT-TEMPLATE_ITEM_THUMBNAIL_MAX_HEIGHT,
149 0 : TEMPLATE_ITEM_PADDING);
150 :
151 0 : maView->setItemStateHdl(LINK(this,SfxTemplateManagerDlg,TVFolderStateHdl));
152 0 : maView->setOverlayItemStateHdl(LINK(this,SfxTemplateManagerDlg,TVTemplateStateHdl));
153 0 : maView->setOverlayDblClickHdl(LINK(this,SfxTemplateManagerDlg,OpenTemplateHdl));
154 0 : maView->setOverlayCloseHdl(LINK(this,SfxTemplateManagerDlg,CloseOverlayHdl));
155 :
156 : // Set online view position and dimensions
157 0 : mpOnlineView->setItemMaxTextLength(TEMPLATE_ITEM_MAX_TEXT_LENGTH);
158 :
159 : mpOnlineView->setItemDimensions(TEMPLATE_ITEM_MAX_WIDTH,TEMPLATE_ITEM_THUMBNAIL_MAX_HEIGHT,
160 : TEMPLATE_ITEM_MAX_HEIGHT-TEMPLATE_ITEM_THUMBNAIL_MAX_HEIGHT,
161 0 : TEMPLATE_ITEM_PADDING);
162 :
163 0 : mpOnlineView->setOverlayItemStateHdl(LINK(this,SfxTemplateManagerDlg,TVTemplateStateHdl));
164 0 : mpOnlineView->setOverlayDblClickHdl(LINK(this,SfxTemplateManagerDlg,OpenTemplateHdl));
165 0 : mpOnlineView->setOverlayCloseHdl(LINK(this,SfxTemplateManagerDlg,CloseOverlayHdl));
166 :
167 0 : mpSearchView->setItemMaxTextLength(TEMPLATE_ITEM_MAX_TEXT_LENGTH);
168 :
169 : mpSearchView->setItemDimensions(TEMPLATE_ITEM_MAX_WIDTH,TEMPLATE_ITEM_THUMBNAIL_MAX_HEIGHT,
170 : TEMPLATE_ITEM_MAX_HEIGHT-TEMPLATE_ITEM_THUMBNAIL_MAX_HEIGHT,
171 0 : TEMPLATE_ITEM_PADDING);
172 :
173 0 : mpSearchView->setItemStateHdl(LINK(this,SfxTemplateManagerDlg,TVTemplateStateHdl));
174 :
175 0 : maTabControl.SetActivatePageHdl(LINK(this,SfxTemplateManagerDlg,ActivatePageHdl));
176 :
177 0 : mpViewBar->Show();
178 0 : mpActionBar->Show();
179 :
180 0 : switchMainView(true);
181 :
182 0 : mpOnlineView->Populate();
183 :
184 0 : createRepositoryMenu();
185 0 : createDefaultTemplateMenu();
186 :
187 0 : maView->Populate();
188 0 : maView->Show();
189 :
190 0 : FreeResource();
191 0 : }
192 :
193 0 : SfxTemplateManagerDlg::~SfxTemplateManagerDlg ()
194 : {
195 0 : mpOnlineView->syncRepositories();
196 :
197 0 : delete mpSearchEdit;
198 0 : delete mpViewBar;
199 0 : delete mpActionBar;
200 0 : delete mpTemplateBar;
201 0 : delete mpSearchView;
202 0 : delete maView;
203 0 : delete mpOnlineView;
204 0 : delete mpActionMenu;
205 0 : delete mpRepositoryMenu;
206 0 : delete mpTemplateDefaultMenu;
207 0 : delete mpToolbars;
208 0 : }
209 :
210 0 : void SfxTemplateManagerDlg::setSaveMode(bool bMode)
211 : {
212 0 : mbIsSaveMode = bMode;
213 :
214 0 : if (bMode)
215 : {
216 0 : mpViewBar->ShowItem(TBI_TEMPLATE_SAVE);
217 0 : mpViewBar->HideItem(TBI_TEMPLATE_IMPORT);
218 0 : mpViewBar->HideItem(TBI_TEMPLATE_REPOSITORY);
219 : }
220 : else
221 : {
222 0 : mpViewBar->HideItem(TBI_TEMPLATE_SAVE);
223 0 : mpViewBar->ShowItem(TBI_TEMPLATE_IMPORT);
224 0 : mpViewBar->ShowItem(TBI_TEMPLATE_REPOSITORY);
225 : }
226 0 : }
227 :
228 0 : void SfxTemplateManagerDlg::setDocumentModel(const uno::Reference<frame::XModel> &rModel)
229 : {
230 0 : m_xModel = rModel;
231 0 : }
232 :
233 0 : IMPL_LINK_NOARG(SfxTemplateManagerDlg,ActivatePageHdl)
234 : {
235 0 : FILTER_APPLICATION eFilter = FILTER_APP_NONE;
236 0 : switch (maTabControl.GetCurPageId())
237 : {
238 : case FILTER_DOCS:
239 0 : eFilter = FILTER_APP_WRITER;
240 0 : break;
241 : case FILTER_PRESENTATIONS:
242 0 : eFilter = FILTER_APP_IMPRESS;
243 0 : break;
244 : case FILTER_SHEETS:
245 0 : eFilter = FILTER_APP_CALC;
246 0 : break;
247 : case FILTER_DRAWS:
248 0 : eFilter = FILTER_APP_DRAW;
249 0 : break;
250 : default:
251 : case FILTER_ALL:
252 : ;
253 : }
254 0 : mpCurView->filterTemplatesByApp(eFilter);
255 0 : return 0;
256 : }
257 :
258 0 : void SfxTemplateManagerDlg::MouseButtonDown( const MouseEvent& rMEvt )
259 : {
260 0 : if (!maView->GetActiveClipRegion().IsInside(rMEvt.GetPosPixel()) && maView->isOverlayVisible())
261 : {
262 0 : maSelTemplates.clear();
263 0 : mpTemplateBar->Hide();
264 0 : mpViewBar->Show();
265 :
266 0 : maView->showOverlay(false);
267 : }
268 0 : }
269 :
270 0 : void SfxTemplateManagerDlg::Resize()
271 : {
272 0 : Size aWinSize = GetSizePixel();
273 :
274 : // Fit the tab page control and the toolbars
275 0 : Size aTabSize = maTabControl.GetSizePixel();
276 0 : aTabSize.setWidth(aWinSize.getWidth());
277 0 : maTabControl.SetSizePixel(aTabSize);
278 0 : Size aTabPageSize = maTabControl.GetTabPageSizePixel();
279 0 : Point aToolbarsPos(0, aTabSize.getHeight() - aTabPageSize.getHeight());
280 0 : mpToolbars->SetPosPixel(aToolbarsPos);
281 0 : aTabPageSize.setHeight(mpToolbars->GetSizePixel().getHeight() + 3);
282 0 : maTabControl.SetTabPageSizePixel(aTabPageSize);
283 :
284 0 : Size aToolbarsSize = mpToolbars->GetSizePixel();
285 0 : aToolbarsSize.setWidth(aWinSize.getWidth());
286 0 : mpToolbars->SetSizePixel(aToolbarsSize);
287 :
288 : // Calculate toolboxes size and positions
289 0 : Size aViewSize = mpViewBar->CalcMinimumWindowSizePixel();
290 0 : Size aActionSize = mpActionBar->CalcMinimumWindowSizePixel();
291 0 : Size aTemplateSize = mpTemplateBar->CalcMinimumWindowSizePixel();
292 :
293 0 : aActionSize.setWidth(3*aActionSize.getWidth());
294 0 : aViewSize.setWidth(aWinSize.getWidth()-aActionSize.getWidth()-mpViewBar->GetPosPixel().X());
295 0 : aTemplateSize.setWidth(aWinSize.getWidth());
296 :
297 0 : Point aActionPos = mpActionBar->GetPosPixel();
298 0 : aActionPos.setX(aWinSize.getWidth() - aActionSize.getWidth());
299 :
300 0 : mpViewBar->SetSizePixel(aViewSize);
301 0 : mpActionBar->SetPosSizePixel(aActionPos,aActionSize);
302 0 : mpTemplateBar->SetSizePixel(aTemplateSize);
303 :
304 : // Set view position below toolbox
305 0 : Point aViewPos = maView->GetPosPixel();
306 0 : aViewPos.setY(maTabControl.GetPosPixel().Y() + maTabControl.GetSizePixel().getHeight());
307 0 : aViewPos.setX(0);
308 0 : Size aThumbSize(aWinSize.getWidth(), aWinSize.getHeight() - aViewPos.getY());
309 0 : maView->SetPosSizePixel(aViewPos, aThumbSize);
310 :
311 0 : if (aWinSize.getHeight() < aViewPos.getY() + aThumbSize.getHeight() + PADDING_DLG_BORDER)
312 0 : aWinSize.setHeight(aViewPos.getY() + aThumbSize.getHeight() + PADDING_DLG_BORDER);
313 :
314 : // Set search box position and size
315 0 : Size aSearchSize = mpSearchEdit->CalcMinimumSize();
316 0 : aSearchSize.setWidth(aWinSize.getWidth() - 2*PADDING_DLG_BORDER);
317 :
318 0 : mpSearchEdit->SetSizePixel(aSearchSize);
319 0 : mpSearchEdit->SetPosPixel(Point(PADDING_DLG_BORDER,aViewPos.Y()));
320 :
321 0 : maView->SetSizePixel(aThumbSize);
322 0 : mpOnlineView->SetPosSizePixel(aViewPos,aThumbSize);
323 0 : mpSearchView->SetSizePixel(aThumbSize);
324 :
325 0 : mpCurView->Resize();
326 :
327 0 : ModelessDialog::Resize();
328 0 : }
329 :
330 0 : IMPL_LINK_NOARG(SfxTemplateManagerDlg, CloseOverlayHdl)
331 : {
332 0 : maSelTemplates.clear();
333 0 : mpTemplateBar->Hide();
334 0 : mpViewBar->Show();
335 0 : mpActionBar->Show();
336 :
337 0 : if (mpCurView == maView)
338 0 : mpCurView->showOverlay(false);
339 : else
340 0 : switchMainView(true);
341 :
342 0 : return 0;
343 : }
344 :
345 0 : IMPL_LINK_NOARG(SfxTemplateManagerDlg,TBXViewHdl)
346 : {
347 0 : switch(mpViewBar->GetCurItemId())
348 : {
349 : case TBI_TEMPLATE_IMPORT:
350 0 : OnTemplateImport();
351 0 : break;
352 : case TBI_TEMPLATE_FOLDER_DEL:
353 0 : if (mpCurView == maView)
354 0 : OnFolderDelete();
355 : else
356 0 : OnRepositoryDelete();
357 0 : break;
358 : case TBI_TEMPLATE_SAVE:
359 0 : OnTemplateSaveAs();
360 0 : break;
361 : default:
362 0 : break;
363 : }
364 :
365 0 : return 0;
366 : }
367 :
368 0 : IMPL_LINK_NOARG(SfxTemplateManagerDlg,TBXActionHdl)
369 : {
370 0 : switch(mpActionBar->GetCurItemId())
371 : {
372 : case TBI_TEMPLATE_SEARCH:
373 0 : OnTemplateSearch();
374 0 : break;
375 : default:
376 0 : break;
377 : }
378 :
379 0 : return 0;
380 : }
381 :
382 0 : IMPL_LINK_NOARG(SfxTemplateManagerDlg,TBXTemplateHdl)
383 : {
384 0 : switch(mpTemplateBar->GetCurItemId())
385 : {
386 : case TBI_TEMPLATE_EDIT:
387 0 : OnTemplateEdit();
388 0 : break;
389 : case TBI_TEMPLATE_PROPERTIES:
390 0 : OnTemplateProperties();
391 0 : break;
392 : case TBI_TEMPLATE_DELETE:
393 0 : OnTemplateDelete();
394 0 : break;
395 : case TBI_TEMPLATE_DEFAULT:
396 0 : OnTemplateAsDefault();
397 0 : break;
398 : case TBI_TEMPLATE_EXPORT:
399 0 : OnTemplateExport();
400 0 : break;
401 : default:
402 0 : break;
403 : }
404 :
405 0 : return 0;
406 : }
407 :
408 0 : IMPL_LINK(SfxTemplateManagerDlg, TBXDropdownHdl, ToolBox*, pBox)
409 : {
410 0 : const sal_uInt16 nCurItemId = pBox->GetCurItemId();
411 :
412 0 : switch(nCurItemId)
413 : {
414 : case TBI_TEMPLATE_ACTION:
415 0 : pBox->SetItemDown( nCurItemId, true );
416 :
417 : mpActionMenu->Execute(pBox,pBox->GetItemRect(TBI_TEMPLATE_ACTION),
418 0 : POPUPMENU_EXECUTE_DOWN);
419 :
420 0 : pBox->SetItemDown( nCurItemId, false );
421 0 : pBox->EndSelection();
422 0 : pBox->Invalidate();
423 0 : break;
424 : case TBI_TEMPLATE_MOVE:
425 : {
426 0 : pBox->SetItemDown( nCurItemId, true );
427 :
428 0 : std::vector<OUString> aNames = maView->getFolderNames();
429 :
430 0 : PopupMenu *pMoveMenu = new PopupMenu;
431 0 : pMoveMenu->SetSelectHdl(LINK(this,SfxTemplateManagerDlg,MoveMenuSelectHdl));
432 :
433 0 : if (!aNames.empty())
434 : {
435 0 : for (size_t i = 0, n = aNames.size(); i < n; ++i)
436 0 : pMoveMenu->InsertItem(MNI_MOVE_FOLDER_BASE+i,aNames[i]);
437 : }
438 :
439 0 : pMoveMenu->InsertSeparator();
440 :
441 0 : pMoveMenu->InsertItem(MNI_MOVE_NEW,SfxResId(STR_MOVE_NEW).toString());
442 :
443 : pMoveMenu->Execute(pBox,pBox->GetItemRect(TBI_TEMPLATE_MOVE),
444 0 : POPUPMENU_EXECUTE_DOWN);
445 :
446 0 : delete pMoveMenu;
447 :
448 0 : pBox->SetItemDown( nCurItemId, false );
449 0 : pBox->EndSelection();
450 0 : pBox->Invalidate();
451 0 : break;
452 : }
453 : case TBI_TEMPLATE_REPOSITORY:
454 0 : pBox->SetItemDown( nCurItemId, true );
455 :
456 : mpRepositoryMenu->Execute(pBox,pBox->GetItemRect(TBI_TEMPLATE_REPOSITORY),
457 0 : POPUPMENU_EXECUTE_DOWN);
458 :
459 0 : pBox->SetItemDown( nCurItemId, false );
460 0 : pBox->EndSelection();
461 0 : pBox->Invalidate();
462 0 : break;
463 : default:
464 0 : break;
465 : }
466 :
467 0 : return 0;
468 : }
469 :
470 0 : IMPL_LINK(SfxTemplateManagerDlg, TVFolderStateHdl, const ThumbnailViewItem*, pItem)
471 : {
472 0 : if (pItem->isSelected())
473 : {
474 0 : if (maSelFolders.empty() && !mbIsSaveMode)
475 : {
476 0 : mpViewBar->ShowItem(TBI_TEMPLATE_IMPORT);
477 0 : mpViewBar->ShowItem(TBI_TEMPLATE_FOLDER_DEL);
478 : }
479 :
480 0 : maSelFolders.insert(pItem);
481 : }
482 : else
483 : {
484 0 : maSelFolders.erase(pItem);
485 :
486 0 : if (maSelFolders.empty() && !mbIsSaveMode)
487 : {
488 0 : mpViewBar->HideItem(TBI_TEMPLATE_IMPORT);
489 0 : mpViewBar->HideItem(TBI_TEMPLATE_FOLDER_DEL);
490 : }
491 : }
492 :
493 0 : return 0;
494 : }
495 :
496 0 : IMPL_LINK(SfxTemplateManagerDlg, TVTemplateStateHdl, const ThumbnailViewItem*, pItem)
497 : {
498 0 : if (pItem->isSelected())
499 : {
500 0 : if (!mbIsSaveMode)
501 : {
502 0 : if (maSelTemplates.empty())
503 : {
504 0 : mpViewBar->Show(false);
505 0 : mpActionBar->Show(false);
506 0 : mpTemplateBar->Show();
507 : }
508 : else
509 : {
510 0 : mpTemplateBar->HideItem(TBI_TEMPLATE_EDIT);
511 0 : mpTemplateBar->HideItem(TBI_TEMPLATE_PROPERTIES);
512 0 : mpTemplateBar->HideItem(TBI_TEMPLATE_DEFAULT);
513 : }
514 : }
515 :
516 0 : maSelTemplates.insert(pItem);
517 : }
518 : else
519 : {
520 0 : if (maSelTemplates.find(pItem) != maSelTemplates.end())
521 : {
522 0 : maSelTemplates.erase(pItem);
523 :
524 0 : if (!mbIsSaveMode)
525 : {
526 0 : if (maSelTemplates.empty())
527 : {
528 0 : mpTemplateBar->Show(false);
529 0 : mpViewBar->Show();
530 0 : mpActionBar->Show();
531 : }
532 0 : else if (maSelTemplates.size() == 1)
533 : {
534 0 : mpTemplateBar->ShowItem(TBI_TEMPLATE_EDIT);
535 0 : mpTemplateBar->ShowItem(TBI_TEMPLATE_PROPERTIES);
536 0 : mpTemplateBar->ShowItem(TBI_TEMPLATE_DEFAULT);
537 : }
538 : }
539 : }
540 : }
541 :
542 0 : return 0;
543 : }
544 :
545 0 : IMPL_LINK(SfxTemplateManagerDlg, MenuSelectHdl, Menu*, pMenu)
546 : {
547 0 : sal_uInt16 nMenuId = pMenu->GetCurItemId();
548 :
549 0 : switch(nMenuId)
550 : {
551 : case MNI_ACTION_SORT_NAME:
552 0 : if (maView->isOverlayVisible())
553 0 : maView->sortOverlayItems(SortView_Name());
554 : else
555 0 : maView->sortItems(SortView_Name());
556 0 : break;
557 : case MNI_ACTION_REFRESH:
558 0 : mpCurView->reload();
559 0 : break;
560 : default:
561 0 : break;
562 : }
563 :
564 0 : return 0;
565 : }
566 :
567 0 : IMPL_LINK(SfxTemplateManagerDlg, MoveMenuSelectHdl, Menu*, pMenu)
568 : {
569 0 : sal_uInt16 nMenuId = pMenu->GetCurItemId();
570 :
571 0 : if (mpSearchView->IsVisible())
572 : {
573 : // Check if we are searching the local or remote templates
574 0 : if (mpCurView == maView)
575 0 : localSearchMoveTo(nMenuId);
576 : }
577 : else
578 : {
579 : // Check if we are displaying the local or remote templates
580 0 : if (mpCurView == maView)
581 0 : localMoveTo(nMenuId);
582 : else
583 0 : remoteMoveTo(nMenuId);
584 : }
585 :
586 0 : return 0;
587 : }
588 :
589 0 : IMPL_LINK(SfxTemplateManagerDlg, RepositoryMenuSelectHdl, Menu*, pMenu)
590 : {
591 0 : sal_uInt16 nMenuId = pMenu->GetCurItemId();
592 :
593 0 : if (nMenuId == MNI_REPOSITORY_LOCAL)
594 : {
595 0 : switchMainView(true);
596 : }
597 0 : else if (nMenuId == MNI_REPOSITORY_NEW)
598 : {
599 0 : PlaceEditDialog dlg(this);
600 :
601 0 : if (dlg.Execute())
602 : {
603 0 : boost::shared_ptr<Place> pPlace = dlg.GetPlace();
604 :
605 0 : if (mpOnlineView->insertRepository(pPlace->GetName(),pPlace->GetUrl()))
606 : {
607 : // update repository list menu.
608 0 : createRepositoryMenu();
609 : }
610 : else
611 : {
612 0 : OUString aMsg(SfxResId(STR_MSG_ERROR_REPOSITORY_NAME).toString());
613 0 : aMsg = aMsg.replaceFirst("$1",pPlace->GetName());
614 0 : ErrorBox(this,WB_OK,aMsg).Execute();
615 0 : }
616 0 : }
617 : }
618 : else
619 : {
620 0 : sal_uInt16 nRepoId = nMenuId - MNI_REPOSITORY_BASE;
621 :
622 0 : if (mpOnlineView->loadRepository(nRepoId,false))
623 : {
624 0 : switchMainView(false);
625 0 : mpOnlineView->showOverlay(true);
626 : }
627 : }
628 :
629 0 : return 0;
630 : }
631 :
632 0 : IMPL_LINK(SfxTemplateManagerDlg, DefaultTemplateMenuSelectHdl, Menu*, pMenu)
633 : {
634 0 : sal_uInt16 nId = pMenu->GetCurItemId();
635 :
636 0 : OUString aServiceName = SfxObjectShell::GetServiceNameFromFactory( mpTemplateDefaultMenu->GetItemCommand(nId));
637 0 : SfxObjectFactory::SetStandardTemplate( aServiceName, OUString() );
638 :
639 0 : createDefaultTemplateMenu();
640 :
641 0 : return 0;
642 : }
643 :
644 0 : IMPL_LINK(SfxTemplateManagerDlg, OpenTemplateHdl, ThumbnailViewItem*, pItem)
645 : {
646 0 : if (!mbIsSaveMode)
647 : {
648 0 : uno::Sequence< PropertyValue > aArgs(1);
649 0 : aArgs[0].Name = "AsTemplate";
650 0 : aArgs[0].Value <<= sal_True;
651 :
652 0 : TemplateViewItem *pTemplateItem = static_cast<TemplateViewItem*>(pItem);
653 :
654 : try
655 : {
656 0 : mxDesktop->loadComponentFromURL(pTemplateItem->getPath(),"_default", 0, aArgs );
657 : }
658 0 : catch( const uno::Exception& )
659 : {
660 : }
661 :
662 0 : Close();
663 : }
664 :
665 0 : return 0;
666 : }
667 :
668 0 : IMPL_LINK_NOARG(SfxTemplateManagerDlg, SearchUpdateHdl)
669 : {
670 : // if the search view is hidden, hide the folder view and display search one
671 0 : if (!mpCurView->isOverlayVisible() && !mpSearchView->IsVisible())
672 : {
673 0 : mpSearchView->Clear();
674 0 : mpSearchView->Show();
675 0 : mpCurView->Hide();
676 : }
677 :
678 0 : OUString aKeyword = mpSearchEdit->GetText();
679 :
680 0 : if (!aKeyword.isEmpty())
681 : {
682 0 : if (mpCurView->isOverlayVisible())
683 : {
684 0 : mpCurView->filterTemplatesByKeyword(aKeyword);
685 : }
686 : else
687 : {
688 0 : mpSearchView->Clear();
689 :
690 : std::vector<TemplateItemProperties> aItems =
691 0 : maView->getFilteredItems(SearchView_Keyword(aKeyword));
692 :
693 0 : size_t nCounter = 0;
694 0 : for (size_t i = 0; i < aItems.size(); ++i)
695 : {
696 0 : TemplateItemProperties *pItem = &aItems[i];
697 :
698 : mpSearchView->AppendItem(++nCounter,pItem->nRegionId,
699 : pItem->nId-1,
700 : pItem->aName,
701 : maView->GetItemText(pItem->nRegionId+1),
702 : pItem->aPath,
703 0 : pItem->aThumbnail);
704 : }
705 :
706 0 : mpSearchView->Invalidate();
707 : }
708 : }
709 : else
710 : {
711 0 : if (mpCurView->isOverlayVisible())
712 : {
713 0 : mpCurView->filterTemplatesByApp(FILTER_APP_NONE);
714 : }
715 : else
716 : {
717 0 : mpSearchView->Hide();
718 0 : mpCurView->Show();
719 : }
720 : }
721 :
722 0 : return 0;
723 : }
724 :
725 0 : void SfxTemplateManagerDlg::OnTemplateImport ()
726 : {
727 : sal_Int16 nDialogType =
728 0 : com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE;
729 :
730 0 : sfx2::FileDialogHelper aFileDlg(nDialogType, SFXWB_MULTISELECTION);
731 :
732 : // add "All" filter
733 : aFileDlg.AddFilter( String(SfxResId( STR_SFX_FILTERNAME_ALL) ),
734 0 : DEFINE_CONST_UNICODE(FILEDIALOG_FILTER_ALL) );
735 :
736 : // add template filter
737 0 : OUString sFilterExt;
738 0 : OUString sFilterName( SfxResId( STR_TEMPLATE_FILTER ).toString() );
739 :
740 : // add filters of modules which are installed
741 0 : SvtModuleOptions aModuleOpt;
742 0 : if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SWRITER ) )
743 0 : sFilterExt += "*.ott;*.stw;*.oth";
744 :
745 0 : if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SCALC ) )
746 : {
747 0 : if ( !sFilterExt.isEmpty() )
748 0 : sFilterExt += ";";
749 :
750 0 : sFilterExt += "*.ots;*.stc";
751 : }
752 :
753 0 : if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SIMPRESS ) )
754 : {
755 0 : if ( !sFilterExt.isEmpty() )
756 0 : sFilterExt += ";";
757 :
758 0 : sFilterExt += "*.otp;*.sti";
759 : }
760 :
761 0 : if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SDRAW ) )
762 : {
763 0 : if ( !sFilterExt.isEmpty() )
764 0 : sFilterExt += ";";
765 :
766 0 : sFilterExt += "*.otg;*.std";
767 : }
768 :
769 0 : if ( !sFilterExt.isEmpty() )
770 0 : sFilterExt += ";";
771 :
772 0 : sFilterExt += "*.vor";
773 :
774 0 : sFilterName += " (";
775 0 : sFilterName += sFilterExt;
776 0 : sFilterName += ")";
777 :
778 0 : aFileDlg.AddFilter( sFilterName, sFilterExt );
779 0 : aFileDlg.SetCurrentFilter( sFilterName );
780 :
781 0 : ErrCode nCode = aFileDlg.Execute();
782 :
783 0 : if ( nCode == ERRCODE_NONE )
784 : {
785 0 : com::sun::star::uno::Sequence<OUString> aFiles = aFileDlg.GetSelectedFiles();
786 :
787 0 : if (aFiles.hasElements())
788 : {
789 0 : std::set<const ThumbnailViewItem*>::const_iterator pIter;
790 0 : for (pIter = maSelFolders.begin(); pIter != maSelFolders.end(); ++pIter)
791 : {
792 0 : OUString aTemplateList;
793 0 : TemplateLocalViewItem *pFolder = (TemplateLocalViewItem*)(*pIter);
794 :
795 0 : for (size_t i = 0, n = aFiles.getLength(); i < n; ++i)
796 : {
797 0 : if(!maView->copyFrom(pFolder,aFiles[i]))
798 : {
799 0 : if (aTemplateList.isEmpty())
800 0 : aTemplateList = aFiles[i];
801 : else
802 0 : aTemplateList = aTemplateList + "\n" + aFiles[i];
803 : }
804 : }
805 :
806 0 : if (!aTemplateList.isEmpty())
807 : {
808 0 : OUString aMsg(SfxResId(STR_MSG_ERROR_IMPORT).toString());
809 0 : aMsg = aMsg.replaceFirst("$1",pFolder->maTitle);
810 0 : ErrorBox(this,WB_OK,aMsg.replaceFirst("$2",aTemplateList));
811 : }
812 0 : }
813 :
814 0 : maView->Invalidate(INVALIDATE_NOERASE);
815 0 : }
816 0 : }
817 0 : }
818 :
819 0 : void SfxTemplateManagerDlg::OnTemplateExport()
820 : {
821 0 : uno::Reference<XComponentContext> xContext(comphelper::getProcessComponentContext());
822 0 : uno::Reference<XFolderPicker2> xFolderPicker = FolderPicker::create(xContext);
823 :
824 0 : xFolderPicker->setDisplayDirectory(SvtPathOptions().GetWorkPath());
825 :
826 0 : sal_Int16 nResult = xFolderPicker->execute();
827 :
828 0 : if( nResult == ExecutableDialogResults::OK )
829 : {
830 0 : OUString aTemplateList;
831 0 : INetURLObject aPathObj(xFolderPicker->getDirectory());
832 0 : aPathObj.setFinalSlash();
833 :
834 0 : if (mpSearchView->IsVisible())
835 : {
836 0 : sal_uInt16 i = 1;
837 :
838 0 : std::set<const ThumbnailViewItem*>::const_iterator pIter = maSelTemplates.begin();
839 0 : for (pIter = maSelTemplates.begin(); pIter != maSelTemplates.end(); ++pIter, ++i)
840 : {
841 0 : const TemplateSearchViewItem *pItem = static_cast<const TemplateSearchViewItem*>(*pIter);
842 :
843 0 : INetURLObject aItemPath(pItem->getPath());
844 :
845 0 : if ( 1 == i )
846 0 : aPathObj.Append(aItemPath.getName());
847 : else
848 0 : aPathObj.setName(aItemPath.getName());
849 :
850 0 : OUString aPath = aPathObj.GetMainURL( INetURLObject::NO_DECODE );
851 :
852 0 : if (!maView->exportTo(pItem->mnIdx+1,pItem->mnRegionId+1,aPath))
853 : {
854 0 : if (aTemplateList.isEmpty())
855 0 : aTemplateList = pItem->maTitle;
856 : else
857 0 : aTemplateList = aTemplateList + "\n" + pItem->maTitle;
858 : }
859 0 : }
860 :
861 0 : mpSearchView->deselectItems();
862 : }
863 : else
864 : {
865 : // export templates from the current open overlay
866 :
867 0 : sal_uInt16 i = 1;
868 0 : sal_uInt16 nRegionItemId = maView->getOverlayRegionId() + 1;
869 :
870 0 : std::set<const ThumbnailViewItem*>::const_iterator pIter = maSelTemplates.begin();
871 0 : for (pIter = maSelTemplates.begin(); pIter != maSelTemplates.end(); ++pIter, ++i)
872 : {
873 0 : const TemplateViewItem *pItem = static_cast<const TemplateViewItem*>(*pIter);
874 :
875 0 : INetURLObject aItemPath(pItem->getPath());
876 :
877 0 : if ( 1 == i )
878 0 : aPathObj.Append(aItemPath.getName());
879 : else
880 0 : aPathObj.setName(aItemPath.getName());
881 :
882 0 : OUString aPath = aPathObj.GetMainURL( INetURLObject::NO_DECODE );
883 :
884 0 : if (!maView->exportTo(pItem->mnId,nRegionItemId,aPath))
885 : {
886 0 : if (aTemplateList.isEmpty())
887 0 : aTemplateList = pItem->maTitle;
888 : else
889 0 : aTemplateList = aTemplateList + "\n" + pItem->maTitle;
890 : }
891 0 : }
892 :
893 0 : maView->deselectOverlayItems();
894 : }
895 :
896 0 : if (!aTemplateList.isEmpty())
897 : {
898 0 : OUString aText( SfxResId(STR_MSG_ERROR_EXPORT).toString() );
899 0 : ErrorBox(this, WB_OK,aText.replaceFirst("$1",aTemplateList)).Execute();
900 0 : }
901 0 : }
902 0 : }
903 :
904 0 : void SfxTemplateManagerDlg::OnTemplateSearch ()
905 : {
906 0 : Point aPos = maView->GetPosPixel();
907 0 : bool bVisible = mpSearchEdit->IsVisible();
908 0 : Size aWinSize = GetSizePixel();
909 0 : long nEditHeight = mpSearchEdit->GetSizePixel().getHeight();
910 :
911 0 : if (bVisible)
912 : {
913 0 : aWinSize.setHeight(aWinSize.getHeight() - nEditHeight );
914 0 : aPos.setY(aPos.getY() - nEditHeight );
915 0 : mpActionBar->SetItemState(TBI_TEMPLATE_SEARCH,STATE_NOCHECK);
916 : }
917 : else
918 : {
919 0 : aWinSize.setHeight(aWinSize.getHeight() + nEditHeight );
920 0 : aPos.setY(aPos.getY() + nEditHeight );
921 0 : mpActionBar->SetItemState(TBI_TEMPLATE_SEARCH,STATE_CHECK);
922 : }
923 :
924 : // SetSizePixel(aWinSize);
925 0 : maView->SetPosPixel(aPos);
926 0 : mpOnlineView->SetPosPixel(aPos);
927 0 : mpSearchView->SetPosPixel(aPos);
928 :
929 : // Hide search view
930 0 : if (bVisible)
931 : {
932 0 : mpSearchView->Hide();
933 0 : mpCurView->Show();
934 : }
935 :
936 0 : mpSearchEdit->Show(!bVisible);
937 0 : mpSearchEdit->SetText(OUString());
938 :
939 : // display all templates if we hide the search bar
940 0 : if (bVisible && mpCurView->isOverlayVisible())
941 0 : mpCurView->filterTemplatesByApp(FILTER_APP_NONE);
942 0 : }
943 :
944 0 : void SfxTemplateManagerDlg::OnTemplateEdit ()
945 : {
946 0 : uno::Sequence< PropertyValue > aArgs(1);
947 0 : aArgs[0].Name = "AsTemplate";
948 0 : aArgs[0].Value <<= sal_False;
949 :
950 0 : uno::Reference< XStorable > xStorable;
951 0 : std::set<const ThumbnailViewItem*>::const_iterator pIter;
952 0 : for (pIter = maSelTemplates.begin(); pIter != maSelTemplates.end(); ++pIter)
953 : {
954 0 : const TemplateViewItem *pItem = static_cast<const TemplateViewItem*>(*pIter);
955 :
956 : try
957 : {
958 : xStorable = uno::Reference< XStorable >(
959 0 : mxDesktop->loadComponentFromURL(pItem->getPath(),"_default", 0, aArgs ),
960 0 : uno::UNO_QUERY );
961 : }
962 0 : catch( const uno::Exception& )
963 : {
964 : }
965 : }
966 :
967 0 : Close();
968 0 : }
969 :
970 0 : void SfxTemplateManagerDlg::OnTemplateProperties ()
971 : {
972 0 : const TemplateViewItem *pItem = static_cast<const TemplateViewItem*>(*maSelTemplates.begin());
973 :
974 0 : SfxTemplateInfoDlg aDlg;
975 0 : aDlg.loadDocument(pItem->getPath());
976 0 : aDlg.Execute();
977 0 : }
978 :
979 0 : void SfxTemplateManagerDlg::OnTemplateDelete ()
980 : {
981 0 : OUString aTemplateList;
982 :
983 0 : if (mpSearchView->IsVisible())
984 : {
985 0 : std::set<const ThumbnailViewItem*>::const_iterator pIter;
986 0 : for (pIter = maSelTemplates.begin(); pIter != maSelTemplates.end();)
987 : {
988 : const TemplateSearchViewItem *pItem =
989 0 : static_cast<const TemplateSearchViewItem*>(*pIter);
990 :
991 0 : sal_uInt16 nItemId = pItem->mnIdx + 1;
992 0 : sal_uInt16 nItemRegionId = pItem->mnRegionId + 1;
993 :
994 0 : if (maView->removeTemplate(nItemId,nItemRegionId))
995 0 : maSelTemplates.erase(pIter++);
996 : else
997 : {
998 0 : if (aTemplateList.isEmpty())
999 0 : aTemplateList = pItem->maTitle;
1000 : else
1001 0 : aTemplateList = aTemplateList + "\n" + pItem->maTitle;
1002 :
1003 0 : ++pIter;
1004 : }
1005 : }
1006 :
1007 : // Update search results
1008 0 : if (maSelTemplates.empty())
1009 : {
1010 0 : mpTemplateBar->Show(false);
1011 0 : mpViewBar->Show();
1012 0 : mpActionBar->Show();
1013 : }
1014 :
1015 0 : SearchUpdateHdl(mpSearchEdit);
1016 : }
1017 : else
1018 : {
1019 0 : std::set<const ThumbnailViewItem*>::const_iterator pIter;
1020 0 : for (pIter = maSelTemplates.begin(); pIter != maSelTemplates.end();)
1021 : {
1022 0 : if (maView->removeTemplate((*pIter)->mnId,maView->getOverlayRegionId()+1))
1023 0 : maSelTemplates.erase(pIter++);
1024 : else
1025 : {
1026 0 : if (aTemplateList.isEmpty())
1027 0 : aTemplateList = (*pIter)->maTitle;
1028 : else
1029 0 : aTemplateList = aTemplateList + "\n" + (*pIter)->maTitle;
1030 :
1031 0 : ++pIter;
1032 : }
1033 : }
1034 :
1035 0 : if (maSelTemplates.empty())
1036 : {
1037 0 : mpTemplateBar->SetItemDown(TBI_TEMPLATE_DELETE,false);
1038 0 : mpTemplateBar->Show(false);
1039 0 : mpViewBar->Show();
1040 0 : mpActionBar->Show();
1041 : }
1042 : }
1043 :
1044 0 : if (!aTemplateList.isEmpty())
1045 : {
1046 0 : OUString aMsg( SfxResId(STR_MSG_ERROR_DELETE_TEMPLATE).toString() );
1047 0 : ErrorBox(this, WB_OK,aMsg.replaceFirst("$1",aTemplateList)).Execute();
1048 0 : }
1049 0 : }
1050 :
1051 0 : void SfxTemplateManagerDlg::OnTemplateAsDefault ()
1052 : {
1053 : assert(!maSelTemplates.empty());
1054 :
1055 0 : const TemplateViewItem *pItem = static_cast<const TemplateViewItem*>(*(maSelTemplates.begin()));
1056 :
1057 0 : OUString aServiceName;
1058 0 : if (lcl_getServiceName(pItem->getPath(),aServiceName))
1059 : {
1060 0 : SfxObjectFactory::SetStandardTemplate(aServiceName,pItem->getPath());
1061 :
1062 0 : createDefaultTemplateMenu();
1063 :
1064 : // clear selection and display view/action toolbars
1065 0 : maView->deselectOverlayItem(pItem->mnId);
1066 0 : }
1067 0 : }
1068 :
1069 0 : void SfxTemplateManagerDlg::OnFolderDelete()
1070 : {
1071 0 : QueryBox aQueryDlg(this, WB_YES_NO | WB_DEF_YES, SfxResId(STR_QMSG_SEL_FOLDER_DELETE).toString());
1072 :
1073 0 : if ( aQueryDlg.Execute() == RET_NO )
1074 0 : return;
1075 :
1076 0 : OUString aFolderList;
1077 :
1078 0 : std::set<const ThumbnailViewItem*>::const_iterator pIter;
1079 0 : for (pIter = maSelFolders.begin(); pIter != maSelFolders.end();)
1080 : {
1081 0 : if (maView->removeRegion((*pIter)->mnId))
1082 0 : maSelFolders.erase(pIter++);
1083 : else
1084 : {
1085 0 : if (aFolderList.isEmpty())
1086 0 : aFolderList = (*pIter)->maTitle;
1087 : else
1088 0 : aFolderList = aFolderList + "\n" + (*pIter)->maTitle;
1089 :
1090 0 : ++pIter;
1091 : }
1092 : }
1093 :
1094 0 : if (maSelFolders.empty())
1095 : {
1096 0 : mpViewBar->HideItem(TBI_TEMPLATE_IMPORT);
1097 0 : mpViewBar->HideItem(TBI_TEMPLATE_FOLDER_DEL);
1098 : }
1099 :
1100 0 : if (!aFolderList.isEmpty())
1101 : {
1102 0 : OUString aMsg( SfxResId(STR_MSG_ERROR_DELETE_FOLDER).toString() );
1103 0 : ErrorBox(this, WB_OK,aMsg.replaceFirst("$1",aFolderList)).Execute();
1104 0 : }
1105 : }
1106 :
1107 0 : void SfxTemplateManagerDlg::OnRepositoryDelete()
1108 : {
1109 0 : if(mpOnlineView->deleteRepository(mpOnlineView->getOverlayRegionId()))
1110 : {
1111 : // close overlay and switch to local view
1112 0 : switchMainView(true);
1113 :
1114 0 : createRepositoryMenu();
1115 : }
1116 0 : }
1117 :
1118 0 : void SfxTemplateManagerDlg::OnTemplateSaveAs()
1119 : {
1120 : assert(m_xModel.is());
1121 :
1122 0 : if (!maView->isOverlayVisible() && maSelFolders.empty())
1123 : {
1124 0 : ErrorBox(this, WB_OK,SfxResId(STR_MSG_ERROR_SELECT_FOLDER).toString()).Execute();
1125 : return;
1126 : }
1127 :
1128 0 : InputDialog aDlg(SfxResId(STR_INPUT_TEMPLATE_NEW).toString(),this);
1129 :
1130 0 : if (aDlg.Execute())
1131 : {
1132 0 : OUString aName = aDlg.getEntryText();
1133 :
1134 0 : if (!aName.isEmpty())
1135 : {
1136 0 : OUString aFolderList;
1137 0 : OUString aQMsg(SfxResId(STR_QMSG_TEMPLATE_OVERWRITE).toString());
1138 0 : QueryBox aQueryDlg(this,WB_YES_NO | WB_DEF_YES, OUString());
1139 :
1140 0 : if (maView->isOverlayVisible())
1141 : {
1142 0 : sal_uInt16 nRegionItemId = maView->getOverlayRegionId()+1;
1143 :
1144 0 : if (!maView->isTemplateNameUnique(nRegionItemId,aName))
1145 : {
1146 0 : aQMsg = aQMsg.replaceFirst("$1",aName);
1147 0 : aQueryDlg.SetMessText(aQMsg.replaceFirst("$2",maView->getOverlayName()));
1148 :
1149 0 : if (aQueryDlg.Execute() == RET_NO)
1150 : return;
1151 : }
1152 :
1153 0 : if (!maView->saveTemplateAs(nRegionItemId,m_xModel,aName))
1154 0 : aFolderList = maView->getOverlayName();
1155 : }
1156 : else
1157 : {
1158 0 : std::set<const ThumbnailViewItem*>::const_iterator pIter;
1159 0 : for (pIter = maSelFolders.begin(); pIter != maSelFolders.end(); ++pIter)
1160 : {
1161 0 : TemplateLocalViewItem *pItem = (TemplateLocalViewItem*)(*pIter);
1162 :
1163 0 : if (!maView->isTemplateNameUnique(pItem->mnId,aName))
1164 : {
1165 0 : OUString aDQMsg = aQMsg.replaceFirst("$1",aName);
1166 0 : aQueryDlg.SetMessText(aDQMsg.replaceFirst("$2",pItem->maTitle));
1167 :
1168 0 : if (aQueryDlg.Execute() == RET_NO)
1169 0 : continue;
1170 : }
1171 :
1172 0 : if (!maView->saveTemplateAs(pItem,m_xModel,aName))
1173 : {
1174 0 : if (aFolderList.isEmpty())
1175 0 : aFolderList = (*pIter)->maTitle;
1176 : else
1177 0 : aFolderList = aFolderList + "\n" + (*pIter)->maTitle;
1178 : }
1179 : }
1180 : }
1181 :
1182 0 : maView->reload();
1183 :
1184 0 : if (!aFolderList.isEmpty())
1185 : {
1186 0 : }
1187 0 : }
1188 0 : }
1189 : }
1190 :
1191 0 : void SfxTemplateManagerDlg::createRepositoryMenu()
1192 : {
1193 0 : mpRepositoryMenu->Clear();
1194 :
1195 0 : mpRepositoryMenu->InsertItem(MNI_REPOSITORY_LOCAL,SfxResId(STR_REPOSITORY_LOCAL).toString());
1196 :
1197 0 : const std::vector<TemplateRemoteViewItem*> &rRepos = mpOnlineView->getRepositories();
1198 :
1199 0 : for (size_t i = 0, n = rRepos.size(); i < n; ++i)
1200 0 : mpRepositoryMenu->InsertItem(MNI_REPOSITORY_BASE+rRepos[i]->mnId,rRepos[i]->maTitle);
1201 :
1202 0 : mpRepositoryMenu->InsertSeparator();
1203 0 : mpRepositoryMenu->InsertItem(MNI_REPOSITORY_NEW,SfxResId(STR_REPOSITORY_NEW).toString());
1204 0 : }
1205 :
1206 0 : void SfxTemplateManagerDlg::createDefaultTemplateMenu ()
1207 : {
1208 0 : std::vector<OUString> aList = lcl_getAllFactoryURLs();
1209 :
1210 0 : if (!aList.empty())
1211 : {
1212 0 : mpTemplateDefaultMenu->Clear();
1213 :
1214 0 : sal_uInt16 nItemId = MNI_ACTION_DEFAULT + 1;
1215 0 : for( std::vector<OUString>::const_iterator i = aList.begin(); i != aList.end(); ++i )
1216 : {
1217 0 : INetURLObject aObj(*i);
1218 0 : OUString aTitle = SvFileInformationManager::GetDescription(aObj);
1219 0 : mpTemplateDefaultMenu->InsertItem(nItemId, aTitle, SvFileInformationManager::GetImage(aObj, false));
1220 0 : mpTemplateDefaultMenu->SetItemCommand(nItemId++, *i);
1221 0 : }
1222 :
1223 0 : mpActionMenu->ShowItem(MNI_ACTION_DEFAULT);
1224 : }
1225 : else
1226 0 : mpActionMenu->HideItem(MNI_ACTION_DEFAULT);
1227 0 : }
1228 :
1229 0 : void SfxTemplateManagerDlg::switchMainView(bool bDisplayLocal)
1230 : {
1231 0 : if (bDisplayLocal)
1232 : {
1233 0 : mpCurView = maView;
1234 :
1235 0 : mpViewBar->HideItem(TBI_TEMPLATE_FOLDER_DEL);
1236 :
1237 : // Enable deleting and exporting items from the filesystem
1238 0 : mpTemplateBar->ShowItem(TBI_TEMPLATE_EXPORT);
1239 0 : mpTemplateBar->ShowItem(TBI_TEMPLATE_DELETE);
1240 :
1241 0 : mpOnlineView->Hide();
1242 0 : maView->Show();
1243 : }
1244 : else
1245 : {
1246 0 : mpCurView = mpOnlineView;
1247 :
1248 0 : mpViewBar->ShowItem(TBI_TEMPLATE_FOLDER_DEL);
1249 :
1250 : // Disable deleting and exporting items from remote repositories
1251 0 : mpTemplateBar->HideItem(TBI_TEMPLATE_EXPORT);
1252 0 : mpTemplateBar->HideItem(TBI_TEMPLATE_DELETE);
1253 :
1254 0 : maView->Hide();
1255 0 : mpOnlineView->Show();
1256 : }
1257 0 : }
1258 :
1259 0 : void SfxTemplateManagerDlg::localMoveTo(sal_uInt16 nMenuId)
1260 : {
1261 0 : sal_uInt16 nItemId = 0;
1262 :
1263 0 : if (nMenuId == MNI_MOVE_NEW)
1264 : {
1265 0 : InputDialog dlg(SfxResId(STR_INPUT_NEW).toString(),this);
1266 :
1267 0 : int ret = dlg.Execute();
1268 :
1269 0 : if (ret)
1270 : {
1271 0 : OUString aName = dlg.getEntryText();
1272 :
1273 0 : if (!aName.isEmpty())
1274 0 : nItemId = maView->createRegion(aName);
1275 0 : }
1276 : }
1277 : else
1278 : {
1279 0 : nItemId = maView->GetItemId(nMenuId-MNI_MOVE_FOLDER_BASE);
1280 : }
1281 :
1282 0 : if (nItemId)
1283 : {
1284 : // Move templates to desired folder if for some reason move fails
1285 : // try copying them.
1286 0 : if (!maView->moveTemplates(maSelTemplates,nItemId,false) &&
1287 0 : !maView->moveTemplates(maSelTemplates,nItemId,true))
1288 : {
1289 0 : OUString aTemplateList;
1290 :
1291 0 : std::set<const ThumbnailViewItem*>::const_iterator pIter;
1292 0 : for (pIter = maSelFolders.begin(); pIter != maSelFolders.end(); ++pIter)
1293 : {
1294 0 : if (aTemplateList.isEmpty())
1295 0 : aTemplateList = (*pIter)->maTitle;
1296 : else
1297 0 : aTemplateList = aTemplateList + "\n" + (*pIter)->maTitle;
1298 : }
1299 :
1300 0 : OUString aDst = maView->GetItemText(nItemId);
1301 0 : OUString aMsg(SfxResId(STR_MSG_ERROR_LOCAL_MOVE).toString());
1302 0 : aMsg = aMsg.replaceFirst("$1",aDst);
1303 0 : ErrorBox(this, WB_OK,aMsg.replaceFirst( "$2",aTemplateList)).Execute();
1304 : }
1305 : }
1306 0 : }
1307 :
1308 0 : void SfxTemplateManagerDlg::remoteMoveTo(const sal_uInt16 nMenuId)
1309 : {
1310 0 : sal_uInt16 nItemId = 0;
1311 :
1312 0 : if (nMenuId == MNI_MOVE_NEW)
1313 : {
1314 0 : InputDialog dlg(SfxResId(STR_INPUT_NEW).toString(),this);
1315 :
1316 0 : int ret = dlg.Execute();
1317 :
1318 0 : if (ret)
1319 : {
1320 0 : OUString aName = dlg.getEntryText();
1321 :
1322 0 : if (!aName.isEmpty())
1323 0 : nItemId = maView->createRegion(aName);
1324 0 : }
1325 : }
1326 : else
1327 : {
1328 0 : nItemId = maView->GetItemId(nMenuId-MNI_MOVE_FOLDER_BASE);
1329 : }
1330 :
1331 0 : if (nItemId)
1332 : {
1333 0 : OUString aTemplateList;
1334 :
1335 0 : std::set<const ThumbnailViewItem*>::const_iterator aIter;
1336 0 : for (aIter = maSelTemplates.begin(); aIter != maSelTemplates.end(); ++aIter)
1337 : {
1338 : const TemplateSearchViewItem *pItem =
1339 0 : static_cast<const TemplateSearchViewItem*>(*aIter);
1340 :
1341 0 : if(!maView->copyFrom(nItemId,pItem->maPreview1,pItem->getPath()))
1342 : {
1343 0 : if (aTemplateList.isEmpty())
1344 0 : aTemplateList = pItem->maTitle;
1345 : else
1346 0 : aTemplateList = aTemplateList + "\n" + pItem->maTitle;
1347 : }
1348 : }
1349 :
1350 0 : maView->Invalidate(INVALIDATE_NOERASE);
1351 :
1352 0 : if (!aTemplateList.isEmpty())
1353 : {
1354 0 : OUString aMsg(SfxResId(STR_MSG_ERROR_REMOTE_MOVE).toString());
1355 0 : aMsg = aMsg.replaceFirst("$1",mpOnlineView->getOverlayName());
1356 0 : aMsg = aMsg.replaceFirst("$2",maView->GetItemText(nItemId));
1357 0 : ErrorBox(this,WB_OK,aMsg.replaceFirst("$1",aTemplateList)).Execute();
1358 0 : }
1359 : }
1360 0 : }
1361 :
1362 0 : void SfxTemplateManagerDlg::localSearchMoveTo(sal_uInt16 nMenuId)
1363 : {
1364 0 : sal_uInt16 nItemId = 0;
1365 :
1366 0 : if (nMenuId == MNI_MOVE_NEW)
1367 : {
1368 0 : InputDialog dlg(SfxResId(STR_INPUT_NEW).toString(),this);
1369 :
1370 0 : int ret = dlg.Execute();
1371 :
1372 0 : if (ret)
1373 : {
1374 0 : OUString aName = dlg.getEntryText();
1375 :
1376 0 : if (!aName.isEmpty())
1377 0 : nItemId = maView->createRegion(aName);
1378 0 : }
1379 : }
1380 : else
1381 : {
1382 0 : nItemId = maView->GetItemId(nMenuId-MNI_MOVE_FOLDER_BASE);
1383 : }
1384 :
1385 0 : if (nItemId)
1386 : {
1387 0 : OUString aTemplateList;
1388 :
1389 : // Move templates to desired folder if for some reason move fails
1390 : // try copying them.
1391 0 : std::set<const ThumbnailViewItem*>::const_iterator aIter;
1392 0 : for (aIter = maSelTemplates.begin(); aIter != maSelTemplates.end(); ++aIter)
1393 : {
1394 : const TemplateSearchViewItem *pItem =
1395 0 : static_cast<const TemplateSearchViewItem*>(*aIter);
1396 :
1397 0 : if(!maView->moveTemplate(pItem,pItem->mnRegionId+1,nItemId,false)
1398 0 : && !maView->moveTemplate(pItem,pItem->mnRegionId+1,nItemId,true))
1399 : {
1400 0 : if (aTemplateList.isEmpty())
1401 0 : aTemplateList = (*aIter)->maTitle;
1402 : else
1403 0 : aTemplateList = aTemplateList + "\n" + (*aIter)->maTitle;
1404 : }
1405 : }
1406 :
1407 0 : if (!aTemplateList.isEmpty())
1408 : {
1409 0 : OUString aDst = maView->GetItemText(nItemId);
1410 0 : OUString aMsg(SfxResId(STR_MSG_ERROR_LOCAL_MOVE).toString());
1411 0 : aMsg = aMsg.replaceFirst("$1",aDst);
1412 0 : ErrorBox(this, WB_OK,aMsg.replaceFirst( "$2",aTemplateList)).Execute();
1413 0 : }
1414 : }
1415 :
1416 : // Deselect all items and update search results
1417 0 : mpSearchView->deselectItems();
1418 :
1419 0 : SearchUpdateHdl(mpSearchEdit);
1420 0 : }
1421 :
1422 0 : static bool lcl_getServiceName ( const OUString &rFileURL, OUString &rName )
1423 : {
1424 0 : bool bRet = false;
1425 :
1426 0 : if ( !rFileURL.isEmpty() )
1427 : {
1428 : try
1429 : {
1430 : uno::Reference< embed::XStorage > xStorage =
1431 0 : comphelper::OStorageHelper::GetStorageFromURL( rFileURL, embed::ElementModes::READ );
1432 :
1433 0 : sal_uIntPtr nFormat = SotStorage::GetFormatID( xStorage );
1434 :
1435 0 : const SfxFilter* pFilter = SFX_APP()->GetFilterMatcher().GetFilter4ClipBoardId( nFormat );
1436 :
1437 0 : if ( pFilter )
1438 : {
1439 0 : rName = pFilter->GetServiceName();
1440 0 : bRet = true;
1441 0 : }
1442 : }
1443 0 : catch( uno::Exception& )
1444 : {}
1445 : }
1446 :
1447 0 : return bRet;
1448 : }
1449 :
1450 0 : static std::vector<OUString> lcl_getAllFactoryURLs ()
1451 : {
1452 0 : SvtModuleOptions aModOpt;
1453 0 : std::vector<OUString> aList;
1454 0 : const ::com::sun::star::uno::Sequence<OUString> &aServiceNames = aModOpt.GetAllServiceNames();
1455 :
1456 0 : for( sal_Int32 i=0, nCount = aServiceNames.getLength(); i < nCount; ++i )
1457 : {
1458 0 : if ( SfxObjectFactory::GetStandardTemplate( aServiceNames[i] ).Len() > 0 )
1459 : {
1460 0 : SvtModuleOptions::EFactory eFac = SvtModuleOptions::E_WRITER;
1461 0 : SvtModuleOptions::ClassifyFactoryByName( aServiceNames[i], eFac );
1462 0 : aList.push_back(aModOpt.GetFactoryEmptyDocumentURL(eFac));
1463 : }
1464 : }
1465 :
1466 0 : return aList;
1467 234 : }
1468 :
1469 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|