summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2020-11-18 17:55:13 +0100
committerMiklos Vajna <vmiklos@collabora.com>2020-11-19 17:55:45 +0100
commitd121a9959adb9bc2e3781ae24b3f36763cd6f0c8 (patch)
tree42900a19ef336add35fba9e0d1eaff5cb725e373
parent0a9012e5375a84de8065947d8a8a75dd53976cfc (diff)
sw replacement image creation: fix this when an ODT's settings.xml is invalid
This builds on top of commit c123bfff501229f398a1b679fc7434b82d53685c (Bin overly eager early return that stops replacement image creation, 2020-08-20), and handles a similar case, when SwView::ReadUserDataSequence() is not called at all. The result is the same: no shell is selected on the command dispatcher stack, so .uno:UpdateAll is ignored and the replacement images are not created. (cherry picked from commit 693f12ad57912c2356a197d9a794e6108ce79ef2) Conflicts: sfx2/source/view/sfxbasecontroller.cxx sw/source/uibase/uiview/view.cxx Change-Id: If8b74424b0ad88e63129fd8f7efd09f85e300895
-rw-r--r--sfx2/source/view/sfxbasecontroller.cxx12
-rw-r--r--sw/qa/uibase/uiview/data/update-replacement-nosetting.odtbin0 -> 40982 bytes
-rw-r--r--sw/qa/uibase/uiview/uiview.cxx45
-rw-r--r--sw/source/uibase/uiview/view.cxx1
4 files changed, 54 insertions, 4 deletions
diff --git a/sfx2/source/view/sfxbasecontroller.cxx b/sfx2/source/view/sfxbasecontroller.cxx
index b7947d3dc648..12f44335230c 100644
--- a/sfx2/source/view/sfxbasecontroller.cxx
+++ b/sfx2/source/view/sfxbasecontroller.cxx
@@ -1384,12 +1384,18 @@ void SfxBaseController::ConnectSfxFrame_Impl( const ConnectSfxFrame i_eConnect )
break;
}
}
- if ( nViewDataIndex < nCount )
+ if (nViewDataIndex < nCount || !xViewData.is())
{
Sequence< PropertyValue > aViewData;
- OSL_VERIFY( xViewData->getByIndex( nViewDataIndex ) >>= aViewData );
- if ( aViewData.getLength() > 0 )
+ if (xViewData.is())
+ {
+ OSL_VERIFY(xViewData->getByIndex(nViewDataIndex) >>= aViewData);
+ }
+ if (aViewData.getLength() > 0 || !xViewData.is())
+ {
+ // Tolerate empty xViewData, ReadUserDataSequence() has side effects.
m_pData->m_pViewShell->ReadUserDataSequence( aViewData );
+ }
}
}
catch (const Exception&)
diff --git a/sw/qa/uibase/uiview/data/update-replacement-nosetting.odt b/sw/qa/uibase/uiview/data/update-replacement-nosetting.odt
new file mode 100644
index 000000000000..055c3d1a2c2a
--- /dev/null
+++ b/sw/qa/uibase/uiview/data/update-replacement-nosetting.odt
Binary files differ
diff --git a/sw/qa/uibase/uiview/uiview.cxx b/sw/qa/uibase/uiview/uiview.cxx
index 8827cea10752..72900f9db54b 100644
--- a/sw/qa/uibase/uiview/uiview.cxx
+++ b/sw/qa/uibase/uiview/uiview.cxx
@@ -12,6 +12,7 @@
#include <unotools/mediadescriptor.hxx>
#include <comphelper/processfactory.hxx>
#include <osl/file.hxx>
+#include <comphelper/propertyvalue.hxx>
#include <com/sun/star/frame/DispatchHelper.hpp>
#include <com/sun/star/frame/XComponentLoader.hpp>
@@ -87,6 +88,50 @@ CPPUNIT_TEST_FIXTURE(SwUibaseUiviewTest, testUpdateAllObjectReplacements)
CPPUNIT_ASSERT(xNameAccess->hasByName("ObjectReplacements/Components_1"));
}
+namespace
+{
+void dispatchCommand(const uno::Reference<lang::XComponent>& xComponent,
+ const OUString& rCommand,
+ const uno::Sequence<beans::PropertyValue>& rPropertyValues)
+{
+ uno::Reference<frame::XController> xController
+ = uno::Reference<frame::XModel>(xComponent, uno::UNO_QUERY_THROW)->getCurrentController();
+ CPPUNIT_ASSERT(xController.is());
+ uno::Reference<frame::XDispatchProvider> xFrame(xController->getFrame(), uno::UNO_QUERY);
+ CPPUNIT_ASSERT(xFrame.is());
+
+ uno::Reference<uno::XComponentContext> xContext = ::comphelper::getProcessComponentContext();
+ uno::Reference<frame::XDispatchHelper> xDispatchHelper(frame::DispatchHelper::create(xContext));
+ CPPUNIT_ASSERT(xDispatchHelper.is());
+
+ xDispatchHelper->executeDispatch(xFrame, rCommand, OUString(), 0, rPropertyValues);
+}
+}
+
+CPPUNIT_TEST_FIXTURE(SwUibaseUiviewTest, testUpdateReplacementNosetting)
+{
+ // Load a copy of the document in hidden mode.
+ OUString aSourceURL
+ = m_directories.getURLFromSrc(DATA_DIRECTORY) + "update-replacement-nosetting.odt";
+ CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, osl::File::copy(aSourceURL, maTempFile.GetURL()));
+ mxComponent = loadFromDesktop(maTempFile.GetURL(), "com.sun.star.text.TextDocument",
+ { comphelper::makePropertyValue("Hidden", true) });
+
+ // Update "everything" (including object replacements) and save it.
+ dispatchCommand(mxComponent, ".uno:UpdateAll", {});
+ uno::Reference<frame::XStorable2> xStorable(mxComponent, uno::UNO_QUERY);
+ xStorable->storeSelf({});
+
+ // Check the contents of the updated copy.
+ uno::Reference<uno::XComponentContext> xContext = comphelper::getProcessComponentContext();
+ uno::Reference<packages::zip::XZipFileAccess2> xNameAccess
+ = packages::zip::ZipFileAccess::createWithURL(xContext, maTempFile.GetURL());
+
+ // Without the accompanying fix in place, this test would have failed, because the embedded
+ // object replacement image was not generated.
+ CPPUNIT_ASSERT(xNameAccess->hasByName("ObjectReplacements/Components"));
+}
+
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/uibase/uiview/view.cxx b/sw/source/uibase/uiview/view.cxx
index c6cbd9319be8..d806b3758153 100644
--- a/sw/source/uibase/uiview/view.cxx
+++ b/sw/source/uibase/uiview/view.cxx
@@ -1242,7 +1242,6 @@ void SwView::ReadUserDataSequence ( const uno::Sequence < beans::PropertyValue >
return;
bool bIsOwnDocument = lcl_IsOwnDocument( *this );
sal_Int32 nLength = rSequence.getLength();
- if (nLength)
{
SET_CURR_SHELL(m_pWrtShell);
const beans::PropertyValue *pValue = rSequence.getConstArray();