diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2019-08-16 15:04:15 +0200 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2019-08-16 20:46:06 +0200 |
commit | 6dc0f6b65e79ca4af69338411e3887d9aaef1cac (patch) | |
tree | e9076d801bbc7280785f5299c9cc577f8cf8aaf1 /sw | |
parent | e380e353485c3479abe645d3b6da9e007057a079 (diff) |
This was meant to be 'continue', not 'break'
... when commit ee0bf5d58bc59052923c4ced928a989956e71456 had introduced
SwUnoCursorHelper::SetPropertyValues, and the intent obviously was to
skip bad values, populating relevant error messages, and set all correct
values.
Change-Id: Id699f74a9df179c810608400983f88db1a7164b8
Reviewed-on: https://gerrit.libreoffice.org/77584
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'sw')
-rw-r--r-- | sw/qa/extras/unowriter/unowriter.cxx | 23 | ||||
-rw-r--r-- | sw/source/core/unocore/unoobj.cxx | 12 |
2 files changed, 29 insertions, 6 deletions
diff --git a/sw/qa/extras/unowriter/unowriter.cxx b/sw/qa/extras/unowriter/unowriter.cxx index e819cb9d7d7d..ffb57d836f48 100644 --- a/sw/qa/extras/unowriter/unowriter.cxx +++ b/sw/qa/extras/unowriter/unowriter.cxx @@ -621,6 +621,29 @@ CPPUNIT_TEST_FIXTURE(SwUnoWriter, testViewCursorPageStyle) CPPUNIT_ASSERT_EQUAL(OUString("Standard"), aActualPageStyleName); } +CPPUNIT_TEST_FIXTURE(SwUnoWriter, testXTextCursor_setPropertyValues) +{ + // Create a new document, type a character, pass a set of property/value pairs consisting of one + // unknown property and CharStyleName, assert that it threw UnknownPropertyException (actually + // wrapped into WrappedTargetException), and assert the style was set, not discarded. + loadURL("private:factory/swriter", nullptr); + + uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY); + uno::Reference<text::XSimpleText> xBodyText = xTextDocument->getText(); + xBodyText->insertString(xBodyText->getStart(), "x", false); + + uno::Reference<text::XTextCursor> xCursor(xBodyText->createTextCursor()); + xCursor->goLeft(1, true); + + uno::Reference<beans::XMultiPropertySet> xCursorProps(xCursor, uno::UNO_QUERY); + uno::Sequence<OUString> aPropNames = { "OneUnknownProperty", "CharStyleName" }; + uno::Sequence<uno::Any> aPropValues = { uno::Any(), uno::Any(OUString("Emphasis")) }; + CPPUNIT_ASSERT_THROW(xCursorProps->setPropertyValues(aPropNames, aPropValues), + lang::WrappedTargetException); + CPPUNIT_ASSERT_EQUAL(OUString("Emphasis"), + getProperty<OUString>(xCursorProps, "CharStyleName")); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/core/unocore/unoobj.cxx b/sw/source/core/unocore/unoobj.cxx index 7da731df197a..0b1b3c78b083 100644 --- a/sw/source/core/unocore/unoobj.cxx +++ b/sw/source/core/unocore/unoobj.cxx @@ -1784,7 +1784,7 @@ void SwUnoCursorHelper::SetPropertyValues( // Build set of attributes we want to fetch std::vector<sal_uInt16> aWhichPairs; - std::vector<SfxItemPropertySimpleEntry const*> aEntries; + std::vector<std::pair<const SfxItemPropertySimpleEntry*, const uno::Any&>> aEntries; aEntries.reserve(rPropertyValues.getLength()); for (const auto& rPropVal : rPropertyValues) { @@ -1797,18 +1797,18 @@ void SwUnoCursorHelper::SetPropertyValues( if (!pEntry) { aUnknownExMsg += "Unknown property: '" + rPropertyName + "' "; - break; + continue; } else if (pEntry->nFlags & beans::PropertyAttribute::READONLY) { aPropertyVetoExMsg += "Property is read-only: '" + rPropertyName + "' "; - break; + continue; } else { // FIXME: we should have some nice way of merging ranges surely ? aWhichPairs.push_back(pEntry->nWID); aWhichPairs.push_back(pEntry->nWID); } - aEntries.push_back(pEntry); + aEntries.emplace_back(pEntry, rPropVal.Value); } if (!aWhichPairs.empty()) @@ -1821,7 +1821,7 @@ void SwUnoCursorHelper::SetPropertyValues( bool bPreviousPropertyCausesSideEffectsInNodes = false; for (size_t i = 0; i < aEntries.size(); ++i) { - SfxItemPropertySimpleEntry const*const pEntry = aEntries[i]; + SfxItemPropertySimpleEntry const*const pEntry = aEntries[i].first; bool bPropertyCausesSideEffectsInNodes = propertyCausesSideEffectsInNodes(pEntry->nWID); @@ -1832,7 +1832,7 @@ void SwUnoCursorHelper::SetPropertyValues( SwUnoCursorHelper::GetCursorAttr(rPaM, aItemSet); } - const uno::Any &rValue = rPropertyValues[i].Value; + const uno::Any &rValue = aEntries[i].second; // this can set some attributes in nodes' mpAttrSet if (!SwUnoCursorHelper::SetCursorPropertyValue(*pEntry, rValue, rPaM, aItemSet)) rPropSet.setPropertyValue(*pEntry, rValue, aItemSet); |