summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2022-01-20 21:13:26 +0900
committerAndras Timar <andras.timar@collabora.com>2022-02-14 12:09:32 +0100
commitb900907fde6d4507cff7844c5bcd6cc2f7b3821f (patch)
tree2868712f083d1aaed721218ca38250a355c1d181
parent3b351cdad5f13a43f826ebeece4377f4f225d02d (diff)
tdf#118246 add support for Application.GetOpenFilename func.
Opens the file dialog and returns the selected filename. Change-Id: I4eccd34a7fbb892c0950b2f7c34977cf2aad6f89 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/128721 Tested-by: Tomaž Vajngerl <quikee@gmail.com> Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
-rw-r--r--oovbaapi/ooo/vba/excel/XApplication.idl10
-rw-r--r--oovbaapi/ooo/vba/excel/XFileDialog.idl2
-rw-r--r--sc/source/ui/vba/vbaapplication.cxx39
-rw-r--r--sc/source/ui/vba/vbaapplication.hxx2
-rw-r--r--sc/source/ui/vba/vbafiledialog.cxx11
-rw-r--r--sc/source/ui/vba/vbafiledialog.hxx4
-rw-r--r--sc/source/ui/vba/vbafiledialogitems.hxx5
7 files changed, 72 insertions, 1 deletions
diff --git a/oovbaapi/ooo/vba/excel/XApplication.idl b/oovbaapi/ooo/vba/excel/XApplication.idl
index 89a19197116f..b1bcf46336be 100644
--- a/oovbaapi/ooo/vba/excel/XApplication.idl
+++ b/oovbaapi/ooo/vba/excel/XApplication.idl
@@ -65,6 +65,16 @@ interface XApplication
string getDefaultFilePath() raises(com::sun::star::script::BasicErrorException);
+ // Opens the file dialog and returns the selected file
+ // Parameters:
+ // Title: title of the file dialog
+ // MultiSelect: true if multi selection is allowed (false by default)
+ // returns:
+ // false - if file dialog was canceled
+ // filename - if "MultiSelect" is false
+ // array of filename - if "MultiSelect" is true
+ any GetOpenFilename([in] any FileFilter, [in] any FilterIndex, [in] any Title, [in] any ButtonText, [in] any MultiSelect);
+
any International( [in] long Index );
any Workbooks( [in] any Index );
any Worksheets( [in] any Index );
diff --git a/oovbaapi/ooo/vba/excel/XFileDialog.idl b/oovbaapi/ooo/vba/excel/XFileDialog.idl
index e73813e53807..bf9ff2391ee8 100644
--- a/oovbaapi/ooo/vba/excel/XFileDialog.idl
+++ b/oovbaapi/ooo/vba/excel/XFileDialog.idl
@@ -34,6 +34,8 @@ interface XFileDialog
[attribute] any InitialFileName;
[attribute] any Title;
+ [attribute] any AllowMultiSelect;
+
[attribute, readonly] XFileDialogSelectedItems SelectedItems;
long Show();
diff --git a/sc/source/ui/vba/vbaapplication.cxx b/sc/source/ui/vba/vbaapplication.cxx
index 01885a36f0e3..494ee9c27b97 100644
--- a/sc/source/ui/vba/vbaapplication.cxx
+++ b/sc/source/ui/vba/vbaapplication.cxx
@@ -34,6 +34,7 @@
#include <ooo/vba/excel/XlMousePointer.hpp>
#include <ooo/vba/office/MsoShapeType.hpp>
#include <ooo/vba/office/MsoAutoShapeType.hpp>
+#include <ooo/vba/office/MsoFileDialogType.hpp>
#include "vbaapplication.hxx"
#include "vbaworkbooks.hxx"
@@ -55,6 +56,7 @@
#include <sc.hrc>
#include <macromgr.hxx>
#include "vbafiledialog.hxx"
+#include "vbafiledialogitems.hxx"
#include <osl/file.hxx>
@@ -70,13 +72,13 @@
#include <basic/sbuno.hxx>
#include <basic/sbmeth.hxx>
#include <basic/sberrors.hxx>
+#include <comphelper/sequence.hxx>
#include <convuno.hxx>
#include <cellsuno.hxx>
#include <unonames.hxx>
#include <docsh.hxx>
#include "excelvbahelper.hxx"
-
#include <basic/sbxobj.hxx>
#include <viewutil.hxx>
@@ -353,6 +355,41 @@ ScVbaApplication::getActiveCell()
}
uno::Any SAL_CALL
+ScVbaApplication::GetOpenFilename(const uno::Any& /*aFileFilter*/, const uno::Any& /*aFilterIndex*/, const uno::Any& aTitle, const uno::Any& /*aButtonText*/, const uno::Any& aMultiSelect)
+{
+ // TODO - take all parameters into account
+ auto xDialog = uno::Reference<excel::XFileDialog> (new ScVbaFileDialog( this, mxContext, office::MsoFileDialogType::msoFileDialogFilePicker));
+ xDialog->setTitle(aTitle);
+ xDialog->setAllowMultiSelect(aMultiSelect);
+
+ bool bMultiSelect = false;
+ aMultiSelect >>= bMultiSelect;
+
+ if (xDialog->Show() == 0)
+ {
+ // return FALSE when canceled
+ return uno::makeAny(false);
+ }
+
+ uno::Reference<excel::XFileDialogSelectedItems> xItems = xDialog->getSelectedItems();
+ auto* pItems = dynamic_cast<ScVbaFileDialogSelectedItems*>(xItems.get());
+ auto const & rItemVector = pItems->getItems();
+
+ if (!bMultiSelect) // only 1 selection allowed - return path
+ {
+ OUString aPath;
+ if (!rItemVector.empty())
+ aPath = rItemVector.at(0);
+ return uno::makeAny(aPath);
+ }
+ else
+ {
+ // convert to sequence
+ return uno::makeAny(comphelper::containerToSequence(rItemVector));
+ }
+}
+
+uno::Any SAL_CALL
ScVbaApplication::International( sal_Int32 /*Index*/ )
{
// complete stub for now
diff --git a/sc/source/ui/vba/vbaapplication.hxx b/sc/source/ui/vba/vbaapplication.hxx
index f439a91aa763..09d2b02d3b59 100644
--- a/sc/source/ui/vba/vbaapplication.hxx
+++ b/sc/source/ui/vba/vbaapplication.hxx
@@ -96,6 +96,8 @@ public:
virtual css::uno::Reference< ov::XAssistant > SAL_CALL getAssistant() override;
virtual css::uno::Reference< ov::excel::XWorkbook > SAL_CALL getThisWorkbook() override;
+
+ virtual css::uno::Any SAL_CALL GetOpenFilename(const css::uno::Any& FileFilter, const css::uno::Any& FilterIndex, const css::uno::Any& Title, const css::uno::Any& ButtonText, const css::uno::Any& MultiSelect) override;
virtual css::uno::Any SAL_CALL International( sal_Int32 Index ) override;
virtual css::uno::Any SAL_CALL FileDialog( const css::uno::Any& DialogType ) override;
virtual css::uno::Any SAL_CALL Workbooks( const css::uno::Any& aIndex ) override;
diff --git a/sc/source/ui/vba/vbafiledialog.cxx b/sc/source/ui/vba/vbafiledialog.cxx
index 1aa4e77e83ea..49b00408426d 100644
--- a/sc/source/ui/vba/vbafiledialog.cxx
+++ b/sc/source/ui/vba/vbafiledialog.cxx
@@ -36,6 +36,7 @@ ScVbaFileDialog::ScVbaFileDialog( const uno::Reference< XHelperInterface >& xPar
: ScVbaFileDialog_BASE( xParent, xContext)
, m_nType(nType)
, m_sTitle("FileDialog")
+ , m_bMultiSelectMode(false)
{}
uno::Any
@@ -64,6 +65,16 @@ void ScVbaFileDialog::setTitle( const css::uno::Any& rTitle )
rTitle >>= m_sTitle;
}
+uno::Any ScVbaFileDialog::getAllowMultiSelect()
+{
+ return uno::makeAny(m_bMultiSelectMode);
+}
+
+void ScVbaFileDialog::setAllowMultiSelect(const uno::Any& rAllowMultiSelect)
+{
+ rAllowMultiSelect >>= m_bMultiSelectMode;
+}
+
uno::Reference< excel::XFileDialogSelectedItems > SAL_CALL ScVbaFileDialog::getSelectedItems()
{
// TODO use InitialFileName when m_xItems is empty
diff --git a/sc/source/ui/vba/vbafiledialog.hxx b/sc/source/ui/vba/vbafiledialog.hxx
index c91398149f67..f339e4a977b3 100644
--- a/sc/source/ui/vba/vbafiledialog.hxx
+++ b/sc/source/ui/vba/vbafiledialog.hxx
@@ -33,6 +33,7 @@ private:
sal_Int32 m_nType;
OUString m_sTitle;
OUString m_sInitialFileName;
+ bool m_bMultiSelectMode;
css::uno::Reference< ov::excel::XFileDialogSelectedItems> m_xItems;
public:
ScVbaFileDialog( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const sal_Int32 nType);
@@ -41,6 +42,9 @@ public:
virtual void SAL_CALL setInitialFileName( const css::uno::Any& rName ) override;
virtual css::uno::Any SAL_CALL getTitle() override;
virtual void SAL_CALL setTitle( const css::uno::Any& rTitle ) override;
+ virtual css::uno::Any SAL_CALL getAllowMultiSelect() override;
+ virtual void SAL_CALL setAllowMultiSelect(const css::uno::Any& rAllowMultiSelect) override;
+
virtual css::uno::Reference< ov::excel::XFileDialogSelectedItems > SAL_CALL getSelectedItems() override;
virtual sal_Int32 SAL_CALL Show() override;
diff --git a/sc/source/ui/vba/vbafiledialogitems.hxx b/sc/source/ui/vba/vbafiledialogitems.hxx
index 7a656237359b..5a01df010216 100644
--- a/sc/source/ui/vba/vbafiledialogitems.hxx
+++ b/sc/source/ui/vba/vbafiledialogitems.hxx
@@ -17,6 +17,11 @@ class ScVbaFileDialogSelectedItems final : public FileDialogSelectedItems_BASE
{
const std::vector<OUString> m_sItems;
public:
+ std::vector<OUString> const& getItems()
+ {
+ return m_sItems;
+ }
+
ScVbaFileDialogSelectedItems( const css::uno::Reference< ov::XHelperInterface >& xParent,
const css::uno::Reference< css::uno::XComponentContext >& xContext,
std::vector<OUString>&& sItems);