bump product version to 5.0.4.1
[LibreOffice.git] / cui / source / options / optpath.cxx
blob0bab1a92168ae144d892f8a503be0f259a6b1fb6
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <svx/svxdlg.hxx>
21 #include <vcl/msgbox.hxx>
22 #include <sfx2/filedlghelper.hxx>
23 #include <sfx2/app.hxx>
24 #include <svl/aeitem.hxx>
25 #include <svtools/svtabbx.hxx>
26 #include "svtools/treelistentry.hxx"
27 #include <tools/urlobj.hxx>
28 #include <vcl/svapp.hxx>
29 #include <unotools/defaultoptions.hxx>
30 #include <unotools/localfilehelper.hxx>
31 #include <unotools/pathoptions.hxx>
32 #include <unotools/moduleoptions.hxx>
33 #include <unotools/viewoptions.hxx>
35 #include "optpath.hxx"
36 #include <dialmgr.hxx>
37 #include <cuires.hrc>
38 #include "helpid.hrc"
39 #include <comphelper/configuration.hxx>
40 #include <comphelper/processfactory.hxx>
41 #include <comphelper/string.hxx>
42 #include <com/sun/star/uno/Exception.hpp>
43 #include <com/sun/star/beans/XPropertySet.hpp>
44 #include <com/sun/star/beans/PropertyAttribute.hpp>
45 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
46 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
47 #include <com/sun/star/ui/dialogs/XAsynchronousExecutableDialog.hpp>
48 #include <com/sun/star/ui/dialogs/FolderPicker.hpp>
49 #include <com/sun/star/util/thePathSettings.hpp>
50 #include <officecfg/Office/Common.hxx>
51 #include "optHeaderTabListbox.hxx"
52 #include <vcl/help.hxx>
54 using namespace ::com::sun::star::beans;
55 using namespace ::com::sun::star::lang;
56 using namespace ::com::sun::star::ui::dialogs;
57 using namespace ::com::sun::star::uno;
58 using namespace svx;
60 // define ----------------------------------------------------------------
62 #define TAB_WIDTH_MIN 10
63 #define ITEMID_TYPE 1
64 #define ITEMID_PATH 2
66 #define POSTFIX_INTERNAL OUString("_internal")
67 #define POSTFIX_USER OUString("_user")
68 #define POSTFIX_WRITABLE OUString("_writable")
69 #define VAR_ONE OUString("%1")
70 #define IODLG_CONFIGNAME OUString("FilePicker_Save")
72 // struct OptPath_Impl ---------------------------------------------------
74 struct OptPath_Impl
76 SvtDefaultOptions m_aDefOpt;
77 Image m_aLockImage;
78 OUString m_sMultiPathDlg;
79 Reference< css::util::XPathSettings > m_xPathSettings;
81 OptPath_Impl(const Image& rLockImage, const OUString& rMultiPathDlg)
82 : m_aLockImage(rLockImage)
83 , m_sMultiPathDlg(rMultiPathDlg)
88 // struct PathUserData_Impl ----------------------------------------------
90 struct PathUserData_Impl
92 sal_uInt16 nRealId;
93 SfxItemState eState;
94 OUString sUserPath;
95 OUString sWritablePath;
97 PathUserData_Impl( sal_uInt16 nId ) :
98 nRealId( nId ), eState( SfxItemState::UNKNOWN ) {}
101 struct Handle2CfgNameMapping_Impl
103 sal_uInt16 m_nHandle;
104 const char* m_pCfgName;
107 static Handle2CfgNameMapping_Impl const Hdl2CfgMap_Impl[] =
109 { SvtPathOptions::PATH_AUTOCORRECT, "AutoCorrect" },
110 { SvtPathOptions::PATH_AUTOTEXT, "AutoText" },
111 { SvtPathOptions::PATH_BACKUP, "Backup" },
112 { SvtPathOptions::PATH_GALLERY, "Gallery" },
113 { SvtPathOptions::PATH_GRAPHIC, "Graphic" },
114 { SvtPathOptions::PATH_TEMP, "Temp" },
115 { SvtPathOptions::PATH_TEMPLATE, "Template" },
116 { SvtPathOptions::PATH_WORK, "Work" },
117 { SvtPathOptions::PATH_DICTIONARY, "Dictionary" },
118 #if OSL_DEBUG_LEVEL > 1
119 { SvtPathOptions::PATH_LINGUISTIC, "Linguistic" },
120 #endif
121 { USHRT_MAX, NULL }
124 static OUString getCfgName_Impl( sal_uInt16 _nHandle )
126 OUString sCfgName;
127 sal_uInt16 nIndex = 0;
128 while ( Hdl2CfgMap_Impl[ nIndex ].m_nHandle != USHRT_MAX )
130 if ( Hdl2CfgMap_Impl[ nIndex ].m_nHandle == _nHandle )
132 // config name found
133 sCfgName = OUString::createFromAscii( Hdl2CfgMap_Impl[ nIndex ].m_pCfgName );
134 break;
136 ++nIndex;
139 return sCfgName;
142 #define MULTIPATH_DELIMITER ';'
144 OUString Convert_Impl( const OUString& rValue )
146 char cDelim = MULTIPATH_DELIMITER;
147 sal_uInt16 nCount = comphelper::string::getTokenCount(rValue, cDelim);
148 OUString aReturn;
149 for ( sal_uInt16 i=0; i<nCount ; ++i )
151 OUString aValue = rValue.getToken( i, cDelim );
152 INetURLObject aObj( aValue );
153 if ( aObj.GetProtocol() == INetProtocol::File )
154 aReturn += aObj.PathToFileName();
155 else if ( ::utl::LocalFileHelper::IsFileContent( aValue ) )
156 aReturn += aObj.GetURLPath( INetURLObject::DECODE_WITH_CHARSET );
157 if ( i+1 < nCount)
158 aReturn += OUString(MULTIPATH_DELIMITER);
161 return aReturn;
164 // functions -------------------------------------------------------------
166 bool IsMultiPath_Impl( const sal_uInt16 nIndex )
168 #if OSL_DEBUG_LEVEL > 1
169 return ( SvtPathOptions::PATH_AUTOCORRECT == nIndex ||
170 SvtPathOptions::PATH_AUTOTEXT == nIndex ||
171 SvtPathOptions::PATH_BASIC == nIndex ||
172 SvtPathOptions::PATH_GALLERY == nIndex ||
173 SvtPathOptions::PATH_TEMPLATE == nIndex );
174 #else
175 return ( SvtPathOptions::PATH_AUTOCORRECT == nIndex ||
176 SvtPathOptions::PATH_AUTOTEXT == nIndex ||
177 SvtPathOptions::PATH_BASIC == nIndex ||
178 SvtPathOptions::PATH_GALLERY == nIndex ||
179 SvtPathOptions::PATH_TEMPLATE == nIndex ||
180 SvtPathOptions::PATH_LINGUISTIC == nIndex ||
181 SvtPathOptions::PATH_DICTIONARY == nIndex );
182 #endif
185 // class SvxPathTabPage --------------------------------------------------
187 SvxPathTabPage::SvxPathTabPage(vcl::Window* pParent, const SfxItemSet& rSet)
188 :SfxTabPage( pParent, "OptPathsPage", "cui/ui/optpathspage.ui", &rSet)
189 , xDialogListener ( new ::svt::DialogClosedListener() )
191 pImpl = new OptPath_Impl(get<FixedImage>("lock")->GetImage(),
192 get<FixedText>("editpaths")->GetText());
193 get(m_pStandardBtn, "default");
194 get(m_pPathBtn, "edit");
195 get(m_pPathCtrl, "paths");
197 m_pStandardBtn->SetClickHdl(LINK(this, SvxPathTabPage, StandardHdl_Impl));
198 Link<> aLink = LINK( this, SvxPathTabPage, PathHdl_Impl );
199 m_pPathBtn->SetClickHdl( aLink );
201 Size aControlSize(236 , 147);
202 aControlSize = LogicToPixel(aControlSize, MAP_APPFONT);
203 m_pPathCtrl->set_width_request(aControlSize.Width());
204 m_pPathCtrl->set_height_request(aControlSize.Height());
205 WinBits nBits = WB_SORT | WB_HSCROLL | WB_CLIPCHILDREN | WB_TABSTOP;
206 pPathBox = VclPtr<svx::OptHeaderTabListBox>::Create( *m_pPathCtrl, nBits );
208 HeaderBar &rBar = pPathBox->GetTheHeaderBar();
209 rBar.SetSelectHdl( LINK( this, SvxPathTabPage, HeaderSelect_Impl ) );
210 rBar.SetEndDragHdl( LINK( this, SvxPathTabPage, HeaderEndDrag_Impl ) );
212 rBar.InsertItem( ITEMID_TYPE, get<FixedText>("type")->GetText(),
214 HeaderBarItemBits::LEFT | HeaderBarItemBits::VCENTER | HeaderBarItemBits::CLICKABLE | HeaderBarItemBits::UPARROW );
215 rBar.InsertItem( ITEMID_PATH, get<FixedText>("path")->GetText(),
217 HeaderBarItemBits::LEFT | HeaderBarItemBits::VCENTER );
219 long nWidth1 = rBar.GetTextWidth(rBar.GetItemText(ITEMID_TYPE));
220 long nWidth2 = rBar.GetTextWidth(rBar.GetItemText(ITEMID_PATH));
222 long aTabs[] = {3, 0, 0, 0};
223 aTabs[2] = nWidth1 + 12;
224 aTabs[3] = aTabs[2] + nWidth2 + 12;
225 pPathBox->SetTabs(aTabs, MAP_PIXEL);
227 pPathBox->SetDoubleClickHdl( aLink );
228 pPathBox->SetSelectHdl( LINK( this, SvxPathTabPage, PathSelect_Impl ) );
229 pPathBox->SetSelectionMode( MULTIPLE_SELECTION );
230 pPathBox->SetHighlightRange();
232 xDialogListener->SetDialogClosedLink( LINK( this, SvxPathTabPage, DialogClosedHdl ) );
237 SvxPathTabPage::~SvxPathTabPage()
239 disposeOnce();
242 void SvxPathTabPage::dispose()
244 if ( pPathBox )
246 for ( sal_uInt16 i = 0; i < pPathBox->GetEntryCount(); ++i )
247 delete static_cast<PathUserData_Impl*>(pPathBox->GetEntry(i)->GetUserData());
248 pPathBox.disposeAndClear();
250 delete pImpl;
251 pImpl = NULL;
252 m_pPathCtrl.clear();
253 m_pStandardBtn.clear();
254 m_pPathBtn.clear();
255 SfxTabPage::dispose();
258 VclPtr<SfxTabPage> SvxPathTabPage::Create( vcl::Window* pParent,
259 const SfxItemSet* rAttrSet )
261 return VclPtr<SvxPathTabPage>::Create( pParent, *rAttrSet );
264 bool SvxPathTabPage::FillItemSet( SfxItemSet* )
266 for ( sal_uInt16 i = 0; i < pPathBox->GetEntryCount(); ++i )
268 PathUserData_Impl* pPathImpl = static_cast<PathUserData_Impl*>(pPathBox->GetEntry(i)->GetUserData());
269 sal_uInt16 nRealId = pPathImpl->nRealId;
270 if ( pPathImpl->eState == SfxItemState::SET )
271 SetPathList( nRealId, pPathImpl->sUserPath, pPathImpl->sWritablePath );
273 return true;
278 void SvxPathTabPage::Reset( const SfxItemSet* )
280 pPathBox->Clear();
282 HeaderBar &rBar = pPathBox->GetTheHeaderBar();
283 long nWidth1 = rBar.GetTextWidth(rBar.GetItemText(1));
284 long nWidth2 = rBar.GetTextWidth(rBar.GetItemText(2));
286 for( sal_uInt16 i = 0; i <= (sal_uInt16)SvtPathOptions::PATH_WORK; ++i )
288 // only writer uses autotext
289 if ( i == SvtPathOptions::PATH_AUTOTEXT
290 && !SvtModuleOptions().IsModuleInstalled( SvtModuleOptions::EModule::WRITER ) )
291 continue;
293 switch (i)
295 case SvtPathOptions::PATH_AUTOCORRECT:
296 case SvtPathOptions::PATH_AUTOTEXT:
297 case SvtPathOptions::PATH_BACKUP:
298 case SvtPathOptions::PATH_GALLERY:
299 case SvtPathOptions::PATH_GRAPHIC:
300 case SvtPathOptions::PATH_TEMP:
301 case SvtPathOptions::PATH_TEMPLATE:
302 case SvtPathOptions::PATH_DICTIONARY:
303 #if OSL_DEBUG_LEVEL > 1
304 case SvtPathOptions::PATH_LINGUISTIC:
305 #endif
306 case SvtPathOptions::PATH_WORK:
308 OUString aStr( CUI_RES( RID_SVXSTR_PATH_NAME_START + i ) );
309 nWidth1 = std::max(nWidth1, pPathBox->GetTextWidth(aStr));
310 aStr += "\t";
311 OUString sInternal, sUser, sWritable;
312 bool bReadOnly = false;
313 GetPathList( i, sInternal, sUser, sWritable, bReadOnly );
314 OUString sTmpPath = sUser;
315 if ( !sTmpPath.isEmpty() && !sWritable.isEmpty() )
316 sTmpPath += OUString(MULTIPATH_DELIMITER);
317 sTmpPath += sWritable;
318 OUString aValue( sTmpPath );
319 aValue = Convert_Impl( aValue );
320 nWidth2 = std::max(nWidth2, pPathBox->GetTextWidth(aValue));
321 aStr += aValue;
322 SvTreeListEntry* pEntry = pPathBox->InsertEntry( aStr );
323 if ( bReadOnly )
325 pPathBox->SetCollapsedEntryBmp( pEntry, pImpl->m_aLockImage );
327 PathUserData_Impl* pPathImpl = new PathUserData_Impl(i);
328 pPathImpl->sUserPath = sUser;
329 pPathImpl->sWritablePath = sWritable;
330 pEntry->SetUserData( pPathImpl );
335 long aTabs[] = {3, 0, 0, 0};
336 aTabs[2] = nWidth1 + 12;
337 aTabs[3] = aTabs[2] + nWidth2 + 12;
338 pPathBox->SetTabs(aTabs, MAP_PIXEL);
340 #if 0
341 String aUserData = GetUserData();
342 if ( aUserData.Len() )
344 fprintf(stderr, "FOO\n");
346 // restore column width
347 rBar.SetItemSize( ITEMID_TYPE, aUserData.GetToken(0).ToInt32() );
348 HeaderEndDrag_Impl( &rBar );
349 // restore sort direction
350 sal_Bool bUp = (sal_Bool)(sal_uInt16)aUserData.GetToken(1).ToInt32();
351 HeaderBarItemBits nBits = rBar.GetItemBits(ITEMID_TYPE);
353 if ( bUp )
355 nBits &= ~HeaderBarItemBits::UPARROW;
356 nBits |= HeaderBarItemBits::DOWNARROW;
358 else
360 nBits &= ~HeaderBarItemBits::DOWNARROW;
361 nBits |= HeaderBarItemBits::UPARROW;
363 rBar.SetItemBits( ITEMID_TYPE, nBits );
364 HeaderSelect_Impl( &rBar );
366 #endif
367 PathSelect_Impl( NULL );
372 void SvxPathTabPage::FillUserData()
374 HeaderBar &rBar = pPathBox->GetTheHeaderBar();
376 OUString aUserData = OUString::number( rBar.GetItemSize( ITEMID_TYPE ) ) + ";";
377 HeaderBarItemBits nBits = rBar.GetItemBits( ITEMID_TYPE );
378 bool bUp = ( ( nBits & HeaderBarItemBits::UPARROW ) == HeaderBarItemBits::UPARROW );
379 aUserData += bUp ? OUString("1") : OUString("0");
380 SetUserData( aUserData );
385 IMPL_LINK_NOARG(SvxPathTabPage, PathSelect_Impl)
387 sal_uInt16 nSelCount = 0;
388 SvTreeListEntry* pEntry = pPathBox->FirstSelected();
390 //the entry image indicates whether the path is write protected
391 Image aEntryImage;
392 if(pEntry)
393 aEntryImage = SvTreeListBox::GetCollapsedEntryBmp( pEntry );
394 bool bEnable = !aEntryImage;
395 while ( pEntry && ( nSelCount < 2 ) )
397 nSelCount++;
398 pEntry = pPathBox->NextSelected( pEntry );
401 m_pPathBtn->Enable( 1 == nSelCount && bEnable);
402 m_pStandardBtn->Enable( nSelCount > 0 && bEnable);
403 return 0;
408 IMPL_LINK_NOARG(SvxPathTabPage, StandardHdl_Impl)
410 SvTreeListEntry* pEntry = pPathBox->FirstSelected();
411 while ( pEntry )
413 PathUserData_Impl* pPathImpl = static_cast<PathUserData_Impl*>(pEntry->GetUserData());
414 OUString aOldPath = pImpl->m_aDefOpt.GetDefaultPath( pPathImpl->nRealId );
416 if ( !aOldPath.isEmpty() )
418 OUString sInternal, sUser, sWritable, sTemp;
419 bool bReadOnly = false;
420 GetPathList( pPathImpl->nRealId, sInternal, sUser, sWritable, bReadOnly );
422 sal_uInt16 i;
423 sal_uInt16 nOldCount = comphelper::string::getTokenCount(aOldPath, MULTIPATH_DELIMITER);
424 sal_uInt16 nIntCount = comphelper::string::getTokenCount(sInternal, MULTIPATH_DELIMITER);
425 for ( i = 0; i < nOldCount; ++i )
427 bool bFound = false;
428 OUString sOnePath = aOldPath.getToken( i, MULTIPATH_DELIMITER );
429 for ( sal_uInt16 j = 0; !bFound && j < nIntCount; ++j )
431 if ( sInternal.getToken( i, MULTIPATH_DELIMITER ) == sOnePath )
432 bFound = true;
434 if ( !bFound )
436 if ( !sTemp.isEmpty() )
437 sTemp += OUString(MULTIPATH_DELIMITER);
438 sTemp += sOnePath;
442 OUString sUserPath, sWritablePath;
443 nOldCount = comphelper::string::getTokenCount(sTemp, MULTIPATH_DELIMITER);
444 for ( i = 0; nOldCount > 0 && i < nOldCount - 1; ++i )
446 if ( !sUserPath.isEmpty() )
447 sUserPath += OUString(MULTIPATH_DELIMITER);
448 sUserPath += sTemp.getToken( i, MULTIPATH_DELIMITER );
450 sWritablePath = sTemp.getToken( nOldCount - 1, MULTIPATH_DELIMITER );
452 pPathBox->SetEntryText( Convert_Impl( sTemp ), pEntry, 1 );
453 pPathImpl->eState = SfxItemState::SET;
454 pPathImpl->sUserPath = sUserPath;
455 pPathImpl->sWritablePath = sWritablePath;
457 pEntry = pPathBox->NextSelected( pEntry );
459 return 0;
464 void SvxPathTabPage::ChangeCurrentEntry( const OUString& _rFolder )
466 SvTreeListEntry* pEntry = pPathBox->GetCurEntry();
467 if ( !pEntry )
469 SAL_WARN( "cui.options", "SvxPathTabPage::ChangeCurrentEntry(): no entry" );
470 return;
473 OUString sInternal, sUser, sWritable;
474 PathUserData_Impl* pPathImpl = static_cast<PathUserData_Impl*>(pEntry->GetUserData());
475 bool bReadOnly = false;
476 GetPathList( pPathImpl->nRealId, sInternal, sUser, sWritable, bReadOnly );
477 sUser = pPathImpl->sUserPath;
478 sWritable = pPathImpl->sWritablePath;
479 sal_uInt16 nPos = pPathImpl->nRealId;
481 // old path is an URL?
482 INetURLObject aObj( sWritable );
483 bool bURL = ( aObj.GetProtocol() != INetProtocol::NotValid );
484 OUString aPathStr( _rFolder );
485 INetURLObject aNewObj( aPathStr );
486 aNewObj.removeFinalSlash();
488 // then the new path also an URL else system path
489 OUString sNewPathStr = bURL ? aPathStr : aNewObj.getFSysPath( INetURLObject::FSYS_DETECT );
491 bool bChanged =
492 #ifdef UNX
493 // Unix is case sensitive
494 ( sNewPathStr != sWritable );
495 #else
496 ( !sNewPathStr.equalsIgnoreAsciiCase( sWritable ) );
497 #endif
499 if ( bChanged )
501 pPathBox->SetEntryText( Convert_Impl( sNewPathStr ), pEntry, 1 );
502 nPos = (sal_uInt16)pPathBox->GetModel()->GetAbsPos( pEntry );
503 pPathImpl = static_cast<PathUserData_Impl*>(pPathBox->GetEntry(nPos)->GetUserData());
504 pPathImpl->eState = SfxItemState::SET;
505 pPathImpl->sWritablePath = sNewPathStr;
506 if ( SvtPathOptions::PATH_WORK == pPathImpl->nRealId )
508 // Remove view options entry so the new work path
509 // will be used for the next open dialog.
510 SvtViewOptions aDlgOpt( E_DIALOG, IODLG_CONFIGNAME );
511 aDlgOpt.Delete();
512 // Reset also last used dir in the sfx application instance
513 SfxApplication *pSfxApp = SfxGetpApp();
514 pSfxApp->ResetLastDir();
516 // Set configuration flag to notify file picker that it's necessary
517 // to take over the path provided.
518 std::shared_ptr< comphelper::ConfigurationChanges > batch(
519 comphelper::ConfigurationChanges::create());
520 officecfg::Office::Common::Path::Info::WorkPathChanged::set(
521 true, batch);
522 batch->commit();
529 IMPL_LINK_NOARG(SvxPathTabPage, PathHdl_Impl)
531 SvTreeListEntry* pEntry = pPathBox->GetCurEntry();
532 sal_uInt16 nPos = ( pEntry != NULL ) ? static_cast<PathUserData_Impl*>(pEntry->GetUserData())->nRealId : 0;
533 OUString sInternal, sUser, sWritable;
534 if ( pEntry )
536 PathUserData_Impl* pPathImpl = static_cast<PathUserData_Impl*>(pEntry->GetUserData());
537 bool bReadOnly = false;
538 GetPathList( pPathImpl->nRealId, sInternal, sUser, sWritable, bReadOnly );
539 sUser = pPathImpl->sUserPath;
540 sWritable = pPathImpl->sWritablePath;
543 if(pEntry && !(!SvTreeListBox::GetCollapsedEntryBmp(pEntry)))
544 return 0;
546 if ( IsMultiPath_Impl( nPos ) )
548 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
549 if ( pFact )
551 boost::scoped_ptr<AbstractSvxMultiPathDialog> pMultiDlg(
552 pFact->CreateSvxMultiPathDialog( this ));
553 DBG_ASSERT( pMultiDlg, "Dialog creation failed!" );
555 OUString sPath( sUser );
556 if ( !sPath.isEmpty() )
557 sPath += OUString(MULTIPATH_DELIMITER);
558 sPath += sWritable;
559 pMultiDlg->SetPath( sPath );
561 OUString sPathName = SvTabListBox::GetEntryText( pEntry, 0 );
562 OUString sNewTitle( pImpl->m_sMultiPathDlg );
563 sNewTitle = sNewTitle.replaceFirst( VAR_ONE, sPathName );
564 pMultiDlg->SetTitle( sNewTitle );
566 if ( pMultiDlg->Execute() == RET_OK && pEntry )
568 sUser.clear();
569 sWritable.clear();
570 OUString sFullPath;
571 OUString sNewPath = pMultiDlg->GetPath();
572 char cDelim = MULTIPATH_DELIMITER;
573 sal_uInt16 nCount = comphelper::string::getTokenCount(sNewPath, cDelim);
574 if ( nCount > 0 )
576 sal_uInt16 i = 0;
577 for ( ; i < nCount - 1; ++i )
579 if ( !sUser.isEmpty() )
580 sUser += OUString(cDelim);
581 sUser += sNewPath.getToken( i, cDelim );
583 if ( !sFullPath.isEmpty() )
584 sFullPath += OUString(cDelim);
585 sFullPath += sUser;
586 sWritable += sNewPath.getToken( i, cDelim );
587 if ( !sFullPath.isEmpty() )
588 sFullPath += OUString(cDelim);
589 sFullPath += sWritable;
592 pPathBox->SetEntryText( Convert_Impl( sFullPath ), pEntry, 1 );
593 // save modified flag
594 PathUserData_Impl* pPathImpl = static_cast<PathUserData_Impl*>(pEntry->GetUserData());
595 pPathImpl->eState = SfxItemState::SET;
596 pPathImpl->sUserPath = sUser;
597 pPathImpl->sWritablePath = sWritable;
601 else if ( pEntry )
605 Reference < XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
606 xFolderPicker = FolderPicker::create(xContext);;
608 INetURLObject aURL( sWritable, INetProtocol::File );
609 xFolderPicker->setDisplayDirectory( aURL.GetMainURL( INetURLObject::NO_DECODE ) );
611 Reference< XAsynchronousExecutableDialog > xAsyncDlg( xFolderPicker, UNO_QUERY );
612 if ( xAsyncDlg.is() )
613 xAsyncDlg->startExecuteModal( xDialogListener.get() );
614 else
616 short nRet = xFolderPicker->execute();
617 if ( ExecutableDialogResults::OK != nRet )
618 return 0;
620 OUString sFolder( xFolderPicker->getDirectory() );
621 ChangeCurrentEntry( sFolder );
624 catch( Exception& )
626 SAL_WARN( "cui.options", "SvxPathTabPage::PathHdl_Impl: exception from folder picker" );
629 return 0;
634 IMPL_LINK( SvxPathTabPage, HeaderSelect_Impl, HeaderBar*, pBar )
636 if (!pBar || pBar->GetCurItemId() != ITEMID_TYPE)
637 return 0;
639 HeaderBarItemBits nBits = pBar->GetItemBits(ITEMID_TYPE);
640 bool bUp = ( ( nBits & HeaderBarItemBits::UPARROW ) == HeaderBarItemBits::UPARROW );
641 SvSortMode eMode = SortAscending;
643 if ( bUp )
645 nBits &= ~HeaderBarItemBits::UPARROW;
646 nBits |= HeaderBarItemBits::DOWNARROW;
647 eMode = SortDescending;
649 else
651 nBits &= ~HeaderBarItemBits::DOWNARROW;
652 nBits |= HeaderBarItemBits::UPARROW;
654 pBar->SetItemBits( ITEMID_TYPE, nBits );
655 SvTreeList* pModel = pPathBox->GetModel();
656 pModel->SetSortMode( eMode );
657 pModel->Resort();
658 return 1;
663 IMPL_LINK( SvxPathTabPage, HeaderEndDrag_Impl, HeaderBar*, pBar )
665 if (!pBar || !pBar->GetCurItemId())
666 return 0;
668 if ( !pBar->IsItemMode() )
670 Size aSz;
671 sal_uInt16 nTabs = pBar->GetItemCount();
672 long nTmpSz = 0;
673 long nWidth = pBar->GetItemSize(ITEMID_TYPE);
674 long nBarWidth = pBar->GetSizePixel().Width();
676 if(nWidth < TAB_WIDTH_MIN)
677 pBar->SetItemSize( ITEMID_TYPE, TAB_WIDTH_MIN);
678 else if ( ( nBarWidth - nWidth ) < TAB_WIDTH_MIN )
679 pBar->SetItemSize( ITEMID_TYPE, nBarWidth - TAB_WIDTH_MIN );
681 for ( sal_uInt16 i = 1; i <= nTabs; ++i )
683 long _nWidth = pBar->GetItemSize(i);
684 aSz.Width() = _nWidth + nTmpSz;
685 nTmpSz += _nWidth;
686 pPathBox->SetTab( i, PixelToLogic( aSz, MapMode(MAP_APPFONT) ).Width(), MAP_APPFONT );
689 return 1;
694 IMPL_LINK( SvxPathTabPage, DialogClosedHdl, DialogClosedEvent*, pEvt )
696 if ( RET_OK == pEvt->DialogResult )
698 DBG_ASSERT( xFolderPicker.is(), "SvxPathTabPage::DialogClosedHdl(): no folder picker" );
700 OUString sURL = xFolderPicker->getDirectory();
701 ChangeCurrentEntry( sURL );
703 return 0L;
708 void SvxPathTabPage::GetPathList(
709 sal_uInt16 _nPathHandle, OUString& _rInternalPath,
710 OUString& _rUserPath, OUString& _rWritablePath, bool& _rReadOnly )
712 OUString sCfgName = getCfgName_Impl( _nPathHandle );
716 // load PathSettings service if necessary
717 if ( !pImpl->m_xPathSettings.is() )
719 Reference< XComponentContext > xContext = comphelper::getProcessComponentContext();
720 pImpl->m_xPathSettings = css::util::thePathSettings::get( xContext );
723 // load internal paths
724 OUString sProp( sCfgName );
725 sProp += POSTFIX_INTERNAL;
726 Any aAny = pImpl->m_xPathSettings->getPropertyValue( sProp );
727 Sequence< OUString > aPathSeq;
728 if ( aAny >>= aPathSeq )
730 long i, nCount = aPathSeq.getLength();
731 const OUString* pPaths = aPathSeq.getConstArray();
733 for ( i = 0; i < nCount; ++i )
735 if ( !_rInternalPath.isEmpty() )
736 _rInternalPath += ";";
737 _rInternalPath += pPaths[i];
740 // load user paths
741 sProp = sCfgName;
742 sProp += POSTFIX_USER;
743 aAny = pImpl->m_xPathSettings->getPropertyValue( sProp );
744 if ( aAny >>= aPathSeq )
746 long i, nCount = aPathSeq.getLength();
747 const OUString* pPaths = aPathSeq.getConstArray();
749 for ( i = 0; i < nCount; ++i )
751 if ( !_rUserPath.isEmpty() )
752 _rUserPath += ";";
753 _rUserPath += pPaths[i];
756 // then the writable path
757 sProp = sCfgName;
758 sProp += POSTFIX_WRITABLE;
759 aAny = pImpl->m_xPathSettings->getPropertyValue( sProp );
760 OUString sWritablePath;
761 if ( aAny >>= sWritablePath )
762 _rWritablePath = sWritablePath;
764 // and the readonly flag
765 sProp = sCfgName;
766 Reference< XPropertySetInfo > xInfo = pImpl->m_xPathSettings->getPropertySetInfo();
767 Property aProp = xInfo->getPropertyByName( sProp );
768 _rReadOnly = ( ( aProp.Attributes & PropertyAttribute::READONLY ) == PropertyAttribute::READONLY );
770 catch( const Exception& )
772 OSL_FAIL( "SvxPathTabPage::GetPathList(): caught an exception!" );
778 void SvxPathTabPage::SetPathList(
779 sal_uInt16 _nPathHandle, const OUString& _rUserPath, const OUString& _rWritablePath )
781 OUString sCfgName = getCfgName_Impl( _nPathHandle );
785 // load PathSettings service if necessary
786 if ( !pImpl->m_xPathSettings.is() )
788 Reference< XComponentContext > xContext = comphelper::getProcessComponentContext();
789 pImpl->m_xPathSettings = css::util::thePathSettings::get( xContext );
792 // save user paths
793 char cDelim = MULTIPATH_DELIMITER;
794 sal_uInt16 nCount = comphelper::string::getTokenCount(_rUserPath, cDelim);
795 Sequence< OUString > aPathSeq( nCount );
796 OUString* pArray = aPathSeq.getArray();
797 for ( sal_uInt16 i = 0; i < nCount; ++i )
798 pArray[i] = _rUserPath.getToken( i, cDelim );
799 OUString sProp( sCfgName );
800 sProp += POSTFIX_USER;
801 Any aValue = makeAny( aPathSeq );
802 pImpl->m_xPathSettings->setPropertyValue( sProp, aValue );
804 // then the writable path
805 aValue = makeAny( OUString( _rWritablePath ) );
806 sProp = sCfgName;
807 sProp += POSTFIX_WRITABLE;
808 pImpl->m_xPathSettings->setPropertyValue( sProp, aValue );
810 catch( const Exception& e )
812 SAL_WARN("cui.tabpages", "caught: " << e.Message);
816 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */