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 "OfficeFolderPicker.hxx"
25 #include <tools/urlobj.hxx>
26 #include <com/sun/star/container/XContentEnumerationAccess.hpp>
27 #include <com/sun/star/container/XSet.hpp>
28 #include <com/sun/star/uno/Any.hxx>
29 #include <cppuhelper/factory.hxx>
30 #include <com/sun/star/beans/XPropertySet.hpp>
31 #include <unotools/pathoptions.hxx>
33 using namespace ::com::sun::star::container
;
34 using namespace ::com::sun::star::lang
;
35 using namespace ::com::sun::star::uno
;
36 using namespace ::com::sun::star::beans
;
38 SvtFolderPicker::SvtFolderPicker( const Reference
< XMultiServiceFactory
>& _rxFactory
)
39 :SvtFolderPicker_Base( _rxFactory
)
43 SvtFolderPicker::~SvtFolderPicker()
47 void SAL_CALL
SvtFolderPicker::setTitle( const OUString
& _rTitle
) throw (RuntimeException
)
49 OCommonPicker::setTitle( _rTitle
);
52 sal_Int16 SAL_CALL
SvtFolderPicker::execute( ) throw (RuntimeException
)
54 return OCommonPicker::execute();
57 void SAL_CALL
SvtFolderPicker::setDialogTitle( const OUString
& _rTitle
) throw (RuntimeException
)
62 void SAL_CALL
SvtFolderPicker::startExecuteModal( const Reference
< ::com::sun::star::ui::dialogs::XDialogClosedListener
>& xListener
) throw (RuntimeException
)
64 m_xListener
= xListener
;
67 getDialog()->EnableAutocompletion( sal_True
);
68 getDialog()->StartExecuteModal( LINK( this, SvtFolderPicker
, DialogClosedHdl
) );
71 SvtFileDialog
* SvtFolderPicker::implCreateDialog( Window
* _pParent
)
73 return new SvtFileDialog( _pParent
, SFXWB_PATHDIALOG
);
76 sal_Int16
SvtFolderPicker::implExecutePicker( )
80 // now we are ready to execute the dialog
81 getDialog()->EnableAutocompletion( sal_False
);
82 sal_Int16 nRet
= getDialog()->Execute();
87 void SvtFolderPicker::prepareExecute()
89 // set the default directory
90 if ( !m_aDisplayDirectory
.isEmpty() )
91 getDialog()->SetPath( m_aDisplayDirectory
);
94 // Default-Standard-Dir setzen
95 INetURLObject
aStdDirObj( SvtPathOptions().GetWorkPath() );
96 getDialog()->SetPath( aStdDirObj
.GetMainURL( INetURLObject::NO_DECODE
) );
100 IMPL_LINK( SvtFolderPicker
, DialogClosedHdl
, Dialog
*, pDlg
)
102 if ( m_xListener
.is() )
104 sal_Int16 nRet
= static_cast< sal_Int16
>( pDlg
->GetResult() );
105 ::com::sun::star::ui::dialogs::DialogClosedEvent
aEvent( *this, nRet
);
106 m_xListener
->dialogClosed( aEvent
);
112 void SAL_CALL
SvtFolderPicker::setDisplayDirectory( const OUString
& aDirectory
)
113 throw( IllegalArgumentException
, RuntimeException
)
115 m_aDisplayDirectory
= aDirectory
;
118 OUString SAL_CALL
SvtFolderPicker::getDisplayDirectory() throw( RuntimeException
)
121 return m_aDisplayDirectory
;
123 std::vector
<OUString
> aPathList(getDialog()->GetPathList());
125 if(!aPathList
.empty())
131 OUString SAL_CALL
SvtFolderPicker::getDirectory() throw( RuntimeException
)
134 return m_aDisplayDirectory
;
136 std::vector
<OUString
> aPathList(getDialog()->GetPathList());
138 if(!aPathList
.empty())
144 void SAL_CALL
SvtFolderPicker::setDescription( const OUString
& aDescription
)
145 throw( RuntimeException
)
147 m_aDescription
= aDescription
;
150 void SvtFolderPicker::cancel() throw (RuntimeException
)
152 OCommonPicker::cancel();
156 OUString SAL_CALL
SvtFolderPicker::getImplementationName() throw( RuntimeException
)
158 return impl_getStaticImplementationName();
162 sal_Bool SAL_CALL
SvtFolderPicker::supportsService( const OUString
& sServiceName
) throw( RuntimeException
)
164 Sequence
< OUString
> seqServiceNames
= getSupportedServiceNames();
165 const OUString
* pArray
= seqServiceNames
.getConstArray();
166 for ( sal_Int32 i
= 0; i
< seqServiceNames
.getLength(); i
++ )
168 if ( sServiceName
== pArray
[i
] )
177 Sequence
< OUString
> SAL_CALL
SvtFolderPicker::getSupportedServiceNames() throw( RuntimeException
)
179 return impl_getStaticSupportedServiceNames();
182 /* Helper for XServiceInfo */
183 Sequence
< OUString
> SvtFolderPicker::impl_getStaticSupportedServiceNames()
185 Sequence
< OUString
> seqServiceNames(1);
186 seqServiceNames
[0] = OUString( "com.sun.star.ui.dialogs.OfficeFolderPicker" );
187 return seqServiceNames
;
190 /* Helper for XServiceInfo */
191 OUString
SvtFolderPicker::impl_getStaticImplementationName()
193 return OUString( "com.sun.star.svtools.OfficeFolderPicker" );
196 /* Helper for registry */
197 Reference
< XInterface
> SAL_CALL
SvtFolderPicker::impl_createInstance( const Reference
< XComponentContext
>& rxContext
)
200 Reference
< XMultiServiceFactory
> xServiceManager (rxContext
->getServiceManager(), UNO_QUERY_THROW
);
201 return Reference
< XInterface
>( *new SvtFolderPicker( xServiceManager
) );
204 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */