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 <cppuhelper/supportsservice.hxx>
27 #include <unotools/pathoptions.hxx>
29 using namespace ::com::sun::star::container
;
30 using namespace ::com::sun::star::lang
;
31 using namespace ::com::sun::star::uno
;
32 using namespace ::com::sun::star::beans
;
34 SvtFolderPicker::SvtFolderPicker()
38 SvtFolderPicker::~SvtFolderPicker()
42 void SAL_CALL
SvtFolderPicker::setTitle( const OUString
& _rTitle
)
44 OCommonPicker::setTitle( _rTitle
);
47 sal_Int16 SAL_CALL
SvtFolderPicker::execute( )
49 return OCommonPicker::execute();
52 void SAL_CALL
SvtFolderPicker::setDialogTitle( const OUString
& _rTitle
)
57 void SAL_CALL
SvtFolderPicker::startExecuteModal( const Reference
< css::ui::dialogs::XDialogClosedListener
>& xListener
)
59 m_xListener
= xListener
;
63 m_xDlg
->EnableAutocompletion();
64 if (!m_xDlg
->PrepareExecute())
66 weld::DialogController::runAsync(m_xDlg
, [this](sal_Int32 nResult
){
67 DialogClosedHdl(nResult
);
71 std::unique_ptr
<SvtFileDialog_Base
> SvtFolderPicker::implCreateDialog( weld::Window
* pParent
)
73 return std::make_unique
<SvtFileDialog
>(pParent
, PickerFlags::PathDialog
);
76 sal_Int16
SvtFolderPicker::implExecutePicker( )
80 // now we are ready to execute the dialog
81 m_xDlg
->EnableAutocompletion( false );
85 void SvtFolderPicker::prepareExecute()
87 // set the default directory
88 if ( !m_aDisplayDirectory
.isEmpty() )
89 m_xDlg
->SetPath( m_aDisplayDirectory
);
92 // set the default standard dir
93 INetURLObject
aStdDirObj( SvtPathOptions().GetWorkPath() );
94 m_xDlg
->SetPath( aStdDirObj
.GetMainURL( INetURLObject::DecodeMechanism::NONE
) );
98 void SvtFolderPicker::DialogClosedHdl(sal_Int32 nResult
)
100 if ( m_xListener
.is() )
102 sal_Int16 nRet
= static_cast<sal_Int16
>(nResult
);
103 css::ui::dialogs::DialogClosedEvent
aEvent( *this, nRet
);
104 m_xListener
->dialogClosed( aEvent
);
109 void SAL_CALL
SvtFolderPicker::setDisplayDirectory( const OUString
& aDirectory
)
111 m_aDisplayDirectory
= aDirectory
;
114 OUString SAL_CALL
SvtFolderPicker::getDisplayDirectory()
117 return m_aDisplayDirectory
;
119 std::vector
<OUString
> aPathList(m_xDlg
->GetPathList());
121 if(!aPathList
.empty())
127 OUString SAL_CALL
SvtFolderPicker::getDirectory()
130 return m_aDisplayDirectory
;
132 std::vector
<OUString
> aPathList(m_xDlg
->GetPathList());
134 if(!aPathList
.empty())
140 void SAL_CALL
SvtFolderPicker::setDescription( const OUString
& )
144 void SvtFolderPicker::cancel()
146 OCommonPicker::cancel();
150 OUString SAL_CALL
SvtFolderPicker::getImplementationName()
152 return impl_getStaticImplementationName();
156 sal_Bool SAL_CALL
SvtFolderPicker::supportsService( const OUString
& sServiceName
)
158 return cppu::supportsService(this, sServiceName
);
162 Sequence
< OUString
> SAL_CALL
SvtFolderPicker::getSupportedServiceNames()
164 return impl_getStaticSupportedServiceNames();
167 /* Helper for XServiceInfo */
168 Sequence
< OUString
> SvtFolderPicker::impl_getStaticSupportedServiceNames()
170 Sequence
< OUString
> seqServiceNames
{ "com.sun.star.ui.dialogs.OfficeFolderPicker" };
171 return seqServiceNames
;
174 /* Helper for XServiceInfo */
175 OUString
SvtFolderPicker::impl_getStaticImplementationName()
177 return "com.sun.star.svtools.OfficeFolderPicker";
180 /* Helper for registry */
181 Reference
< XInterface
> SvtFolderPicker::impl_createInstance( const Reference
< XComponentContext
>& )
183 return Reference
< XInterface
>( *new SvtFolderPicker
);
186 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */