LibreOffice Module fpicker (master) 1
SalAquaFolderPicker.mm
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
20#include <com/sun/star/lang/DisposedException.hpp>
21#include <com/sun/star/lang/XMultiServiceFactory.hpp>
22#include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
23#include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
24#include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp>
27#include <osl/diagnose.h>
28#include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
29#include <osl/mutex.hxx>
30#include <sal/log.hxx>
31#include <vcl/svapp.hxx>
33
34#include <iostream>
35
36#include "resourceprovider.hxx"
37
38#include <osl/file.hxx>
41
42#pragma mark DEFINES
43
44using namespace ::com::sun::star;
45using namespace ::com::sun::star::ui::dialogs;
46using namespace ::com::sun::star::lang;
47using namespace ::com::sun::star::uno;
48
50{
52}
53
54// XExecutableDialog
55
56void SAL_CALL SalAquaFolderPicker::setTitle( const OUString& aTitle )
57{
58 SolarMutexGuard aGuard;
59
60 implsetTitle(aTitle);
61}
62
63sal_Int16 SAL_CALL SalAquaFolderPicker::execute()
64{
65 SolarMutexGuard aGuard;
66
67 sal_Int16 retVal = 0;
68
69 int nResult = runandwaitforresult();
70
71 switch( nResult )
72 {
73 case NSModalResponseOK:
74 retVal = ExecutableDialogResults::OK;
75 break;
76
77 case NSModalResponseCancel:
78 retVal = ExecutableDialogResults::CANCEL;
79 break;
80
81 default:
82 throw uno::RuntimeException("The dialog returned with an unknown result!", getXWeak());
83 break;
84 }
85
86 return retVal;
87}
88
89// XFolderPicker
90
91void SAL_CALL SalAquaFolderPicker::setDisplayDirectory( const OUString& aDirectory )
92{
93 SolarMutexGuard aGuard;
94
95 implsetDisplayDirectory(aDirectory);
96}
97
99{
100 SolarMutexGuard aGuard;
101
102 OUString aDirectory = implgetDisplayDirectory();
103
104 return aDirectory;
105}
106
108{
109 SolarMutexGuard aGuard;
110
111 NSArray *files = nil;
113 files = [static_cast<NSOpenPanel*>(m_pDialog) URLs];
114 }
115
116 NSUInteger nFiles = [files count];
117 SAL_INFO("fpicker.aqua", "# of items: " << nFiles);
118
119 if (nFiles < 1) {
120 throw uno::RuntimeException("no directory selected", getXWeak());
121 }
122
123 OUString aDirectory;
124
125 NSURL *url = [files objectAtIndex:0];
126
127 aDirectory = [url OUString];
128
129 implsetDisplayDirectory(aDirectory);
130
131 return aDirectory;
132}
133
134void SAL_CALL SalAquaFolderPicker::setDescription( const OUString& rDescription )
135{
136 [m_pDialog setMessage:[NSString stringWithOUString:rDescription]];
137}
138
139// XServiceInfo
140
142{
143 return "com.sun.star.ui.dialogs.SalAquaFolderPicker";
144}
145
146sal_Bool SAL_CALL SalAquaFolderPicker::supportsService( const OUString& sServiceName )
147{
149}
150
151uno::Sequence<OUString> SAL_CALL SalAquaFolderPicker::getSupportedServiceNames()
152{
153 return { "com.sun.star.ui.dialogs.SystemFolderPicker", "com.sun.star.ui.dialogs.AquaFolderPicker" };
154}
155
156// XCancellable
157
159{
160 SolarMutexGuard aGuard;
161
162 [m_pDialog cancel:nil];
163}
164
165// XEventListener
166
167void SAL_CALL SalAquaFolderPicker::disposing( const lang::EventObject& )
168{
169}
170
171extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
173 css::uno::XComponentContext* , css::uno::Sequence<css::uno::Any> const&)
174{
175 return cppu::acquire(new SalAquaFolderPicker());
176}
177
178
179/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * fpicker_SalAquaFolderPicker_get_implementation(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)
constexpr OUStringLiteral sServiceName
virtual sal_Int16 SAL_CALL execute() override
virtual void SAL_CALL setDescription(const OUString &rDescription) override
virtual OUString SAL_CALL getDisplayDirectory() override
virtual void SAL_CALL setTitle(const OUString &aTitle) override
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual OUString SAL_CALL getDirectory() override
virtual OUString SAL_CALL getImplementationName() override
virtual void SAL_CALL cancel() override
virtual void SAL_CALL disposing(const css::lang::EventObject &aEvent) override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual void SAL_CALL setDisplayDirectory(const OUString &rDirectory) override
OUString const & implgetDisplayDirectory()
@ NAVIGATIONSERVICES_DIRECTORY
int runandwaitforresult()
void implsetTitle(const OUString &aTitle)
NavigationServices_DialogType m_nDialogType
NSSavePanel * m_pDialog
void implsetDisplayDirectory(const OUString &rDirectory)
#define SAL_INFO(area, stream)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
unsigned char sal_Bool