diff options
author | Tamas Bunth <tamas.bunth@collabora.co.uk> | 2017-07-11 12:22:06 +0200 |
---|---|---|
committer | Tamás Bunth <btomi96@gmail.com> | 2017-07-14 23:24:44 +0200 |
commit | 07fb14be7f79cbbf65f47458b7b2337c8ffcc4f7 (patch) | |
tree | 01a47a0db59f9cfbb5394cfa418dba5c58329629 /sc/source/ui/vba/vbafiledialog.cxx | |
parent | d6a16aedca28ad5a907104c02174abd88fb03aed (diff) |
implement Application.FileDialog attribute
Documentation:
https://msdn.microsoft.com/en-us/vba/excel-vba/articles/application-filedialog-property-excel
https://msdn.microsoft.com/VBA/Office-Shared-VBA/articles/filedialog-object-office
Using FilePicker and FolderPicker uno services.
Change-Id: Ifd3b3fc9c135efb0663d2ef36ecbe2b2fbe6132f
Reviewed-on: https://gerrit.libreoffice.org/39806
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Tamás Bunth <btomi96@gmail.com>
Diffstat (limited to 'sc/source/ui/vba/vbafiledialog.cxx')
-rw-r--r-- | sc/source/ui/vba/vbafiledialog.cxx | 141 |
1 files changed, 141 insertions, 0 deletions
diff --git a/sc/source/ui/vba/vbafiledialog.cxx b/sc/source/ui/vba/vbafiledialog.cxx new file mode 100644 index 000000000000..1129953dff02 --- /dev/null +++ b/sc/source/ui/vba/vbafiledialog.cxx @@ -0,0 +1,141 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include "vbafiledialog.hxx" + +#include <ooo/vba/office/MsoFileDialogType.hpp> + +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/ui/dialogs/FilePicker.hpp> +#include <com/sun/star/ui/dialogs/FolderPicker.hpp> +#include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp> +#include <com/sun/star/ui/dialogs/TemplateDescription.hpp> + +using namespace ::com::sun::star; +using namespace ::ooo::vba; + +ScVbaFileDialog::ScVbaFileDialog( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const sal_Int32 nType ) + : ScVbaFileDialog_BASE( xParent, xContext) + , m_nType(nType) + , m_sTitle("FileDialog") +{} + +uno::Any +ScVbaFileDialog::getInitialFileName() { return uno::makeAny( m_sInitialFileName ); } + +void ScVbaFileDialog::setInitialFileName( const css::uno::Any& rName ) +{ + rName >>= m_sInitialFileName; +} + +css::uno::Any ScVbaFileDialog::getTitle() { return uno::makeAny( m_sTitle ); } + +void ScVbaFileDialog::setTitle( const css::uno::Any& rTitle ) +{ + rTitle >>= m_sTitle; +} + +uno::Reference< excel::XFileDialogSelectedItems > SAL_CALL ScVbaFileDialog::getSelectedItems() +{ + // TODO use InitialFileName when m_xItems is empty + return m_xItems; +} + +sal_Int32 ScVbaFileDialog::Show() +{ + std::vector<OUString> sSelectedPaths; + sal_Int32 nRet = -1; + + switch (m_nType) + { + case office::MsoFileDialogType::msoFileDialogOpen: + // TODO implement + break; + case office::MsoFileDialogType::msoFileDialogSaveAs: + // TODO implement + break; + case office::MsoFileDialogType::msoFileDialogFilePicker: + { + uno::Reference<ui::dialogs::XFilePicker3> xFilePicker = + ui::dialogs::FilePicker::createWithMode( + mxContext, ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE ); + + // TODO set initial directory + + if( xFilePicker->execute() != ui::dialogs::ExecutableDialogResults::OK) + { + nRet = 0; // cancel pressed + break; + } + + for( auto& sPath : xFilePicker->getSelectedFiles() ) + { + sSelectedPaths.push_back(sPath); + } + } + break; + case office::MsoFileDialogType::msoFileDialogFolderPicker: + { + uno::Reference< ui::dialogs::XFolderPicker2 > xFolderPicker = + ui::dialogs::FolderPicker::create(mxContext); + + // TODO set initial directory + + if( xFolderPicker->execute() != ui::dialogs::ExecutableDialogResults::OK) + { + nRet = 0; // cancel pressed + break; + } + + OUString sPath = xFolderPicker->getDirectory(); + + if(!sPath.isEmpty()) + sSelectedPaths.push_back(sPath); + + } + break; + default: + throw uno::RuntimeException(); + } + + m_xItems = css::uno::Reference< ov::excel::XFileDialogSelectedItems >( + new ScVbaFileDialogSelectedItems(this, mxContext, sSelectedPaths) ); + return nRet; +} + +// XHelperInterface +OUString +ScVbaFileDialog::getServiceImplName() +{ + return OUString("ScVbaFileDialog"); +} + +uno::Sequence<OUString> +ScVbaFileDialog::getServiceNames() +{ + static uno::Sequence< OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = "ooo.vba.FileDialog"; + } + return aServiceNames; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |