1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <tools/shl.hxx>
22 #include <vcl/msgbox.hxx>
23 #include <sfx2/filedlghelper.hxx>
24 #include <sfx2/app.hxx>
25 #include <svl/aeitem.hxx>
26 #include <svtools/svtabbx.hxx>
27 #include "svtools/treelistentry.hxx"
28 #include <tools/urlobj.hxx>
29 #include <vcl/svapp.hxx>
30 #include <unotools/defaultoptions.hxx>
31 #include <unotools/localfilehelper.hxx>
32 #include <unotools/pathoptions.hxx>
33 #include <unotools/moduleoptions.hxx>
34 #include <unotools/viewoptions.hxx>
36 #include "optpath.hxx"
37 #include <dialmgr.hxx>
40 #include <comphelper/configuration.hxx>
41 #include <comphelper/processfactory.hxx>
42 #include <comphelper/string.hxx>
43 #include <com/sun/star/uno/Exception.hpp>
44 #include <com/sun/star/beans/XPropertySet.hpp>
45 #include <com/sun/star/beans/PropertyAttribute.hpp>
46 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
47 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
48 #include <com/sun/star/ui/dialogs/XAsynchronousExecutableDialog.hpp>
49 #include <com/sun/star/ui/dialogs/FolderPicker.hpp>
50 #include <com/sun/star/util/PathSettings.hpp>
51 #include <officecfg/Office/Common.hxx>
52 #include "optHeaderTabListbox.hxx"
53 #include <readonlyimage.hxx>
54 #include <vcl/help.hxx>
56 using namespace ::com::sun::star::beans
;
57 using namespace ::com::sun::star::lang
;
58 using namespace ::com::sun::star::ui::dialogs
;
59 using namespace ::com::sun::star::uno
;
62 // define ----------------------------------------------------------------
64 #define TAB_WIDTH_MIN 10
68 #define POSTFIX_INTERNAL OUString("_internal")
69 #define POSTFIX_USER OUString("_user")
70 #define POSTFIX_WRITABLE OUString("_writable")
71 #define VAR_ONE OUString("%1")
72 #define IODLG_CONFIGNAME OUString("FilePicker_Save")
74 // struct OptPath_Impl ---------------------------------------------------
78 SvtDefaultOptions m_aDefOpt
;
80 OUString m_sMultiPathDlg
;
81 Reference
< css::util::XPathSettings
> m_xPathSettings
;
83 OptPath_Impl(const Image
& rLockImage
, const OUString
& rMultiPathDlg
)
84 : m_aLockImage(rLockImage
)
85 , m_sMultiPathDlg(rMultiPathDlg
)
90 // struct PathUserData_Impl ----------------------------------------------
92 struct PathUserData_Impl
99 PathUserData_Impl( sal_uInt16 nId
) :
100 nRealId( nId
), eState( SFX_ITEM_UNKNOWN
) {}
103 struct Handle2CfgNameMapping_Impl
105 sal_uInt16 m_nHandle
;
106 const char* m_pCfgName
;
109 static Handle2CfgNameMapping_Impl
const Hdl2CfgMap_Impl
[] =
111 { SvtPathOptions::PATH_AUTOCORRECT
, "AutoCorrect" },
112 { SvtPathOptions::PATH_AUTOTEXT
, "AutoText" },
113 { SvtPathOptions::PATH_BACKUP
, "Backup" },
114 { SvtPathOptions::PATH_GALLERY
, "Gallery" },
115 { SvtPathOptions::PATH_GRAPHIC
, "Graphic" },
116 { SvtPathOptions::PATH_TEMP
, "Temp" },
117 { SvtPathOptions::PATH_TEMPLATE
, "Template" },
118 { SvtPathOptions::PATH_WORK
, "Work" },
119 { SvtPathOptions::PATH_DICTIONARY
, "Dictionary" },
120 #if OSL_DEBUG_LEVEL > 1
121 { SvtPathOptions::PATH_LINGUISTIC
, "Linguistic" },
126 static String
getCfgName_Impl( sal_uInt16 _nHandle
)
129 sal_uInt16 nIndex
= 0;
130 while ( Hdl2CfgMap_Impl
[ nIndex
].m_nHandle
!= USHRT_MAX
)
132 if ( Hdl2CfgMap_Impl
[ nIndex
].m_nHandle
== _nHandle
)
135 sCfgName
= OUString::createFromAscii( Hdl2CfgMap_Impl
[ nIndex
].m_pCfgName
);
144 #define MULTIPATH_DELIMITER ';'
146 String
Convert_Impl( const String
& rValue
)
148 char cDelim
= MULTIPATH_DELIMITER
;
149 sal_uInt16 nCount
= comphelper::string::getTokenCount(rValue
, cDelim
);
151 for ( sal_uInt16 i
=0; i
<nCount
; ++i
)
153 String aValue
= rValue
.GetToken( i
, cDelim
);
154 INetURLObject
aObj( aValue
);
155 if ( aObj
.GetProtocol() == INET_PROT_FILE
)
156 aReturn
+= String(aObj
.PathToFileName());
157 else if ( ::utl::LocalFileHelper::IsFileContent( aValue
) )
158 aReturn
+= String(aObj
.GetURLPath( INetURLObject::DECODE_WITH_CHARSET
));
160 aReturn
+= MULTIPATH_DELIMITER
;
166 // class SvxControlFocusHelper ---------------------------------------------
168 long SvxControlFocusHelper::Notify( NotifyEvent
& rNEvt
)
170 long nRet
= Control::Notify( rNEvt
);
172 if ( m_pFocusCtrl
&& rNEvt
.GetWindow() != m_pFocusCtrl
&& rNEvt
.GetType() == EVENT_GETFOCUS
)
173 m_pFocusCtrl
->GrabFocus();
177 // functions -------------------------------------------------------------
179 sal_Bool
IsMultiPath_Impl( const sal_uInt16 nIndex
)
181 #if OSL_DEBUG_LEVEL > 1
182 return ( SvtPathOptions::PATH_AUTOCORRECT
== nIndex
||
183 SvtPathOptions::PATH_AUTOTEXT
== nIndex
||
184 SvtPathOptions::PATH_BASIC
== nIndex
||
185 SvtPathOptions::PATH_GALLERY
== nIndex
||
186 SvtPathOptions::PATH_TEMPLATE
== nIndex
);
188 return ( SvtPathOptions::PATH_AUTOCORRECT
== nIndex
||
189 SvtPathOptions::PATH_AUTOTEXT
== nIndex
||
190 SvtPathOptions::PATH_BASIC
== nIndex
||
191 SvtPathOptions::PATH_GALLERY
== nIndex
||
192 SvtPathOptions::PATH_TEMPLATE
== nIndex
||
193 SvtPathOptions::PATH_LINGUISTIC
== nIndex
||
194 SvtPathOptions::PATH_DICTIONARY
== nIndex
);
198 // class SvxPathTabPage --------------------------------------------------
200 SvxPathTabPage::SvxPathTabPage(Window
* pParent
, const SfxItemSet
& rSet
)
201 :SfxTabPage( pParent
, "OptPathsPage", "cui/ui/optpathspage.ui", rSet
)
202 , xDialogListener ( new ::svt::DialogClosedListener() )
204 pImpl
= new OptPath_Impl(get
<FixedImage
>("lock")->GetImage(),
205 get
<FixedText
>("editpaths")->GetText());
206 get(m_pStandardBtn
, "default");
207 get(m_pPathBtn
, "edit");
208 get(m_pPathCtrl
, "paths");
210 m_pStandardBtn
->SetClickHdl(LINK(this, SvxPathTabPage
, StandardHdl_Impl
));
211 Link aLink
= LINK( this, SvxPathTabPage
, PathHdl_Impl
);
212 m_pPathBtn
->SetClickHdl( aLink
);
214 Size
aControlSize(236 , 147);
215 aControlSize
= LogicToPixel(aControlSize
, MAP_APPFONT
);
216 m_pPathCtrl
->set_width_request(aControlSize
.Width());
217 m_pPathCtrl
->set_height_request(aControlSize
.Height());
218 WinBits nBits
= WB_SORT
| WB_HSCROLL
| WB_CLIPCHILDREN
| WB_TABSTOP
;
219 pPathBox
= new svx::OptHeaderTabListBox( *m_pPathCtrl
, nBits
);
221 HeaderBar
&rBar
= pPathBox
->GetTheHeaderBar();
222 rBar
.SetSelectHdl( LINK( this, SvxPathTabPage
, HeaderSelect_Impl
) );
223 rBar
.SetEndDragHdl( LINK( this, SvxPathTabPage
, HeaderEndDrag_Impl
) );
225 rBar
.InsertItem( ITEMID_TYPE
, get
<FixedText
>("type")->GetText(),
227 HIB_LEFT
| HIB_VCENTER
| HIB_CLICKABLE
| HIB_UPARROW
);
228 rBar
.InsertItem( ITEMID_PATH
, get
<FixedText
>("path")->GetText(),
230 HIB_LEFT
| HIB_VCENTER
);
232 long nWidth1
= rBar
.GetTextWidth(rBar
.GetItemText(1));
233 long nWidth2
= rBar
.GetTextWidth(rBar
.GetItemText(2));
235 long aTabs
[] = {3, 0, 0, 0};
236 aTabs
[2] = nWidth1
+ 12;
237 aTabs
[3] = aTabs
[2] + nWidth2
+ 12;
238 pPathBox
->SetTabs(aTabs
, MAP_PIXEL
);
240 pPathBox
->SetDoubleClickHdl( aLink
);
241 pPathBox
->SetSelectHdl( LINK( this, SvxPathTabPage
, PathSelect_Impl
) );
242 pPathBox
->SetSelectionMode( MULTIPLE_SELECTION
);
243 pPathBox
->SetHighlightRange();
245 xDialogListener
->SetDialogClosedLink( LINK( this, SvxPathTabPage
, DialogClosedHdl
) );
248 // -----------------------------------------------------------------------
250 SvxPathTabPage::~SvxPathTabPage()
252 for ( sal_uInt16 i
= 0; i
< pPathBox
->GetEntryCount(); ++i
)
253 delete (PathUserData_Impl
*)pPathBox
->GetEntry(i
)->GetUserData();
258 // -----------------------------------------------------------------------
260 SfxTabPage
* SvxPathTabPage::Create( Window
* pParent
,
261 const SfxItemSet
& rAttrSet
)
263 return ( new SvxPathTabPage( pParent
, rAttrSet
) );
266 // -----------------------------------------------------------------------
268 sal_Bool
SvxPathTabPage::FillItemSet( SfxItemSet
& )
270 for ( sal_uInt16 i
= 0; i
< pPathBox
->GetEntryCount(); ++i
)
272 PathUserData_Impl
* pPathImpl
= (PathUserData_Impl
*)pPathBox
->GetEntry(i
)->GetUserData();
273 sal_uInt16 nRealId
= pPathImpl
->nRealId
;
274 if ( pPathImpl
->eState
== SFX_ITEM_SET
)
275 SetPathList( nRealId
, pPathImpl
->sUserPath
, pPathImpl
->sWritablePath
);
280 // -----------------------------------------------------------------------
282 void SvxPathTabPage::Reset( const SfxItemSet
& )
286 HeaderBar
&rBar
= pPathBox
->GetTheHeaderBar();
287 long nWidth1
= rBar
.GetTextWidth(rBar
.GetItemText(1));
288 long nWidth2
= rBar
.GetTextWidth(rBar
.GetItemText(2));
290 for( sal_uInt16 i
= 0; i
<= (sal_uInt16
)SvtPathOptions::PATH_WORK
; ++i
)
292 // only writer uses autotext
293 if ( i
== SvtPathOptions::PATH_AUTOTEXT
294 && !SvtModuleOptions().IsModuleInstalled( SvtModuleOptions::E_SWRITER
) )
299 case SvtPathOptions::PATH_AUTOCORRECT
:
300 case SvtPathOptions::PATH_AUTOTEXT
:
301 case SvtPathOptions::PATH_BACKUP
:
302 case SvtPathOptions::PATH_GALLERY
:
303 case SvtPathOptions::PATH_GRAPHIC
:
304 case SvtPathOptions::PATH_TEMP
:
305 case SvtPathOptions::PATH_TEMPLATE
:
306 case SvtPathOptions::PATH_DICTIONARY
:
307 #if OSL_DEBUG_LEVEL > 1
308 case SvtPathOptions::PATH_LINGUISTIC
:
310 case SvtPathOptions::PATH_WORK
:
312 String
aStr( CUI_RES( RID_SVXSTR_PATH_NAME_START
+ i
) );
313 nWidth1
= std::max(nWidth1
, pPathBox
->GetTextWidth(aStr
));
315 String sInternal
, sUser
, sWritable
;
316 sal_Bool bReadOnly
= sal_False
;
317 GetPathList( i
, sInternal
, sUser
, sWritable
, bReadOnly
);
318 String sTmpPath
= sUser
;
319 if ( sTmpPath
.Len() > 0 && sWritable
.Len() > 0 )
320 sTmpPath
+= MULTIPATH_DELIMITER
;
321 sTmpPath
+= sWritable
;
322 String
aValue( sTmpPath
);
323 aValue
= Convert_Impl( aValue
);
324 nWidth2
= std::max(nWidth2
, pPathBox
->GetTextWidth(aValue
));
326 SvTreeListEntry
* pEntry
= pPathBox
->InsertEntry( aStr
);
329 pPathBox
->SetCollapsedEntryBmp( pEntry
, pImpl
->m_aLockImage
);
331 PathUserData_Impl
* pPathImpl
= new PathUserData_Impl(i
);
332 pPathImpl
->sUserPath
= sUser
;
333 pPathImpl
->sWritablePath
= sWritable
;
334 pEntry
->SetUserData( pPathImpl
);
339 long aTabs
[] = {3, 0, 0, 0};
340 aTabs
[2] = nWidth1
+ 12;
341 aTabs
[3] = aTabs
[2] + nWidth2
+ 12;
342 pPathBox
->SetTabs(aTabs
, MAP_PIXEL
);
345 String aUserData
= GetUserData();
346 if ( aUserData
.Len() )
348 fprintf(stderr
, "FOO\n");
350 // restore column width
351 rBar
.SetItemSize( ITEMID_TYPE
, aUserData
.GetToken(0).ToInt32() );
352 HeaderEndDrag_Impl( &rBar
);
353 // restore sort direction
354 sal_Bool bUp
= (sal_Bool
)(sal_uInt16
)aUserData
.GetToken(1).ToInt32();
355 HeaderBarItemBits nBits
= rBar
.GetItemBits(ITEMID_TYPE
);
359 nBits
&= ~HIB_UPARROW
;
360 nBits
|= HIB_DOWNARROW
;
364 nBits
&= ~HIB_DOWNARROW
;
365 nBits
|= HIB_UPARROW
;
367 rBar
.SetItemBits( ITEMID_TYPE
, nBits
);
368 HeaderSelect_Impl( &rBar
);
371 PathSelect_Impl( NULL
);
374 // -----------------------------------------------------------------------
376 void SvxPathTabPage::FillUserData()
378 HeaderBar
&rBar
= pPathBox
->GetTheHeaderBar();
380 String aUserData
= OUString::number( rBar
.GetItemSize( ITEMID_TYPE
) ) + ";";
381 HeaderBarItemBits nBits
= rBar
.GetItemBits( ITEMID_TYPE
);
382 sal_Bool bUp
= ( ( nBits
& HIB_UPARROW
) == HIB_UPARROW
);
383 aUserData
+= bUp
? '1' : '0';
384 SetUserData( aUserData
);
387 // -----------------------------------------------------------------------
389 IMPL_LINK_NOARG(SvxPathTabPage
, PathSelect_Impl
)
391 sal_uInt16 nSelCount
= 0;
392 SvTreeListEntry
* pEntry
= pPathBox
->FirstSelected();
394 //the entry image indicates whether the path is write protected
397 aEntryImage
= pPathBox
->GetCollapsedEntryBmp( pEntry
);
398 sal_Bool bEnable
= !aEntryImage
;
399 while ( pEntry
&& ( nSelCount
< 2 ) )
402 pEntry
= pPathBox
->NextSelected( pEntry
);
405 m_pPathBtn
->Enable( 1 == nSelCount
&& bEnable
);
406 m_pStandardBtn
->Enable( nSelCount
> 0 && bEnable
);
410 // -----------------------------------------------------------------------
412 IMPL_LINK_NOARG(SvxPathTabPage
, StandardHdl_Impl
)
414 SvTreeListEntry
* pEntry
= pPathBox
->FirstSelected();
417 PathUserData_Impl
* pPathImpl
= (PathUserData_Impl
*)pEntry
->GetUserData();
418 String aOldPath
= pImpl
->m_aDefOpt
.GetDefaultPath( pPathImpl
->nRealId
);
420 if ( aOldPath
.Len() )
422 String sInternal
, sUser
, sWritable
, sTemp
;
423 sal_Bool bReadOnly
= sal_False
;
424 GetPathList( pPathImpl
->nRealId
, sInternal
, sUser
, sWritable
, bReadOnly
);
427 sal_uInt16 nOldCount
= comphelper::string::getTokenCount(aOldPath
, MULTIPATH_DELIMITER
);
428 sal_uInt16 nIntCount
= comphelper::string::getTokenCount(sInternal
, MULTIPATH_DELIMITER
);
429 for ( i
= 0; i
< nOldCount
; ++i
)
432 String sOnePath
= aOldPath
.GetToken( i
, MULTIPATH_DELIMITER
);
433 for ( sal_uInt16 j
= 0; !bFound
&& j
< nIntCount
; ++j
)
435 if ( sInternal
.GetToken( i
, MULTIPATH_DELIMITER
) == sOnePath
)
440 if ( sTemp
.Len() > 0 )
441 sTemp
+= MULTIPATH_DELIMITER
;
446 String sUserPath
, sWritablePath
;
447 nOldCount
= comphelper::string::getTokenCount(sTemp
, MULTIPATH_DELIMITER
);
448 for ( i
= 0; nOldCount
> 0 && i
< nOldCount
- 1; ++i
)
450 if ( sUserPath
.Len() > 0 )
451 sUserPath
+= MULTIPATH_DELIMITER
;
452 sUserPath
+= sTemp
.GetToken( i
, MULTIPATH_DELIMITER
);
454 sWritablePath
= sTemp
.GetToken( nOldCount
- 1, MULTIPATH_DELIMITER
);
456 pPathBox
->SetEntryText( Convert_Impl( sTemp
), pEntry
, 1 );
457 pPathImpl
->eState
= SFX_ITEM_SET
;
458 pPathImpl
->sUserPath
= sUserPath
;
459 pPathImpl
->sWritablePath
= sWritablePath
;
461 pEntry
= pPathBox
->NextSelected( pEntry
);
466 // -----------------------------------------------------------------------
468 void SvxPathTabPage::ChangeCurrentEntry( const String
& _rFolder
)
470 SvTreeListEntry
* pEntry
= pPathBox
->GetCurEntry();
473 SAL_WARN( "cui.options", "SvxPathTabPage::ChangeCurrentEntry(): no entry" );
477 String sInternal
, sUser
, sWritable
;
478 PathUserData_Impl
* pPathImpl
= (PathUserData_Impl
*)pEntry
->GetUserData();
479 sal_Bool bReadOnly
= sal_False
;
480 GetPathList( pPathImpl
->nRealId
, sInternal
, sUser
, sWritable
, bReadOnly
);
481 sUser
= pPathImpl
->sUserPath
;
482 sWritable
= pPathImpl
->sWritablePath
;
483 sal_uInt16 nPos
= pPathImpl
->nRealId
;
485 // old path is an URL?
486 INetURLObject
aObj( sWritable
);
487 bool bURL
= ( aObj
.GetProtocol() != INET_PROT_NOT_VALID
);
488 OUString
aPathStr( _rFolder
);
489 INetURLObject
aNewObj( aPathStr
);
490 aNewObj
.removeFinalSlash();
492 // then the new path also an URL else system path
493 String sNewPathStr
= bURL
? aPathStr
: aNewObj
.getFSysPath( INetURLObject::FSYS_DETECT
);
497 // Unix is case sensitive
498 ( sNewPathStr
!= sWritable
);
500 ( sNewPathStr
.CompareIgnoreCaseToAscii( sWritable
) != COMPARE_EQUAL
);
505 pPathBox
->SetEntryText( Convert_Impl( sNewPathStr
), pEntry
, 1 );
506 nPos
= (sal_uInt16
)pPathBox
->GetModel()->GetAbsPos( pEntry
);
507 pPathImpl
= (PathUserData_Impl
*)pPathBox
->GetEntry(nPos
)->GetUserData();
508 pPathImpl
->eState
= SFX_ITEM_SET
;
509 pPathImpl
->sWritablePath
= sNewPathStr
;
510 if ( SvtPathOptions::PATH_WORK
== pPathImpl
->nRealId
)
512 // Remove view options entry so the new work path
513 // will be used for the next open dialog.
514 SvtViewOptions
aDlgOpt( E_DIALOG
, IODLG_CONFIGNAME
);
516 // Reset also last used dir in the sfx application instance
517 SfxApplication
*pSfxApp
= SFX_APP();
518 pSfxApp
->ResetLastDir();
520 // Set configuration flag to notify file picker that it's necessary
521 // to take over the path provided.
522 boost::shared_ptr
< comphelper::ConfigurationChanges
> batch(
523 comphelper::ConfigurationChanges::create());
524 officecfg::Office::Common::Path::Info::WorkPathChanged::set(
531 // -----------------------------------------------------------------------
533 IMPL_LINK_NOARG(SvxPathTabPage
, PathHdl_Impl
)
535 SvTreeListEntry
* pEntry
= pPathBox
->GetCurEntry();
536 sal_uInt16 nPos
= ( pEntry
!= NULL
) ? ( (PathUserData_Impl
*)pEntry
->GetUserData() )->nRealId
: 0;
537 String sInternal
, sUser
, sWritable
;
540 PathUserData_Impl
* pPathImpl
= (PathUserData_Impl
*)pEntry
->GetUserData();
541 sal_Bool bReadOnly
= sal_False
;
542 GetPathList( pPathImpl
->nRealId
, sInternal
, sUser
, sWritable
, bReadOnly
);
543 sUser
= pPathImpl
->sUserPath
;
544 sWritable
= pPathImpl
->sWritablePath
;
547 if(pEntry
&& !(!((OptHeaderTabListBox
*)pPathBox
)->GetCollapsedEntryBmp(pEntry
)))
550 if ( IsMultiPath_Impl( nPos
) )
552 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
555 AbstractSvxMultiPathDialog
* pMultiDlg
=
556 pFact
->CreateSvxMultiPathDialog( this );
557 DBG_ASSERT( pMultiDlg
, "Dialogdiet fail!" );
558 pMultiDlg
->EnableRadioButtonMode();
560 String
sPath( sUser
);
561 if ( sPath
.Len() > 0 )
562 sPath
+= MULTIPATH_DELIMITER
;
564 pMultiDlg
->SetPath( sPath
);
566 String sPathName
= pPathBox
->GetEntryText( pEntry
, 0 );
567 String
sNewTitle( pImpl
->m_sMultiPathDlg
);
568 sNewTitle
.SearchAndReplace( VAR_ONE
, sPathName
);
569 pMultiDlg
->SetTitle( sNewTitle
);
571 if ( pMultiDlg
->Execute() == RET_OK
&& pEntry
)
576 String sNewPath
= pMultiDlg
->GetPath();
577 char cDelim
= MULTIPATH_DELIMITER
;
578 sal_uInt16 nCount
= comphelper::string::getTokenCount(sNewPath
, cDelim
);
582 for ( ; i
< nCount
- 1; ++i
)
584 if ( sUser
.Len() > 0 )
586 sUser
+= sNewPath
.GetToken( i
, cDelim
);
588 if ( sFullPath
.Len() > 0 )
591 sWritable
+= sNewPath
.GetToken( i
, cDelim
);
592 if ( sFullPath
.Len() > 0 )
594 sFullPath
+= sWritable
;
597 pPathBox
->SetEntryText( Convert_Impl( sFullPath
), pEntry
, 1 );
598 // save modified flag
599 PathUserData_Impl
* pPathImpl
= (PathUserData_Impl
*)pEntry
->GetUserData();
600 pPathImpl
->eState
= SFX_ITEM_SET
;
601 pPathImpl
->sUserPath
= sUser
;
602 pPathImpl
->sWritablePath
= sWritable
;
611 Reference
< XComponentContext
> xContext( ::comphelper::getProcessComponentContext() );
612 xFolderPicker
= FolderPicker::create(xContext
);;
614 INetURLObject
aURL( sWritable
, INET_PROT_FILE
);
615 xFolderPicker
->setDisplayDirectory( aURL
.GetMainURL( INetURLObject::NO_DECODE
) );
617 Reference
< XAsynchronousExecutableDialog
> xAsyncDlg( xFolderPicker
, UNO_QUERY
);
618 if ( xAsyncDlg
.is() )
619 xAsyncDlg
->startExecuteModal( xDialogListener
.get() );
622 short nRet
= xFolderPicker
->execute();
623 if ( ExecutableDialogResults::OK
!= nRet
)
626 String
sFolder( xFolderPicker
->getDirectory() );
627 ChangeCurrentEntry( sFolder
);
632 SAL_WARN( "cui.options", "SvxPathTabPage::PathHdl_Impl: exception from folder picker" );
638 // -----------------------------------------------------------------------
640 IMPL_LINK( SvxPathTabPage
, HeaderSelect_Impl
, HeaderBar
*, pBar
)
642 if ( pBar
&& pBar
->GetCurItemId() != ITEMID_TYPE
)
645 HeaderBarItemBits nBits
= pBar
->GetItemBits(ITEMID_TYPE
);
646 sal_Bool bUp
= ( ( nBits
& HIB_UPARROW
) == HIB_UPARROW
);
647 SvSortMode eMode
= SortAscending
;
651 nBits
&= ~HIB_UPARROW
;
652 nBits
|= HIB_DOWNARROW
;
653 eMode
= SortDescending
;
657 nBits
&= ~HIB_DOWNARROW
;
658 nBits
|= HIB_UPARROW
;
660 pBar
->SetItemBits( ITEMID_TYPE
, nBits
);
661 SvTreeList
* pModel
= pPathBox
->GetModel();
662 pModel
->SetSortMode( eMode
);
667 // -----------------------------------------------------------------------
669 IMPL_LINK( SvxPathTabPage
, HeaderEndDrag_Impl
, HeaderBar
*, pBar
)
671 if ( pBar
&& !pBar
->GetCurItemId() )
674 if ( !pBar
->IsItemMode() )
677 sal_uInt16 nTabs
= pBar
->GetItemCount();
679 long nWidth
= pBar
->GetItemSize(ITEMID_TYPE
);
680 long nBarWidth
= pBar
->GetSizePixel().Width();
682 if(nWidth
< TAB_WIDTH_MIN
)
683 pBar
->SetItemSize( ITEMID_TYPE
, TAB_WIDTH_MIN
);
684 else if ( ( nBarWidth
- nWidth
) < TAB_WIDTH_MIN
)
685 pBar
->SetItemSize( ITEMID_TYPE
, nBarWidth
- TAB_WIDTH_MIN
);
687 for ( sal_uInt16 i
= 1; i
<= nTabs
; ++i
)
689 long _nWidth
= pBar
->GetItemSize(i
);
690 aSz
.Width() = _nWidth
+ nTmpSz
;
692 pPathBox
->SetTab( i
, PixelToLogic( aSz
, MapMode(MAP_APPFONT
) ).Width(), MAP_APPFONT
);
698 // -----------------------------------------------------------------------
700 IMPL_LINK( SvxPathTabPage
, DialogClosedHdl
, DialogClosedEvent
*, pEvt
)
702 if ( RET_OK
== pEvt
->DialogResult
)
704 DBG_ASSERT( xFolderPicker
.is() == sal_True
, "SvxPathTabPage::DialogClosedHdl(): no folder picker" );
706 String sURL
= String( xFolderPicker
->getDirectory() );
707 ChangeCurrentEntry( sURL
);
712 // -----------------------------------------------------------------------
714 void SvxPathTabPage::GetPathList(
715 sal_uInt16 _nPathHandle
, String
& _rInternalPath
,
716 String
& _rUserPath
, String
& _rWritablePath
, sal_Bool
& _rReadOnly
)
718 String sCfgName
= getCfgName_Impl( _nPathHandle
);
722 // load PathSettings service if necessary
723 if ( !pImpl
->m_xPathSettings
.is() )
725 Reference
< XComponentContext
> xContext
= comphelper::getProcessComponentContext();
726 pImpl
->m_xPathSettings
= css::util::PathSettings::create( xContext
);
729 // load internal paths
730 String
sProp( sCfgName
);
731 sProp
+= POSTFIX_INTERNAL
;
732 Any aAny
= pImpl
->m_xPathSettings
->getPropertyValue( sProp
);
733 Sequence
< OUString
> aPathSeq
;
734 if ( aAny
>>= aPathSeq
)
736 long i
, nCount
= aPathSeq
.getLength();
737 const OUString
* pPaths
= aPathSeq
.getConstArray();
739 for ( i
= 0; i
< nCount
; ++i
)
741 if ( _rInternalPath
.Len() > 0 )
742 _rInternalPath
+= ';';
743 _rInternalPath
+= String( pPaths
[i
] );
748 sProp
+= POSTFIX_USER
;
749 aAny
= pImpl
->m_xPathSettings
->getPropertyValue( sProp
);
750 if ( aAny
>>= aPathSeq
)
752 long i
, nCount
= aPathSeq
.getLength();
753 const OUString
* pPaths
= aPathSeq
.getConstArray();
755 for ( i
= 0; i
< nCount
; ++i
)
757 if ( _rUserPath
.Len() > 0 )
759 _rUserPath
+= String( pPaths
[i
] );
762 // then the writable path
764 sProp
+= POSTFIX_WRITABLE
;
765 aAny
= pImpl
->m_xPathSettings
->getPropertyValue( sProp
);
766 OUString sWritablePath
;
767 if ( aAny
>>= sWritablePath
)
768 _rWritablePath
= String( sWritablePath
);
770 // and the readonly flag
772 Reference
< XPropertySetInfo
> xInfo
= pImpl
->m_xPathSettings
->getPropertySetInfo();
773 Property aProp
= xInfo
->getPropertyByName( sProp
);
774 _rReadOnly
= ( ( aProp
.Attributes
& PropertyAttribute::READONLY
) == PropertyAttribute::READONLY
);
776 catch( const Exception
& )
778 OSL_FAIL( "SvxPathTabPage::GetPathList(): caught an exception!" );
782 // -----------------------------------------------------------------------
784 void SvxPathTabPage::SetPathList(
785 sal_uInt16 _nPathHandle
, const String
& _rUserPath
, const String
& _rWritablePath
)
787 String sCfgName
= getCfgName_Impl( _nPathHandle
);
791 // load PathSettings service if necessary
792 if ( !pImpl
->m_xPathSettings
.is() )
794 Reference
< XComponentContext
> xContext
= comphelper::getProcessComponentContext();
795 pImpl
->m_xPathSettings
= css::util::PathSettings::create( xContext
);
799 char cDelim
= MULTIPATH_DELIMITER
;
800 sal_uInt16 nCount
= comphelper::string::getTokenCount(_rUserPath
, cDelim
);
801 Sequence
< OUString
> aPathSeq( nCount
);
802 OUString
* pArray
= aPathSeq
.getArray();
803 for ( sal_uInt16 i
= 0; i
< nCount
; ++i
)
804 pArray
[i
] = OUString( _rUserPath
.GetToken( i
, cDelim
) );
805 String
sProp( sCfgName
);
806 sProp
+= POSTFIX_USER
;
807 Any aValue
= makeAny( aPathSeq
);
808 pImpl
->m_xPathSettings
->setPropertyValue( sProp
, aValue
);
810 // then the writable path
811 aValue
= makeAny( OUString( _rWritablePath
) );
813 sProp
+= POSTFIX_WRITABLE
;
814 pImpl
->m_xPathSettings
->setPropertyValue( sProp
, aValue
);
816 catch( const Exception
& e
)
818 SAL_WARN("cui.tabpages", "caught: " << e
.Message
);
822 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */