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

László Németh (via logerrit) logerrit at kemper.freedesktop.org
Thu Jun 10 07:07:42 UTC 2021


 sw/qa/extras/uiwriter/data/ole2.png |binary
 sw/qa/extras/uiwriter/uiwriter2.cxx |   29 +++++++++++++++++++++++++++++
 sw/source/core/frmedt/fefly1.cxx    |   12 ++++++++++++
 sw/source/uibase/wrtsh/wrtsh1.cxx   |    5 +++++
 4 files changed, 46 insertions(+)

New commits:
commit 68b6004fe9df184bcbaf46dd53abfec228219df6
Author:     László Németh <nemeth at numbertext.org>
AuthorDate: Wed Jun 9 15:56:09 2021 +0200
Commit:     László Németh <nemeth at numbertext.org>
CommitDate: Thu Jun 10 09:07:03 2021 +0200

    tdf#141994 track changes: record insertion of images
    
    by adding a SwRangeRedline to the anchoring point of
    the image inserted with Insert->Image... or
    "Insert Image" of the Standard toolbar.
    
    Note: Only images anchored as characters can be
    recorded this way, so change the default to-character
    anchoring at enabled change tracking. (In other office
    suites, as-character insertion is the default anchoring
    for inserted images with disabled change tracking, too.)
    
    Follow-up to commit d6322bcedc197a654abc7d64bfea8cf570f123bf
    "tdf#59463 track changes: record deletion of images".
    
    Change-Id: I593abbdb6f9f2b1a5265f112103479c1833166af
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/116924
    Tested-by: László Németh <nemeth at numbertext.org>
    Reviewed-by: László Németh <nemeth at numbertext.org>

diff --git a/sw/qa/extras/uiwriter/data/ole2.png b/sw/qa/extras/uiwriter/data/ole2.png
new file mode 100644
index 000000000000..fdad35484e7c
Binary files /dev/null and b/sw/qa/extras/uiwriter/data/ole2.png differ
diff --git a/sw/qa/extras/uiwriter/uiwriter2.cxx b/sw/qa/extras/uiwriter/uiwriter2.cxx
index 736704b45d04..5e6cfb1fc0f4 100644
--- a/sw/qa/extras/uiwriter/uiwriter2.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter2.cxx
@@ -26,6 +26,7 @@
 #include <com/sun/star/text/XTextViewCursorSupplier.hpp>
 #include <com/sun/star/table/XTableRows.hpp>
 #include <comphelper/propertysequence.hxx>
+#include <comphelper/propertyvalue.hxx>
 #include <comphelper/configuration.hxx>
 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
 #include <i18nlangtag/languagetag.hxx>
@@ -3533,6 +3534,34 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTrackImageDeletion)
     CPPUNIT_ASSERT_EQUAL(static_cast<SwRedlineTable::size_type>(1), rTable.size());
 }
 
+CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTrackImageInsertion)
+{
+    loadURL("private:factory/swriter", nullptr);
+    SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
+    SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+
+    // turn on red-lining and show changes
+    IDocumentRedlineAccess& rIDRA(pDoc->getIDocumentRedlineAccess());
+
+    rIDRA.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()));
+
+    // Insert an image with change tracking
+    OUString aImageURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "ole2.png";
+    uno::Sequence<beans::PropertyValue> aArgs = {
+        comphelper::makePropertyValue("FileName", aImageURL),
+    };
+    dispatchCommand(mxComponent, ".uno:InsertGraphic", aArgs);
+
+    const SwRedlineTable& rTable = rIDRA.GetRedlineTable();
+    // this was 0 (missing recording of insertion of images)
+    CPPUNIT_ASSERT_EQUAL(static_cast<SwRedlineTable::size_type>(1), rTable.size());
+}
+
 CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf120338)
 {
     load(DATA_DIRECTORY, "tdf120338.docx");
diff --git a/sw/source/core/frmedt/fefly1.cxx b/sw/source/core/frmedt/fefly1.cxx
index 6ecb3c2c2a20..18e46f9bce47 100644
--- a/sw/source/core/frmedt/fefly1.cxx
+++ b/sw/source/core/frmedt/fefly1.cxx
@@ -48,6 +48,8 @@
 #include <IDocumentUndoRedo.hxx>
 #include <IDocumentState.hxx>
 #include <IDocumentLayoutAccess.hxx>
+#include <IDocumentRedlineAccess.hxx>
+#include <redline.hxx>
 #include <dview.hxx>
 #include <dflyobj.hxx>
 #include <dcontact.hxx>
@@ -890,6 +892,16 @@ void SwFEShell::Insert( const OUString& rGrfName, const OUString& rFltName,
 
     if( pFrame )
     {
+        // add a redline to the anchor point at tracked insertion of picture
+        if ( IsRedlineOn() )
+        {
+            SwPosition aPos(*pFormat->GetAnchor().GetContentAnchor());
+            SwPaM aPaM(aPos.nNode.GetNode(), aPos.nContent.GetIndex(),
+                    aPos.nNode.GetNode(), aPos.nContent.GetIndex() + 1);
+            GetDoc()->getIDocumentRedlineAccess().AppendRedline(
+                    new SwRangeRedline( RedlineType::Insert, aPaM ), true);
+        }
+
         // fdo#36681: Invalidate the content and layout to refresh
         // the picture anchoring properly
         SwPageFrame* pPageFrame = pFrame->FindPageFrameOfAnchor();
diff --git a/sw/source/uibase/wrtsh/wrtsh1.cxx b/sw/source/uibase/wrtsh/wrtsh1.cxx
index b26af831754d..d32a6154146d 100644
--- a/sw/source/uibase/wrtsh/wrtsh1.cxx
+++ b/sw/source/uibase/wrtsh/wrtsh1.cxx
@@ -336,6 +336,11 @@ void SwWrtShell::Insert( const OUString &rPath, const OUString &rFilter,
         pFrameMgr->SetHeightSizeType(SwFrameSize::Fixed);
     }
 
+    // during change tracking, insert the image anchored as character
+    // (to create an SwRangeRedline on its anchor point)
+    if ( IsRedlineOn() && nAnchorType != RndStdIds::FLY_AS_CHAR )
+        pFrameMgr->SetAnchor( RndStdIds::FLY_AS_CHAR );
+
     // Insert the graphic
     SwFEShell::Insert(rPath, rFilter, &rGrf, &pFrameMgr->GetAttrSet());
     if ( bOwnMgr )


More information about the Libreoffice-commits mailing list