From 2bc4c7ea1922daec14a23cea9d9452205d58b408 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= Date: Sun, 27 Sep 2026 15:48:43 +0000 Subject: [PATCH] save the document Basic and dialog libraries without the BasicManager MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Store the library containers directly. Creating the BasicManager first loads the libraries only to save them again. Signed-off-by: Caolán McNamara Change-Id: I056cf4d8549ab5b9ecf31072704bfcd70e13f7e6 Reviewed-on: https://gerrit.collaboraoffice.com/c/online/+/13645 Reviewed-by: Noel Grandin Tested-by: Jenkins CPCI (cherry picked from commit 358ad5b06facfa12061d94586f66cfbd01ffe4d3) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/211525 Tested-by: Jenkins Reviewed-by: Xisco Fauli --- sfx2/source/doc/objstor.cxx | 58 +++++++++++++++++++++++++++---------- 1 file changed, 42 insertions(+), 16 deletions(-) diff --git a/sfx2/source/doc/objstor.cxx b/sfx2/source/doc/objstor.cxx index 136b1678e5cf..47ca42c49816 100644 --- a/sfx2/source/doc/objstor.cxx +++ b/sfx2/source/doc/objstor.cxx @@ -56,6 +56,7 @@ #include #include #include +#include #include #include #include @@ -1232,6 +1233,22 @@ bool SfxObjectShell::IsPackageStorageFormat_Impl(const SfxMedium &rMedium) } +#if HAVE_FEATURE_SCRIPTING +namespace +{ +// A loaded library is stored through the document BasicManager, and an unloaded one is copied +// from the old storage. +bool lcl_isAnyLibraryLoaded( const uno::Reference< script::XStorageBasedLibraryContainer >& xContainer ) +{ + if ( !xContainer.is() ) + return false; + const uno::Sequence< OUString > aNames = xContainer->getElementNames(); + return std::any_of( aNames.begin(), aNames.end(), + [&xContainer]( const OUString& rName ) { return xContainer->isLibraryLoaded( rName ); } ); +} +} +#endif + bool SfxObjectShell::DoSave() // DoSave is only invoked for OLE. Save your own documents in the SFX through // DoSave_Impl order to allow for the creation of backups. @@ -1277,7 +1294,7 @@ bool SfxObjectShell::DoSave() bOk = true; } #if HAVE_FEATURE_SCRIPTING - if ( HasBasic() ) + if ( !pImpl->m_bNoBasicCapabilities ) { try { @@ -1296,16 +1313,21 @@ bool SfxObjectShell::DoSave() if ( GetMedium()->GetStorage()->hasByName( aDialogsStorageName ) ) GetMedium()->GetStorage()->copyElementTo( aDialogsStorageName, xTmpStorage, aDialogsStorageName ); - GetBasicManager(); - - // disconnect from the current storage - pImpl->aBasicManager.setStorage( xTmpStorage ); - - // store to the current storage - pImpl->aBasicManager.storeLibrariesToStorage( GetMedium()->GetStorage() ); - - // connect to the current storage back - pImpl->aBasicManager.setStorage( GetMedium()->GetStorage() ); + const uno::Reference< script::XStorageBasedLibraryContainer > aContainers[] + = { GetBasicContainer(), GetDialogContainer() }; + if ( lcl_isAnyLibraryLoaded( aContainers[0] ) ) + GetBasicManager(); + for ( const auto& xContainer : aContainers ) + { + if ( !xContainer.is() ) + continue; + // disconnect from the current storage + xContainer->setRootStorage( xTmpStorage ); + // store to the current storage + xContainer->storeLibrariesToStorage( GetMedium()->GetStorage() ); + // connect to the current storage back + xContainer->setRootStorage( GetMedium()->GetStorage() ); + } } catch( uno::Exception& ) { @@ -3475,13 +3497,17 @@ bool SfxObjectShell::SaveAsOwnFormat( SfxMedium& rMedium ) SetupStorage( xStorage, nVersion, bTemplate ); #if HAVE_FEATURE_SCRIPTING - if ( HasBasic() ) + if ( !pImpl->m_bNoBasicCapabilities ) { - // Initialize Basic - GetBasicManager(); - // Save dialog/script container - pImpl->aBasicManager.storeLibrariesToStorage( xStorage ); + if ( uno::Reference< script::XStorageBasedLibraryContainer > xBasicLibraries = GetBasicContainer() ) + { + if ( lcl_isAnyLibraryLoaded( xBasicLibraries ) ) + GetBasicManager(); + xBasicLibraries->storeLibrariesToStorage( xStorage ); + } + if ( uno::Reference< script::XStorageBasedLibraryContainer > xDialogLibraries = GetDialogContainer() ) + xDialogLibraries->storeLibrariesToStorage( xStorage ); } #endif