sfx2/source/doc/objstor.cxx | 49 +++++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 21 deletions(-)
New commits: commit 56f49a41b8ebdf07a5cb1059e470037e3609e337 Author: Caolán McNamara <[email protected]> AuthorDate: Wed Nov 5 09:32:00 2025 +0000 Commit: Andras Timar <[email protected]> CommitDate: Mon Nov 10 11:13:57 2025 +0100 always restore original interaction handler after dosave this is similar to: commit a2007364e77aebbbc45fa8fab2c58f95a821dd18 Date: Thu May 16 14:37:52 2024 +0100 always restore existing interaction handler after save except for this other save-alike case which is used to export elements of the document Change-Id: I7da6ddde2503364274ac1292f92a7666b3afaced Reviewed-on: https://gerrit.libreoffice.org/c/core/+/193449 Tested-by: Jenkins CollaboraOffice <[email protected]> Reviewed-by: Miklos Vajna <[email protected]> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/193730 Tested-by: Andras Timar <[email protected]> Reviewed-by: Andras Timar <[email protected]> diff --git a/sfx2/source/doc/objstor.cxx b/sfx2/source/doc/objstor.cxx index d132b2df4337..43a7a9e140c2 100644 --- a/sfx2/source/doc/objstor.cxx +++ b/sfx2/source/doc/objstor.cxx @@ -2984,6 +2984,20 @@ bool SfxObjectShell::ConvertTo return false; } +static Any getItemSetInteractionHandler(const SfxItemSet& rItemSet) +{ + if (const SfxUnoAnyItem *pItem = rItemSet.GetItemIfSet(SID_INTERACTIONHANDLER, false)) + return pItem->GetValue(); + return Any(); +} + +static void setItemSetInteractionHandler(SfxItemSet& rItemSet, const Any& rOriginalInteract) +{ + if (rOriginalInteract.hasValue()) + rItemSet.Put(SfxUnoAnyItem(SID_INTERACTIONHANDLER, rOriginalInteract)); + else + rItemSet.ClearItem(SID_INTERACTIONHANDLER); +} bool SfxObjectShell::DoSave_Impl( const SfxItemSet* pArgs ) { @@ -3027,16 +3041,9 @@ bool SfxObjectShell::DoSave_Impl( const SfxItemSet* pArgs ) pMediumTmp->TransferVersionList_Impl( *pRetrMedium ); // Save the original interaction handler - Any aOriginalInteract; - if (const SfxUnoAnyItem *pItem = pRetrMedium->GetItemSet().GetItemIfSet(SID_INTERACTIONHANDLER, false)) - { - aOriginalInteract = pItem->GetValue(); -#ifndef NDEBUG - // The original pRetrMedium and potential replacement pMediumTmp have the same interaction handler at this point - const SfxUnoAnyItem *pMediumItem = pMediumTmp->GetItemSet().GetItemIfSet(SID_INTERACTIONHANDLER, false); - assert(pMediumItem && pMediumItem->GetValue() == aOriginalInteract); -#endif - } + Any aOriginalInteract = getItemSetInteractionHandler(pRetrMedium->GetItemSet()); + // The original pRetrMedium and potential replacement pMediumTmp have the same interaction handler at this point + assert(getItemSetInteractionHandler(pMediumTmp->GetItemSet()) == aOriginalInteract); // an interaction handler here can acquire only in case of GUI Saving // and should be removed after the saving is done @@ -3054,10 +3061,7 @@ bool SfxObjectShell::DoSave_Impl( const SfxItemSet* pArgs ) { bSaved = true; - if (aOriginalInteract.hasValue()) - pMediumTmp->GetItemSet().Put(SfxUnoAnyItem(SID_INTERACTIONHANDLER, aOriginalInteract)); - else - pMediumTmp->GetItemSet().ClearItem(SID_INTERACTIONHANDLER); + setItemSetInteractionHandler(pMediumTmp->GetItemSet(), aOriginalInteract); pMediumTmp->GetItemSet().ClearItem( SID_PROGRESS_STATUSBAR_CONTROL ); SetError(pMediumTmp->GetErrorCode()); @@ -3083,10 +3087,7 @@ bool SfxObjectShell::DoSave_Impl( const SfxItemSet* pArgs ) // reconnect to object storage DoSaveCompleted(); - if (aOriginalInteract.hasValue()) - pRetrMedium->GetItemSet().Put(SfxUnoAnyItem(SID_INTERACTIONHANDLER, aOriginalInteract)); - else - pRetrMedium->GetItemSet().ClearItem(SID_INTERACTIONHANDLER); + setItemSetInteractionHandler(pRetrMedium->GetItemSet(), aOriginalInteract); pRetrMedium->GetItemSet().ClearItem( SID_PROGRESS_STATUSBAR_CONTROL ); delete pMediumTmp; @@ -3212,12 +3213,18 @@ bool SfxObjectShell::CommonSaveAs_Impl(const INetURLObject& aURL, const OUString aTempFileURL = pMedium->GetURLObject().GetMainURL( INetURLObject::DecodeMechanism::NONE ); #endif - if (PreDoSaveAs_Impl(aURL.GetMainURL(INetURLObject::DecodeMechanism::NONE), aFilterName, - rItemSet, rArgs)) + // Save the original interaction handler + Any aOriginalInteract = getItemSetInteractionHandler(GetMedium()->GetItemSet()); + + bool bResult = PreDoSaveAs_Impl(aURL.GetMainURL(INetURLObject::DecodeMechanism::NONE), aFilterName, + rItemSet, rArgs); + + setItemSetInteractionHandler(GetMedium()->GetItemSet(), aOriginalInteract); + + if (bResult) { // Update Data on media SfxItemSet& rSet = GetMedium()->GetItemSet(); - rSet.ClearItem( SID_INTERACTIONHANDLER ); rSet.ClearItem( SID_PROGRESS_STATUSBAR_CONTROL ); rSet.ClearItem( SID_STANDARD_DIR ); rSet.ClearItem( SID_PATH );
