sfx2/source/doc/objstor.cxx |   19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

New commits:
commit 19ac02dbae7474a1c88a545e6cab6fda678fdb95
Author:     Caolán McNamara <caolan.mcnam...@collabora.com>
AuthorDate: Thu May 16 14:37:52 2024 +0100
Commit:     Michael Meeks <michael.me...@collabora.com>
CommitDate: Thu May 16 16:14:14 2024 +0200

    always restore existing interaction handler after save
    
    In an error case we end up removing any existing interaction handler.
    So in all cases leave with the same interaction handler that
    existed before the save attempt.
    
    See also:
    
    commit 3b294f6139028014e72379ebe8eda24a2bd32195
    Date:   Thu Jun 8 20:53:16 2023 +0100
    
        restore, not clear, existing interaction handler after save
    
    where the same problem can be reproduced of every change is a
    full-document invalidation once someone else joins a document which has
    had a save-fail.
    
    Change-Id: I211183c551b1d64898cfe4aaf11dd9ef23f8ca15
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167747
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Michael Meeks <michael.me...@collabora.com>

diff --git a/sfx2/source/doc/objstor.cxx b/sfx2/source/doc/objstor.cxx
index f4826b93ad7d..ce548a81ea6a 100644
--- a/sfx2/source/doc/objstor.cxx
+++ b/sfx2/source/doc/objstor.cxx
@@ -2734,17 +2734,21 @@ bool SfxObjectShell::DoSave_Impl( const SfxItemSet* 
pArgs )
     if (pImpl->bPreserveVersions)
         pMediumTmp->TransferVersionList_Impl( *pRetrMedium );
 
+    // Save the original interaction handler
+    Any aOriginalInteract;
+    if (const SfxUnoAnyItem *pItem = 
pRetrMedium->GetItemSet().GetItemIfSet(SID_INTERACTIONHANDLER, false))
+    {
+        aOriginalInteract = pItem->GetValue();
+        // The original pRetrMedium and potential replacement pMediumTmp have 
the same interaction handler at this point
+        assert(pMediumTmp->GetItemSet().GetItemIfSet(SID_INTERACTIONHANDLER, 
false)->GetValue() == aOriginalInteract);
+    }
+
     // an interaction handler here can acquire only in case of GUI Saving
     // and should be removed after the saving is done
-    Any aOriginalInteract;
     css::uno::Reference< XInteractionHandler > xInteract;
     const SfxUnoAnyItem* pxInteractionItem = 
SfxItemSet::GetItem<SfxUnoAnyItem>(pArgs, SID_INTERACTIONHANDLER, false);
     if ( pxInteractionItem && ( pxInteractionItem->GetValue() >>= xInteract ) 
&& xInteract.is() )
-    {
-        if (const SfxUnoAnyItem *pItem = 
pMediumTmp->GetItemSet().GetItemIfSet(SID_INTERACTIONHANDLER, false))
-            aOriginalInteract = pItem->GetValue();
         pMediumTmp->GetItemSet().Put( SfxUnoAnyItem( SID_INTERACTIONHANDLER, 
Any( xInteract ) ) );
-    }
 
     const SfxBoolItem* pNoFileSync = 
pArgs->GetItem<SfxBoolItem>(SID_NO_FILE_SYNC, false);
     if (pNoFileSync && pNoFileSync->GetValue())
@@ -2784,7 +2788,10 @@ bool SfxObjectShell::DoSave_Impl( const SfxItemSet* 
pArgs )
         // reconnect to object storage
         DoSaveCompleted();
 
-        pRetrMedium->GetItemSet().ClearItem( SID_INTERACTIONHANDLER );
+        if (aOriginalInteract.hasValue())
+            
pRetrMedium->GetItemSet().Put(SfxUnoAnyItem(SID_INTERACTIONHANDLER, 
aOriginalInteract));
+        else
+            pRetrMedium->GetItemSet().ClearItem(SID_INTERACTIONHANDLER);
         pRetrMedium->GetItemSet().ClearItem( SID_PROGRESS_STATUSBAR_CONTROL );
 
         delete pMediumTmp;

Reply via email to