xref: /trunk/main/sfx2/source/view/orgmgr.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sfx2.hxx"
30 #include <com/sun/star/embed/XStorage.hpp>
31 #include <com/sun/star/embed/XTransactedObject.hpp>
32 #include <com/sun/star/embed/ElementModes.hpp>
33 
34 #ifndef _MSGBOX_HXX //autogen
35 #include <vcl/msgbox.hxx>
36 #endif
37 #include <tools/urlobj.hxx>
38 #ifndef GCC
39 #endif
40 
41 #ifndef _UNOTOOLS_PROCESSFACTORY_HXX
42 #include <comphelper/processfactory.hxx>
43 #endif
44 #include <unotools/intlwrapper.hxx>
45 
46 #include <comphelper/storagehelper.hxx>
47 
48 #include <sfx2/app.hxx>
49 #include <sfx2/objsh.hxx>
50 #include <sfx2/docfile.hxx>
51 #include <sfx2/docfac.hxx>
52 #include <sfx2/doctempl.hxx>
53 #include "docvor.hxx"
54 #include "orgmgr.hxx"
55 #include "sfxtypes.hxx"
56 #include "sfx2/sfxresid.hxx"
57 #include "view.hrc"
58 #include <sfx2/docfilt.hxx>
59 #include "fltfnc.hxx"
60 
61 using namespace ::com::sun::star;
62 
63 //=========================================================================
64 
65 /*  [Beschreibung]
66 
67     Implementierungsklasse; einzelner Eintrag in der Dateiansicht
68 
69 */
70 
71 struct _FileListEntry
72 {
73     String aFileName;           // Dateiname mit komplettem Pfad
74     String aBaseName;           // Dateiname
75     const CollatorWrapper* pCollator;
76     SfxObjectShellLock aDocShell; // ObjectShell als Ref-Klasse
77 
78 //REMOVE        SvStorageRef aStor;         // Referenz auf Storage, wenn wir diesen geoeffnet haben
79     //uno::Reference< embed::XStorage > xStorage;
80 
81     sal_Bool bFile;                 // als Datei auf Platte
82                                 // (!= unbenannt1, nicht als Dok. geladen;
83                                 // diese werden nicht gespeichert!)
84     sal_Bool bOwner;                // selbst erzeugt
85     sal_Bool bNoName;
86     sal_Bool bOwnFormat;
87 
88     _FileListEntry( const String& rFileName,
89                     const CollatorWrapper* pColl, const String* pTitle = NULL );
90     ~_FileListEntry();
91 
92     int operator==( const _FileListEntry &rCmp) const;
93     int operator< ( const _FileListEntry &rCmp) const;
94     sal_Bool DeleteObjectShell();
95 };
96 
97 //-------------------------------------------------------------------------
98 
99 inline int _FileListEntry::operator==(const _FileListEntry &rCmp) const
100 {
101     DBG_ASSERT( pCollator, "invalid CollatorWrapper" );
102     return COMPARE_EQUAL == pCollator->compareString(aBaseName, rCmp.aBaseName);
103 }
104 
105 //-------------------------------------------------------------------------
106 
107 inline int _FileListEntry::operator< (const _FileListEntry &rCmp) const
108 {
109     DBG_ASSERT( pCollator, "invalid CollatorWrapper" );
110     return COMPARE_LESS == pCollator->compareString(aBaseName, rCmp.aBaseName);
111 }
112 
113 //-------------------------------------------------------------------------
114 
115 _FileListEntry::_FileListEntry( const String& rFileName,
116                                 const CollatorWrapper* pColl, const String* pTitle ) :
117 
118     aFileName   ( rFileName ),
119     pCollator   ( pColl ),
120     bFile       ( sal_False ),
121     bOwner      ( sal_False ),
122     bNoName     ( sal_True ),
123     bOwnFormat  ( sal_True )
124 {
125     if ( pTitle )
126         aBaseName = *pTitle;
127     else
128     {
129         INetURLObject aObj( rFileName, INET_PROT_FILE );
130         aBaseName = aObj.getName( INetURLObject::LAST_SEGMENT, true,
131                                   INetURLObject::DECODE_WITH_CHARSET );
132     }
133 }
134 
135 //-------------------------------------------------------------------------
136 
137 _FileListEntry::~_FileListEntry()
138 {
139     DeleteObjectShell();
140 }
141 
142 //-------------------------------------------------------------------------
143 
144 SV_IMPL_OP_PTRARR_SORT(_SfxObjectList, _FileListEntry*)
145 
146 //=========================================================================
147 
148 sal_Bool _FileListEntry::DeleteObjectShell()
149 
150 /*  [Beschreibung]
151 
152     Freigabe der DokumentShell
153 
154     [Returnwert]            sal_True: alles Ok
155                             sal_False: es ist ein Fehler aufgetreten (das
156                             Dokument konnte nicht gesichert werden)
157 
158 */
159 
160 {
161     sal_Bool bRet = sal_True;
162     //Falls wir die Shell angelegt haben und sie veraendert wurde
163     if(bOwner && aDocShell.Is() && aDocShell->IsModified())
164     {
165         //Mussten wir konvertieren?
166         if( bOwnFormat )
167         {
168             if(!aDocShell->Save() )
169                 bRet = sal_False;
170             else
171             {
172                 try {
173                     uno::Reference< embed::XTransactedObject > xTransact( aDocShell->GetStorage(), uno::UNO_QUERY );
174                     OSL_ENSURE( xTransact.is(), "Storage must implement XTransactedObject!\n" );
175                     if ( !xTransact.is() )
176                         throw uno::RuntimeException();
177 
178                     xTransact->commit();
179                 }
180                 catch( uno::Exception& )
181                 {
182                 }
183 
184 //              aDocShell->SfxObjectShell::DoSaveCompleted();
185             }
186         }
187         else
188         {
189             // Falls konvertiert im eigenen Format speichern
190             INetURLObject aObj( aFileName );
191             String aTitle = aObj.getName( INetURLObject::LAST_SEGMENT, true,
192                                           INetURLObject::DECODE_WITH_CHARSET );
193             bRet = aDocShell->PreDoSaveAs_Impl(
194                         aTitle, aDocShell->GetFactory().GetFilterContainer()->GetAnyFilter( SFX_FILTER_IMPORT | SFX_FILTER_EXPORT )->GetFilterName(), 0 );
195         }
196     }
197 
198     if( bOwner)
199     {
200         aDocShell.Clear();
201     }
202 
203     return bRet;
204 }
205 
206 //-------------------------------------------------------------------------
207 
208 SfxObjectList::SfxObjectList()
209 {
210 }
211 
212 //-------------------------------------------------------------------------
213 
214 SfxObjectList::~SfxObjectList()
215 {
216     DeleteAndDestroy(0, Count());
217 }
218 
219 //-------------------------------------------------------------------------
220 
221 const String &SfxObjectList::GetBaseName(sal_uInt16 i) const
222 {
223     return (*this)[i]->aBaseName;
224 }
225 
226 //-------------------------------------------------------------------------
227 
228 const String& SfxObjectList::GetFileName( sal_uInt16 i ) const
229 {
230     return (*this)[i]->aFileName;
231 }
232 
233 //-------------------------------------------------------------------------
234 
235 SfxOrganizeMgr::SfxOrganizeMgr( SfxOrganizeListBox_Impl *pLeft,
236                                 SfxOrganizeListBox_Impl *pRight,
237                                 SfxDocumentTemplates *pTempl) :
238     pImpl(new SfxOrganizeMgr_Impl),
239     pTemplates(pTempl? pTempl: new SfxDocumentTemplates),
240     pLeftBox(pLeft),
241     pRightBox(pRight),
242     bDeleteTemplates(pTempl == 0),
243     bModified(0)
244 
245 /*  [Beschreibung]
246 
247     Konstruktor
248 
249     Das aktuelle Dokument wird in die Liste der Dokumente
250     aufgenommen.
251 
252 */
253 {
254     pImpl->pDocList = new SfxObjectList;
255     pImpl->pIntlWrapper = new IntlWrapper( ::comphelper::getProcessServiceFactory(), Application::GetSettings().GetLocale() );
256     const CollatorWrapper* pCollator = pImpl->pIntlWrapper->getCaseCollator();
257     for ( SfxObjectShell* pTmp = SfxObjectShell::GetFirst(); pTmp; pTmp = SfxObjectShell::GetNext(*pTmp) )
258     {
259         if ( pTmp->GetCreateMode() != SFX_CREATE_MODE_STANDARD ||
260              !( pTmp->GetFlags() & SFXOBJECTSHELL_HASOPENDOC ) || !pTmp->GetStyleSheetPool() )
261             continue;
262         _FileListEntry* pNewEntry = NULL;
263         String aTitle = pTmp->GetTitle( SFX_TITLE_TITLE );
264         pNewEntry = new _FileListEntry( pTmp->GetMedium()->GetName(), pCollator, &aTitle );
265         pNewEntry->aDocShell = pTmp;
266         pImpl->pDocList->C40_PTR_INSERT( _FileListEntry, pNewEntry );
267     }
268 }
269 
270 //-------------------------------------------------------------------------
271 
272 SfxOrganizeMgr::~SfxOrganizeMgr()
273 {
274     if ( bDeleteTemplates )
275         delete pTemplates;
276     delete pImpl->pDocList;
277     delete pImpl->pIntlWrapper;
278     delete pImpl;
279     pLeftBox = pRightBox = NULL;
280 }
281 
282 //-------------------------------------------------------------------------
283 
284 SfxObjectShellRef SfxOrganizeMgr::CreateObjectShell( sal_uInt16 nIdx )
285 
286 /*  [Beschreibung]
287 
288     Zugriff auf die DokumentShell an der Position nIdx
289 
290     [Returnwert]            Referenz auf die DokumentShell
291 
292 */
293 
294 {
295     _FileListEntry* pEntry = (*pImpl->pDocList)[nIdx];
296     // andernfalls Doc-Shell anlegen
297     if ( !pEntry->aDocShell.Is() )
298     {
299 //(mba)/task        SfxWaitCursor aWaitCursor;
300         INetURLObject aFileObj( pEntry->aFileName );
301         sal_Bool bDum = sal_False;
302         SfxApplication* pSfxApp = SFX_APP();
303         String aFilePath = aFileObj.GetMainURL( INetURLObject::NO_DECODE );
304         pEntry->aDocShell = pSfxApp->DocAlreadyLoaded( aFilePath, sal_False, bDum );
305         if ( !pEntry->aDocShell.Is() )
306         {
307             pEntry->bOwner = sal_True;
308             SfxMedium* pMed = new SfxMedium(
309                 aFilePath, ( STREAM_READ | STREAM_SHARE_DENYWRITE ), sal_False, 0 );
310             const SfxFilter* pFilter = NULL;
311             pMed->UseInteractionHandler(sal_True);
312             if (
313                 pSfxApp->GetFilterMatcher().GuessFilter(*pMed, &pFilter, SFX_FILTER_TEMPLATE, 0) ||
314                 (pFilter && !pFilter->IsOwnFormat()) ||
315                 (pFilter && !pFilter->UsesStorage())
316                )
317             {
318                 pSfxApp->LoadTemplate( pEntry->aDocShell, aFilePath );
319                 pEntry->bOwnFormat = sal_False;
320                 delete pMed;
321                 if ( pEntry->aDocShell.Is() )
322                     return (SfxObjectShellRef)(SfxObjectShell*)(pEntry->aDocShell);
323             }
324             else
325             {
326                 if ( pFilter )
327                 {
328                     pEntry->bOwnFormat = sal_True;
329                     pEntry->aDocShell = SfxObjectShell::CreateObject( pFilter->GetServiceName(), SFX_CREATE_MODE_ORGANIZER );
330                     if ( pEntry->aDocShell.Is() )
331                     {
332                         pEntry->aDocShell->DoInitNew(0);
333                         pEntry->aDocShell->LoadFrom( *pMed );
334                         // Medium is now owned by DocShell
335                         pEntry->aDocShell->DoSaveCompleted( pMed );
336                     }
337                 }
338             }
339         }
340     }
341     return ( SfxObjectShellRef )(SfxObjectShell*)(pEntry->aDocShell);
342 }
343 
344 //-------------------------------------------------------------------------
345 
346 sal_Bool SfxOrganizeMgr::DeleteObjectShell(sal_uInt16 nIdx)
347 
348 /*  [Beschreibung]
349 
350     Freigabe der DokumentShell an der Position nIdx
351 
352     [Returnwert]            sal_True: alles Ok
353                             sal_False: es ist ein Fehler aufgetreten (das
354                             Dokument konnte nicht gesichert werden)
355 
356 */
357 {
358     return (*pImpl->pDocList)[nIdx]->DeleteObjectShell();
359 }
360 
361 //-------------------------------------------------------------------------
362 
363 SfxObjectShellRef SfxOrganizeMgr::CreateObjectShell(sal_uInt16 nRegion,
364                                                         sal_uInt16 nIdx)
365 /*  [Beschreibung]
366 
367     Zugriff auf die DokumentShell an der Position nIdx im Bereich
368     nRegion (Dokumentvorlage)
369 
370     [Returnwert]            Referenz auf die DokumentShell
371 
372 */
373 {
374 //(mba)/task    SfxWaitCursor aWaitCursor;
375     return pTemplates->CreateObjectShell(nRegion, nIdx);
376 }
377 
378 //-------------------------------------------------------------------------
379 
380 sal_Bool SfxOrganizeMgr::DeleteObjectShell(sal_uInt16 nRegion, sal_uInt16 nIdx)
381 
382 /*  [Beschreibung]
383 
384     Freigabe der DokumentShell an der Position nIdx im Bereich
385     nRegion (Dokumentvorlage)
386 
387     [Returnwert]            sal_True: alles Ok
388                             sal_False: es ist ein Fehler aufgetreten (das
389                             Dokument konnte nicht gesichert werden)
390 
391 */
392 
393 {
394     return pTemplates->DeleteObjectShell(nRegion, nIdx);
395 }
396 
397 //-------------------------------------------------------------------------
398 
399 sal_Bool    SfxOrganizeMgr::Copy(sal_uInt16 nTargetRegion,
400                             sal_uInt16 nTargetIdx,
401                             sal_uInt16 nSourceRegion,
402                             sal_uInt16 nSourceIdx)
403 
404 /*  [Beschreibung]
405 
406     Kopieren einer Dokumentvorlage
407 
408     [Parameter]
409 
410     sal_uInt16 nTargetRegion            Index des Zielbereiches
411     sal_uInt16 nTargetIdx               Index Zielposition
412     sal_uInt16 nSourceRegion            Index des Quellbereiches
413     sal_uInt16 nSourceIdx               Index der zu kopierenden / z uverschiebenden
414                                     Dokumentvorlage
415 
416     [R"uckgabewert]                 Erfolg (TRUE) oder Mi"serfolg (FALSE)
417 
418 
419     [Querverweise]
420 
421     <SfxDocumentTemplates::Copy(sal_uInt16 nTargetRegion,
422                                 sal_uInt16 nTargetIdx,
423                                 sal_uInt16 nSourceRegion,
424                                 sal_uInt16 nSourceIdx)>
425 
426 */
427 
428 {
429     if(nSourceIdx == USHRT_MAX) // keine Verzeichnisse kopieren
430         return sal_False ;
431     const sal_Bool bOk = pTemplates->Copy(nTargetRegion, nTargetIdx,
432                                         nSourceRegion, nSourceIdx);
433     if(bOk)
434         bModified = 1;
435     return bOk;
436 }
437 
438 //-------------------------------------------------------------------------
439 
440 sal_Bool    SfxOrganizeMgr::Move(sal_uInt16 nTargetRegion,
441                             sal_uInt16 nTargetIdx,
442                             sal_uInt16 nSourceRegion,
443                             sal_uInt16 nSourceIdx)
444 
445 /*  [Beschreibung]
446 
447     Verschieben einer Dokumentvorlage
448 
449     [Parameter]
450 
451     sal_uInt16 nTargetRegion            Index des Zielbereiches
452     sal_uInt16 nTargetIdx               Index Zielposition
453     sal_uInt16 nSourceRegion            Index des Quellbereiches
454     sal_uInt16 nSourceIdx               Index der zu kopierenden / z uverschiebenden
455                                     Dokumentvorlage
456 
457     [R"uckgabewert]                 Erfolg (TRUE) oder Mi"serfolg (FALSE)
458 
459 
460     [Querverweise]
461 
462     <SfxDocumentTemplates::Move(sal_uInt16 nTargetRegion,
463                                 sal_uInt16 nTargetIdx,
464                                 sal_uInt16 nSourceRegion,
465                                 sal_uInt16 nSourceIdx)>
466 
467 */
468 
469 {
470     if(nSourceIdx == USHRT_MAX) // keine Verzeichnisse verschieben
471         return sal_False ;
472     const sal_Bool bOk = pTemplates->Move(nTargetRegion, nTargetIdx,
473                                         nSourceRegion, nSourceIdx);
474     if(bOk)
475         bModified = 1;
476     return bOk;
477 }
478 
479 //-------------------------------------------------------------------------
480 
481 sal_Bool    SfxOrganizeMgr::Delete(SfxOrganizeListBox_Impl *pCaller,
482                                 sal_uInt16 nRegion, sal_uInt16 nIdx)
483 
484 /*  [Beschreibung]
485 
486     "oschen einer Dokumentvorlage
487 
488     [Parameter]
489 
490     SfxOrganizeListBox *pCaller     rufende ListBox; da dieses
491                                     Event durch das Men"u oder
492                                     durch das Keyboard angetriggert wird,
493                                     mu"s das Model der ListBox anschlie"send
494                                     aktualisiert werden.
495     sal_uInt16 nRegion                  Index des Bereiches
496     sal_uInt16 nIdx                     Index der Dokumentvorlage
497 
498     [R"uckgabewert]                 Erfolg (TRUE) oder Mi"serfolg (FALSE)
499 
500 
501     [Querverweise]
502 
503     <SfxDocumentTemplates::Delete(sal_uInt16 nRegion, sal_uInt16 nIdx)>
504 
505 */
506 
507 {
508     sal_Bool bOk = sal_False;
509 
510     if ( USHRT_MAX == nIdx )
511     {
512         // deleting of a group
513 
514         SvLBoxEntry *pGroupToDelete = pCaller->SvLBox::GetEntry(nRegion);
515         if ( pGroupToDelete )
516         {
517             sal_uInt16 nItemNum = (sal_uInt16)( pCaller->GetModel()->GetChildCount( pGroupToDelete ) );
518             sal_uInt16 nToDeleteNum = 0;
519             SvLBoxEntry **pEntriesToDelete = new SvLBoxEntry*[nItemNum];
520 
521             sal_uInt16 nInd = 0;
522             for ( nInd = 0; nInd < nItemNum; nInd++ )
523                 pEntriesToDelete[nInd] = NULL;
524 
525             for ( nInd = 0; nInd < nItemNum; nInd++ )
526             {
527                 // TODO/LATER: check that nInd is the same index that is used in pTemplates
528                 if ( pTemplates->Delete( nRegion, nInd ) )
529                 {
530                     bModified = 1;
531                     pEntriesToDelete[nToDeleteNum++] = pCaller->SvLBox::GetEntry( pGroupToDelete, nInd );
532                 }
533             }
534 
535             for ( nInd = 0; nInd < nToDeleteNum; nInd++ )
536                 if ( pEntriesToDelete[nInd] )
537                     pCaller->GetModel()->Remove( pEntriesToDelete[nInd] );
538 
539             if ( !pCaller->GetModel()->GetChildCount( pGroupToDelete ) )
540             {
541                 bOk = pTemplates->Delete( nRegion, nIdx );
542                 if ( bOk )
543                     pCaller->GetModel()->Remove( pGroupToDelete );
544             }
545         }
546     }
547     else
548     {
549         // deleting of a template
550         bOk = pTemplates->Delete(nRegion, nIdx);
551         if(bOk)
552         {
553             bModified = 1;
554                 // zu loeschender Eintrag
555             SvLBoxEntry *pEntryToDelete = pCaller->SvLBox::GetEntry(pCaller->SvLBox::GetEntry(nRegion), nIdx);
556 
557             pCaller->GetModel()->Remove(pEntryToDelete);
558         }
559     }
560 
561     return bOk;
562 }
563 
564 //-------------------------------------------------------------------------
565 
566 sal_Bool    SfxOrganizeMgr::InsertDir
567 (
568     SfxOrganizeListBox_Impl*    pCaller,/*  rufende ListBox; da dieses Event
569                                             durch das Men"u oder durch das
570                                             Keyboard angetriggert wird,
571                                             mu\s das Model der ListBox
572                                             anschlie\send aktualisiert werden */
573     const String&               rText,  //  logischer Name des Bereiches
574     sal_uInt16                      nRegion //  Index des Bereiches
575 )
576 
577 /*  [Beschreibung]
578 
579     Einf"ugen eines Bereiches
580 
581 
582     [R"uckgabewert]
583 
584     Erfolg (sal_True) oder Mi\serfolg (sal_False)
585 
586 
587     [Querverweise]
588 
589     <SfxDocumentTemplates::InsertDir(const String &, sal_uInt16 nRegion)>
590 */
591 
592 {
593     const sal_Bool bOk = pTemplates->InsertDir(rText, nRegion);
594     if(bOk)
595     {
596         bModified = 1;
597         SvLBoxEntry *pEntry = pCaller->InsertEntry(rText,
598                                                    pCaller->GetOpenedBmp(0),
599                                                    pCaller->GetClosedBmp(0),
600                                                    0, sal_True, nRegion);
601         pCaller->Update();
602         pCaller->EditEntry(pEntry);
603     }
604     return bOk;
605 }
606 
607 //-------------------------------------------------------------------------
608 
609 sal_Bool SfxOrganizeMgr::SetName(const String &rName,
610                              sal_uInt16 nRegion, sal_uInt16 nIdx)
611 
612 /*  [Beschreibung]
613 
614     "Andern eines (logischen) Namens
615 
616     [Parameter]
617 
618     const String &rName             der neue Name
619     sal_uInt16 nRegion                  Index des Bereiches
620     sal_uInt16 nIdx                     Index der Dokumentvorlage
621 
622     [R"uckgabewert]                 Erfolg (TRUE) oder Mi"serfolg (FALSE)
623 
624 
625     [Querverweise]
626 
627     <SfxDocumentTemplates::SetName(const String &, sal_uInt16 nRegion, sal_uInt16 nIdx)>
628 
629 */
630 
631 {
632     const sal_Bool bOk = pTemplates->SetName(rName, nRegion, nIdx);
633     if(bOk)
634         bModified = 1;
635     return bOk;
636 }
637 
638 //-------------------------------------------------------------------------
639 
640 sal_Bool SfxOrganizeMgr::CopyTo(sal_uInt16 nRegion, sal_uInt16 nIdx, const String &rName) const
641 
642 /*  [Beschreibung]
643 
644     Export einer Vorlage
645 
646     [Parameter]
647 
648     sal_uInt16 nRegion                  Index des Bereiches
649     sal_uInt16 nIdx                     Index der Dokumentvorlage
650     const String &rName             Dateiname
651 
652     [R"uckgabewert]                 Erfolg (TRUE) oder Mi"serfolg (FALSE)
653 
654 
655     [Querverweise]
656 
657     <SfxDocumentTemplates::CopyTo( sal_uInt16 nRegion, sal_uInt16 nIdx, const String &)>
658 
659 */
660 
661 {
662     return pTemplates->CopyTo(nRegion, nIdx, rName);
663 }
664 
665 //-------------------------------------------------------------------------
666 
667 sal_Bool SfxOrganizeMgr::CopyFrom(SfxOrganizeListBox_Impl *pCaller,
668                               sal_uInt16 nRegion, sal_uInt16 nIdx, String &rName)
669 
670 /*  [Beschreibung]
671 
672     Import einer Vorlage
673 
674     [Parameter]
675 
676     SfxOrganizeListBox *pCaller     rufende ListBox; da dieses
677                                     Event durch das Men"u angetriggert wird,
678                                     mu"s das Model der ListBox anschlie"send
679                                     aktualisiert werden.
680     sal_uInt16 nRegion                  Index des Bereiches
681     sal_uInt16 nIdx                     Index der Dokumentvorlage
682     String &rName                   Dateiname
683 
684     [R"uckgabewert]                 Erfolg (TRUE) oder Mi"serfolg (FALSE)
685 
686 
687     [Querverweise]
688 
689     <SfxDocumentTemplates::CopyFrom( sal_uInt16 nRegion, sal_uInt16 nIdx, const String &)>
690 
691 */
692 
693 {
694     SvLBoxEntry *pParent = pCaller->FirstSelected();
695     if( nIdx!=USHRT_MAX )
696         pParent = pCaller->GetParent(pParent);
697     if( pTemplates->CopyFrom( nRegion, nIdx, rName ) )
698     {
699         // pCaller aktualisieren
700         if( nIdx == USHRT_MAX )
701             nIdx = 0;
702         else nIdx++;
703 
704         pCaller->InsertEntry( rName,
705                               pCaller->GetOpenedBmp(1),
706                               pCaller->GetClosedBmp(1),
707                               pParent,
708                               sal_True,
709                               nIdx);
710         pCaller->Update();
711         // pCaller->EditEntry( pEntry );
712         pCaller->Expand( pParent );
713         bModified = sal_True;
714         return sal_True;
715     }
716     return sal_False;
717 }
718 
719 //-------------------------------------------------------------------------
720 
721 sal_Bool SfxOrganizeMgr::InsertFile( SfxOrganizeListBox_Impl* pCaller, const String& rFileName )
722 
723 /*  [Beschreibung]
724 
725     Eine Datei in der Dateiansicht hinzuf"ugen
726 
727     [Parameter]
728 
729     SfxOrganizeListBox *pCaller     rufende ListBox; da dieses
730                                     Event durch das Men"u angetriggert wird,
731                                     mu"s das Model der ListBox anschlie"send
732                                     aktualisiert werden.
733     const String &rFileName         Name der hinzuf"ugenden Datei
734 
735     [R"uckgabewert]                 Erfolg (TRUE) oder Mi"serfolg (FALSE)
736 
737 */
738 
739 {
740     const CollatorWrapper* pCollator = pImpl->pIntlWrapper->getCaseCollator();
741     _FileListEntry* pEntry = new _FileListEntry( rFileName, pCollator );
742     if ( pImpl->pDocList->C40_PTR_INSERT( _FileListEntry, pEntry ) )
743     {
744         sal_uInt16 nPos = 0;
745         pImpl->pDocList->Seek_Entry( pEntry, &nPos );
746         pCaller->InsertEntry( pEntry->aBaseName, pCaller->GetOpenedBmp(1),
747                               pCaller->GetClosedBmp(1), 0, sal_True, nPos );
748         return sal_True;
749     }
750     return sal_False;
751 }
752 
753 //-------------------------------------------------------------------------
754 
755 sal_Bool SfxOrganizeMgr::Rescan()
756 
757 /*  [Beschreibung]
758 
759     Aktualisieren der Datenbasis
760 
761     [R"uckgabewert]
762 
763     sal_True                    es bestanden Unterschiede
764     FALSE                   keine "Anderung
765 
766     [Querverweise]
767 
768     <SfxDocumentTemplates::Rescan()>
769 */
770 
771 {
772     if(pTemplates->Rescan())
773     {
774         bModified = sal_True;
775         return sal_True;
776     }
777     return sal_False;
778 }
779 
780 //-------------------------------------------------------------------------
781 
782 void SfxOrganizeMgr::SaveAll(Window *pParent)
783 
784 /*  [Beschreibung]
785 
786     Schreiben aller ge"anderten Dokumente
787 
788     [Parameter]
789 
790     Window *pParent         Parent der Boxen f"ur Fehlermeldungen
791 
792 */
793 
794 {
795     sal_uInt16 nRangeCount = pTemplates->GetRegionCount();
796     sal_uInt16 i;
797     for(i = 0; i < nRangeCount; ++i)
798     {
799         if( pTemplates->IsRegionLoaded( i ))
800         {
801             const sal_uInt16 nCount = pTemplates->GetCount(i);
802             for(sal_uInt16 j = 0; j < nCount; ++j)
803             {
804                 if(!pTemplates->DeleteObjectShell(i, j))
805                 {
806                     String aText = String(SfxResId(STR_ERROR_SAVE_TEMPLATE));
807                     aText += pTemplates->GetName(i, j);
808                     ErrorBox aBox(pParent,
809                                   WinBits(WB_OK_CANCEL | WB_DEF_CANCEL),
810                                   aText);
811                     if(RET_CANCEL == aBox.Execute())
812                         break;
813                 }
814             }
815         }
816     }
817     nRangeCount = pImpl->pDocList->Count();
818     for(i = 0; i < nRangeCount; ++i)
819     {
820         _FileListEntry *pEntry = (*pImpl->pDocList)[i];
821         if(!pEntry->DeleteObjectShell())
822         {
823             String aText(SfxResId(STR_ERROR_SAVE_TEMPLATE));
824             aText += pEntry->aBaseName;
825             ErrorBox aBox(pParent, WinBits(WB_OK_CANCEL | WB_DEF_CANCEL), aText);
826             if(RET_CANCEL == aBox.Execute())
827                 break;
828         }
829     }
830 }
831 
832 
833