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

Caolán McNamara caolanm at redhat.com
Tue Jan 13 09:33:14 PST 2015


 sw/source/core/doc/doccomp.cxx |  136 +++++++++++++++++++++++++++++++++--------
 1 file changed, 110 insertions(+), 26 deletions(-)

New commits:
commit d7bfd7ab1b5554ba7dbc45f8fe8889a68b0bf5ab
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Tue Jan 13 16:59:31 2015 +0000

    misunderstood that MergeDoc and CompareDoc used different diff modes
    
    i.e. there was a reason to the inheritence I removed in
    
    commit bdca5a7ec083d24c360c2da86de2415567442605
    Date:   Tue Jan 13 13:55:58 2015 +0000
        merge CompareData and SwCompareData
    
        the inheritence doesn't help us here at all and we can remove
        the virtuals and the casting becomes unnecessary
    
    so restore the different modality
    
    Change-Id: I8f20b8652b7949b04b442b89bed5df3093ad24d8

diff --git a/sw/source/core/doc/doccomp.cxx b/sw/source/core/doc/doccomp.cxx
index 350d190..4a46f78 100644
--- a/sw/source/core/doc/doccomp.cxx
+++ b/sw/source/core/doc/doccomp.cxx
@@ -79,6 +79,7 @@ private:
 
     vector< CompareLine* > aLines;
     sal_uLong nSttLineNum;
+    bool m_bRecordDiff;
 
     // Truncate beginning and end and add all others to the LinesArray
     void CheckRanges( CompareData& );
@@ -86,9 +87,9 @@ private:
     virtual const SwNode& GetEndOfContent() = 0;
 
 public:
-    CompareData( SwDoc& rD )
+    CompareData(SwDoc& rD, bool bRecordDiff)
         : rDoc( rD ), pIndex( 0 ), pChangedFlag( 0 ), pInsRing(0), pDelRing(0)
-        , nSttLineNum( 0 )
+        , nSttLineNum( 0 ), m_bRecordDiff(bRecordDiff)
     {
     }
     virtual ~CompareData();
@@ -135,8 +136,8 @@ public:
 class CompareMainText : public CompareData
 {
 public:
-    CompareMainText(SwDoc &rD)
-        : CompareData(rD)
+    CompareMainText(SwDoc &rD, bool bRecordDiff=true)
+        : CompareData(rD, bRecordDiff)
     {
     }
 
@@ -150,8 +151,8 @@ class CompareFrmFmtText : public CompareData
 {
     const SwNodeIndex &m_rIndex;
 public:
-    CompareFrmFmtText(SwDoc &rD, const SwNodeIndex &rIndex)
-        : CompareData(rD)
+    CompareFrmFmtText(SwDoc &rD, const SwNodeIndex &rIndex, bool bRecordDiff=true)
+        : CompareData(rD, bRecordDiff)
         , m_rIndex(rIndex)
     {
     }
@@ -447,9 +448,12 @@ sal_uLong CompareData::ShowDiffs( const CompareData& rData )
             while( nStt1 < nLen1 && rData.GetChanged( nStt1 )) ++nStt1;
             while( nStt2 < nLen2 && GetChanged( nStt2 )) ++nStt2;
 
-            // Check if there are changed lines (only slightly different) and
-            // compare them in detail.
-            CheckForChangesInLine( rData, nSav1, nStt1, nSav2, nStt2 );
+            if (m_bRecordDiff)
+            {
+                // Check if there are changed lines (only slightly different) and
+                // compare them in detail.
+                CheckForChangesInLine( rData, nSav1, nStt1, nSav2, nStt2 );
+            }
 
             ++nCnt;
         }
@@ -2062,8 +2066,8 @@ long SwDoc::MergeDoc( const SwDoc& rDoc )
     rSrcDoc.getIDocumentRedlineAccess().SetRedlineMode( nsRedlineMode_t::REDLINE_SHOW_DELETE );
     getIDocumentRedlineAccess().SetRedlineMode( nsRedlineMode_t::REDLINE_SHOW_DELETE );
 
-    CompareMainText aD0(rSrcDoc);
-    CompareMainText aD1(*this);
+    CompareMainText aD0(rSrcDoc, false);
+    CompareMainText aD1(*this, false);
     aD1.CompareLines( aD0 );
     if( !aD1.HasDiffs( aD0 ) )
     {
commit 16916a14a2ce382aa4ff2a25f8e477108aba5a67
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Tue Jan 13 16:52:22 2015 +0000

    allow comparing documents which only differ by frame contents
    
    if two documents have the same number of frames then have an additional stab at
    comparing the contents of those frames
    
    Change-Id: Ie7f1a8906d49d720a74620ad8d69fd97c76304e3

diff --git a/sw/source/core/doc/doccomp.cxx b/sw/source/core/doc/doccomp.cxx
index 526ea1b..350d190 100644
--- a/sw/source/core/doc/doccomp.cxx
+++ b/sw/source/core/doc/doccomp.cxx
@@ -38,6 +38,7 @@
 #include <section.hxx>
 #include <tox.hxx>
 #include <docsh.hxx>
+#include <fmtcntnt.hxx>
 
 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
 #include <com/sun/star/document/XDocumentProperties.hpp>
@@ -65,10 +66,12 @@ public:
 
 class CompareData
 {
+protected:
+    SwDoc& rDoc;
+private:
     size_t* pIndex;
     bool* pChangedFlag;
 
-    SwDoc& rDoc;
     SwPaM *pInsRing, *pDelRing;
 
     sal_uLong PrevIdx( const SwNode* pNd );
@@ -80,14 +83,15 @@ class CompareData
     // Truncate beginning and end and add all others to the LinesArray
     void CheckRanges( CompareData& );
 
+    virtual const SwNode& GetEndOfContent() = 0;
+
 public:
     CompareData( SwDoc& rD )
-        : pIndex( 0 ), pChangedFlag( 0 )
-        , rDoc( rD ), pInsRing(0), pDelRing(0)
+        : rDoc( rD ), pIndex( 0 ), pChangedFlag( 0 ), pInsRing(0), pDelRing(0)
         , nSttLineNum( 0 )
     {
     }
-    ~CompareData();
+    virtual ~CompareData();
 
     // Are there differences?
     bool HasDiffs( const CompareData& rData ) const;
@@ -128,6 +132,36 @@ public:
     void SetRedlinesToDoc( bool bUseDocInfo );
 };
 
+class CompareMainText : public CompareData
+{
+public:
+    CompareMainText(SwDoc &rD)
+        : CompareData(rD)
+    {
+    }
+
+    virtual const SwNode& GetEndOfContent() SAL_OVERRIDE
+    {
+        return rDoc.GetNodes().GetEndOfContent();
+    }
+};
+
+class CompareFrmFmtText : public CompareData
+{
+    const SwNodeIndex &m_rIndex;
+public:
+    CompareFrmFmtText(SwDoc &rD, const SwNodeIndex &rIndex)
+        : CompareData(rD)
+        , m_rIndex(rIndex)
+    {
+    }
+
+    virtual const SwNode& GetEndOfContent() SAL_OVERRIDE
+    {
+        return *m_rIndex.GetNode().EndOfSectionNode();
+    }
+};
+
 class Hash
 {
     struct _HashData
@@ -1416,8 +1450,8 @@ void CompareData::CheckRanges( CompareData& rData )
     const SwNodes& rSrcNds = rData.rDoc.GetNodes();
     const SwNodes& rDstNds = rDoc.GetNodes();
 
-    const SwNode& rSrcEndNd = rSrcNds.GetEndOfContent();
-    const SwNode& rDstEndNd = rDstNds.GetEndOfContent();
+    const SwNode& rSrcEndNd = rData.GetEndOfContent();
+    const SwNode& rDstEndNd = GetEndOfContent();
 
     sal_uLong nSrcSttIdx = NextIdx( rSrcEndNd.StartOfSectionNode() );
     sal_uLong nSrcEndIdx = rSrcEndNd.GetIndex();
@@ -1508,7 +1542,7 @@ void CompareData::ShowDelete(
     }
     else
     {
-        pLineNd = &rDoc.GetNodes().GetEndOfContent();
+        pLineNd = &GetEndOfContent();
         nOffset = 0;
     }
 
@@ -1637,7 +1671,7 @@ void CompareData::SetRedlinesToDoc( bool bUseDocInfo )
             }
             // #i101009#
             // prevent redlines that end on structural end node
-            if (& rDoc.GetNodes().GetEndOfContent() ==
+            if (& GetEndOfContent() ==
                 & pTmp->GetPoint()->nNode.GetNode())
             {
                 pTmp->GetPoint()->nNode--;
@@ -1669,7 +1703,7 @@ void CompareData::SetRedlinesToDoc( bool bUseDocInfo )
             }
             // #i101009#
             // prevent redlines that end on structural end node
-            if (& rDoc.GetNodes().GetEndOfContent() ==
+            if (& GetEndOfContent() ==
                 & pTmp->GetPoint()->nNode.GetNode())
             {
                 pTmp->GetPoint()->nNode--;
@@ -1724,6 +1758,48 @@ void CompareData::SetRedlinesToDoc( bool bUseDocInfo )
     }
 }
 
+typedef std::shared_ptr<CompareData> CompareDataPtr;
+typedef std::pair<CompareDataPtr, CompareDataPtr> CompareDataPtrPair;
+typedef std::vector<CompareDataPtrPair> Comparators;
+
+namespace
+{
+    Comparators buildComparators(SwDoc &rSrcDoc, SwDoc &rDestDoc)
+    {
+        Comparators aComparisons;
+        //compare main text
+        aComparisons.push_back(CompareDataPtrPair(CompareDataPtr(new CompareMainText(rSrcDoc)),
+                                                  CompareDataPtr(new CompareMainText(rDestDoc))));
+
+        //if we have the same number of frames then try to compare within them
+        const SwFrmFmts *pSrcFrmFmts = rSrcDoc.GetSpzFrmFmts();
+        const SwFrmFmts *pDestFrmFmts = rDestDoc.GetSpzFrmFmts();
+        if (pSrcFrmFmts->size() == pDestFrmFmts->size())
+        {
+            for (size_t i = 0; i < pSrcFrmFmts->size(); ++i)
+            {
+                const SwFrmFmt& rSrcFmt = *(*pSrcFrmFmts)[i];
+                const SwFrmFmt& rDestFmt = *(*pDestFrmFmts)[i];
+                const SwNodeIndex* pSrcIdx = rSrcFmt.GetCntnt().GetCntntIdx();
+                const SwNodeIndex* pDestIdx = rDestFmt.GetCntnt().GetCntntIdx();
+                if (!pSrcIdx && !pDestIdx)
+                    continue;
+                if (!pSrcIdx || !pDestIdx)
+                    break;
+                const SwNode* pSrcNode = pSrcIdx->GetNode().EndOfSectionNode();
+                const SwNode* pDestNode = pDestIdx->GetNode().EndOfSectionNode();
+                if (!pSrcNode && !pDestNode)
+                    continue;
+                if (!pSrcNode || !pDestNode)
+                    break;
+                aComparisons.push_back(CompareDataPtrPair(CompareDataPtr(new CompareFrmFmtText(rSrcDoc, *pSrcIdx)),
+                                                          CompareDataPtr(new CompareFrmFmtText(rDestDoc, *pDestIdx))));
+            }
+        }
+        return aComparisons;
+    }
+}
+
 // Returns (the difference count?) if something is different
 long SwDoc::CompareDoc( const SwDoc& rDoc )
 {
@@ -1764,19 +1840,26 @@ long SwDoc::CompareDoc( const SwDoc& rDoc )
     rSrcDoc.getIDocumentRedlineAccess().SetRedlineMode( nsRedlineMode_t::REDLINE_SHOW_INSERT );
     getIDocumentRedlineAccess().SetRedlineMode((RedlineMode_t)(nsRedlineMode_t::REDLINE_ON | nsRedlineMode_t::REDLINE_SHOW_INSERT));
 
-    CompareData aD0( rSrcDoc );
-    CompareData aD1( *this );
+    Comparators aComparisons(buildComparators(rSrcDoc, *this));
 
-    aD1.CompareLines( aD0 );
-
-    nRet = aD1.ShowDiffs( aD0 );
+    for (auto a : aComparisons)
+    {
+        CompareData& rD0 = *a.first.get();
+        CompareData& rD1 = *a.second.get();
+        rD1.CompareLines( rD0 );
+        nRet |= rD1.ShowDiffs( rD0 );
+    }
 
     if( nRet )
     {
         getIDocumentRedlineAccess().SetRedlineMode((RedlineMode_t)(nsRedlineMode_t::REDLINE_ON |
                        nsRedlineMode_t::REDLINE_SHOW_INSERT | nsRedlineMode_t::REDLINE_SHOW_DELETE));
 
-        aD1.SetRedlinesToDoc( !bDocWasModified );
+        for (auto a : aComparisons)
+        {
+            CompareData& rD1 = *a.second.get();
+            rD1.SetRedlinesToDoc( !bDocWasModified );
+        }
         getIDocumentState().SetModified();
     }
 
@@ -1979,11 +2062,9 @@ long SwDoc::MergeDoc( const SwDoc& rDoc )
     rSrcDoc.getIDocumentRedlineAccess().SetRedlineMode( nsRedlineMode_t::REDLINE_SHOW_DELETE );
     getIDocumentRedlineAccess().SetRedlineMode( nsRedlineMode_t::REDLINE_SHOW_DELETE );
 
-    CompareData aD0( rSrcDoc );
-    CompareData aD1( *this );
-
+    CompareMainText aD0(rSrcDoc);
+    CompareMainText aD1(*this);
     aD1.CompareLines( aD0 );
-
     if( !aD1.HasDiffs( aD0 ) )
     {
         // we want to get all redlines from the SourceDoc
commit 084e623ff989896d11d042d682064b10aec71a0a
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Tue Jan 13 15:15:52 2015 +0000

    protected->private
    
    Change-Id: I8a772d6e5fdaa1223ed15f8221c64010eddbe75a

diff --git a/sw/source/core/doc/doccomp.cxx b/sw/source/core/doc/doccomp.cxx
index 93282c7..526ea1b 100644
--- a/sw/source/core/doc/doccomp.cxx
+++ b/sw/source/core/doc/doccomp.cxx
@@ -74,7 +74,6 @@ class CompareData
     sal_uLong PrevIdx( const SwNode* pNd );
     sal_uLong NextIdx( const SwNode* pNd );
 
-protected:
     vector< CompareLine* > aLines;
     sal_uLong nSttLineNum;
 
@@ -1774,7 +1773,7 @@ long SwDoc::CompareDoc( const SwDoc& rDoc )
 
     if( nRet )
     {
-      getIDocumentRedlineAccess().SetRedlineMode((RedlineMode_t)(nsRedlineMode_t::REDLINE_ON |
+        getIDocumentRedlineAccess().SetRedlineMode((RedlineMode_t)(nsRedlineMode_t::REDLINE_ON |
                        nsRedlineMode_t::REDLINE_SHOW_INSERT | nsRedlineMode_t::REDLINE_SHOW_DELETE));
 
         aD1.SetRedlinesToDoc( !bDocWasModified );


More information about the Libreoffice-commits mailing list