[Libreoffice-commits] core.git: Branch 'feature/sw-delete-undo-rework' - 2 commits - sw/source

Rosemary Sebastian rosemary.seb8 at gmail.com
Mon Aug 14 13:09:31 UTC 2017


Rebased ref, commits from common ancestor:
commit eccc5c200ae1c56f823038ca284068ada49adda5
Author: Rosemary Sebastian <rosemary.seb8 at gmail.com>
Date:   Mon Aug 14 16:25:03 2017 +0530

    Do not continue grouping if the Track Changes mode has changed
    
    Change-Id: I8331c11fd7ce3b7b464a57a5710e9f4ee0cfb4fb

diff --git a/sw/source/core/doc/DocumentContentOperationsManager.cxx b/sw/source/core/doc/DocumentContentOperationsManager.cxx
index 95842c89c49f..005a54e5a4fb 100644
--- a/sw/source/core/doc/DocumentContentOperationsManager.cxx
+++ b/sw/source/core/doc/DocumentContentOperationsManager.cxx
@@ -3602,7 +3602,7 @@ bool DocumentContentOperationsManager::DeleteAndJoinWithRedlineImpl( SwPaM & rPa
                     SwUndoDelete * const pUndoDel( dynamic_cast< SwUndoDelete* >( pLastUndo ) );
                     if( pUndoDel )
                     {
-                        bMerged = pUndoDel->CanGrouping( &m_rDoc, rPam );
+                        bMerged = pUndoDel->CanGrouping( &m_rDoc, rPam, bRedlineDelete );
                         // if CanGrouping() returns true it's already merged
                     }
                 }
diff --git a/sw/source/core/inc/UndoDelete.hxx b/sw/source/core/inc/UndoDelete.hxx
index ac22b3217a1e..fc934aa702ad 100644
--- a/sw/source/core/inc/UndoDelete.hxx
+++ b/sw/source/core/inc/UndoDelete.hxx
@@ -88,7 +88,7 @@ public:
     */
     virtual SwRewriter GetRewriter() const override;
 
-    bool CanGrouping( SwDoc*, const SwPaM& );
+    bool CanGrouping( SwDoc*, const SwPaM&, bool bRedlineDelete = false );
 
     void SetTableDelLastNd()      { m_bTableDelLastNd = true; }
 
diff --git a/sw/source/core/undo/undel.cxx b/sw/source/core/undo/undel.cxx
index 9e82c2541e88..0e9681af5b6d 100644
--- a/sw/source/core/undo/undel.cxx
+++ b/sw/source/core/undo/undel.cxx
@@ -444,8 +444,12 @@ bool SwUndoDelete::SaveContent( const SwPosition* pStt, const SwPosition* pEnd,
     return true;                // move Nodes lying in between
 }
 
-bool SwUndoDelete::CanGrouping( SwDoc* pDoc, const SwPaM& rDelPam )
+bool SwUndoDelete::CanGrouping( SwDoc* pDoc, const SwPaM& rDelPam, bool bRedlineDelete )
 {
+    // Make sure the Track Changes mode is the same
+    if( m_bRedlineDelete != bRedlineDelete )
+        return false;
+
     // Is Undo greater than one Node (that is Start and EndString)?
     if( !m_pSttStr || m_pSttStr->isEmpty() || m_pEndStr )
         return false;
commit b2fa5f3f5ee68a0aa2225d7b5aa80ccef2cb70ac
Author: Rosemary Sebastian <rosemary.seb8 at gmail.com>
Date:   Mon Jul 17 16:31:36 2017 +0530

    tdf#109151: Enable grouping of undo actions for delete redlines
    
    Change-Id: I74183e5df58d8d0c5e892182f545a5ff17eb7936

diff --git a/sw/source/core/doc/DocumentContentOperationsManager.cxx b/sw/source/core/doc/DocumentContentOperationsManager.cxx
index df6455ed33bc..95842c89c49f 100644
--- a/sw/source/core/doc/DocumentContentOperationsManager.cxx
+++ b/sw/source/core/doc/DocumentContentOperationsManager.cxx
@@ -3552,54 +3552,71 @@ bool DocumentContentOperationsManager::DeleteAndJoinWithRedlineImpl( SwPaM & rPa
     OSL_ENSURE( m_rDoc.getIDocumentRedlineAccess().IsRedlineOn(), "DeleteAndJoinWithRedline: redline off" );
 
     {
-        SwUndoRedlineDelete* pUndo = nullptr;
+        SwUndo *const pLastUndo( m_rDoc.GetUndoManager().GetLastUndo() );
         RedlineFlags eOld = m_rDoc.getIDocumentRedlineAccess().GetRedlineFlags();
         m_rDoc.GetDocumentRedlineManager().checkRedlining( eOld );
         if (m_rDoc.GetIDocumentUndoRedo().DoesUndo())
         {
-
             /* please don't translate -- for cultural reasons this comment is protected
                until the redline implementation is finally fixed some day */
             //JP 06.01.98: MUSS noch optimiert werden!!!
+
+            m_rDoc.GetIDocumentUndoRedo().ClearRedo();
             m_rDoc.getIDocumentRedlineAccess().SetRedlineFlags(
                 RedlineFlags::On | RedlineFlags::ShowInsert | RedlineFlags::ShowDelete );
+            bool bAppendUndo(true);
+            bool bRedlineDelete(true);
 
-            pUndo = new SwUndoRedlineDelete( rPam, SwUndoId::DELETE );
-            const SwRewriter aRewriter = pUndo->GetRewriter();
-            m_rDoc.GetIDocumentUndoRedo().StartUndo( SwUndoId::DELETE, &aRewriter );
-            m_rDoc.GetIDocumentUndoRedo().AppendUndo( pUndo );
-        }
-
-        if ( *rPam.GetPoint() != *rPam.GetMark() )
-            m_rDoc.getIDocumentRedlineAccess().AppendRedline( new SwRangeRedline( nsRedlineType_t::REDLINE_DELETE, rPam ), true );
-        m_rDoc.getIDocumentState().SetModified();
+            const SwPosition* pStt = rPam.Start();
+            const SwPosition* pEnd = rPam.End();
+            const SwRedlineTable& rTable = rPam.GetDoc()->getIDocumentRedlineAccess().GetRedlineTable();
+            SwRedlineTable::size_type n = 0;
+            /* Check whether the delete redline falls inside an existing redline
+               We don't have to add an undo action if the redline lies inside an existing redline.
+               It will be taken care of in DocumentRedlineManager::AppendRedline() that's called below. */
+            for( ; n < rTable.size(); ++n )
+            {
+                SwRangeRedline* pRedl = rTable[ n ];
+                SwComparePosition eCmpPos = ComparePosition( *pStt, *pEnd, *pRedl->Start(), *pRedl->End() );
+                if ( eCmpPos == SwComparePosition::Inside )
+                {
+                    bAppendUndo = false;
+                    break;
+                }
+                else if( eCmpPos == SwComparePosition::Equal )
+                {
+                    if( pRedl->GetType() == nsRedlineType_t::REDLINE_INSERT )
+                        bRedlineDelete = false;
+                    else
+                        bAppendUndo = false;
+                    break;
+                }
+            }
 
-        if ( pUndo )
-        {
-            m_rDoc.GetIDocumentUndoRedo().EndUndo( SwUndoId::EMPTY, nullptr );
-            // ??? why the hell is the AppendUndo not below the
-            // CanGrouping, so this hideous cleanup wouldn't be necessary?
-            // bah, this is redlining, probably changing this would break it...
-            if ( m_rDoc.GetIDocumentUndoRedo().DoesGroupUndo() )
+            if( bAppendUndo )
             {
-                SwUndo * const pLastUndo( m_rDoc.GetUndoManager().GetLastUndo() );
-                SwUndoRedlineDelete * const pUndoRedlineDel( dynamic_cast< SwUndoRedlineDelete* >( pLastUndo ) );
-                if ( pUndoRedlineDel )
+
+                bool bMerged(false);
+                if( m_rDoc.GetIDocumentUndoRedo().DoesGroupUndo() )
                 {
-                    bool const bMerged = pUndoRedlineDel->CanGrouping( *pUndo );
-                    if ( bMerged )
+                    SwUndoDelete * const pUndoDel( dynamic_cast< SwUndoDelete* >( pLastUndo ) );
+                    if( pUndoDel )
                     {
-                        ::sw::UndoGuard const undoGuard( m_rDoc.GetIDocumentUndoRedo() );
-                        SwUndo const* const pDeleted = m_rDoc.GetUndoManager().RemoveLastUndo();
-                        OSL_ENSURE( pDeleted == pUndo, "DeleteAndJoinWithRedlineImpl: "
-                            "undo removed is not undo inserted?" );
-                        delete pDeleted;
+                        bMerged = pUndoDel->CanGrouping( &m_rDoc, rPam );
+                        // if CanGrouping() returns true it's already merged
                     }
                 }
+                if( !bMerged )
+                {
+                    m_rDoc.GetIDocumentUndoRedo().AppendUndo( new SwUndoDelete( rPam, false, false, bRedlineDelete ) );
+                }
             }
-            //JP 06.01.98: MUSS noch optimiert werden!!!
-            m_rDoc.getIDocumentRedlineAccess().SetRedlineFlags( eOld );
         }
+        if ( *rPam.GetPoint() != *rPam.GetMark() )
+            m_rDoc.getIDocumentRedlineAccess().AppendRedline( new SwRangeRedline( nsRedlineType_t::REDLINE_DELETE, rPam ), true );
+        m_rDoc.getIDocumentState().SetModified();
+            //JP 06.01.98: MUSS noch optimiert werden!!!
+        m_rDoc.getIDocumentRedlineAccess().SetRedlineFlags( eOld );
         return true;
     }
 }
diff --git a/sw/source/core/inc/UndoDelete.hxx b/sw/source/core/inc/UndoDelete.hxx
index a29993610cd2..ac22b3217a1e 100644
--- a/sw/source/core/inc/UndoDelete.hxx
+++ b/sw/source/core/inc/UndoDelete.hxx
@@ -59,6 +59,7 @@ class SwUndoDelete
     bool m_bResetPgDesc : 1;   // TRUE: reset PgDsc on following node
     bool m_bResetPgBrk : 1;    // TRUE: reset PgBreak on following node
     bool m_bFromTableCopy : 1; // TRUE: called by SwUndoTableCpyTable
+    bool m_bRedlineDelete : 1;    // TRUE: if it is a tracked change of delete type
 
     bool SaveContent( const SwPosition* pStt, const SwPosition* pEnd,
                     SwTextNode* pSttTextNd, SwTextNode* pEndTextNd );
@@ -67,7 +68,8 @@ public:
     SwUndoDelete(
         SwPaM&,
         bool bFullPara = false,
-        bool bCalledByTableCpy = false );
+        bool bCalledByTableCpy = false,
+        bool bRedlineDelete = false );
     virtual ~SwUndoDelete() override;
 
     virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
diff --git a/sw/source/core/undo/undel.cxx b/sw/source/core/undo/undel.cxx
index 6787c6a3125b..9e82c2541e88 100644
--- a/sw/source/core/undo/undel.cxx
+++ b/sw/source/core/undo/undel.cxx
@@ -95,7 +95,8 @@ static void lcl_MakeAutoFrames( const SwFrameFormats& rSpzArr, sal_uLong nMovedI
 SwUndoDelete::SwUndoDelete(
     SwPaM& rPam,
     bool bFullPara,
-    bool bCalledByTableCpy )
+    bool bCalledByTableCpy,
+    bool bRedlineDelete )
     : SwUndo(SwUndoId::DELETE, rPam.GetDoc()),
     SwUndRng( rPam ),
     m_pMvStt( nullptr ),
@@ -115,7 +116,8 @@ SwUndoDelete::SwUndoDelete(
     m_bDelFullPara( bFullPara ),
     m_bResetPgDesc( false ),
     m_bResetPgBrk( false ),
-    m_bFromTableCopy( bCalledByTableCpy )
+    m_bFromTableCopy( bCalledByTableCpy ),
+    m_bRedlineDelete( bRedlineDelete )
 {
 
     bCacheComment = false;
@@ -213,7 +215,8 @@ SwUndoDelete::SwUndoDelete(
 
     if( !pSttTextNd && !pEndTextNd )
         --rPam.GetPoint()->nNode;
-    rPam.DeleteMark();          // the SPoint is in the selection
+    if( !m_bRedlineDelete )     // Make sure that it's not a redline since calling DeleteMark() will result in an empty redline
+        rPam.DeleteMark();          // the SPoint is in the selection
 
     if( !pEndTextNd )
         nEndContent = 0;
@@ -384,7 +387,8 @@ bool SwUndoDelete::SaveContent( const SwPosition* pStt, const SwPosition* pEnd,
         // delete now also the text (all attribute changes are added to
         // UNDO history)
         m_pSttStr.reset( new OUString( pSttTextNd->GetText().copy(nSttContent, nLen)) );
-        pSttTextNd->EraseText( pStt->nContent, nLen );
+        if( !m_bRedlineDelete )
+            pSttTextNd->EraseText( pStt->nContent, nLen );
         if( pSttTextNd->GetpSwpHints() )
             pSttTextNd->GetpSwpHints()->DeRegister();
 
@@ -420,7 +424,8 @@ bool SwUndoDelete::SaveContent( const SwPosition* pStt, const SwPosition* pEnd,
         // UNDO history)
         m_pEndStr.reset( new OUString( pEndTextNd->GetText().copy( 0,
                                     pEnd->nContent.GetIndex() )) );
-        pEndTextNd->EraseText( aEndIdx, pEnd->nContent.GetIndex() );
+        if( !m_bRedlineDelete )
+            pEndTextNd->EraseText( aEndIdx, pEnd->nContent.GetIndex() );
         if( pEndTextNd->GetpSwpHints() )
             pEndTextNd->GetpSwpHints()->DeRegister();
 
@@ -509,7 +514,9 @@ bool SwUndoDelete::CanGrouping( SwDoc* pDoc, const SwPaM& rDelPam )
         nUChrPos++;
     }
     (*m_pSttStr) = m_pSttStr->replaceAt( nUChrPos, 0, OUString(cDelChar) );
-    pDelTextNd->EraseText( pStt->nContent, 1 );
+
+    if( !m_bRedlineDelete )
+        pDelTextNd->EraseText( pStt->nContent, 1 );
 
     m_bGroup = true;
     return true;
@@ -760,6 +767,13 @@ void SwUndoDelete::UndoImpl(::sw::UndoRedoContext & rContext)
 {
     SwDoc& rDoc = rContext.GetDoc();
 
+    if(m_bRedlineDelete)
+    {
+        SwPaM & rPam = AddUndoRedoPaM(rContext);
+        rDoc.getIDocumentRedlineAccess().DeleteRedline(rPam, true, USHRT_MAX);
+        return;
+    }
+
     sal_uLong nCalcStt = nSttNode - m_nNdDiff;
 
     if( m_nSectDiff && m_bBackSp )
@@ -970,6 +984,19 @@ void SwUndoDelete::RedoImpl(::sw::UndoRedoContext & rContext)
     SwPaM & rPam = AddUndoRedoPaM(rContext);
     SwDoc& rDoc = *rPam.GetDoc();
 
+    if(m_bRedlineDelete)
+    {
+        RedlineFlags eOld = rDoc.getIDocumentRedlineAccess().GetRedlineFlags();
+        rDoc.getIDocumentRedlineAccess().SetRedlineFlags_intern(( eOld & ~RedlineFlags::Ignore) | RedlineFlags::On );
+        if (rPam.GetPoint() != rPam.GetMark())
+        {
+            rDoc.getIDocumentRedlineAccess().AppendRedline( new SwRangeRedline(nsRedlineType_t::REDLINE_DELETE, rPam), false );
+        }
+        SetPaM(rPam, true);
+        rDoc.getIDocumentRedlineAccess().SetRedlineFlags_intern( eOld );
+        return;
+    }
+
     if( m_pRedlSaveData )
     {
         const bool bSuccess = FillSaveData(rPam, *m_pRedlSaveData);


More information about the Libreoffice-commits mailing list