diff options
author | Frank Schoenheit [fs] <frank.schoenheit@sun.com> | 2010-10-25 12:48:42 +0200 |
---|---|---|
committer | Frank Schoenheit [fs] <frank.schoenheit@sun.com> | 2010-10-25 12:48:42 +0200 |
commit | 5104853dfb200f505247de2c66fc4a16045422c7 (patch) | |
tree | 6449ec5c9e508d19d802bb3dd833de39f83ba96f /svl/source | |
parent | 209d53b5f76137122bd3f142952e45d730aa31db (diff) |
undoapi: implementation/tests for hidden Undo contexts
Diffstat (limited to 'svl/source')
-rw-r--r-- | svl/source/undo/undo.cxx | 78 |
1 files changed, 55 insertions, 23 deletions
diff --git a/svl/source/undo/undo.cxx b/svl/source/undo/undo.cxx index 461ea54fcc73..b61d3c6be25b 100644 --- a/svl/source/undo/undo.cxx +++ b/svl/source/undo/undo.cxx @@ -685,11 +685,20 @@ USHORT SfxUndoManager::GetListActionDepth() const //------------------------------------------------------------------------ USHORT SfxUndoManager::LeaveListAction() +{ + return ImplLeaveListAction( false ); +} -/* [Beschreibung] +//------------------------------------------------------------------------ - Verlaesst die aktuelle ListAction und geht eine Ebene nach oben. -*/ +USHORT SfxUndoManager::LeaveAndMergeListAction() +{ + return ImplLeaveListAction( true ); +} + +//------------------------------------------------------------------------ + +USHORT SfxUndoManager::ImplLeaveListAction( const bool i_merge ) { if ( !IsUndoEnabled() ) return 0; @@ -699,45 +708,68 @@ USHORT SfxUndoManager::LeaveListAction() if( !IsInListAction() ) { - DBG_ERROR( "svl::SfxUndoManager::LeaveListAction(), called without calling EnterListAction()!" ); + DBG_ERROR( "svl::SfxUndoManager::ImplLeaveListAction, called without calling EnterListAction()!" ); return 0; } - DBG_ASSERT(m_pData->pActUndoArray->pFatherUndoArray,"svl::SfxUndoManager::LeaveListAction(), no father undo array!?"); + DBG_ASSERT(m_pData->pActUndoArray->pFatherUndoArray,"svl::SfxUndoManager::ImplLeaveListAction, no father undo array!?"); - SfxUndoArray* pTmp = m_pData->pActUndoArray; + // the array/level which we're about to leave + SfxUndoArray* pArrayToLeave = m_pData->pActUndoArray; + // one step up m_pData->pActUndoArray = m_pData->pActUndoArray->pFatherUndoArray; // If no undo action where added, delete the undo list action - SfxUndoAction *pTmpAction= m_pData->pActUndoArray->aUndoActions[m_pData->pActUndoArray->nCurUndoAction-1]; - const USHORT nListActionElements = pTmp->nCurUndoAction; + const USHORT nListActionElements = pArrayToLeave->nCurUndoAction; if( nListActionElements == 0 ) { - m_pData->pActUndoArray->aUndoActions.Remove( --m_pData->pActUndoArray->nCurUndoAction); - delete pTmpAction; + SfxUndoAction* pCurrentAction= m_pData->pActUndoArray->aUndoActions[ m_pData->pActUndoArray->nCurUndoAction-1 ]; + m_pData->pActUndoArray->aUndoActions.Remove( --m_pData->pActUndoArray->nCurUndoAction ); + delete pCurrentAction; + + ::std::for_each( m_pData->aListeners.begin(), m_pData->aListeners.end(), + NotifyUndoListener( &SfxUndoListener::listActionCancelled ) ); + return 0; + } + + + SfxUndoAction* pCurrentAction= m_pData->pActUndoArray->aUndoActions[ m_pData->pActUndoArray->nCurUndoAction-1 ]; + SfxListUndoAction* pListAction = dynamic_cast< SfxListUndoAction * >( pCurrentAction ); + OSL_ENSURE( pListAction, "SfxUndoManager::ImplLeaveListAction: list action expected at this position!" ); + + if ( pListAction && i_merge ) + { + // merge the list action with its predecessor on the same level + OSL_ENSURE( m_pData->pActUndoArray->nCurUndoAction > 1, + "SfxUndoManager::ImplLeaveListAction: cannot merge the list action if there's no other action on the same level - check this beforehand!" ); + if ( m_pData->pActUndoArray->nCurUndoAction > 1 ) + { + const SfxUndoAction* pPreviousAction = m_pData->pActUndoArray->aUndoActions[ m_pData->pActUndoArray->nCurUndoAction - 2 ]; + m_pData->pActUndoArray->aUndoActions.Remove( m_pData->pActUndoArray->nCurUndoAction - 2 ); + --m_pData->pActUndoArray->nCurUndoAction; + pListAction->aUndoActions.Insert( pPreviousAction, 0 ); + ++pListAction->nCurUndoAction; // should not matter, as we're not expected to ever re-enter this list ... + + pListAction->SetComment( pPreviousAction->GetComment() ); + } } - else + + // if the undo array has no comment, try to get it from its children + if ( pListAction && pListAction->GetComment().Len() == 0 ) { - // if the undo array has no comment, try to get it from its children - SfxListUndoAction* pList = dynamic_cast< SfxListUndoAction * >( pTmpAction ); - if( pList && pList->GetComment().Len() == 0 ) + for( USHORT n = 0; n < pListAction->aUndoActions.Count(); n++ ) { - USHORT n; - for( n = 0; n < pList->aUndoActions.Count(); n++ ) + if( pListAction->aUndoActions[n]->GetComment().Len() ) { - if( pList->aUndoActions[n]->GetComment().Len() ) - { - pList->SetComment( pList->aUndoActions[n]->GetComment() ); - break; - } + pListAction->SetComment( pListAction->aUndoActions[n]->GetComment() ); + break; } } } // notify listeners - const bool leftContext = ( nListActionElements > 0 ); ::std::for_each( m_pData->aListeners.begin(), m_pData->aListeners.end(), - NotifyUndoListener( leftContext ? &SfxUndoListener::listActionLeft : &SfxUndoListener::listActionCancelled ) ); + NotifyUndoListener( &SfxUndoListener::listActionLeft ) ); return nListActionElements; } |