sfx2/source/doc/objstor.cxx | 49 +++++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 21 deletions(-)
New commits: commit 273d3b0bfaa9c425fd4355e3ffb5a7f029210923 Author: Caolán McNamara <[email protected]> AuthorDate: Wed Nov 5 09:32:00 2025 +0000 Commit: Miklos Vajna <[email protected]> CommitDate: Fri Nov 7 14:20:43 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]> diff --git a/sfx2/source/doc/objstor.cxx b/sfx2/source/doc/objstor.cxx index d7fea17a5c4b..c1449a020343 100644 --- a/sfx2/source/doc/objstor.cxx +++ b/sfx2/source/doc/objstor.cxx @@ -2992,6 +2992,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 ) { @@ -3035,16 +3049,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 @@ -3062,10 +3069,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()); @@ -3091,10 +3095,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; @@ -3220,12 +3221,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 );
