Kaydet (Commit) 58ea2712 authored tarafından Caolán McNamara's avatar Caolán McNamara

make FilePicker::createWithMode not crash

i.e. calc->data->XML Source->"browse to set source" calls
com_sun_star_comp_svt_FilePicker_get_implementation with its
single argument in arguments as opposed to the empty argument
expected there.

So allow the single-argument case, and pass the argument through and apply it
automatically via XInitialization::initialize in Application::createFilePicker.

I'm far from sure that this is the right solution, but it has the advantage of
working vs crashing.

Change-Id: I07c1baae7f47781920eac56763e8fd003a7b99e1
üst fe868bf7
...@@ -389,9 +389,9 @@ public: ...@@ -389,9 +389,9 @@ public:
/** Create a platform specific file picker, if one is available, /** Create a platform specific file picker, if one is available,
otherwise return an empty reference otherwise return an empty reference
*/ */
static com::sun::star::uno::Reference< com::sun::star::ui::dialogs::XFilePicker2 > static css::uno::Reference<css::ui::dialogs::XFilePicker2>
createFilePicker( const com::sun::star::uno::Reference< createFilePicker(const css::uno::Sequence<css::uno::Any>& rArguments,
com::sun::star::uno::XComponentContext >& rServiceManager ); const css::uno::Reference<css::uno::XComponentContext>& rServiceManager);
/** Create a platform specific folder picker, if one is available, /** Create a platform specific folder picker, if one is available,
otherwise return an empty reference otherwise return an empty reference
......
...@@ -57,19 +57,22 @@ extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL ...@@ -57,19 +57,22 @@ extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
com_sun_star_comp_svt_FilePicker_get_implementation( com_sun_star_comp_svt_FilePicker_get_implementation(
css::uno::XComponentContext *context, uno_Sequence * arguments) css::uno::XComponentContext *context, uno_Sequence * arguments)
{ {
assert(arguments != 0 && arguments->nElements == 0); (void) arguments; assert(arguments != 0 && (arguments->nElements == 0 || arguments->nElements == 1));
css::uno::Sequence<css::uno::Any> aArgs(reinterpret_cast<css::uno::Any *>(arguments->elements),
arguments->nElements);
Reference< css::uno::XInterface > xResult; Reference< css::uno::XInterface > xResult;
Reference< css::lang::XMultiComponentFactory > xFactory (context->getServiceManager()); Reference< css::lang::XMultiComponentFactory > xFactory (context->getServiceManager());
if (xFactory.is() && SvtMiscOptions().UseSystemFileDialog()) if (xFactory.is() && SvtMiscOptions().UseSystemFileDialog())
{ {
xResult = Reference< css::uno::XInterface >( Application::createFilePicker( context ) ); xResult = Reference<css::uno::XInterface>(Application::createFilePicker(aArgs, context));
if (!xResult.is()) if (!xResult.is())
{ {
try try
{ {
xResult = xFactory->createInstanceWithContext ( xResult = xFactory->createInstanceWithArgumentsAndContext(
FilePicker_getSystemPickerServiceName(), FilePicker_getSystemPickerServiceName(),
aArgs,
context); context);
} }
catch (css::uno::Exception const &) catch (css::uno::Exception const &)
...@@ -83,8 +86,9 @@ com_sun_star_comp_svt_FilePicker_get_implementation( ...@@ -83,8 +86,9 @@ com_sun_star_comp_svt_FilePicker_get_implementation(
if (!xResult.is() && xFactory.is()) if (!xResult.is() && xFactory.is())
{ {
// Always fall back to OfficeFilePicker. // Always fall back to OfficeFilePicker.
xResult = xFactory->createInstanceWithContext ( xResult = xFactory->createInstanceWithArgumentsAndContext(
OUString( "com.sun.star.ui.dialogs.OfficeFilePicker"), "com.sun.star.ui.dialogs.OfficeFilePicker",
aArgs,
context); context);
} }
if (xResult.is()) if (xResult.is())
......
...@@ -62,6 +62,7 @@ ...@@ -62,6 +62,7 @@
#include "com/sun/star/uno/Reference.h" #include "com/sun/star/uno/Reference.h"
#include "com/sun/star/awt/XToolkit.hpp" #include "com/sun/star/awt/XToolkit.hpp"
#include "com/sun/star/uno/XNamingService.hpp" #include "com/sun/star/uno/XNamingService.hpp"
#include "com/sun/star/lang/XInitialization.hpp"
#include "com/sun/star/lang/XMultiServiceFactory.hpp" #include "com/sun/star/lang/XMultiServiceFactory.hpp"
#include "comphelper/solarmutex.hxx" #include "comphelper/solarmutex.hxx"
#include "osl/process.h" #include "osl/process.h"
...@@ -1647,10 +1648,17 @@ bool Application::hasNativeFileSelection() ...@@ -1647,10 +1648,17 @@ bool Application::hasNativeFileSelection()
} }
Reference< ui::dialogs::XFilePicker2 > Reference< ui::dialogs::XFilePicker2 >
Application::createFilePicker( const Reference< uno::XComponentContext >& xSM ) Application::createFilePicker(const uno::Sequence<uno::Any>& rArguments,
const Reference< uno::XComponentContext >& xSM)
{ {
ImplSVData* pSVData = ImplGetSVData(); ImplSVData* pSVData = ImplGetSVData();
return pSVData->mpDefInst->createFilePicker( xSM ); Reference< ui::dialogs::XFilePicker2 > xRet(pSVData->mpDefInst->createFilePicker(xSM));
if (xRet.is() && rArguments.getLength())
{
uno::Reference<lang::XInitialization> xInit(xRet, uno::UNO_QUERY_THROW);
xInit->initialize(rArguments);
}
return xRet;
} }
Reference< ui::dialogs::XFolderPicker2 > Reference< ui::dialogs::XFolderPicker2 >
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment