summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRosemary Sebastian <rosemary.seb8@gmail.com>2017-07-17 16:31:36 +0530
committerRosemary Sebastian <rosemary.seb8@gmail.com>2017-08-30 20:18:02 +0530
commit67263a70cb0e9cc581c316ef50e7703fc0c24c1d (patch)
tree3eeb4da4fa04842f8451af056b8d025b5b0204ae
parentbd37233020266a5892d6ec7022688e3dfb9cef75 (diff)
tdf#109151: Enable grouping of undo actions for delete redlines
Change-Id: I74183e5df58d8d0c5e892182f545a5ff17eb7936
-rw-r--r--sw/source/core/doc/DocumentContentOperationsManager.cxx65
-rw-r--r--sw/source/core/inc/UndoDelete.hxx4
-rw-r--r--sw/source/core/undo/undel.cxx39
3 files changed, 71 insertions, 37 deletions
diff --git a/sw/source/core/doc/DocumentContentOperationsManager.cxx b/sw/source/core/doc/DocumentContentOperationsManager.cxx
index df6455ed33bc..fd5590cc89ee 100644
--- a/sw/source/core/doc/DocumentContentOperationsManager.cxx
+++ b/sw/source/core/doc/DocumentContentOperationsManager.cxx
@@ -3552,54 +3552,59 @@ 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();
+ for( SwRedlineTable::size_type n = 0; n < rTable.size(); ++n )
+ {
+ SwRangeRedline* pRedl = rTable[ n ];
+ SwComparePosition eCmpPos = ComparePosition( *pStt, *pEnd, *pRedl->Start(), *pRedl->End() );
+ if ( eCmpPos == SwComparePosition::Inside || eCmpPos == SwComparePosition::Equal )
+ {
+ 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);