tdf#117895: "Edit document properties before saving"...
option leaves just-saved document modified; changes are not saved Change-Id: Icad48fe1edcfb4c10c40f297326c23110144df53 Reviewed-on: https://gerrit.libreoffice.org/57211 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
This commit is contained in:
committed by
Mike Kaganski
parent
8e9d43546c
commit
3add3e5b70
@@ -0,0 +1,39 @@
|
||||
/* -*- 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/.
|
||||
*/
|
||||
|
||||
#ifndef INCLUDED_SFX2_ASYNCFUNC_HXX
|
||||
#define INCLUDED_SFX2_ASYNCFUNC_HXX
|
||||
|
||||
#include <functional>
|
||||
|
||||
#include <com/sun/star/lang/XUnoTunnel.hpp>
|
||||
#include <cppuhelper/implbase.hxx>
|
||||
|
||||
class AsyncFunc : public cppu::WeakImplHelper<css::lang::XUnoTunnel>
|
||||
{
|
||||
private:
|
||||
std::function<void()> m_pAsyncFunc;
|
||||
|
||||
public:
|
||||
AsyncFunc(const std::function<void()>&);
|
||||
virtual ~AsyncFunc() override;
|
||||
|
||||
static const css::uno::Sequence<sal_Int8>& getUnoTunnelId();
|
||||
static AsyncFunc* getImplementation(const css::uno::Reference<css::uno::XInterface>&);
|
||||
|
||||
void Execute();
|
||||
|
||||
//XUnoTunnel
|
||||
virtual sal_Int64 SAL_CALL
|
||||
getSomething(const css::uno::Sequence<sal_Int8>& aIdentifier) override;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||
@@ -197,6 +197,7 @@ class SFX2_DLLPUBLIC SfxUnoAnyItem : public SfxPoolItem
|
||||
css::uno::Any aValue;
|
||||
public:
|
||||
static SfxPoolItem* CreateDefault();
|
||||
SfxUnoAnyItem();
|
||||
SfxUnoAnyItem( sal_uInt16 nWhich, const css::uno::Any& rAny );
|
||||
const css::uno::Any& GetValue() const
|
||||
{ return aValue; }
|
||||
|
||||
@@ -125,6 +125,7 @@ $(eval $(call gb_Library_add_exception_objects,sfx,\
|
||||
sfx2/source/bastyp/sfxhtml \
|
||||
sfx2/source/bastyp/sfxresid \
|
||||
sfx2/source/config/evntconf \
|
||||
sfx2/source/control/asyncfunc \
|
||||
sfx2/source/control/bindings \
|
||||
sfx2/source/control/ctrlitem \
|
||||
sfx2/source/control/ctrlfactoryimpl \
|
||||
|
||||
+1
-1
@@ -3244,7 +3244,7 @@ SfxBoolItem PrintPreview SID_PRINTPREVIEW
|
||||
|
||||
|
||||
SfxVoidItem SetDocumentProperties SID_DOCINFO
|
||||
(SfxDocumentInfoItem Properties SID_DOCINFO)
|
||||
(SfxDocumentInfoItem Properties SID_DOCINFO,SfxUnoAnyItem AsyncFunc FN_PARAM_2)
|
||||
[
|
||||
AutoUpdate = FALSE,
|
||||
FastCall = FALSE,
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
/* -*- 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/.
|
||||
*/
|
||||
|
||||
#include <sfx2/asyncfunc.hxx>
|
||||
#include <comphelper/servicehelper.hxx>
|
||||
|
||||
#include <com/sun/star/uno/Reference.hxx>
|
||||
|
||||
namespace
|
||||
{
|
||||
class theAsyncFuncUnoTunnelId : public rtl::Static<UnoTunnelIdInit, theAsyncFuncUnoTunnelId>
|
||||
{
|
||||
};
|
||||
}
|
||||
|
||||
AsyncFunc::AsyncFunc(const std::function<void()>& rAsyncFunc)
|
||||
: m_pAsyncFunc(rAsyncFunc)
|
||||
{
|
||||
}
|
||||
|
||||
AsyncFunc::~AsyncFunc() {}
|
||||
|
||||
void AsyncFunc::Execute()
|
||||
{
|
||||
if (m_pAsyncFunc)
|
||||
m_pAsyncFunc();
|
||||
}
|
||||
|
||||
const css::uno::Sequence<sal_Int8>& AsyncFunc::getUnoTunnelId()
|
||||
{
|
||||
return theAsyncFuncUnoTunnelId::get().getSeq();
|
||||
}
|
||||
|
||||
AsyncFunc* AsyncFunc::getImplementation(const css::uno::Reference<css::uno::XInterface>& xInterface)
|
||||
{
|
||||
css::uno::Reference<css::lang::XUnoTunnel> xUnoTunnel(xInterface, css::uno::UNO_QUERY);
|
||||
if (xUnoTunnel.is())
|
||||
{
|
||||
return reinterpret_cast<AsyncFunc*>(xUnoTunnel->getSomething(AsyncFunc::getUnoTunnelId()));
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
//XUnoTunnel
|
||||
sal_Int64 SAL_CALL AsyncFunc::getSomething(const css::uno::Sequence<sal_Int8>& rId)
|
||||
{
|
||||
if (rId.getLength() == 16
|
||||
&& 0 == memcmp(getUnoTunnelId().getConstArray(), rId.getConstArray(), 16))
|
||||
{
|
||||
return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||
@@ -76,6 +76,7 @@
|
||||
#include <sfx2/sfxresid.hxx>
|
||||
#include <sfx2/docfilt.hxx>
|
||||
#include <sfx2/filedlghelper.hxx>
|
||||
#include <sfx2/asyncfunc.hxx>
|
||||
#include <sfx2/app.hxx>
|
||||
#include <sfx2/objsh.hxx>
|
||||
#include <sfx2/request.hxx>
|
||||
@@ -334,7 +335,7 @@ public:
|
||||
const css::uno::Sequence< OUString >& rBlackList
|
||||
);
|
||||
|
||||
bool ShowDocumentInfoDialog();
|
||||
bool ShowDocumentInfoDialog(const std::function< void () >&);
|
||||
|
||||
static OUString GetRecommendedExtension( const OUString& aTypeName );
|
||||
OUString GetRecommendedDir( const OUString& aSuggestedDir );
|
||||
@@ -1102,7 +1103,7 @@ bool ModelData_Impl::OutputFileDialog( sal_Int16 nStoreMode,
|
||||
}
|
||||
|
||||
|
||||
bool ModelData_Impl::ShowDocumentInfoDialog()
|
||||
bool ModelData_Impl::ShowDocumentInfoDialog(const std::function< void () >& aFunc)
|
||||
{
|
||||
bool bDialogUsed = false;
|
||||
|
||||
@@ -1125,7 +1126,11 @@ bool ModelData_Impl::ShowDocumentInfoDialog()
|
||||
0 );
|
||||
if ( xDispatch.is() )
|
||||
{
|
||||
xDispatch->dispatch( aURL, uno::Sequence< beans::PropertyValue >() );
|
||||
uno::Sequence< beans::PropertyValue > aProperties(1);
|
||||
uno::Reference< lang::XUnoTunnel > aAsyncFunc(new AsyncFunc(aFunc));
|
||||
aProperties[0].Name = "AsyncFunc";
|
||||
aProperties[0].Value <<= aAsyncFunc;
|
||||
xDispatch->dispatch( aURL, aProperties );
|
||||
bDialogUsed = true;
|
||||
}
|
||||
}
|
||||
@@ -1631,35 +1636,34 @@ bool SfxStoringHelper::GUIStoreModel( const uno::Reference< frame::XModel >& xMo
|
||||
uno::Reference<document::XDocumentProperties> xOldDocProps(
|
||||
xCloneable->createClone(), uno::UNO_QUERY_THROW);
|
||||
|
||||
std::function< void () > aFunc = [xModel, xOldDocProps, nStoreMode, aURL, aArgsSequence]() {
|
||||
SfxStoringHelper aStoringHelper;
|
||||
ModelData_Impl aModel(aStoringHelper, xModel, aArgsSequence );
|
||||
|
||||
try
|
||||
{
|
||||
if ( nStoreMode & EXPORT_REQUESTED )
|
||||
aModel.GetStorable()->storeToURL( aURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ), aArgsSequence );
|
||||
else
|
||||
aModel.GetStorable()->storeAsURL( aURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ), aArgsSequence );
|
||||
}
|
||||
catch( const uno::Exception& )
|
||||
{
|
||||
}
|
||||
|
||||
if ( nStoreMode & EXPORT_REQUESTED )
|
||||
{
|
||||
SfxStoringHelper::SetDocInfoState(aModel.GetModel(), xOldDocProps, true);
|
||||
}
|
||||
};
|
||||
|
||||
// use dispatch API to show document info dialog
|
||||
if ( aModelData.ShowDocumentInfoDialog() )
|
||||
if ( aModelData.ShowDocumentInfoDialog(aFunc) )
|
||||
bDialogUsed = true;
|
||||
else
|
||||
{
|
||||
OSL_FAIL( "Can't execute document info dialog!" );
|
||||
}
|
||||
|
||||
try {
|
||||
// Document properties can contain streams that should be freed before storing
|
||||
aModelData.FreeDocumentProps();
|
||||
if ( nStoreMode & EXPORT_REQUESTED )
|
||||
aModelData.GetStorable()->storeToURL( aURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ), aArgsSequence );
|
||||
else
|
||||
aModelData.GetStorable()->storeAsURL( aURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ), aArgsSequence );
|
||||
}
|
||||
catch( const uno::Exception& )
|
||||
{
|
||||
if ( nStoreMode & EXPORT_REQUESTED )
|
||||
{
|
||||
SetDocInfoState(aModelData.GetModel(), xOldDocProps, true);
|
||||
}
|
||||
throw;
|
||||
}
|
||||
|
||||
if ( nStoreMode & EXPORT_REQUESTED )
|
||||
{
|
||||
SetDocInfoState(aModelData.GetModel(), xOldDocProps, true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -66,6 +66,7 @@
|
||||
#include <comphelper/storagehelper.hxx>
|
||||
#include <tools/link.hxx>
|
||||
|
||||
#include <sfx2/asyncfunc.hxx>
|
||||
#include <sfx2/app.hxx>
|
||||
#include <sfx2/signaturestate.hxx>
|
||||
#include <sfx2/sfxresid.hxx>
|
||||
@@ -496,6 +497,14 @@ void SfxObjectShell::ExecFile_Impl(SfxRequest &rReq)
|
||||
pReq->AppendItem( SfxDocumentInfoItem( GetTitle(),
|
||||
getDocProperties(), aNewCmisProperties, IsUseUserData(), IsUseThumbnailSave() ) );
|
||||
}
|
||||
|
||||
css::uno::Reference< css::uno::XInterface > xInterface;
|
||||
const SfxUnoAnyItem* pUnoAny = pReq->GetArg<SfxUnoAnyItem>(FN_PARAM_2);
|
||||
AsyncFunc* pAsyncFunc = pUnoAny && (pUnoAny->GetValue() >>= xInterface ) ?
|
||||
AsyncFunc::getImplementation(xInterface) : nullptr;
|
||||
if (pAsyncFunc)
|
||||
pAsyncFunc->Execute();
|
||||
|
||||
pReq->Done();
|
||||
}
|
||||
else
|
||||
|
||||
@@ -73,12 +73,16 @@ using namespace ::com::sun::star::util;
|
||||
using namespace ::com::sun::star::frame;
|
||||
using namespace ::com::sun::star::container;
|
||||
|
||||
SfxPoolItem* SfxUnoAnyItem::CreateDefault() { SAL_WARN( "sfx", "No SfxUnoAnyItem factory available"); return nullptr; }
|
||||
SfxPoolItem* SfxUnoAnyItem::CreateDefault()
|
||||
{
|
||||
return new SfxUnoAnyItem();
|
||||
}
|
||||
|
||||
SfxPoolItem* SfxUnoFrameItem::CreateDefault()
|
||||
{
|
||||
return new SfxUnoFrameItem();
|
||||
}
|
||||
|
||||
void SfxFrame::Construct_Impl()
|
||||
{
|
||||
pImpl.reset(new SfxFrame_Impl);
|
||||
@@ -456,6 +460,10 @@ bool SfxFrameItem::PutValue( const css::uno::Any& rVal, sal_uInt8 )
|
||||
return false;
|
||||
}
|
||||
|
||||
SfxUnoAnyItem::SfxUnoAnyItem()
|
||||
: SfxPoolItem( 0 )
|
||||
{
|
||||
}
|
||||
|
||||
SfxUnoAnyItem::SfxUnoAnyItem( sal_uInt16 nWhichId, const css::uno::Any& rAny )
|
||||
: SfxPoolItem( nWhichId )
|
||||
|
||||
Reference in New Issue
Block a user