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