framework/source/uiconfiguration/imagemanagerimpl.cxx | 55 ++++++++++++++++-- framework/source/uiconfiguration/imagemanagerimpl.hxx | 1 sw/qa/extras/odfexport/odfexport.cxx | 4 - 3 files changed, 53 insertions(+), 7 deletions(-)
New commits: commit 0e5981487a480e850b1a3259b5de462d9e17823a Author: David Hashe <m...@dhashe.com> AuthorDate: Wed Apr 2 14:34:05 2025 -0400 Commit: Caolán McNamara <caolan.mcnam...@collabora.com> CommitDate: Tue May 27 13:49:27 2025 +0200 tdf#60700 stop creating empty Configurations2/images in ODFs This change stops the creation of empty Configurations2/images dirs on new documents that do not have anything that needs to be stored there. Previously, LibreOffice would always create this directory. Whenever an XStorage is opened readwrite on a path, it will immediately create that path. LibreOffice was opening all of these paths readwrite. So, the solution is to always open these paths as readonly, and then when we need to write data to them we close them and re-open them as readwrite. If we never need to write data to a path, then it won't be created. This patch specifically stops the creation of subdirectories that were being created by ImageManager. Other patches in the relation chain handle paths created by UIConfigurationManager and DocumentAcceleratorConfiguration. Test coverage was added in b9054fed3724a19479e221a8b4818a127a18aabe $ CPPUNIT_TEST_NAME="Test testTdf60700_images" make CppunitTest_sw_odfexport I also manually tested with the following procedure: 1. Open a new document in writer. 2. Tools > Customize > Toolbars. 3. Set scope to "Untitled 1". 4. Add a new toolbar "New Toolbar 1". 5. Add any command from Available Commands to the new toolbar. 6. Add any icon 7. OK. 8. Visually verify that the toolbar is present with the custom icon. 9. Save the document. 10. Verify that the custom icon is saved correctly inside the file. $ unzip -l Untitled\ 1.odt Archive: Untitled 1.odt Length Date Time Name --------- ---------- ----- ---- 39 2025-05-17 16:01 mimetype 353 2025-05-17 16:01 Configurations2/toolbar/custom_toolbar_cba48a4e.xml 444 2025-05-17 16:01 Configurations2/images/lc_imagelist.xml 469 2025-05-17 16:01 Configurations2/images/Bitmaps/lc_userimages.png 0 2025-05-17 16:01 Configurations2/accelerator/ 13358 2025-05-17 16:01 styles.xml 899 2025-05-17 16:01 manifest.rdf 3771 2025-05-17 16:01 content.xml 1011 2025-05-17 16:01 meta.xml 14746 2025-05-17 16:01 settings.xml 318 2025-05-17 16:01 Thumbnails/thumbnail.png 1406 2025-05-17 16:01 META-INF/manifest.xml --------- ------- 36814 12 files 10. Close and reopen the document. 11. Visually verify that the toolbar with the custom icon is present. Change-Id: I48b2b8f540f7640ae25da6f27065e7b07f955c7e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/185450 Tested-by: Jenkins Tested-by: Caolán McNamara <caolan.mcnam...@collabora.com> Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com> diff --git a/framework/source/uiconfiguration/imagemanagerimpl.cxx b/framework/source/uiconfiguration/imagemanagerimpl.cxx index c351971aa1bb..86b450afd86c 100644 --- a/framework/source/uiconfiguration/imagemanagerimpl.cxx +++ b/framework/source/uiconfiguration/imagemanagerimpl.cxx @@ -289,16 +289,14 @@ void ImageManagerImpl::implts_initialize() if ( !m_xUserConfigStorage.is() ) return; - tools::Long nModes = m_bReadOnly ? ElementModes::READ : ElementModes::READWRITE; - try { m_xUserImageStorage = m_xUserConfigStorage->openStorageElement( IMAGE_FOLDER, - nModes ); + ElementModes::READ ); if ( m_xUserImageStorage.is() ) { m_xUserBitmapsStorage = m_xUserImageStorage->openStorageElement( BITMAPS_FOLDER, - nModes ); + ElementModes::READ ); } } catch ( const css::container::NoSuchElementException& ) @@ -516,6 +514,7 @@ ImageManagerImpl::ImageManagerImpl( uno::Reference< uno::XComponentContext > xCo , m_bInitialized( false ) , m_bModified( false ) , m_bDisposed( false ) + , m_bShouldReloadRWOnStore( false ) { for ( vcl::ImageType n : o3tl::enumrange<vcl::ImageType>() ) { @@ -614,8 +613,10 @@ void ImageManagerImpl::initialize( const Sequence< Any >& aArguments ) if ( xPropSet.is() ) { tools::Long nOpenMode = 0; - if ( xPropSet->getPropertyValue(u"OpenMode"_ustr) >>= nOpenMode ) + if ( xPropSet->getPropertyValue(u"OpenMode"_ustr) >>= nOpenMode ) { m_bReadOnly = !( nOpenMode & ElementModes::WRITE ); + m_bShouldReloadRWOnStore = !m_bReadOnly; + } } } @@ -1128,6 +1129,50 @@ void ImageManagerImpl::store() if ( !m_bModified ) return; + if ( m_bShouldReloadRWOnStore ) { + m_bShouldReloadRWOnStore = false; + + m_xUserBitmapsStorage.clear(); + m_xUserImageStorage.clear(); + + try + { + uno::Reference< XStorage > xUserImageStorage = + m_xUserConfigStorage->openStorageElement( IMAGE_FOLDER, ElementModes::READWRITE ); + if ( !xUserImageStorage.is() ) + throw css::uno::Exception(); + + uno::Reference< XStorage > xUserBitmapsStorage = + xUserImageStorage->openStorageElement( BITMAPS_FOLDER, ElementModes::READWRITE ); + if ( !xUserBitmapsStorage.is() ) + throw css::uno::Exception(); + + m_xUserImageStorage = std::move( xUserImageStorage ); + m_xUserBitmapsStorage = std::move( xUserBitmapsStorage ); + } catch ( const css::uno::Exception& ) + { + try + { + uno::Reference< XStorage > xUserImageStorage = + m_xUserConfigStorage->openStorageElement( IMAGE_FOLDER, ElementModes::READ ); + if ( !xUserImageStorage.is() ) + return; + + uno::Reference< XStorage > xUserBitmapsStorage = + xUserImageStorage->openStorageElement( BITMAPS_FOLDER, ElementModes::READ ); + if ( !xUserBitmapsStorage.is() ) + return; + + m_xUserImageStorage = std::move( xUserImageStorage ); + m_xUserBitmapsStorage = std::move( xUserBitmapsStorage ); + } catch ( const css::uno::Exception& ) + { + } + + return; + } + } + bool bWritten( false ); for ( vcl::ImageType i : o3tl::enumrange<vcl::ImageType>() ) { diff --git a/framework/source/uiconfiguration/imagemanagerimpl.hxx b/framework/source/uiconfiguration/imagemanagerimpl.hxx index 643436d48b36..fee621c8b17e 100644 --- a/framework/source/uiconfiguration/imagemanagerimpl.hxx +++ b/framework/source/uiconfiguration/imagemanagerimpl.hxx @@ -183,6 +183,7 @@ namespace framework bool m_bInitialized; bool m_bModified; bool m_bDisposed; + bool m_bShouldReloadRWOnStore; }; } diff --git a/sw/qa/extras/odfexport/odfexport.cxx b/sw/qa/extras/odfexport/odfexport.cxx index ca4efa7076be..ce18c0c0fa84 100644 --- a/sw/qa/extras/odfexport/odfexport.cxx +++ b/sw/qa/extras/odfexport/odfexport.cxx @@ -1554,8 +1554,8 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf60700_directories) } } - // There should be two elements ("accelerator", "images") within Configurations2/ on a fresh document. - CPPUNIT_ASSERT_EQUAL(2, nMatches); + // There should be one element ("accelerator") within Configurations2/ on a fresh document. + CPPUNIT_ASSERT_EQUAL(1, nMatches); }