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 <o3tl/make_shared.hxx>
28 #include <unotools/pathoptions.hxx>
30 using namespace ::com::sun::star::container
;
31 using namespace ::com::sun::star::lang
;
32 using namespace ::com::sun::star::uno
;
33 using namespace ::com::sun::star::beans
;
35 SvtFolderPicker::SvtFolderPicker()
39 SvtFolderPicker::~SvtFolderPicker()
43 void SAL_CALL
SvtFolderPicker::setTitle( const OUString
& _rTitle
)
45 OCommonPicker::setTitle( _rTitle
);
48 sal_Int16 SAL_CALL
SvtFolderPicker::execute( )
50 return OCommonPicker::execute();
53 void SAL_CALL
SvtFolderPicker::setDialogTitle( const OUString
& _rTitle
)
58 void SAL_CALL
SvtFolderPicker::startExecuteModal( const Reference
< css::ui::dialogs::XDialogClosedListener
>& xListener
)
60 m_xListener
= xListener
;
64 m_xDlg
->EnableAutocompletion();
65 if (!m_xDlg
->PrepareExecute())
67 weld::DialogController::runAsync(m_xDlg
, [this](sal_Int32 nResult
){
68 DialogClosedHdl(nResult
);
72 std::shared_ptr
<SvtFileDialog_Base
> SvtFolderPicker::implCreateDialog( weld::Window
* pParent
)
74 return o3tl::make_shared
<SvtFileDialog
>(pParent
, PickerFlags::PathDialog
);
77 sal_Int16
SvtFolderPicker::implExecutePicker( )
81 // now we are ready to execute the dialog
82 m_xDlg
->EnableAutocompletion( false );
86 void SvtFolderPicker::prepareExecute()
88 // set the default directory
89 if ( !m_aDisplayDirectory
.isEmpty() )
90 m_xDlg
->SetPath( m_aDisplayDirectory
);
93 // set the default standard dir
94 INetURLObject
aStdDirObj( SvtPathOptions().GetWorkPath() );
95 m_xDlg
->SetPath( aStdDirObj
.GetMainURL( INetURLObject::DecodeMechanism::NONE
) );
99 void SvtFolderPicker::DialogClosedHdl(sal_Int32 nResult
)
101 if ( m_xListener
.is() )
103 sal_Int16 nRet
= static_cast<sal_Int16
>(nResult
);
104 css::ui::dialogs::DialogClosedEvent
aEvent( *this, nRet
);
105 m_xListener
->dialogClosed( aEvent
);
110 void SAL_CALL
SvtFolderPicker::setDisplayDirectory( const OUString
& aDirectory
)
112 m_aDisplayDirectory
= aDirectory
;
115 OUString SAL_CALL
SvtFolderPicker::getDisplayDirectory()
118 return m_aDisplayDirectory
;
120 std::vector
<OUString
> aPathList(m_xDlg
->GetPathList());
122 if(!aPathList
.empty())
128 OUString SAL_CALL
SvtFolderPicker::getDirectory()
131 return m_aDisplayDirectory
;
133 std::vector
<OUString
> aPathList(m_xDlg
->GetPathList());
135 if(!aPathList
.empty())
141 void SAL_CALL
SvtFolderPicker::setDescription( const OUString
& )
145 void SvtFolderPicker::cancel()
147 OCommonPicker::cancel();
151 OUString SAL_CALL
SvtFolderPicker::getImplementationName()
153 return "com.sun.star.svtools.OfficeFolderPicker";
157 sal_Bool SAL_CALL
SvtFolderPicker::supportsService( const OUString
& sServiceName
)
159 return cppu::supportsService(this, sServiceName
);
163 Sequence
< OUString
> SAL_CALL
SvtFolderPicker::getSupportedServiceNames()
165 return { "com.sun.star.ui.dialogs.OfficeFolderPicker" };
168 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
169 fpicker_SvtFolderPicker_get_implementation(
170 css::uno::XComponentContext
* , css::uno::Sequence
<css::uno::Any
> const&)
172 return cppu::acquire(new SvtFolderPicker());
175 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */