[Libreoffice-commits] core.git: sw/qa sw/source

László Németh (via logerrit) logerrit at kemper.freedesktop.org
Wed Jan 20 10:55:08 UTC 2021


 sw/qa/extras/uiwriter/uiwriter2.cxx           |   41 +++++++++++++++++++++++--
 sw/source/core/doc/DocumentRedlineManager.cxx |   42 ++++++++++++++++++++++++++
 sw/source/core/inc/DocumentRedlineManager.hxx |    3 +
 sw/source/core/view/viewsh.cxx                |    8 ++++
 4 files changed, 91 insertions(+), 3 deletions(-)

New commits:
commit 644f9abce55878e27292451b9b2c8d3b6e11104e
Author:     László Németh <nemeth at numbertext.org>
AuthorDate: Mon Jan 18 10:10:24 2021 +0100
Commit:     László Németh <nemeth at numbertext.org>
CommitDate: Wed Jan 20 11:54:24 2021 +0100

    tdf#138666 sw: fix enable/disable of ChangesInMargin mode
    
    by hiding/showing the existing deletions inline.
    
    Change-Id: I643c23b3008c3d58bd4631aa40bec375d811bd5e
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/109555
    Tested-by: Jenkins
    Reviewed-by: László Németh <nemeth at numbertext.org>

diff --git a/sw/qa/extras/uiwriter/uiwriter2.cxx b/sw/qa/extras/uiwriter/uiwriter2.cxx
index 83b119fe0fed..7d24e652d694 100644
--- a/sw/qa/extras/uiwriter/uiwriter2.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter2.cxx
@@ -2150,12 +2150,12 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf137771)
     xmlDocUniquePtr pXmlDoc = dumpAndParse(dumper, *xMetaFile);
     CPPUNIT_ASSERT(pXmlDoc);
 
-    // This was 12 (missing vertical redline mark)
-    assertXPath(pXmlDoc, "/metafile/push/push/push/line", 13);
+    // This would be 5 without the new vertical redline mark
+    assertXPath(pXmlDoc, "/metafile/push/push/push/line", 6);
 
     // This was the content of the next <text> (missing deletion on margin)
     // or only the first character of the deleted character sequence
-    assertXPathContent(pXmlDoc, "/metafile/push/push/push/textarray[16]/text", " saved.");
+    assertXPathContent(pXmlDoc, "/metafile/push/push/push/textarray[9]/text", " saved.");
 
     // this would crash due to bad redline range
     for (int i = 0; i < 6; ++i)
@@ -2362,6 +2362,41 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf138479)
     CPPUNIT_ASSERT(!pWrtShell->GetViewOptions()->IsShowChangesInMargin());
 }
 
+CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf138666)
+{
+    SwDoc* pDoc = createDoc("tdf39721.fodt");
+
+    SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
+    CPPUNIT_ASSERT(pTextDoc);
+
+    //turn on red-lining and show changes
+    pDoc->getIDocumentRedlineAccess().SetRedlineFlags(RedlineFlags::On | RedlineFlags::ShowDelete
+                                                      | RedlineFlags::ShowInsert);
+    CPPUNIT_ASSERT_MESSAGE("redlining should be on",
+                           pDoc->getIDocumentRedlineAccess().IsRedlineOn());
+    CPPUNIT_ASSERT_MESSAGE(
+        "redlines should be visible",
+        IDocumentRedlineAccess::IsShowChanges(pDoc->getIDocumentRedlineAccess().GetRedlineFlags()));
+
+    // show deletions inline
+    CPPUNIT_ASSERT_EQUAL(OUString("Lorem ipsum"), getParagraph(1)->getString());
+    CPPUNIT_ASSERT_EQUAL(OUString("dolor sit"), getParagraph(2)->getString());
+
+    // switch on "Show changes in margin" mode
+    dispatchCommand(mxComponent, ".uno:ShowChangesInMargin", {});
+
+    // show deletions in margin
+    CPPUNIT_ASSERT_EQUAL(OUString("Loremm"), getParagraph(1)->getString());
+    CPPUNIT_ASSERT_EQUAL(OUString("dolsit"), getParagraph(2)->getString());
+
+    // switch on "Show changes in margin" mode
+    dispatchCommand(mxComponent, ".uno:ShowChangesInMargin", {});
+
+    // show deletions inline again
+    CPPUNIT_ASSERT_EQUAL(OUString("Lorem ipsum"), getParagraph(1)->getString());
+    CPPUNIT_ASSERT_EQUAL(OUString("dolor sit"), getParagraph(2)->getString());
+}
+
 CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf126206)
 {
     load(DATA_DIRECTORY, "tdf126206.docx");
diff --git a/sw/source/core/doc/DocumentRedlineManager.cxx b/sw/source/core/doc/DocumentRedlineManager.cxx
index af078b52e985..b6b06e157b42 100644
--- a/sw/source/core/doc/DocumentRedlineManager.cxx
+++ b/sw/source/core/doc/DocumentRedlineManager.cxx
@@ -3289,6 +3289,48 @@ void DocumentRedlineManager::SetAutoFormatRedlineComment( const OUString* pText,
     mnAutoFormatRedlnCommentNo = nSeqNo;
 }
 
+void DocumentRedlineManager::HideAll( bool bDeletion )
+{
+    const SwRedlineTable& rTable = GetRedlineTable();
+    for (SwRedlineTable::size_type i = rTable.size(); i > 0; --i)
+    {
+        SwRangeRedline* pRedline = rTable[i-1];
+        if ( pRedline->GetType() == RedlineType::Delete &&
+             pRedline->IsVisible() )
+        {
+            pRedline->Hide(0, rTable.GetPos(pRedline), false);
+            pRedline->Hide(1, rTable.GetPos(pRedline), false);
+        }
+        else if ( pRedline->GetType() == RedlineType::Insert )
+        {
+            if ( !bDeletion && pRedline->IsVisible() )
+            {
+                pRedline->ShowOriginal(0, rTable.GetPos(pRedline), false);
+                pRedline->ShowOriginal(1, rTable.GetPos(pRedline), false);
+            }
+            else if ( bDeletion && !pRedline->IsVisible() )
+            {
+                pRedline->Show(0, rTable.GetPos(pRedline), true);
+                pRedline->Show(1, rTable.GetPos(pRedline), true);
+            }
+        }
+    }
+}
+
+void DocumentRedlineManager::ShowAll()
+{
+    const SwRedlineTable& rTable = GetRedlineTable();
+    for (SwRedlineTable::size_type i = rTable.size(); i > 0; --i)
+    {
+        SwRangeRedline* pRedline = rTable[i-1];
+        if ( !pRedline->IsVisible() )
+        {
+            pRedline->Show(0, rTable.GetPos(pRedline), true);
+            pRedline->Show(1, rTable.GetPos(pRedline), true);
+        }
+    }
+}
+
 DocumentRedlineManager::~DocumentRedlineManager()
 {
 }
diff --git a/sw/source/core/inc/DocumentRedlineManager.hxx b/sw/source/core/inc/DocumentRedlineManager.hxx
index 8f79088dec0f..9f3a3e8bf806 100644
--- a/sw/source/core/inc/DocumentRedlineManager.hxx
+++ b/sw/source/core/inc/DocumentRedlineManager.hxx
@@ -132,6 +132,9 @@ public:
     bool IsHideRedlines() const { return m_bHideRedlines; }
     void SetHideRedlines(bool const bHideRedlines) { m_bHideRedlines = bHideRedlines; }
 
+    void HideAll(bool bDeletion);
+    void ShowAll();
+
     virtual ~DocumentRedlineManager() override;
 
 private:
diff --git a/sw/source/core/view/viewsh.cxx b/sw/source/core/view/viewsh.cxx
index 1d3aed35a940..0e114908dd50 100644
--- a/sw/source/core/view/viewsh.cxx
+++ b/sw/source/core/view/viewsh.cxx
@@ -64,6 +64,7 @@
 #include <sortedobjs.hxx>
 #include <anchoredobject.hxx>
 #include <DocumentSettingManager.hxx>
+#include <DocumentRedlineManager.hxx>
 
 #include <unotxdoc.hxx>
 #include <view.hxx>
@@ -2208,6 +2209,13 @@ void SwViewShell::ImplApplyViewOptions( const SwViewOption &rOpt )
     {
         bReformat = GetDoc()->ContainsHiddenChars();
     }
+    if ( mpOpt->IsShowChangesInMargin() != rOpt.IsShowChangesInMargin() )
+    {
+        if (rOpt.IsShowChangesInMargin())
+            GetDoc()->GetDocumentRedlineManager().HideAll(/*bDeletion=*/true);
+        else
+            GetDoc()->GetDocumentRedlineManager().ShowAll();
+    }
 
     // bReformat becomes true, if ...
     // - fieldnames apply or not ...


More information about the Libreoffice-commits mailing list