xref: /aoo42x/main/sfx2/source/view/orgmgr.cxx (revision 0a999d18)
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 
operator ==(const _FileListEntry & rCmp) const95 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 
operator <(const _FileListEntry & rCmp) const103 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 
_FileListEntry(const String & rFileName,const CollatorWrapper * pColl,const String * pTitle)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 
~_FileListEntry()133 _FileListEntry::~_FileListEntry()
134 {
135 	DeleteObjectShell();
136 }
137 
138 //-------------------------------------------------------------------------
139 
SV_IMPL_OP_PTRARR_SORT(_SfxObjectList,_FileListEntry *)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 
SfxObjectList()204 SfxObjectList::SfxObjectList()
205 {
206 }
207 
208 //-------------------------------------------------------------------------
209 
~SfxObjectList()210 SfxObjectList::~SfxObjectList()
211 {
212 	DeleteAndDestroy(0, Count());
213 }
214 
215 //-------------------------------------------------------------------------
216 
GetBaseName(sal_uInt16 i) const217 const String &SfxObjectList::GetBaseName(sal_uInt16 i) const
218 {
219 	return (*this)[i]->aBaseName;
220 }
221 
222 //-------------------------------------------------------------------------
223 
GetFileName(sal_uInt16 i) const224 const String& SfxObjectList::GetFileName( sal_uInt16 i ) const
225 {
226 	return (*this)[i]->aFileName;
227 }
228 
229 //-------------------------------------------------------------------------
230 
SfxOrganizeMgr(SfxOrganizeListBox_Impl * pLeft,SfxOrganizeListBox_Impl * pRight,SfxDocumentTemplates * pTempl)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 
~SfxOrganizeMgr()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 
CreateObjectShell(sal_uInt16 nIdx)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 
DeleteObjectShell(sal_uInt16 nIdx)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 
CreateObjectShell(sal_uInt16 nRegion,sal_uInt16 nIdx)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 
DeleteObjectShell(sal_uInt16 nRegion,sal_uInt16 nIdx)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 
Copy(sal_uInt16 nTargetRegion,sal_uInt16 nTargetIdx,sal_uInt16 nSourceRegion,sal_uInt16 nSourceIdx)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 
Move(sal_uInt16 nTargetRegion,sal_uInt16 nTargetIdx,sal_uInt16 nSourceRegion,sal_uInt16 nSourceIdx)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 
Delete(SfxOrganizeListBox_Impl * pCaller,sal_uInt16 nRegion,sal_uInt16 nIdx)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 			delete[] pEntriesToDelete;
535 
536 			if ( !pCaller->GetModel()->GetChildCount( pGroupToDelete ) )
537             {
538                 bOk = pTemplates->Delete( nRegion, nIdx );
539                 if ( bOk )
540                     pCaller->GetModel()->Remove( pGroupToDelete );
541             }
542 		}
543 	}
544 	else
545 	{
546 		// deleting of a template
547 		bOk = pTemplates->Delete(nRegion, nIdx);
548 		if(bOk)
549 		{
550 			bModified = 1;
551 				// zu loeschender Eintrag
552 			SvLBoxEntry *pEntryToDelete = pCaller->SvLBox::GetEntry(pCaller->SvLBox::GetEntry(nRegion), nIdx);
553 
554 			pCaller->GetModel()->Remove(pEntryToDelete);
555 		}
556 	}
557 
558 	return bOk;
559 }
560 
561 //-------------------------------------------------------------------------
562 
InsertDir(SfxOrganizeListBox_Impl * pCaller,const String & rText,sal_uInt16 nRegion)563 sal_Bool	SfxOrganizeMgr::InsertDir
564 (
565 	SfxOrganizeListBox_Impl*	pCaller,/*	rufende ListBox; da dieses Event
566 											durch das Men"u oder durch das
567 											Keyboard angetriggert wird,
568 											mu\s das Model der ListBox
569 											anschlie\send aktualisiert werden */
570 	const String&				rText,	//	logischer Name des Bereiches
571 	sal_uInt16						nRegion //	Index des Bereiches
572 )
573 
574 /*	[Beschreibung]
575 
576 	Einf"ugen eines Bereiches
577 
578 
579 	[R"uckgabewert]
580 
581 	Erfolg (sal_True) oder Mi\serfolg (sal_False)
582 
583 
584 	[Querverweise]
585 
586 	<SfxDocumentTemplates::InsertDir(const String &, sal_uInt16 nRegion)>
587 */
588 
589 {
590 	const sal_Bool bOk = pTemplates->InsertDir(rText, nRegion);
591 	if(bOk)
592 	{
593 		bModified = 1;
594 		SvLBoxEntry *pEntry = pCaller->InsertEntry(rText,
595 												   pCaller->GetOpenedBmp(0),
596 												   pCaller->GetClosedBmp(0),
597 												   0, sal_True, nRegion);
598 		pCaller->Update();
599 		pCaller->EditEntry(pEntry);
600 	}
601 	return bOk;
602 }
603 
604 //-------------------------------------------------------------------------
605 
SetName(const String & rName,sal_uInt16 nRegion,sal_uInt16 nIdx)606 sal_Bool SfxOrganizeMgr::SetName(const String &rName,
607 							 sal_uInt16 nRegion, sal_uInt16 nIdx)
608 
609 /*  [Beschreibung]
610 
611 	"Andern eines (logischen) Namens
612 
613 	[Parameter]
614 
615 	const String &rName				der neue Name
616 	sal_uInt16 nRegion					Index des Bereiches
617 	sal_uInt16 nIdx						Index der Dokumentvorlage
618 
619 	[R"uckgabewert]					Erfolg (TRUE) oder Mi"serfolg (FALSE)
620 
621 
622 	[Querverweise]
623 
624 	<SfxDocumentTemplates::SetName(const String &, sal_uInt16 nRegion, sal_uInt16 nIdx)>
625 
626 */
627 
628 {
629 	const sal_Bool bOk = pTemplates->SetName(rName, nRegion, nIdx);
630 	if(bOk)
631 		bModified = 1;
632 	return bOk;
633 }
634 
635 //-------------------------------------------------------------------------
636 
CopyTo(sal_uInt16 nRegion,sal_uInt16 nIdx,const String & rName) const637 sal_Bool SfxOrganizeMgr::CopyTo(sal_uInt16 nRegion, sal_uInt16 nIdx, const String &rName) const
638 
639 /*  [Beschreibung]
640 
641 	Export einer Vorlage
642 
643 	[Parameter]
644 
645 	sal_uInt16 nRegion					Index des Bereiches
646 	sal_uInt16 nIdx						Index der Dokumentvorlage
647 	const String &rName				Dateiname
648 
649 	[R"uckgabewert]					Erfolg (TRUE) oder Mi"serfolg (FALSE)
650 
651 
652 	[Querverweise]
653 
654 	<SfxDocumentTemplates::CopyTo( sal_uInt16 nRegion, sal_uInt16 nIdx, const String &)>
655 
656 */
657 
658 {
659 	return pTemplates->CopyTo(nRegion, nIdx, rName);
660 }
661 
662 //-------------------------------------------------------------------------
663 
CopyFrom(SfxOrganizeListBox_Impl * pCaller,sal_uInt16 nRegion,sal_uInt16 nIdx,String & rName)664 sal_Bool SfxOrganizeMgr::CopyFrom(SfxOrganizeListBox_Impl *pCaller,
665 							  sal_uInt16 nRegion, sal_uInt16 nIdx, String &rName)
666 
667 /*  [Beschreibung]
668 
669 	Import einer Vorlage
670 
671 	[Parameter]
672 
673 	SfxOrganizeListBox *pCaller		rufende ListBox; da dieses
674 									Event durch das Men"u angetriggert wird,
675 									mu"s das Model der ListBox anschlie"send
676 									aktualisiert werden.
677 	sal_uInt16 nRegion					Index des Bereiches
678 	sal_uInt16 nIdx						Index der Dokumentvorlage
679 	String &rName					Dateiname
680 
681 	[R"uckgabewert]					Erfolg (TRUE) oder Mi"serfolg (FALSE)
682 
683 
684 	[Querverweise]
685 
686 	<SfxDocumentTemplates::CopyFrom( sal_uInt16 nRegion, sal_uInt16 nIdx, const String &)>
687 
688 */
689 
690 {
691     SvLBoxEntry *pParent = pCaller->FirstSelected();
692     if( nIdx!=USHRT_MAX )
693         pParent = pCaller->GetParent(pParent);
694     if( pTemplates->CopyFrom( nRegion, nIdx, rName ) )
695     {
696         // pCaller aktualisieren
697         if( nIdx == USHRT_MAX )
698             nIdx = 0;
699         else nIdx++;
700 
701         pCaller->InsertEntry( rName,
702                               pCaller->GetOpenedBmp(1),
703                               pCaller->GetClosedBmp(1),
704                               pParent,
705                               sal_True,
706                               nIdx);
707         pCaller->Update();
708         // pCaller->EditEntry( pEntry );
709         pCaller->Expand( pParent );
710         bModified = sal_True;
711         return sal_True;
712     }
713     return sal_False;
714 }
715 
716 //-------------------------------------------------------------------------
717 
InsertFile(SfxOrganizeListBox_Impl * pCaller,const String & rFileName)718 sal_Bool SfxOrganizeMgr::InsertFile( SfxOrganizeListBox_Impl* pCaller, const String& rFileName )
719 
720 /*  [Beschreibung]
721 
722 	Eine Datei in der Dateiansicht hinzuf"ugen
723 
724 	[Parameter]
725 
726 	SfxOrganizeListBox *pCaller		rufende ListBox; da dieses
727 									Event durch das Men"u angetriggert wird,
728 									mu"s das Model der ListBox anschlie"send
729 									aktualisiert werden.
730 	const String &rFileName			Name der hinzuf"ugenden Datei
731 
732 	[R"uckgabewert]					Erfolg (TRUE) oder Mi"serfolg (FALSE)
733 
734 */
735 
736 {
737 	const CollatorWrapper* pCollator = pImpl->pIntlWrapper->getCaseCollator();
738 	_FileListEntry* pEntry = new _FileListEntry( rFileName, pCollator );
739 	if ( pImpl->pDocList->C40_PTR_INSERT( _FileListEntry, pEntry ) )
740 	{
741 		sal_uInt16 nPos = 0;
742 		pImpl->pDocList->Seek_Entry( pEntry, &nPos );
743 		pCaller->InsertEntry( pEntry->aBaseName, pCaller->GetOpenedBmp(1),
744 							  pCaller->GetClosedBmp(1), 0, sal_True, nPos );
745 		return sal_True;
746 	}
747 	return sal_False;
748 }
749 
750 //-------------------------------------------------------------------------
751 
Rescan()752 sal_Bool SfxOrganizeMgr::Rescan()
753 
754 /*  [Beschreibung]
755 
756 	Aktualisieren der Datenbasis
757 
758 	[R"uckgabewert]
759 
760 	sal_True					es bestanden Unterschiede
761 	FALSE					keine "Anderung
762 
763 	[Querverweise]
764 
765 	<SfxDocumentTemplates::Rescan()>
766 */
767 
768 {
769 	if(pTemplates->Rescan())
770 	{
771 		bModified = sal_True;
772 		return sal_True;
773 	}
774 	return sal_False;
775 }
776 
777 //-------------------------------------------------------------------------
778 
SaveAll(Window * pParent)779 void SfxOrganizeMgr::SaveAll(Window *pParent)
780 
781 /*  [Beschreibung]
782 
783 	Schreiben aller ge"anderten Dokumente
784 
785 	[Parameter]
786 
787 	Window *pParent			Parent der Boxen f"ur Fehlermeldungen
788 
789 */
790 
791 {
792 	sal_uInt16 nRangeCount = pTemplates->GetRegionCount();
793 	sal_uInt16 i;
794 	for(i = 0; i < nRangeCount; ++i)
795 	{
796 		if( pTemplates->IsRegionLoaded( i ))
797 		{
798 			const sal_uInt16 nCount = pTemplates->GetCount(i);
799 			for(sal_uInt16 j = 0; j < nCount; ++j)
800 			{
801 				if(!pTemplates->DeleteObjectShell(i, j))
802 				{
803 					String aText = String(SfxResId(STR_ERROR_SAVE_TEMPLATE));
804 					aText += pTemplates->GetName(i, j);
805 					ErrorBox aBox(pParent,
806 								  WinBits(WB_OK_CANCEL | WB_DEF_CANCEL),
807 								  aText);
808 					if(RET_CANCEL == aBox.Execute())
809 						break;
810 				}
811 			}
812 		}
813 	}
814 	nRangeCount = pImpl->pDocList->Count();
815 	for(i = 0; i < nRangeCount; ++i)
816 	{
817 		_FileListEntry *pEntry = (*pImpl->pDocList)[i];
818 		if(!pEntry->DeleteObjectShell())
819 		{
820 			String aText(SfxResId(STR_ERROR_SAVE_TEMPLATE));
821 			aText += pEntry->aBaseName;
822 			ErrorBox aBox(pParent, WinBits(WB_OK_CANCEL | WB_DEF_CANCEL), aText);
823 			if(RET_CANCEL == aBox.Execute())
824 				break;
825 		}
826 	}
827 }
828 
829 
830