Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <com/sun/star/embed/XStorage.hpp>
21 : #include <com/sun/star/embed/XTransactedObject.hpp>
22 : #include <com/sun/star/embed/ElementModes.hpp>
23 :
24 : #include <vcl/msgbox.hxx>
25 : #include <tools/urlobj.hxx>
26 :
27 : #include <comphelper/processfactory.hxx>
28 : #include <unotools/intlwrapper.hxx>
29 :
30 : #include <comphelper/storagehelper.hxx>
31 :
32 : #include <sfx2/app.hxx>
33 : #include <sfx2/objsh.hxx>
34 : #include <sfx2/docfile.hxx>
35 : #include <sfx2/docfac.hxx>
36 : #include <sfx2/doctempl.hxx>
37 : #include "docvor.hxx"
38 : #include "orgmgr.hxx"
39 : #include "sfxtypes.hxx"
40 : #include "sfx2/sfxresid.hxx"
41 : #include "view.hrc"
42 : #include <sfx2/docfilt.hxx>
43 : #include "fltfnc.hxx"
44 :
45 : using namespace ::com::sun::star;
46 :
47 : //=========================================================================
48 :
49 : /* [Description]
50 :
51 : Implementation class, single entry in the file view.
52 : */
53 :
54 : struct _FileListEntry
55 : {
56 : String aFileName; // File Name with complete path
57 : String aBaseName; // File Name
58 : const CollatorWrapper* pCollator;
59 : SfxObjectShellLock aDocShell; // ObjectShell as reference class
60 :
61 : sal_Bool bFile; // As File on disk
62 : // (!= not processed, not loaded as document
63 : // these are not saved!)
64 : sal_Bool bOwner; // self-generated
65 : sal_Bool bNoName;
66 : sal_Bool bOwnFormat;
67 :
68 : _FileListEntry( const String& rFileName,
69 : const CollatorWrapper* pColl, const String* pTitle = NULL );
70 : ~_FileListEntry();
71 :
72 : int operator==( const _FileListEntry &rCmp) const;
73 : int operator< ( const _FileListEntry &rCmp) const;
74 : sal_Bool DeleteObjectShell();
75 : };
76 :
77 : //-------------------------------------------------------------------------
78 :
79 : inline int _FileListEntry::operator==(const _FileListEntry &rCmp) const
80 : {
81 : DBG_ASSERT( pCollator, "invalid CollatorWrapper" );
82 : return COMPARE_EQUAL == pCollator->compareString(aBaseName, rCmp.aBaseName);
83 : }
84 :
85 : //-------------------------------------------------------------------------
86 :
87 0 : inline int _FileListEntry::operator< (const _FileListEntry &rCmp) const
88 : {
89 : DBG_ASSERT( pCollator, "invalid CollatorWrapper" );
90 0 : return COMPARE_LESS == pCollator->compareString(aBaseName, rCmp.aBaseName);
91 : }
92 :
93 : //-------------------------------------------------------------------------
94 :
95 0 : _FileListEntry::_FileListEntry( const String& rFileName,
96 : const CollatorWrapper* pColl, const String* pTitle ) :
97 :
98 : aFileName ( rFileName ),
99 : pCollator ( pColl ),
100 : bFile ( sal_False ),
101 : bOwner ( sal_False ),
102 : bNoName ( sal_True ),
103 0 : bOwnFormat ( sal_True )
104 : {
105 0 : if ( pTitle )
106 0 : aBaseName = *pTitle;
107 : else
108 : {
109 0 : INetURLObject aObj( rFileName, INET_PROT_FILE );
110 : aBaseName = aObj.getName( INetURLObject::LAST_SEGMENT, true,
111 0 : INetURLObject::DECODE_WITH_CHARSET );
112 : }
113 0 : }
114 :
115 : //-------------------------------------------------------------------------
116 :
117 0 : _FileListEntry::~_FileListEntry()
118 : {
119 0 : DeleteObjectShell();
120 0 : }
121 :
122 : //=========================================================================
123 :
124 0 : sal_Bool _FileListEntry::DeleteObjectShell()
125 :
126 : /* [Description]
127 :
128 : Release of ther DocumentShell
129 :
130 : [Return value] TRUE: Everything is ok
131 : FALSE: An error occured
132 : (the document could not be saved)
133 : */
134 :
135 : {
136 0 : sal_Bool bRet = sal_True;
137 :
138 0 : if(bOwner && aDocShell.Is() && aDocShell->IsModified())
139 : {
140 : // Converted?
141 0 : if( bOwnFormat )
142 : {
143 0 : if(!aDocShell->Save() )
144 0 : bRet = sal_False;
145 : else
146 : {
147 : try {
148 0 : uno::Reference< embed::XTransactedObject > xTransact( aDocShell->GetStorage(), uno::UNO_QUERY );
149 : OSL_ENSURE( xTransact.is(), "Storage must implement XTransactedObject!\n" );
150 0 : if ( !xTransact.is() )
151 0 : throw uno::RuntimeException();
152 :
153 0 : xTransact->commit();
154 : }
155 0 : catch( uno::Exception& )
156 : {
157 : }
158 :
159 : }
160 : }
161 : else
162 : {
163 : // If converted save in native format
164 0 : INetURLObject aObj( aFileName );
165 : String aTitle = aObj.getName( INetURLObject::LAST_SEGMENT, true,
166 0 : INetURLObject::DECODE_WITH_CHARSET );
167 : bRet = aDocShell->PreDoSaveAs_Impl(
168 0 : aTitle, aDocShell->GetFactory().GetFilterContainer()->GetAnyFilter( SFX_FILTER_IMPORT | SFX_FILTER_EXPORT )->GetFilterName(), 0 );
169 : }
170 : }
171 :
172 0 : if( bOwner)
173 : {
174 0 : aDocShell.Clear();
175 : }
176 :
177 0 : return bRet;
178 : }
179 :
180 : //-------------------------------------------------------------------------
181 :
182 0 : SfxObjectList::SfxObjectList()
183 : {
184 0 : }
185 :
186 : //-------------------------------------------------------------------------
187 :
188 0 : SfxObjectList::~SfxObjectList()
189 : {
190 0 : for( const_iterator it = begin(); it != end(); ++it )
191 0 : delete *it;
192 0 : clear();
193 0 : }
194 :
195 : //-------------------------------------------------------------------------
196 :
197 0 : const String &SfxObjectList::GetBaseName(const _FileListEntry* p) const
198 : {
199 0 : return p->aBaseName;
200 : }
201 :
202 : //-------------------------------------------------------------------------
203 :
204 0 : SfxOrganizeMgr::SfxOrganizeMgr(SfxDocumentTemplates *pTempl) :
205 0 : pImpl(new SfxOrganizeMgr_Impl),
206 0 : pTemplates(pTempl? pTempl: new SfxDocumentTemplates),
207 : bDeleteTemplates(pTempl == 0),
208 0 : bModified(0)
209 :
210 : /* [Description]
211 :
212 : Constructor. The current document is added to the list of documents.
213 : */
214 : {
215 0 : pImpl->pDocList = new SfxObjectList;
216 0 : pImpl->pIntlWrapper = new IntlWrapper( Application::GetSettings().GetLanguageTag() );
217 0 : const CollatorWrapper* pCollator = pImpl->pIntlWrapper->getCaseCollator();
218 0 : for ( SfxObjectShell* pTmp = SfxObjectShell::GetFirst(); pTmp; pTmp = SfxObjectShell::GetNext(*pTmp) )
219 : {
220 0 : if ( pTmp->GetCreateMode() != SFX_CREATE_MODE_STANDARD ||
221 0 : !( pTmp->GetFlags() & SFXOBJECTSHELL_HASOPENDOC ) || !pTmp->GetStyleSheetPool() )
222 0 : continue;
223 0 : _FileListEntry* pNewEntry = NULL;
224 0 : String aTitle = pTmp->GetTitle( SFX_TITLE_TITLE );
225 0 : pNewEntry = new _FileListEntry( pTmp->GetMedium()->GetName(), pCollator, &aTitle );
226 0 : pNewEntry->aDocShell = pTmp;
227 0 : pImpl->pDocList->insert( pNewEntry );
228 0 : }
229 0 : }
230 :
231 : //-------------------------------------------------------------------------
232 :
233 0 : SfxOrganizeMgr::~SfxOrganizeMgr()
234 : {
235 0 : if ( bDeleteTemplates )
236 0 : delete pTemplates;
237 0 : delete pImpl->pDocList;
238 0 : delete pImpl->pIntlWrapper;
239 0 : delete pImpl;
240 0 : }
241 :
242 : //-------------------------------------------------------------------------
243 :
244 0 : SfxObjectShellRef SfxOrganizeMgr::CreateObjectShell( sal_uInt16 nIdx )
245 :
246 : /* [Description]
247 :
248 : Access to the DocumentShell at the position nIdx.
249 :
250 : [Return value] Reference to the DocumentShell
251 :
252 : */
253 :
254 : {
255 0 : _FileListEntry* pEntry = (*pImpl->pDocList)[nIdx];
256 : // otherwise create Doc-Shell
257 0 : if ( !pEntry->aDocShell.Is() )
258 : {
259 0 : INetURLObject aFileObj( pEntry->aFileName );
260 0 : sal_Bool bDum = sal_False;
261 0 : SfxApplication* pSfxApp = SFX_APP();
262 0 : String aFilePath = aFileObj.GetMainURL( INetURLObject::NO_DECODE );
263 0 : pEntry->aDocShell = pSfxApp->DocAlreadyLoaded( aFilePath, sal_False, bDum );
264 0 : if ( !pEntry->aDocShell.Is() )
265 : {
266 0 : pEntry->bOwner = sal_True;
267 : SfxMedium* pMed = new SfxMedium(
268 0 : aFilePath, ( STREAM_READ | STREAM_SHARE_DENYWRITE ) );
269 0 : const SfxFilter* pFilter = NULL;
270 0 : pMed->UseInteractionHandler(sal_True);
271 0 : if (
272 0 : pSfxApp->GetFilterMatcher().GuessFilter(*pMed, &pFilter, SFX_FILTER_TEMPLATE, 0) ||
273 0 : (pFilter && !pFilter->IsOwnFormat()) ||
274 0 : (pFilter && !pFilter->UsesStorage())
275 : )
276 : {
277 0 : pSfxApp->LoadTemplate( pEntry->aDocShell, aFilePath );
278 0 : pEntry->bOwnFormat = sal_False;
279 0 : delete pMed;
280 0 : if ( pEntry->aDocShell.Is() )
281 0 : return (SfxObjectShellRef)(SfxObjectShell*)(pEntry->aDocShell);
282 : }
283 : else
284 : {
285 0 : if ( pFilter )
286 : {
287 0 : pEntry->bOwnFormat = sal_True;
288 0 : pEntry->aDocShell = SfxObjectShell::CreateObject( pFilter->GetServiceName(), SFX_CREATE_MODE_ORGANIZER );
289 0 : if ( pEntry->aDocShell.Is() )
290 : {
291 0 : pEntry->aDocShell->DoInitNew(0);
292 0 : pEntry->aDocShell->LoadFrom( *pMed );
293 : // Medium is now owned by DocShell
294 0 : pEntry->aDocShell->DoSaveCompleted( pMed );
295 : }
296 : }
297 : }
298 0 : }
299 : }
300 0 : return ( SfxObjectShellRef )(SfxObjectShell*)(pEntry->aDocShell);
301 : }
302 :
303 : //-------------------------------------------------------------------------
304 :
305 0 : sal_Bool SfxOrganizeMgr::DeleteObjectShell(sal_uInt16 nIdx)
306 :
307 : /* [Description]
308 :
309 : Release DocumentShell at position nIdx
310 :
311 : [Return value] TRUE: Everything is ok
312 : FALSE: An error occured
313 : (the document could not be saved)
314 : */
315 : {
316 0 : return (*pImpl->pDocList)[nIdx]->DeleteObjectShell();
317 : }
318 :
319 : //-------------------------------------------------------------------------
320 :
321 0 : SfxObjectShellRef SfxOrganizeMgr::CreateObjectShell(sal_uInt16 nRegion,
322 : sal_uInt16 nIdx)
323 : /* [Description]
324 :
325 : Access to the DocumentShell at Position nIdx in Region
326 : nRegion (Document template)
327 :
328 : [Return value] Reference to the DocumentShell
329 :
330 : */
331 : {
332 0 : return pTemplates->CreateObjectShell(nRegion, nIdx);
333 : }
334 :
335 : //-------------------------------------------------------------------------
336 :
337 0 : sal_Bool SfxOrganizeMgr::DeleteObjectShell(sal_uInt16 nRegion, sal_uInt16 nIdx)
338 :
339 : /* [Description]
340 :
341 : Release of the DocumentShell at Position nIdx in Region
342 : nRegion (Document template)
343 :
344 : [Return value] TRUE: Everything is ok
345 : FALSE: An error occured
346 : (the document could not be saved)
347 : */
348 :
349 : {
350 0 : return pTemplates->DeleteObjectShell(nRegion, nIdx);
351 : }
352 :
353 : //-------------------------------------------------------------------------
354 :
355 0 : sal_Bool SfxOrganizeMgr::Copy(sal_uInt16 nTargetRegion,
356 : sal_uInt16 nTargetIdx,
357 : sal_uInt16 nSourceRegion,
358 : sal_uInt16 nSourceIdx)
359 :
360 : /* [Description]
361 :
362 : Copy of a Document Template
363 :
364 : [Parameter]
365 :
366 : sal_uInt16 nTargetRegion Index of the Target Region
367 : sal_uInt16 nTargetIdx Index of the Target Position
368 : sal_uInt16 nSourceRegion Index of the Source Region
369 : sal_uInt16 nSourceIdx Index of the template to be
370 : copied/moved.
371 :
372 : [Return value] Success (TRUE) or Failure (FALSE)
373 :
374 :
375 : [Cross-reference]
376 :
377 : <SfxDocumentTemplates::Copy(sal_uInt16 nTargetRegion,
378 : sal_uInt16 nTargetIdx,
379 : sal_uInt16 nSourceRegion,
380 : sal_uInt16 nSourceIdx)>
381 :
382 : */
383 :
384 : {
385 0 : if(nSourceIdx == USHRT_MAX) // No directories copied
386 0 : return sal_False ;
387 : const sal_Bool bOk = pTemplates->Copy(nTargetRegion, nTargetIdx,
388 0 : nSourceRegion, nSourceIdx);
389 0 : if(bOk)
390 0 : bModified = 1;
391 0 : return bOk;
392 : }
393 :
394 : //-------------------------------------------------------------------------
395 :
396 0 : sal_Bool SfxOrganizeMgr::Move(sal_uInt16 nTargetRegion,
397 : sal_uInt16 nTargetIdx,
398 : sal_uInt16 nSourceRegion,
399 : sal_uInt16 nSourceIdx)
400 :
401 : /* [Description]
402 :
403 : Moving a template
404 :
405 : [Parameter]
406 :
407 : sal_uInt16 nTargetRegion Index of the Target Region
408 : sal_uInt16 nTargetIdx Index of the Target Position
409 : sal_uInt16 nSourceRegion Index of the Source Region
410 : sal_uInt16 nSourceIdx Index of the template to be
411 : copied/moved.
412 :
413 : [Return value] Success (TRUE) or Failure (FALSE)
414 :
415 : [Cross-reference]
416 :
417 : <SfxDocumentTemplates::Move(sal_uInt16 nTargetRegion,
418 : sal_uInt16 nTargetIdx,
419 : sal_uInt16 nSourceRegion,
420 : sal_uInt16 nSourceIdx)>
421 : */
422 :
423 : {
424 0 : if(nSourceIdx == USHRT_MAX) // No directory moved
425 0 : return sal_False ;
426 : const sal_Bool bOk = pTemplates->Move(nTargetRegion, nTargetIdx,
427 0 : nSourceRegion, nSourceIdx);
428 0 : if(bOk)
429 0 : bModified = 1;
430 0 : return bOk;
431 : }
432 :
433 : //-------------------------------------------------------------------------
434 :
435 0 : sal_Bool SfxOrganizeMgr::Delete(SfxOrganizeListBox_Impl *pCaller,
436 : sal_uInt16 nRegion, sal_uInt16 nIdx)
437 :
438 : /* [Description]
439 :
440 : Delete a Document Template
441 :
442 : [Parameter]
443 :
444 : SfxOrganizeListBox *pCaller calling ListBox, since this event
445 : is triggered by the menu or the
446 : keyboard, the ListBox must be updated.
447 : sal_uInt16 nRegion Index for Region
448 : sal_uInt16 nIdx Index of Document template
449 :
450 : [Return value] Success (TRUE) or Failure (FALSE)
451 :
452 : [Cross-reference]
453 :
454 : <SfxDocumentTemplates::Delete(sal_uInt16 nRegion, sal_uInt16 nIdx)>
455 :
456 : */
457 :
458 : {
459 0 : sal_Bool bOk = sal_False;
460 :
461 0 : if ( USHRT_MAX == nIdx )
462 : {
463 : // deleting of a group
464 :
465 0 : SvTreeListEntry *pGroupToDelete = pCaller->GetEntry(nRegion);
466 0 : if ( pGroupToDelete )
467 : {
468 0 : sal_uInt16 nItemNum = (sal_uInt16)( pCaller->GetModel()->GetChildCount( pGroupToDelete ) );
469 : typedef std::deque<SvTreeListEntry*> BoxEntries;
470 0 : BoxEntries pEntriesToDelete;
471 :
472 0 : sal_uInt16 nInd = 0;
473 0 : for ( nInd = 0; nInd < nItemNum; nInd++ )
474 : {
475 : // TODO/LATER: check that nInd is the same index that is used in pTemplates
476 0 : if ( pTemplates->Delete( nRegion, nInd ) )
477 : {
478 0 : bModified = 1;
479 0 : pEntriesToDelete.push_back( pCaller->GetEntry( pGroupToDelete, nInd ) );
480 : }
481 : }
482 :
483 0 : for ( BoxEntries::const_iterator aIt( pEntriesToDelete.begin() ), aEnd( pEntriesToDelete.end() ); aIt != aEnd; ++aIt )
484 0 : pCaller->GetModel()->Remove( *aIt );
485 :
486 0 : if ( !pCaller->GetModel()->GetChildCount( pGroupToDelete ) )
487 : {
488 0 : bOk = pTemplates->Delete( nRegion, nIdx );
489 0 : if ( bOk )
490 0 : pCaller->GetModel()->Remove( pGroupToDelete );
491 0 : }
492 : }
493 : }
494 : else
495 : {
496 : // deleting of a template
497 0 : bOk = pTemplates->Delete(nRegion, nIdx);
498 0 : if(bOk)
499 : {
500 0 : bModified = 1;
501 : // Entry to be deleted.
502 0 : SvTreeListEntry *pEntryToDelete = pCaller->GetEntry(pCaller->GetEntry(nRegion), nIdx);
503 :
504 0 : pCaller->GetModel()->Remove(pEntryToDelete);
505 : }
506 : }
507 :
508 0 : return bOk;
509 : }
510 :
511 : //-------------------------------------------------------------------------
512 :
513 0 : sal_Bool SfxOrganizeMgr::InsertDir
514 : (
515 : SfxOrganizeListBox_Impl* pCaller, /* calling ListBox, since this event
516 : is triggered by the menu or the
517 : keyboard, the ListBox must be updated. */
518 : const String& rText, // logical Name of Region
519 : sal_uInt16 nRegion // Index of Region
520 : )
521 :
522 : /* [Description]
523 :
524 : Insert Region.
525 :
526 : [Return value] Success (TRUE) or Failure (FALSE)
527 :
528 : [Cross-reference]
529 :
530 : <SfxDocumentTemplates::InsertDir(const String &, sal_uInt16 nRegion)>
531 : */
532 :
533 : {
534 0 : const sal_Bool bOk = pTemplates->InsertDir(rText, nRegion);
535 0 : if(bOk)
536 : {
537 0 : bModified = 1;
538 : SvTreeListEntry *pEntry = pCaller->InsertEntry(rText,
539 0 : pCaller->GetOpenedBmp(0),
540 0 : pCaller->GetClosedBmp(0),
541 0 : 0, sal_True, nRegion);
542 0 : pCaller->Update();
543 0 : pCaller->EditEntry(pEntry);
544 : }
545 0 : return bOk;
546 : }
547 :
548 : //-------------------------------------------------------------------------
549 :
550 0 : sal_Bool SfxOrganizeMgr::SetName(const String &rName,
551 : sal_uInt16 nRegion, sal_uInt16 nIdx)
552 :
553 : /* [Description]
554 :
555 : Set (logical) Name
556 :
557 : [Parameter]
558 :
559 : const String &rName The new Name
560 : sal_uInt16 nRegion Index of Region
561 : sal_uInt16 nIdx Index of Document template
562 :
563 : [Return value] Success (TRUE) or Failure (FALSE)
564 :
565 : [Cross-reference]
566 :
567 : <SfxDocumentTemplates::SetName(const String &, sal_uInt16 nRegion, sal_uInt16 nIdx)>
568 : */
569 :
570 : {
571 0 : const sal_Bool bOk = pTemplates->SetName(rName, nRegion, nIdx);
572 0 : if(bOk)
573 0 : bModified = 1;
574 0 : return bOk;
575 : }
576 :
577 : //-------------------------------------------------------------------------
578 :
579 0 : sal_Bool SfxOrganizeMgr::CopyTo(sal_uInt16 nRegion, sal_uInt16 nIdx, const String &rName) const
580 :
581 : /* [Description]
582 :
583 : Export of a Template
584 :
585 : [Parameter]
586 :
587 : sal_uInt16 nRegion Index of Region
588 : sal_uInt16 nIdx Index of Document Template
589 : const String &rName File name
590 :
591 : [Return value] Success (TRUE) or Failure (FALSE)
592 :
593 : [Cross-reference]
594 :
595 : <SfxDocumentTemplates::CopyTo( sal_uInt16 nRegion, sal_uInt16 nIdx, const String &)>
596 : */
597 :
598 : {
599 0 : return pTemplates->CopyTo(nRegion, nIdx, rName);
600 : }
601 :
602 : //-------------------------------------------------------------------------
603 :
604 0 : sal_Bool SfxOrganizeMgr::CopyFrom(SfxOrganizeListBox_Impl *pCaller,
605 : sal_uInt16 nRegion, sal_uInt16 nIdx, String &rName)
606 :
607 : /* [Description]
608 :
609 : Import of Document Template
610 :
611 : [Parameter]
612 :
613 : SfxOrganizeListBox *pCaller calling ListBox, since this event
614 : is triggered by the menu or the
615 : keyboard, the ListBox must be updated.
616 :
617 : sal_uInt16 nRegion Index of Region
618 : sal_uInt16 nIdx Index of Document Template
619 : String &rName File name
620 :
621 : [Return value] Success (TRUE) or Failure (FALSE)
622 :
623 : [Cross-reference]
624 :
625 : <SfxDocumentTemplates::CopyFrom( sal_uInt16 nRegion, sal_uInt16 nIdx, const String &)>
626 : */
627 :
628 : {
629 0 : SvTreeListEntry *pParent = pCaller->FirstSelected();
630 0 : if( nIdx!=USHRT_MAX )
631 0 : pParent = pCaller->GetParent(pParent);
632 0 : if( pTemplates->CopyFrom( nRegion, nIdx, rName ) )
633 : {
634 : // Update pCaller
635 0 : if( nIdx == USHRT_MAX )
636 0 : nIdx = 0;
637 0 : else nIdx++;
638 :
639 : pCaller->InsertEntry( rName,
640 0 : pCaller->GetOpenedBmp(1),
641 0 : pCaller->GetClosedBmp(1),
642 : pParent,
643 : sal_True,
644 0 : nIdx);
645 0 : pCaller->Update();
646 0 : pCaller->Expand( pParent );
647 0 : bModified = sal_True;
648 0 : return sal_True;
649 : }
650 0 : return sal_False;
651 : }
652 :
653 : //-------------------------------------------------------------------------
654 :
655 0 : sal_Bool SfxOrganizeMgr::InsertFile( SfxOrganizeListBox_Impl* pCaller, const String& rFileName )
656 :
657 : /* [Description]
658 :
659 : Insert a file in the file view.
660 :
661 : [Parameter]
662 :
663 : SfxOrganizeListBox *pCaller calling ListBox, since this event
664 : is triggered by the menu or the
665 : keyboard, the ListBox must be updated.
666 :
667 : const String &rFileName Name of inserted File.
668 :
669 : [Return value] Success (TRUE) or Failure (FALSE)
670 : */
671 :
672 : {
673 0 : const CollatorWrapper* pCollator = pImpl->pIntlWrapper->getCaseCollator();
674 0 : _FileListEntry* pEntry = new _FileListEntry( rFileName, pCollator );
675 0 : std::pair<SfxObjectList::const_iterator, bool> aRes = pImpl->pDocList->insert( pEntry );
676 0 : if ( aRes.second )
677 : {
678 0 : sal_uInt16 nPos = aRes.first - pImpl->pDocList->begin();
679 0 : pCaller->InsertEntry( pEntry->aBaseName, pCaller->GetOpenedBmp(1),
680 0 : pCaller->GetClosedBmp(1), 0, sal_True, nPos );
681 0 : return sal_True;
682 : }
683 : else
684 0 : delete pEntry;
685 0 : return sal_False;
686 : }
687 :
688 : //-------------------------------------------------------------------------
689 :
690 0 : sal_Bool SfxOrganizeMgr::Rescan()
691 :
692 : /* [Description]
693 :
694 : Updating the database.
695 :
696 : [Return value]
697 :
698 : TRUE Changes were made
699 : FALSE No changes
700 :
701 : [Cross-reference]
702 :
703 : <SfxDocumentTemplates::Rescan()>
704 : */
705 :
706 : {
707 0 : if(pTemplates->Rescan())
708 : {
709 0 : bModified = sal_True;
710 0 : return sal_True;
711 : }
712 0 : return sal_False;
713 : }
714 :
715 : //-------------------------------------------------------------------------
716 :
717 0 : void SfxOrganizeMgr::SaveAll(Window *pParent)
718 :
719 : /* [Description]
720 :
721 : Save all Documents that have been modified
722 :
723 : [Parameter]
724 :
725 : Window *pParent Parent of the Error message Box
726 : */
727 :
728 : {
729 0 : sal_uInt16 nRangeCount = pTemplates->GetRegionCount();
730 : sal_uInt16 i;
731 0 : for(i = 0; i < nRangeCount; ++i)
732 : {
733 0 : if( pTemplates->IsRegionLoaded( i ))
734 : {
735 0 : const sal_uInt16 nCount = pTemplates->GetCount(i);
736 0 : for(sal_uInt16 j = 0; j < nCount; ++j)
737 : {
738 0 : if(!pTemplates->DeleteObjectShell(i, j))
739 : {
740 0 : String aText = SfxResId(STR_ERROR_SAVE_TEMPLATE).toString();
741 0 : aText += pTemplates->GetName(i, j);
742 : ErrorBox aBox(pParent,
743 : WinBits(WB_OK_CANCEL | WB_DEF_CANCEL),
744 0 : aText);
745 0 : if(RET_CANCEL == aBox.Execute())
746 0 : break;
747 : }
748 : }
749 : }
750 : }
751 0 : for( SfxObjectList::const_iterator it = pImpl->pDocList->begin(); it != pImpl->pDocList->end(); ++it )
752 : {
753 0 : _FileListEntry *pEntry = *it;
754 0 : if(!pEntry->DeleteObjectShell())
755 : {
756 0 : String aText(SfxResId(STR_ERROR_SAVE_TEMPLATE).toString());
757 0 : aText += pEntry->aBaseName;
758 0 : ErrorBox aBox(pParent, WinBits(WB_OK_CANCEL | WB_DEF_CANCEL), aText);
759 0 : if(RET_CANCEL == aBox.Execute())
760 0 : break;
761 : }
762 : }
763 0 : }
764 :
765 :
766 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|