[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.0' - include/sfx2 sfx2/Library_sfx.mk sfx2/sdi sfx2/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Mon Aug 27 16:13:21 UTC 2018


 include/sfx2/asyncfunc.hxx        |   39 +++++++++++++++++++++++
 include/sfx2/frame.hxx            |    1 
 sfx2/Library_sfx.mk               |    1 
 sfx2/sdi/sfx.sdi                  |    2 -
 sfx2/source/control/asyncfunc.cxx |   63 ++++++++++++++++++++++++++++++++++++++
 sfx2/source/doc/guisaveas.cxx     |   54 +++++++++++++++++---------------
 sfx2/source/doc/objserv.cxx       |    9 +++++
 sfx2/source/view/frame.cxx        |   10 +++++-
 8 files changed, 152 insertions(+), 27 deletions(-)

New commits:
commit 28e6b49de404ebd44aaa2fee128e74c7eb3e1b74
Author:     Henry Castro <hcastro at collabora.com>
AuthorDate: Mon Jul 9 20:20:10 2018 -0400
Commit:     Andras Timar <andras.timar at collabora.com>
CommitDate: Mon Aug 27 18:12:59 2018 +0200

    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 at collabora.com>
    Reviewed-on: https://gerrit.libreoffice.org/59631
    Tested-by: Mike Kaganski <mike.kaganski at collabora.com>
    Reviewed-by: Andras Timar <andras.timar at collabora.com>

diff --git a/include/sfx2/asyncfunc.hxx b/include/sfx2/asyncfunc.hxx
new file mode 100644
index 000000000000..16e01969baba
--- /dev/null
+++ b/include/sfx2/asyncfunc.hxx
@@ -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: */
diff --git a/include/sfx2/frame.hxx b/include/sfx2/frame.hxx
index 94c46d6ad05d..081a99de5476 100644
--- a/include/sfx2/frame.hxx
+++ b/include/sfx2/frame.hxx
@@ -200,6 +200,7 @@ class SFX2_DLLPUBLIC SfxUsrAnyItem : public SfxPoolItem
     css::uno::Any  aValue;
 public:
                                 static SfxPoolItem* CreateDefault();
+                                SfxUsrAnyItem();
                                 SfxUsrAnyItem( sal_uInt16 nWhich, const css::uno::Any& rAny );
     const css::uno::Any&        GetValue() const
                                 { return aValue; }
diff --git a/sfx2/Library_sfx.mk b/sfx2/Library_sfx.mk
index b84e51fec330..19beea4765e5 100644
--- a/sfx2/Library_sfx.mk
+++ b/sfx2/Library_sfx.mk
@@ -133,6 +133,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 \
diff --git a/sfx2/sdi/sfx.sdi b/sfx2/sdi/sfx.sdi
index 5f5144498d2d..83d26d5797e8 100644
--- a/sfx2/sdi/sfx.sdi
+++ b/sfx2/sdi/sfx.sdi
@@ -3207,7 +3207,7 @@ SfxBoolItem PrintPreview SID_PRINTPREVIEW
 
 
 SfxVoidItem SetDocumentProperties SID_DOCINFO
-(SfxDocumentInfoItem Properties SID_DOCINFO)
+(SfxDocumentInfoItem Properties SID_DOCINFO,SfxUsrAnyItem AsyncFunc FN_PARAM_2)
 [
     AutoUpdate = FALSE,
     FastCall = FALSE,
diff --git a/sfx2/source/control/asyncfunc.cxx b/sfx2/source/control/asyncfunc.cxx
new file mode 100644
index 000000000000..f27931dcbf09
--- /dev/null
+++ b/sfx2/source/control/asyncfunc.cxx
@@ -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: */
diff --git a/sfx2/source/doc/guisaveas.cxx b/sfx2/source/doc/guisaveas.cxx
index f2982fbc04b8..522fea6935a7 100644
--- a/sfx2/source/doc/guisaveas.cxx
+++ b/sfx2/source/doc/guisaveas.cxx
@@ -74,6 +74,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>
@@ -333,7 +334,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 );
@@ -1100,7 +1101,7 @@ bool ModelData_Impl::OutputFileDialog( sal_Int16 nStoreMode,
 }
 
 
-bool ModelData_Impl::ShowDocumentInfoDialog()
+bool ModelData_Impl::ShowDocumentInfoDialog(const std::function< void () >& aFunc)
 {
     bool bDialogUsed = false;
 
@@ -1123,7 +1124,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;
                     }
                 }
@@ -1628,34 +1633,33 @@ bool SfxStoringHelper::GUIStoreModel( const uno::Reference< frame::XModel >& xMo
         uno::Reference<document::XDocumentProperties> xOldDocProps(
             xCloneable->createClone(), uno::UNO_QUERY_THROW);
 
-        // use dispatch API to show document info dialog
-        if ( aModelData.ShowDocumentInfoDialog() )
-            bDialogUsed = true;
-        else
-        {
-            OSL_FAIL( "Can't execute document info dialog!" );
-        }
+        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& )
+            {
+            }
 
-        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);
+                SfxStoringHelper::SetDocInfoState(aModel.GetModel(), xOldDocProps, true);
             }
-            throw;
-        }
+        };
 
-        if ( nStoreMode & EXPORT_REQUESTED )
+        // use dispatch API to show document info dialog
+        if ( aModelData.ShowDocumentInfoDialog(aFunc) )
+            bDialogUsed = true;
+        else
         {
-            SetDocInfoState(aModelData.GetModel(), xOldDocProps, true);
+            OSL_FAIL( "Can't execute document info dialog!" );
         }
     }
     else
diff --git a/sfx2/source/doc/objserv.cxx b/sfx2/source/doc/objserv.cxx
index 0fc4732c933d..c7c1de11e2ec 100644
--- a/sfx2/source/doc/objserv.cxx
+++ b/sfx2/source/doc/objserv.cxx
@@ -63,6 +63,7 @@
 #include <comphelper/documentconstants.hxx>
 #include <tools/link.hxx>
 
+#include <sfx2/asyncfunc.hxx>
 #include <sfx2/app.hxx>
 #include <sfx2/signaturestate.hxx>
 #include <sfx2/sfxresid.hxx>
@@ -489,6 +490,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
diff --git a/sfx2/source/view/frame.cxx b/sfx2/source/view/frame.cxx
index 8d940ba05bac..5fd0ed09cd4d 100644
--- a/sfx2/source/view/frame.cxx
+++ b/sfx2/source/view/frame.cxx
@@ -76,12 +76,16 @@ using namespace ::com::sun::star::util;
 using namespace ::com::sun::star::frame;
 using namespace ::com::sun::star::container;
 
-SfxPoolItem* SfxUsrAnyItem::CreateDefault() { SAL_WARN( "sfx", "No SfxUsrAnyItem factory available"); return nullptr; }
+SfxPoolItem* SfxUsrAnyItem::CreateDefault()
+{
+    return new SfxUsrAnyItem();
+}
 
 SfxPoolItem* SfxUnoFrameItem::CreateDefault()
 {
     return new SfxUnoFrameItem();
 }
+
 void SfxFrame::Construct_Impl()
 {
     pImpl.reset(new SfxFrame_Impl);
@@ -459,6 +463,10 @@ bool SfxFrameItem::PutValue( const css::uno::Any& rVal, sal_uInt8 )
     return false;
 }
 
+SfxUsrAnyItem::SfxUsrAnyItem()
+    : SfxPoolItem( 0 )
+{
+}
 
 SfxUsrAnyItem::SfxUsrAnyItem( sal_uInt16 nWhichId, const css::uno::Any& rAny )
     : SfxPoolItem( nWhichId )


More information about the Libreoffice-commits mailing list