From 2aad85f84235f362604b5fd385bb77de839d2014 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Tue, 23 Jun 2020 10:31:05 +0200 Subject: sw: fix missing OLE preview on updating links Regression from commit 74844277cc2194c9e43f5bd7a6f78a9603da32f3 (disable generation of ole previews in ODF format until after load, 2016-09-13), if the document has charts without previews, it's loaded, fields are updated and saved, we no longer generate those previews. Given that Tools -> Update -> Update all is always an explicit user action, restore the permission to update OLE previews / links before performing the actual update. With this, comphelper::EmbeddedObjectContainer::StoreAsChildren() will generate those missing previews inside the getUserAllowsLinkUpdate() conditional block. Change-Id: Ib54e06a2e2f2e1c65951fdec302e59e63c71d008 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/96928 Reviewed-by: Miklos Vajna Tested-by: Jenkins --- .../uibase/shells/data/ole-save-preview-update.odt | Bin 0 -> 16006 bytes sw/qa/uibase/shells/shells.cxx | 33 +++++++++++++++++++-- sw/source/uibase/shells/basesh.cxx | 4 +++ 3 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 sw/qa/uibase/shells/data/ole-save-preview-update.odt diff --git a/sw/qa/uibase/shells/data/ole-save-preview-update.odt b/sw/qa/uibase/shells/data/ole-save-preview-update.odt new file mode 100644 index 000000000000..353ce7fa050c Binary files /dev/null and b/sw/qa/uibase/shells/data/ole-save-preview-update.odt differ diff --git a/sw/qa/uibase/shells/shells.cxx b/sw/qa/uibase/shells/shells.cxx index c1012d6af1d1..fbdf35758156 100644 --- a/sw/qa/uibase/shells/shells.cxx +++ b/sw/qa/uibase/shells/shells.cxx @@ -26,16 +26,21 @@ #include #include +static char const DATA_DIRECTORY[] = "/sw/qa/uibase/shells/data/"; + /// Covers sw/source/uibase/shells/ fixes. class SwUibaseShellsTest : public SwModelTestBase { public: - SwDoc* createDoc(); + SwDoc* createDoc(const char* pName = nullptr); }; -SwDoc* SwUibaseShellsTest::createDoc() +SwDoc* SwUibaseShellsTest::createDoc(const char* pName) { - loadURL("private:factory/swriter", nullptr); + if (!pName) + loadURL("private:factory/swriter", nullptr); + else + load(DATA_DIRECTORY, pName); SwXTextDocument* pTextDoc = dynamic_cast(mxComponent.get()); CPPUNIT_ASSERT(pTextDoc); @@ -112,6 +117,28 @@ CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testShapeTextAlignment) #endif } +CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testOleSavePreviewUpdate) +{ + // Load a document with 2 charts in it. The second is down enough that you have to scroll to + // trigger its rendering. Previews are missing for both. + createDoc("ole-save-preview-update.odt"); + + // Explicitly update OLE previews, etc. + dispatchCommand(mxComponent, ".uno:UpdateAll", {}); + + // Save the document and see if we get the previews. + uno::Reference xStorable(mxComponent, uno::UNO_QUERY); + xStorable->storeToURL(maTempFile.GetURL(), {}); + uno::Reference xNameAccess + = packages::zip::ZipFileAccess::createWithURL(comphelper::getComponentContext(m_xSFactory), + maTempFile.GetURL()); + + // Without the accompanying fix in place, this test would have failed, because the object + // replacements were not generated, even after UpdateAll. + CPPUNIT_ASSERT(xNameAccess->hasByName("ObjectReplacements/Object 1")); + CPPUNIT_ASSERT(xNameAccess->hasByName("ObjectReplacements/Object 2")); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/uibase/shells/basesh.cxx b/sw/source/uibase/shells/basesh.cxx index 64fd150e1700..c01c31da877c 100644 --- a/sw/source/uibase/shells/basesh.cxx +++ b/sw/source/uibase/shells/basesh.cxx @@ -716,6 +716,10 @@ void SwBaseShell::Execute(SfxRequest &rReq) case FN_UPDATE_ALL: { + comphelper::EmbeddedObjectContainer& rEmbeddedObjectContainer + = GetObjectShell()->getEmbeddedObjectContainer(); + rEmbeddedObjectContainer.setUserAllowsLinkUpdate(true); + SwView& rTempView = GetView(); rSh.EnterStdMode(); if( !rSh.GetLinkManager().GetLinks().empty() ) -- cgit v1.2.3