diff options
author | László Németh <nemeth@numbertext.org> | 2018-12-04 21:54:24 +0100 |
---|---|---|
committer | László Németh <nemeth@numbertext.org> | 2018-12-05 08:02:14 +0100 |
commit | 1d65ffc5a37be21e0316019b1c96eb9a1c871ac0 (patch) | |
tree | 83beadbc88b9ff42e123c835e35eef824b483b64 | |
parent | 9ad04dad665f9bfc054d0db4174f18ce154e20fc (diff) |
tdf#105413 track changes: keep paragraph styles
applied in Show Changes mode, instead of losing them
after saving the document or hiding the changes. The bug
occured in paragraphs with directly preceding tracked deletions.
Change-Id: I9a5fd1b82cb7e99884d8807d0abee1fea59d5df3
Reviewed-on: https://gerrit.libreoffice.org/64518
Reviewed-by: László Németh <nemeth@numbertext.org>
Tested-by: László Németh <nemeth@numbertext.org>
-rw-r--r-- | sw/qa/extras/uiwriter/data2/tdf105413.fodt | 38 | ||||
-rw-r--r-- | sw/qa/extras/uiwriter/uiwriter2.cxx | 69 | ||||
-rw-r--r-- | sw/source/core/edit/edfcol.cxx | 16 |
3 files changed, 123 insertions, 0 deletions
diff --git a/sw/qa/extras/uiwriter/data2/tdf105413.fodt b/sw/qa/extras/uiwriter/data2/tdf105413.fodt new file mode 100644 index 000000000000..f27ee904d82b --- /dev/null +++ b/sw/qa/extras/uiwriter/data2/tdf105413.fodt @@ -0,0 +1,38 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<office:document xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0" xmlns:ooo="http://openoffice.org/2004/office" xmlns:ooow="http://openoffice.org/2004/writer" xmlns:oooc="http://openoffice.org/2004/calc" xmlns:dom="http://www.w3.org/2001/xml-events" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:rpt="http://openoffice.org/2005/report" xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:grddl="http://www.w3.org/2003/g/data-view#" xmlns:officeooo="http://openoffice.org/2009/office" xmlns:tableooo="http://openoffice.org/2009/table" xmlns:drawooo="http://openoffice.org/2010/draw" xmlns:calcext="urn:org:documentfoundation:names:experimental:calc:xmlns:calcext:1.0" xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0" xmlns:field="urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0" xmlns:formx="urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0" xmlns:css3t="http://www.w3.org/TR/css3-text/" office:version="1.2" office:mimetype="application/vnd.oasis.opendocument.text"> + <office:body> + <office:text> + <text:tracked-changes text:track-changes="false"> + <text:changed-region xml:id="ct101395712" text:id="ct101395712"> + <text:deletion> + <office:change-info> + <dc:creator>Ismeretlen szerző</dc:creator> + <dc:date>2018-12-03T20:35:00</dc:date> + </office:change-info> + </text:deletion> + </text:changed-region> + <text:changed-region xml:id="ct101395264" text:id="ct101395264"> + <text:deletion> + <office:change-info> + <dc:creator>Ismeretlen szerző</dc:creator> + <dc:date>2018-12-03T20:34:58</dc:date> + </office:change-info> + </text:deletion> + </text:changed-region> + </text:tracked-changes> + <text:sequence-decls> + <text:sequence-decl text:display-outline-level="0" text:name="Illustration"/> + <text:sequence-decl text:display-outline-level="0" text:name="Table"/> + <text:sequence-decl text:display-outline-level="0" text:name="Text"/> + <text:sequence-decl text:display-outline-level="0" text:name="Drawing"/> + <text:sequence-decl text:display-outline-level="0" text:name="Figure"/> + </text:sequence-decls> + <text:p text:style-name="P1">Par1<text:change-start text:change-id="ct101395712"/>Par2<text:change-end text:change-id="ct101395712"/><text:change-start text:change-id="ct101395264"/></text:p> + <text:p text:style-name="P1"/> + <text:p text:style-name="P1"><text:change-end text:change-id="ct101395264"/><text:span text:style-name="T1">Format this...</text:span></text:p> + <text:p text:style-name="P1">Par3</text:p> + <text:p text:style-name="P1"/> + </office:text> + </office:body> +</office:document> diff --git a/sw/qa/extras/uiwriter/uiwriter2.cxx b/sw/qa/extras/uiwriter/uiwriter2.cxx index 0b5daf0f0fa5..0ab26ac25485 100644 --- a/sw/qa/extras/uiwriter/uiwriter2.cxx +++ b/sw/qa/extras/uiwriter/uiwriter2.cxx @@ -9,6 +9,8 @@ #include <swmodeltestbase.hxx> #include <com/sun/star/awt/FontSlant.hpp> +#include <com/sun/star/frame/DispatchHelper.hpp> +#include <comphelper/propertysequence.hxx> #include <LibreOfficeKit/LibreOfficeKitEnums.h> #include <svx/svdpage.hxx> #include <svx/svdview.hxx> @@ -38,6 +40,7 @@ public: void testTdf119571(); void testTdf119019(); void testTdf119824(); + void testTdf105413(); CPPUNIT_TEST_SUITE(SwUiWriterTest2); CPPUNIT_TEST(testRedlineMoveInsertInDelete); @@ -48,12 +51,30 @@ public: CPPUNIT_TEST(testTdf119571); CPPUNIT_TEST(testTdf119019); CPPUNIT_TEST(testTdf119824); + CPPUNIT_TEST(testTdf105413); CPPUNIT_TEST_SUITE_END(); private: SwDoc* createDoc(const char* pName = nullptr); }; +static void lcl_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)->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); +} + SwDoc* SwUiWriterTest2::createDoc(const char* pName) { if (!pName) @@ -373,6 +394,54 @@ void SwUiWriterTest2::testTdf119824() CPPUNIT_ASSERT(hasProperty(getRun(getParagraph(3), 6), "RedlineType")); } +void SwUiWriterTest2::testTdf105413() +{ + load(DATA_DIRECTORY, "tdf105413.fodt"); + + SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get()); + CPPUNIT_ASSERT(pTextDoc); + + // all paragraphs have got Standard paragraph style + for (int i = 1; i < 4; ++i) + { + CPPUNIT_ASSERT_EQUAL(OUString("Standard"), + getProperty<OUString>(getParagraph(i), "ParaStyleName")); + } + + // turn on red-lining and show changes + SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc(); + pDoc->getIDocumentRedlineAccess().SetRedlineFlags(RedlineFlags::On | RedlineFlags::ShowInsert + | RedlineFlags::ShowDelete); + CPPUNIT_ASSERT_MESSAGE("redlining should be on", + pDoc->getIDocumentRedlineAccess().IsRedlineOn()); + CPPUNIT_ASSERT_MESSAGE( + "redlines should be visible", + IDocumentRedlineAccess::IsShowChanges(pDoc->getIDocumentRedlineAccess().GetRedlineFlags())); + + // Set Heading 1 paragraph style in the 3th paragraph. + // Because of the tracked deleted region between them, + // this sets also the same style in the first paragraph automatically + // to keep the changed paragraph style at hiding tracked changes or saving the document + SwWrtShell* pWrtShell = pTextDoc->GetDocShell()->GetWrtShell(); + pWrtShell->Down(/*bSelect=*/false); + pWrtShell->Down(/*bSelect=*/false); + pWrtShell->EndPara(/*bSelect=*/false); + + uno::Sequence<beans::PropertyValue> aPropertyValues = comphelper::InitPropertySequence({ + { "Style", uno::makeAny(OUString("Heading 1")) }, + { "FamilyName", uno::makeAny(OUString("ParagraphStyles")) }, + }); + lcl_dispatchCommand(mxComponent, ".uno:StyleApply", aPropertyValues); + + CPPUNIT_ASSERT_EQUAL(OUString("Heading 1"), + getProperty<OUString>(getParagraph(3), "ParaStyleName")); + CPPUNIT_ASSERT_EQUAL(OUString("Standard"), + getProperty<OUString>(getParagraph(2), "ParaStyleName")); + // first paragraph gets the same heading style + CPPUNIT_ASSERT_EQUAL(OUString("Heading 1"), + getProperty<OUString>(getParagraph(1), "ParaStyleName")); +} + CPPUNIT_TEST_SUITE_REGISTRATION(SwUiWriterTest2); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/core/edit/edfcol.cxx b/sw/source/core/edit/edfcol.cxx index 083ad320fbec..3164e00dd0f0 100644 --- a/sw/source/core/edit/edfcol.cxx +++ b/sw/source/core/edit/edfcol.cxx @@ -93,6 +93,7 @@ #include <com/sun/star/beans/PropertyAttribute.hpp> #include <tools/diagnose_ex.h> +#include <IDocumentRedlineAccess.hxx> #define WATERMARK_NAME "PowerPlusWaterMarkObject" #define WATERMARK_AUTO_SIZE sal_uInt32(1) @@ -2173,6 +2174,8 @@ void SwEditShell::SetTextFormatColl(SwTextFormatColl *pFormat, SwTextFormatColl *pLocal = pFormat? pFormat: (*GetDoc()->GetTextFormatColls())[0]; StartAllAction(); + RedlineFlags eRedlMode = GetDoc()->getIDocumentRedlineAccess().GetRedlineFlags(), eOldMode = eRedlMode; + SwRewriter aRewriter; aRewriter.AddRule(UndoArg1, pLocal->GetName()); @@ -2182,6 +2185,17 @@ void SwEditShell::SetTextFormatColl(SwTextFormatColl *pFormat, if ( !rPaM.HasReadonlySel( GetViewOptions()->IsFormView() ) ) { + // tdf#105413 turn off ShowChanges mode for the next loops to apply styles permanently with redlining, + // ie. in all directly preceding deleted paragraphs at the actual cursor positions + if ( IDocumentRedlineAccess::IsShowChanges(eRedlMode) && + // is there redlining at beginning of the position (possible redline block before the modified node) + GetDoc()->getIDocumentRedlineAccess().GetRedlinePos( (*rPaM.Start()).nNode.GetNode(), USHRT_MAX ) < + GetDoc()->getIDocumentRedlineAccess().GetRedlineTable().size() ) + { + eRedlMode = RedlineFlags::ShowInsert | RedlineFlags::Ignore; + GetDoc()->getIDocumentRedlineAccess().SetRedlineFlags( eRedlMode ); + } + // Change the paragraph style to pLocal and remove all direct paragraph formatting. GetDoc()->SetTextFormatColl(rPaM, pLocal, true, bResetListAttrs, GetLayout()); @@ -2198,6 +2212,8 @@ void SwEditShell::SetTextFormatColl(SwTextFormatColl *pFormat, } GetDoc()->GetIDocumentUndoRedo().EndUndo(SwUndoId::SETFMTCOLL, &aRewriter); EndAllAction(); + + GetDoc()->getIDocumentRedlineAccess().SetRedlineFlags( eOldMode ); } SwTextFormatColl* SwEditShell::MakeTextFormatColl(const OUString& rFormatCollName, |