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 <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>
25 #include <cppuhelper/interfacecontainer.h>
26 #include <cppuhelper/supportsservice.hxx>
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>
32 #include "SalAquaFolderPicker.hxx"
36 #include "resourceprovider.hxx"
38 #include <osl/file.hxx>
39 #include "NSString_OOoAdditions.hxx"
40 #include "NSURL_OOoAdditions.hxx"
44 using namespace ::com::sun::star;
45 using namespace ::com::sun::star::ui::dialogs;
46 using namespace ::com::sun::star::lang;
47 using namespace ::com::sun::star::uno;
49 SalAquaFolderPicker::SalAquaFolderPicker()
51 m_nDialogType = NAVIGATIONSERVICES_DIRECTORY;
56 void SAL_CALL SalAquaFolderPicker::setTitle( const OUString& aTitle )
58 SolarMutexGuard aGuard;
63 sal_Int16 SAL_CALL SalAquaFolderPicker::execute()
65 SolarMutexGuard aGuard;
69 int nResult = runandwaitforresult();
73 case NSModalResponseOK:
74 retVal = ExecutableDialogResults::OK;
77 case NSModalResponseCancel:
78 retVal = ExecutableDialogResults::CANCEL;
82 throw uno::RuntimeException("The dialog returned with an unknown result!", static_cast< cppu::OWeakObject * >( this ));
91 void SAL_CALL SalAquaFolderPicker::setDisplayDirectory( const OUString& aDirectory )
93 SolarMutexGuard aGuard;
95 implsetDisplayDirectory(aDirectory);
98 OUString SAL_CALL SalAquaFolderPicker::getDisplayDirectory()
100 SolarMutexGuard aGuard;
102 OUString aDirectory = implgetDisplayDirectory();
107 OUString SAL_CALL SalAquaFolderPicker::getDirectory()
109 SolarMutexGuard aGuard;
111 NSArray *files = nil;
112 if (m_nDialogType == NAVIGATIONSERVICES_DIRECTORY) {
113 files = [static_cast<NSOpenPanel*>(m_pDialog) URLs];
116 NSUInteger nFiles = [files count];
117 SAL_INFO("fpicker.aqua", "# of items: " << nFiles);
120 throw uno::RuntimeException("no directory selected", static_cast< cppu::OWeakObject * >( this ));
125 NSURL *url = [files objectAtIndex:0];
127 aDirectory = [url OUString];
129 implsetDisplayDirectory(aDirectory);
134 void SAL_CALL SalAquaFolderPicker::setDescription( const OUString& rDescription )
136 [m_pDialog setMessage:[NSString stringWithOUString:rDescription]];
141 OUString SAL_CALL SalAquaFolderPicker::getImplementationName()
143 return "com.sun.star.ui.dialogs.SalAquaFolderPicker";
146 sal_Bool SAL_CALL SalAquaFolderPicker::supportsService( const OUString& sServiceName )
148 return cppu::supportsService(this, sServiceName);
151 uno::Sequence<OUString> SAL_CALL SalAquaFolderPicker::getSupportedServiceNames()
153 return { "com.sun.star.ui.dialogs.SystemFolderPicker", "com.sun.star.ui.dialogs.AquaFolderPicker" };
158 void SAL_CALL SalAquaFolderPicker::cancel()
160 SolarMutexGuard aGuard;
162 [m_pDialog cancel:nil];
167 void SAL_CALL SalAquaFolderPicker::disposing( const lang::EventObject& )
171 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
172 fpicker_SalAquaFolderPicker_get_implementation(
173 css::uno::XComponentContext* , css::uno::Sequence<css::uno::Any> const&)
175 return cppu::acquire(new SalAquaFolderPicker());
179 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */