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 "FPServiceInfo.hxx"
30 #include <osl/mutex.hxx>
31 #include <sal/log.hxx>
32 #include <vcl/svapp.hxx>
33 #include "SalAquaFolderPicker.hxx"
37 #include "resourceprovider.hxx"
39 #include <osl/file.hxx>
40 #include "CFStringUtilities.hxx"
41 #include "NSString_OOoAdditions.hxx"
42 #include "NSURL_OOoAdditions.hxx"
46 using namespace ::com::sun::star;
47 using namespace ::com::sun::star::ui::dialogs;
48 using namespace ::com::sun::star::lang;
49 using namespace ::com::sun::star::uno;
53 // controlling event notifications
54 uno::Sequence<OUString> FolderPicker_getSupportedServiceNames()
56 return { "com.sun.star.ui.dialogs.SystemFolderPicker", "com.sun.star.ui.dialogs.AquaFolderPicker" };
60 SalAquaFolderPicker::SalAquaFolderPicker( const uno::Reference<lang::XMultiServiceFactory>& xServiceMgr ) :
61 m_xServiceMgr( xServiceMgr )
63 m_nDialogType = NAVIGATIONSERVICES_DIRECTORY;
68 void SAL_CALL SalAquaFolderPicker::setTitle( const OUString& aTitle )
70 SolarMutexGuard aGuard;
75 sal_Int16 SAL_CALL SalAquaFolderPicker::execute()
77 SolarMutexGuard aGuard;
81 int nResult = runandwaitforresult();
85 case NSModalResponseOK:
86 retVal = ExecutableDialogResults::OK;
89 case NSModalResponseCancel:
90 retVal = ExecutableDialogResults::CANCEL;
94 throw uno::RuntimeException("The dialog returned with an unknown result!", static_cast< cppu::OWeakObject * >( this ));
103 void SAL_CALL SalAquaFolderPicker::setDisplayDirectory( const OUString& aDirectory )
105 SolarMutexGuard aGuard;
107 implsetDisplayDirectory(aDirectory);
110 OUString SAL_CALL SalAquaFolderPicker::getDisplayDirectory()
112 SolarMutexGuard aGuard;
114 OUString aDirectory = implgetDisplayDirectory();
119 OUString SAL_CALL SalAquaFolderPicker::getDirectory()
121 SolarMutexGuard aGuard;
123 NSArray *files = nil;
124 if (m_nDialogType == NAVIGATIONSERVICES_DIRECTORY) {
125 files = [static_cast<NSOpenPanel*>(m_pDialog) URLs];
128 long nFiles = [files count];
129 SAL_INFO("fpicker.aqua", "# of items: " << nFiles);
132 throw uno::RuntimeException("no directory selected", static_cast< cppu::OWeakObject * >( this ));
137 NSURL *url = [files objectAtIndex:0];
139 aDirectory = [url OUStringForInfo:FULLPATH];
141 implsetDisplayDirectory(aDirectory);
146 void SAL_CALL SalAquaFolderPicker::setDescription( const OUString& rDescription )
148 [m_pDialog setMessage:[NSString stringWithOUString:rDescription]];
153 OUString SAL_CALL SalAquaFolderPicker::getImplementationName()
155 return FOLDER_PICKER_IMPL_NAME;
158 sal_Bool SAL_CALL SalAquaFolderPicker::supportsService( const OUString& sServiceName )
160 return cppu::supportsService(this, sServiceName);
163 uno::Sequence<OUString> SAL_CALL SalAquaFolderPicker::getSupportedServiceNames()
165 return FolderPicker_getSupportedServiceNames();
170 void SAL_CALL SalAquaFolderPicker::cancel()
172 SolarMutexGuard aGuard;
174 [m_pDialog cancel:nil];
179 void SAL_CALL SalAquaFolderPicker::disposing( const lang::EventObject& )
183 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */