Bump version to 24.04.3.4
[LibreOffice.git] / fpicker / source / office / OfficeFolderPicker.cxx
blobc941d6cb63c32049e95e447e520eb8f6eeb3bbb8
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 "OfficeFolderPicker.hxx"
22 #include "iodlg.hxx"
24 #include <vector>
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)
55 setTitle( _rTitle );
58 void SAL_CALL SvtFolderPicker::startExecuteModal( const Reference< css::ui::dialogs::XDialogClosedListener >& xListener )
60 m_xListener = xListener;
61 prepareDialog();
62 prepareExecute();
64 m_xDlg->EnableAutocompletion();
65 if (!m_xDlg->PrepareExecute())
66 return;
67 weld::DialogController::runAsync(m_xDlg, [this](sal_Int32 nResult){
68 DialogClosedHdl(nResult);
69 });
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( )
79 prepareExecute();
81 // now we are ready to execute the dialog
82 m_xDlg->EnableAutocompletion( false );
83 return m_xDlg->run();
86 void SvtFolderPicker::prepareExecute()
88 // set the default directory
89 if ( !m_aDisplayDirectory.isEmpty() )
90 m_xDlg->SetPath( m_aDisplayDirectory );
91 else
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 );
106 m_xListener.clear();
110 void SAL_CALL SvtFolderPicker::setDisplayDirectory( const OUString& aDirectory )
112 m_aDisplayDirectory = aDirectory;
115 OUString SAL_CALL SvtFolderPicker::getDisplayDirectory()
117 if (!m_xDlg)
118 return m_aDisplayDirectory;
120 std::vector<OUString> aPathList(m_xDlg->GetPathList());
122 if(!aPathList.empty())
123 return aPathList[0];
125 return OUString();
128 OUString SAL_CALL SvtFolderPicker::getDirectory()
130 if (!m_xDlg)
131 return m_aDisplayDirectory;
133 std::vector<OUString> aPathList(m_xDlg->GetPathList());
135 if(!aPathList.empty())
136 return aPathList[0];
138 return OUString();
141 void SAL_CALL SvtFolderPicker::setDescription( const OUString& )
145 void SvtFolderPicker::cancel()
147 OCommonPicker::cancel();
150 /* XServiceInfo */
151 OUString SAL_CALL SvtFolderPicker::getImplementationName()
153 return "com.sun.star.svtools.OfficeFolderPicker";
156 /* XServiceInfo */
157 sal_Bool SAL_CALL SvtFolderPicker::supportsService( const OUString& sServiceName )
159 return cppu::supportsService(this, sServiceName);
162 /* XServiceInfo */
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: */