LibreOffice Module fpicker (master) 1
OfficeFolderPicker.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
21
22#include "iodlg.hxx"
23
24#include <vector>
25#include <tools/urlobj.hxx>
27#include <o3tl/make_shared.hxx>
29
30using namespace ::com::sun::star::container;
31using namespace ::com::sun::star::lang;
32using namespace ::com::sun::star::uno;
33using namespace ::com::sun::star::beans;
34
36{
37}
38
40{
41}
42
43void SAL_CALL SvtFolderPicker::setTitle( const OUString& _rTitle )
44{
45 OCommonPicker::setTitle( _rTitle );
46}
47
48sal_Int16 SAL_CALL SvtFolderPicker::execute( )
49{
50 return OCommonPicker::execute();
51}
52
53void SAL_CALL SvtFolderPicker::setDialogTitle( const OUString& _rTitle)
54{
55 setTitle( _rTitle );
56}
57
58void SAL_CALL SvtFolderPicker::startExecuteModal( const Reference< css::ui::dialogs::XDialogClosedListener >& xListener )
59{
60 m_xListener = xListener;
61 prepareDialog();
63
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 });
70}
71
72std::shared_ptr<SvtFileDialog_Base> SvtFolderPicker::implCreateDialog( weld::Window* pParent )
73{
74 return o3tl::make_shared<SvtFileDialog>(pParent, PickerFlags::PathDialog);
75}
76
78{
80
81 // now we are ready to execute the dialog
82 m_xDlg->EnableAutocompletion( false );
83 return m_xDlg->run();
84}
85
87{
88 // set the default directory
89 if ( !m_aDisplayDirectory.isEmpty() )
90 m_xDlg->SetPath( m_aDisplayDirectory );
91 else
92 {
93 // set the default standard dir
94 INetURLObject aStdDirObj( SvtPathOptions().GetWorkPath() );
95 m_xDlg->SetPath( aStdDirObj.GetMainURL( INetURLObject::DecodeMechanism::NONE) );
96 }
97}
98
99void SvtFolderPicker::DialogClosedHdl(sal_Int32 nResult)
100{
101 if ( m_xListener.is() )
102 {
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();
107 }
108}
109
110void SAL_CALL SvtFolderPicker::setDisplayDirectory( const OUString& aDirectory )
111{
112 m_aDisplayDirectory = aDirectory;
113}
114
116{
117 if (!m_xDlg)
118 return m_aDisplayDirectory;
119
120 std::vector<OUString> aPathList(m_xDlg->GetPathList());
121
122 if(!aPathList.empty())
123 return aPathList[0];
124
125 return OUString();
126}
127
129{
130 if (!m_xDlg)
131 return m_aDisplayDirectory;
132
133 std::vector<OUString> aPathList(m_xDlg->GetPathList());
134
135 if(!aPathList.empty())
136 return aPathList[0];
137
138 return OUString();
139}
140
141void SAL_CALL SvtFolderPicker::setDescription( const OUString& )
142{
143}
144
146{
147 OCommonPicker::cancel();
148}
149
150/* XServiceInfo */
152{
153 return "com.sun.star.svtools.OfficeFolderPicker";
154}
155
156/* XServiceInfo */
157sal_Bool SAL_CALL SvtFolderPicker::supportsService( const OUString& sServiceName )
158{
160}
161
162/* XServiceInfo */
163Sequence< OUString > SAL_CALL SvtFolderPicker::getSupportedServiceNames()
164{
165 return { "com.sun.star.ui.dialogs.OfficeFolderPicker" };
166}
167
168extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
170 css::uno::XComponentContext* , css::uno::Sequence<css::uno::Any> const&)
171{
172 return cppu::acquire(new SvtFolderPicker());
173}
174
175/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * fpicker_SvtFolderPicker_get_implementation(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)
constexpr OUStringLiteral sServiceName
AnyEventRef aEvent
OUString GetMainURL(DecodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
void DialogClosedHdl(sal_Int32 nResult)
virtual sal_Int16 implExecutePicker() override
virtual OUString SAL_CALL getDirectory() override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual void SAL_CALL cancel() override
virtual OUString SAL_CALL getImplementationName() override
css::uno::Reference< css::ui::dialogs::XDialogClosedListener > m_xListener
virtual std::shared_ptr< SvtFileDialog_Base > implCreateDialog(weld::Window *pParent) override
virtual void SAL_CALL setDisplayDirectory(const OUString &aDirectory) override
virtual ~SvtFolderPicker() override
virtual void SAL_CALL setTitle(const OUString &_rTitle) override
virtual void SAL_CALL setDialogTitle(const OUString &_rTitle) override
virtual sal_Int16 SAL_CALL execute() override
virtual OUString SAL_CALL getDisplayDirectory() override
virtual void SAL_CALL startExecuteModal(const css::uno::Reference< css::ui::dialogs::XDialogClosedListener > &xListener) override
virtual sal_Bool SAL_CALL supportsService(const OUString &sServiceName) override
virtual void SAL_CALL setDescription(const OUString &aDescription) override
static bool runAsync(const std::shared_ptr< DialogController > &rController, const std::function< void(sal_Int32)> &)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
unsigned char sal_Bool