From 78fed9b8623faca46c3e1ef4dc633d80682d0414 Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Tue, 9 Nov 2010 21:36:54 +0100 Subject: undoapi: step 0.1 of the migration of css.chart2.XUndoManager to css.document.XUndoManager: remove the XModel paramter from the XUndoManager methods, they're an implicit attribute of the instance --- chart2/source/controller/main/UndoGuard.cxx | 38 ++++++++++++----------------- 1 file changed, 16 insertions(+), 22 deletions(-) (limited to 'chart2/source/controller/main/UndoGuard.cxx') diff --git a/chart2/source/controller/main/UndoGuard.cxx b/chart2/source/controller/main/UndoGuard.cxx index 8513b6ba9093..d55d52f8d41e 100644 --- a/chart2/source/controller/main/UndoGuard.cxx +++ b/chart2/source/controller/main/UndoGuard.cxx @@ -40,10 +40,8 @@ namespace chart { UndoGuard_Base::UndoGuard_Base( const OUString& rUndoString - , const uno::Reference< chart2::XUndoManager > & xUndoManager - , const uno::Reference< frame::XModel > & xModel ) - : m_xModel( xModel ) - , m_xUndoManager( xUndoManager ) + , const uno::Reference< chart2::XUndoManager > & xUndoManager ) + : m_xUndoManager( xUndoManager ) , m_aUndoString( rUndoString ) , m_bActionPosted( false ) { @@ -63,12 +61,11 @@ void UndoGuard_Base::commitAction() //----------------------------------------------------------------------------- UndoGuard::UndoGuard( const OUString& rUndoString - , const uno::Reference< chart2::XUndoManager > & xUndoManager - , const uno::Reference< frame::XModel > & xModel ) - : UndoGuard_Base( rUndoString, xUndoManager, xModel ) + , const uno::Reference< chart2::XUndoManager > & xUndoManager ) + : UndoGuard_Base( rUndoString, xUndoManager ) { if( m_xUndoManager.is() ) - m_xUndoManager->preAction( m_xModel ); + m_xUndoManager->preAction(); } UndoGuard::~UndoGuard() @@ -80,26 +77,24 @@ UndoGuard::~UndoGuard() //----------------------------------------------------------------------------- UndoLiveUpdateGuard::UndoLiveUpdateGuard( const OUString& rUndoString - , const uno::Reference< chart2::XUndoManager > & xUndoManager - , const uno::Reference< frame::XModel > & xModel ) - : UndoGuard_Base( rUndoString, xUndoManager, xModel ) + , const uno::Reference< chart2::XUndoManager > & xUndoManager ) + : UndoGuard_Base( rUndoString, xUndoManager ) { if( m_xUndoManager.is() ) - m_xUndoManager->preAction( m_xModel ); + m_xUndoManager->preAction(); } UndoLiveUpdateGuard::~UndoLiveUpdateGuard() { if( !m_bActionPosted && m_xUndoManager.is() ) - m_xUndoManager->cancelActionWithUndo( m_xModel ); + m_xUndoManager->cancelActionWithUndo(); } //----------------------------------------------------------------------------- UndoLiveUpdateGuardWithData::UndoLiveUpdateGuardWithData( const OUString& rUndoString - , const uno::Reference< chart2::XUndoManager > & xUndoManager - , const uno::Reference< frame::XModel > & xModel ) - : UndoGuard_Base( rUndoString, xUndoManager, xModel ) + , const uno::Reference< chart2::XUndoManager > & xUndoManager ) + : UndoGuard_Base( rUndoString, xUndoManager ) { if( m_xUndoManager.is() ) { @@ -107,22 +102,21 @@ UndoLiveUpdateGuardWithData::UndoLiveUpdateGuardWithData( const OUString& rUndoS aArgs[0] = beans::PropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("WithData")), -1, uno::Any(), beans::PropertyState_DIRECT_VALUE ); - m_xUndoManager->preActionWithArguments( m_xModel, aArgs ); + m_xUndoManager->preActionWithArguments( aArgs ); } } UndoLiveUpdateGuardWithData::~UndoLiveUpdateGuardWithData() { if( !m_bActionPosted && m_xUndoManager.is() ) - m_xUndoManager->cancelActionWithUndo( m_xModel ); + m_xUndoManager->cancelActionWithUndo(); } //----------------------------------------------------------------------------- UndoGuardWithSelection::UndoGuardWithSelection( const rtl::OUString& rUndoString - , const uno::Reference< chart2::XUndoManager > & xUndoManager - , const uno::Reference< frame::XModel > & xModel ) - : UndoGuard_Base( rUndoString, xUndoManager, xModel ) + , const uno::Reference< chart2::XUndoManager > & xUndoManager ) + : UndoGuard_Base( rUndoString, xUndoManager ) { if( m_xUndoManager.is() ) { @@ -130,7 +124,7 @@ UndoGuardWithSelection::UndoGuardWithSelection( const rtl::OUString& rUndoString aArgs[0] = beans::PropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("WithSelection")), -1, uno::Any(), beans::PropertyState_DIRECT_VALUE ); - m_xUndoManager->preActionWithArguments( m_xModel, aArgs ); + m_xUndoManager->preActionWithArguments( aArgs ); } } -- cgit From 587dfc9e8a00e8b97d5460e4e1d7c48de91b7425 Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Tue, 9 Nov 2010 21:37:01 +0100 Subject: undoapi: step 2.0 of the migration of css.chart2.XUndoManager to css.document.XUndoManager: rename css.chart2.XUndoManager to XDocumentActions. Not sure this class will still exist (in either form) after the refactoring is finished. --- chart2/source/controller/main/UndoGuard.cxx | 56 ++++++++++++++--------------- 1 file changed, 28 insertions(+), 28 deletions(-) (limited to 'chart2/source/controller/main/UndoGuard.cxx') diff --git a/chart2/source/controller/main/UndoGuard.cxx b/chart2/source/controller/main/UndoGuard.cxx index d55d52f8d41e..e38bb89d9249 100644 --- a/chart2/source/controller/main/UndoGuard.cxx +++ b/chart2/source/controller/main/UndoGuard.cxx @@ -40,8 +40,8 @@ namespace chart { UndoGuard_Base::UndoGuard_Base( const OUString& rUndoString - , const uno::Reference< chart2::XUndoManager > & xUndoManager ) - : m_xUndoManager( xUndoManager ) + , const uno::Reference< chart2::XDocumentActions > & xDocumentActions ) + : m_xDocumentActions( xDocumentActions ) , m_aUndoString( rUndoString ) , m_bActionPosted( false ) { @@ -53,85 +53,85 @@ UndoGuard_Base::~UndoGuard_Base() void UndoGuard_Base::commitAction() { - if( !m_bActionPosted && m_xUndoManager.is() ) - m_xUndoManager->postAction( m_aUndoString ); + if( !m_bActionPosted && m_xDocumentActions.is() ) + m_xDocumentActions->postAction( m_aUndoString ); m_bActionPosted = true; } //----------------------------------------------------------------------------- UndoGuard::UndoGuard( const OUString& rUndoString - , const uno::Reference< chart2::XUndoManager > & xUndoManager ) - : UndoGuard_Base( rUndoString, xUndoManager ) + , const uno::Reference< chart2::XDocumentActions > & xDocumentActions ) + : UndoGuard_Base( rUndoString, xDocumentActions ) { - if( m_xUndoManager.is() ) - m_xUndoManager->preAction(); + if( m_xDocumentActions.is() ) + m_xDocumentActions->preAction(); } UndoGuard::~UndoGuard() { - if( !m_bActionPosted && m_xUndoManager.is() ) - m_xUndoManager->cancelAction(); + if( !m_bActionPosted && m_xDocumentActions.is() ) + m_xDocumentActions->cancelAction(); } //----------------------------------------------------------------------------- UndoLiveUpdateGuard::UndoLiveUpdateGuard( const OUString& rUndoString - , const uno::Reference< chart2::XUndoManager > & xUndoManager ) - : UndoGuard_Base( rUndoString, xUndoManager ) + , const uno::Reference< chart2::XDocumentActions > & xDocumentActions ) + : UndoGuard_Base( rUndoString, xDocumentActions ) { - if( m_xUndoManager.is() ) - m_xUndoManager->preAction(); + if( m_xDocumentActions.is() ) + m_xDocumentActions->preAction(); } UndoLiveUpdateGuard::~UndoLiveUpdateGuard() { - if( !m_bActionPosted && m_xUndoManager.is() ) - m_xUndoManager->cancelActionWithUndo(); + if( !m_bActionPosted && m_xDocumentActions.is() ) + m_xDocumentActions->cancelActionWithUndo(); } //----------------------------------------------------------------------------- UndoLiveUpdateGuardWithData::UndoLiveUpdateGuardWithData( const OUString& rUndoString - , const uno::Reference< chart2::XUndoManager > & xUndoManager ) - : UndoGuard_Base( rUndoString, xUndoManager ) + , const uno::Reference< chart2::XDocumentActions > & xDocumentActions ) + : UndoGuard_Base( rUndoString, xDocumentActions ) { - if( m_xUndoManager.is() ) + if( m_xDocumentActions.is() ) { Sequence< beans::PropertyValue > aArgs(1); aArgs[0] = beans::PropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("WithData")), -1, uno::Any(), beans::PropertyState_DIRECT_VALUE ); - m_xUndoManager->preActionWithArguments( aArgs ); + m_xDocumentActions->preActionWithArguments( aArgs ); } } UndoLiveUpdateGuardWithData::~UndoLiveUpdateGuardWithData() { - if( !m_bActionPosted && m_xUndoManager.is() ) - m_xUndoManager->cancelActionWithUndo(); + if( !m_bActionPosted && m_xDocumentActions.is() ) + m_xDocumentActions->cancelActionWithUndo(); } //----------------------------------------------------------------------------- UndoGuardWithSelection::UndoGuardWithSelection( const rtl::OUString& rUndoString - , const uno::Reference< chart2::XUndoManager > & xUndoManager ) - : UndoGuard_Base( rUndoString, xUndoManager ) + , const uno::Reference< chart2::XDocumentActions > & xDocumentActions ) + : UndoGuard_Base( rUndoString, xDocumentActions ) { - if( m_xUndoManager.is() ) + if( m_xDocumentActions.is() ) { Sequence< beans::PropertyValue > aArgs(1); aArgs[0] = beans::PropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("WithSelection")), -1, uno::Any(), beans::PropertyState_DIRECT_VALUE ); - m_xUndoManager->preActionWithArguments( aArgs ); + m_xDocumentActions->preActionWithArguments( aArgs ); } } UndoGuardWithSelection::~UndoGuardWithSelection() { - if( !m_bActionPosted && m_xUndoManager.is() ) - m_xUndoManager->cancelAction(); + if( !m_bActionPosted && m_xDocumentActions.is() ) + m_xDocumentActions->cancelAction(); } } // namespace chart -- cgit From 4d0ae2eac2ac03475b7496f81e803b9b71b7481f Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Tue, 16 Nov 2010 08:49:38 +0100 Subject: undoapi: step 2.3 of the migration of css.chart2.XUndoManager to css.document.XUndoManager: migrate the clients of XDocumentActions to using the new XUndoManager, and completely remove the (X)DocumentActions still some more cleanup needed --- chart2/source/controller/main/UndoGuard.cxx | 133 ++++++++++++++++++---------- 1 file changed, 85 insertions(+), 48 deletions(-) (limited to 'chart2/source/controller/main/UndoGuard.cxx') diff --git a/chart2/source/controller/main/UndoGuard.cxx b/chart2/source/controller/main/UndoGuard.cxx index e38bb89d9249..b89b463cc0eb 100644 --- a/chart2/source/controller/main/UndoGuard.cxx +++ b/chart2/source/controller/main/UndoGuard.cxx @@ -29,6 +29,11 @@ #include "precompiled_chart2.hxx" #include "UndoGuard.hxx" +#include "ImplDocumentActions.hxx" + +#include + +#include using namespace ::com::sun::star; @@ -39,99 +44,131 @@ using ::rtl::OUString; namespace chart { -UndoGuard_Base::UndoGuard_Base( const OUString& rUndoString - , const uno::Reference< chart2::XDocumentActions > & xDocumentActions ) - : m_xDocumentActions( xDocumentActions ) - , m_aUndoString( rUndoString ) - , m_bActionPosted( false ) +//----------------------------------------------------------------------------- +namespace { + uno::Reference< uno::XInterface > lcl_getParent( const uno::Reference< uno::XInterface >& i_component ) + { + const uno::Reference< container::XChild > xAsChild( i_component, uno::UNO_QUERY_THROW ); + return xAsChild->getParent(); + } } +//----------------------------------------------------------------------------- + +UndoGuard_Base::UndoGuard_Base( const OUString& i_undoString, const uno::Reference< document::XUndoManager > & i_undoManager ) + :m_xChartModel( lcl_getParent( i_undoManager ), uno::UNO_QUERY_THROW ) + ,m_xUndoManager( i_undoManager ) + ,m_aUndoString( i_undoString ) + ,m_bActionPosted( false ) +{ +} + +//----------------------------------------------------------------------------- + UndoGuard_Base::~UndoGuard_Base() { + if ( !!m_pDocumentSnapshot ) + discardSnapshot(); } -void UndoGuard_Base::commitAction() +//----------------------------------------------------------------------------- + +void UndoGuard_Base::commit() { - if( !m_bActionPosted && m_xDocumentActions.is() ) - m_xDocumentActions->postAction( m_aUndoString ); + if ( !m_bActionPosted && !!m_pDocumentSnapshot && m_xUndoManager.is() ) + { + const Reference< document::XUndoAction > xAction( new impl::UndoElement( m_aUndoString, m_xChartModel, m_pDocumentSnapshot ) ); + m_pDocumentSnapshot.reset(); // don't dispose, it's data went over to the UndoElement + m_xUndoManager->addUndoAction( xAction ); + } m_bActionPosted = true; } //----------------------------------------------------------------------------- -UndoGuard::UndoGuard( const OUString& rUndoString - , const uno::Reference< chart2::XDocumentActions > & xDocumentActions ) - : UndoGuard_Base( rUndoString, xDocumentActions ) +void UndoGuard_Base::rollback() +{ + ENSURE_OR_RETURN_VOID( !!m_pDocumentSnapshot, "no snapshot!" ); + m_pDocumentSnapshot->applyToModel( m_xChartModel ); + discardSnapshot(); +} + +//----------------------------------------------------------------------------- + +void UndoGuard_Base::takeSnapshot( bool i_withData, bool i_withSelection ) { - if( m_xDocumentActions.is() ) - m_xDocumentActions->preAction(); + impl::ModelFacet eModelFacet( impl::E_MODEL ); + if ( i_withData ) + eModelFacet = impl::E_MODEL_WITH_DATA; + else if ( i_withSelection ) + eModelFacet = impl::E_MODEL_WITH_SELECTION; + m_pDocumentSnapshot.reset( new impl::ChartModelClone( m_xChartModel, eModelFacet ) ); +} + +//----------------------------------------------------------------------------- +void UndoGuard_Base::discardSnapshot() +{ + ENSURE_OR_RETURN_VOID( !!m_pDocumentSnapshot, "no snapshot!" ); + m_pDocumentSnapshot->dispose(); + m_pDocumentSnapshot.reset(); +} + +//----------------------------------------------------------------------------- + +UndoGuard::UndoGuard( const OUString& i_undoString, const uno::Reference< document::XUndoManager >& i_undoManager ) + :UndoGuard_Base( i_undoString, i_undoManager ) +{ + takeSnapshot( false, false ); } UndoGuard::~UndoGuard() { - if( !m_bActionPosted && m_xDocumentActions.is() ) - m_xDocumentActions->cancelAction(); + // nothing to do ... TODO: can this class be removed? } //----------------------------------------------------------------------------- -UndoLiveUpdateGuard::UndoLiveUpdateGuard( const OUString& rUndoString - , const uno::Reference< chart2::XDocumentActions > & xDocumentActions ) - : UndoGuard_Base( rUndoString, xDocumentActions ) +UndoLiveUpdateGuard::UndoLiveUpdateGuard( const OUString& i_undoString, const uno::Reference< document::XUndoManager >& i_undoManager ) + :UndoGuard_Base( i_undoString, i_undoManager ) { - if( m_xDocumentActions.is() ) - m_xDocumentActions->preAction(); + takeSnapshot( false, false ); } UndoLiveUpdateGuard::~UndoLiveUpdateGuard() { - if( !m_bActionPosted && m_xDocumentActions.is() ) - m_xDocumentActions->cancelActionWithUndo(); + if ( !isActionPosted() ) + rollback(); } //----------------------------------------------------------------------------- -UndoLiveUpdateGuardWithData::UndoLiveUpdateGuardWithData( const OUString& rUndoString - , const uno::Reference< chart2::XDocumentActions > & xDocumentActions ) - : UndoGuard_Base( rUndoString, xDocumentActions ) +UndoLiveUpdateGuardWithData::UndoLiveUpdateGuardWithData( + const OUString& i_undoString, const uno::Reference< document::XUndoManager >& i_undoManager ) + :UndoGuard_Base( i_undoString, i_undoManager ) { - if( m_xDocumentActions.is() ) - { - Sequence< beans::PropertyValue > aArgs(1); - aArgs[0] = beans::PropertyValue( - OUString( RTL_CONSTASCII_USTRINGPARAM("WithData")), -1, uno::Any(), - beans::PropertyState_DIRECT_VALUE ); - m_xDocumentActions->preActionWithArguments( aArgs ); - } + takeSnapshot( true, false ); } UndoLiveUpdateGuardWithData::~UndoLiveUpdateGuardWithData() { - if( !m_bActionPosted && m_xDocumentActions.is() ) - m_xDocumentActions->cancelActionWithUndo(); + if ( !isActionPosted() ) + rollback(); } //----------------------------------------------------------------------------- -UndoGuardWithSelection::UndoGuardWithSelection( const rtl::OUString& rUndoString - , const uno::Reference< chart2::XDocumentActions > & xDocumentActions ) - : UndoGuard_Base( rUndoString, xDocumentActions ) +UndoGuardWithSelection::UndoGuardWithSelection( + const OUString& i_undoString, const uno::Reference< document::XUndoManager >& i_undoManager ) + :UndoGuard_Base( i_undoString, i_undoManager ) { - if( m_xDocumentActions.is() ) - { - Sequence< beans::PropertyValue > aArgs(1); - aArgs[0] = beans::PropertyValue( - OUString( RTL_CONSTASCII_USTRINGPARAM("WithSelection")), -1, uno::Any(), - beans::PropertyState_DIRECT_VALUE ); - m_xDocumentActions->preActionWithArguments( aArgs ); - } + takeSnapshot( false, true ); } UndoGuardWithSelection::~UndoGuardWithSelection() { - if( !m_bActionPosted && m_xDocumentActions.is() ) - m_xDocumentActions->cancelAction(); + if ( !isActionPosted() ) + rollback(); } } // namespace chart -- cgit From fa0b1d6e1d2850cae0cd11e33d662c8d8fad20a9 Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Tue, 16 Nov 2010 12:22:48 +0100 Subject: undoapi: derive XUndoManager from XChild, to allow convenient access to the document it belongs to --- chart2/source/controller/main/UndoGuard.cxx | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) (limited to 'chart2/source/controller/main/UndoGuard.cxx') diff --git a/chart2/source/controller/main/UndoGuard.cxx b/chart2/source/controller/main/UndoGuard.cxx index b89b463cc0eb..1be8af4de180 100644 --- a/chart2/source/controller/main/UndoGuard.cxx +++ b/chart2/source/controller/main/UndoGuard.cxx @@ -44,23 +44,13 @@ using ::rtl::OUString; namespace chart { -//----------------------------------------------------------------------------- -namespace -{ - uno::Reference< uno::XInterface > lcl_getParent( const uno::Reference< uno::XInterface >& i_component ) - { - const uno::Reference< container::XChild > xAsChild( i_component, uno::UNO_QUERY_THROW ); - return xAsChild->getParent(); - } -} - //----------------------------------------------------------------------------- UndoGuard_Base::UndoGuard_Base( const OUString& i_undoString, const uno::Reference< document::XUndoManager > & i_undoManager ) - :m_xChartModel( lcl_getParent( i_undoManager ), uno::UNO_QUERY_THROW ) - ,m_xUndoManager( i_undoManager ) - ,m_aUndoString( i_undoString ) - ,m_bActionPosted( false ) + :m_xChartModel( i_undoManager->getParent(), uno::UNO_QUERY_THROW ) + ,m_xUndoManager( i_undoManager ) + ,m_aUndoString( i_undoString ) + ,m_bActionPosted( false ) { } -- cgit From 2f09474ea14bf08a33e0788905a2a68bf5f93b2d Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Tue, 16 Nov 2010 13:10:17 +0100 Subject: undoapi: some cleanups after the previos refactoring (more to come) --- chart2/source/controller/main/UndoGuard.cxx | 48 ++++++++--------------------- 1 file changed, 12 insertions(+), 36 deletions(-) (limited to 'chart2/source/controller/main/UndoGuard.cxx') diff --git a/chart2/source/controller/main/UndoGuard.cxx b/chart2/source/controller/main/UndoGuard.cxx index 1be8af4de180..e331aee3a762 100644 --- a/chart2/source/controller/main/UndoGuard.cxx +++ b/chart2/source/controller/main/UndoGuard.cxx @@ -29,6 +29,7 @@ #include "precompiled_chart2.hxx" #include "UndoGuard.hxx" +#include "ChartModelClone.hxx" #include "ImplDocumentActions.hxx" #include @@ -46,17 +47,20 @@ namespace chart //----------------------------------------------------------------------------- -UndoGuard_Base::UndoGuard_Base( const OUString& i_undoString, const uno::Reference< document::XUndoManager > & i_undoManager ) +UndoGuard::UndoGuard( const OUString& i_undoString, const uno::Reference< document::XUndoManager > & i_undoManager, + const ModelFacet i_facet ) :m_xChartModel( i_undoManager->getParent(), uno::UNO_QUERY_THROW ) ,m_xUndoManager( i_undoManager ) + ,m_pDocumentSnapshot() ,m_aUndoString( i_undoString ) ,m_bActionPosted( false ) { + m_pDocumentSnapshot.reset( new ChartModelClone( m_xChartModel, i_facet ) ); } //----------------------------------------------------------------------------- -UndoGuard_Base::~UndoGuard_Base() +UndoGuard::~UndoGuard() { if ( !!m_pDocumentSnapshot ) discardSnapshot(); @@ -64,7 +68,7 @@ UndoGuard_Base::~UndoGuard_Base() //----------------------------------------------------------------------------- -void UndoGuard_Base::commit() +void UndoGuard::commit() { if ( !m_bActionPosted && !!m_pDocumentSnapshot && m_xUndoManager.is() ) { @@ -77,7 +81,7 @@ void UndoGuard_Base::commit() //----------------------------------------------------------------------------- -void UndoGuard_Base::rollback() +void UndoGuard::rollback() { ENSURE_OR_RETURN_VOID( !!m_pDocumentSnapshot, "no snapshot!" ); m_pDocumentSnapshot->applyToModel( m_xChartModel ); @@ -85,19 +89,7 @@ void UndoGuard_Base::rollback() } //----------------------------------------------------------------------------- - -void UndoGuard_Base::takeSnapshot( bool i_withData, bool i_withSelection ) -{ - impl::ModelFacet eModelFacet( impl::E_MODEL ); - if ( i_withData ) - eModelFacet = impl::E_MODEL_WITH_DATA; - else if ( i_withSelection ) - eModelFacet = impl::E_MODEL_WITH_SELECTION; - m_pDocumentSnapshot.reset( new impl::ChartModelClone( m_xChartModel, eModelFacet ) ); -} - -//----------------------------------------------------------------------------- -void UndoGuard_Base::discardSnapshot() +void UndoGuard::discardSnapshot() { ENSURE_OR_RETURN_VOID( !!m_pDocumentSnapshot, "no snapshot!" ); m_pDocumentSnapshot->dispose(); @@ -106,23 +98,9 @@ void UndoGuard_Base::discardSnapshot() //----------------------------------------------------------------------------- -UndoGuard::UndoGuard( const OUString& i_undoString, const uno::Reference< document::XUndoManager >& i_undoManager ) - :UndoGuard_Base( i_undoString, i_undoManager ) -{ - takeSnapshot( false, false ); -} - -UndoGuard::~UndoGuard() -{ - // nothing to do ... TODO: can this class be removed? -} - -//----------------------------------------------------------------------------- - UndoLiveUpdateGuard::UndoLiveUpdateGuard( const OUString& i_undoString, const uno::Reference< document::XUndoManager >& i_undoManager ) - :UndoGuard_Base( i_undoString, i_undoManager ) + :UndoGuard( i_undoString, i_undoManager, E_MODEL ) { - takeSnapshot( false, false ); } UndoLiveUpdateGuard::~UndoLiveUpdateGuard() @@ -135,9 +113,8 @@ UndoLiveUpdateGuard::~UndoLiveUpdateGuard() UndoLiveUpdateGuardWithData::UndoLiveUpdateGuardWithData( const OUString& i_undoString, const uno::Reference< document::XUndoManager >& i_undoManager ) - :UndoGuard_Base( i_undoString, i_undoManager ) + :UndoGuard( i_undoString, i_undoManager, E_MODEL_WITH_DATA ) { - takeSnapshot( true, false ); } UndoLiveUpdateGuardWithData::~UndoLiveUpdateGuardWithData() @@ -150,9 +127,8 @@ UndoLiveUpdateGuardWithData::~UndoLiveUpdateGuardWithData() UndoGuardWithSelection::UndoGuardWithSelection( const OUString& i_undoString, const uno::Reference< document::XUndoManager >& i_undoManager ) - :UndoGuard_Base( i_undoString, i_undoManager ) + :UndoGuard( i_undoString, i_undoManager, E_MODEL_WITH_SELECTION ) { - takeSnapshot( false, true ); } UndoGuardWithSelection::~UndoGuardWithSelection() -- cgit From d2de048b2b685ab3376b8f85d3d51e95fca7b80b Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Tue, 16 Nov 2010 13:20:01 +0100 Subject: undoapi: moved UndoGuard.hxx to the only folder where it is used, renamed ImplDocumentActions.* to UndoActions.* --- chart2/source/controller/main/UndoGuard.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'chart2/source/controller/main/UndoGuard.cxx') diff --git a/chart2/source/controller/main/UndoGuard.cxx b/chart2/source/controller/main/UndoGuard.cxx index e331aee3a762..97418e725140 100644 --- a/chart2/source/controller/main/UndoGuard.cxx +++ b/chart2/source/controller/main/UndoGuard.cxx @@ -30,7 +30,7 @@ #include "UndoGuard.hxx" #include "ChartModelClone.hxx" -#include "ImplDocumentActions.hxx" +#include "UndoActions.hxx" #include -- cgit From fd3ece0777004f5438cf6a352fefb7270228f6d7 Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Tue, 16 Nov 2010 13:22:05 +0100 Subject: undoapi: some exception safety --- chart2/source/controller/main/UndoGuard.cxx | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'chart2/source/controller/main/UndoGuard.cxx') diff --git a/chart2/source/controller/main/UndoGuard.cxx b/chart2/source/controller/main/UndoGuard.cxx index 97418e725140..b2a02aaa3522 100644 --- a/chart2/source/controller/main/UndoGuard.cxx +++ b/chart2/source/controller/main/UndoGuard.cxx @@ -70,11 +70,18 @@ UndoGuard::~UndoGuard() void UndoGuard::commit() { - if ( !m_bActionPosted && !!m_pDocumentSnapshot && m_xUndoManager.is() ) + if ( !m_bActionPosted && !!m_pDocumentSnapshot ) { - const Reference< document::XUndoAction > xAction( new impl::UndoElement( m_aUndoString, m_xChartModel, m_pDocumentSnapshot ) ); - m_pDocumentSnapshot.reset(); // don't dispose, it's data went over to the UndoElement - m_xUndoManager->addUndoAction( xAction ); + try + { + const Reference< document::XUndoAction > xAction( new impl::UndoElement( m_aUndoString, m_xChartModel, m_pDocumentSnapshot ) ); + m_pDocumentSnapshot.reset(); // don't dispose, it's data went over to the UndoElement + m_xUndoManager->addUndoAction( xAction ); + } + catch( const uno::Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } } m_bActionPosted = true; } -- cgit From 33f79158f6dd4ed6a475a826640d47ab88a0be28 Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Thu, 18 Nov 2010 15:45:39 +0100 Subject: undoapi: when inserting shapes, hide the Undo action which results from the initial positioning of the object --- chart2/source/controller/main/UndoGuard.cxx | 51 +++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'chart2/source/controller/main/UndoGuard.cxx') diff --git a/chart2/source/controller/main/UndoGuard.cxx b/chart2/source/controller/main/UndoGuard.cxx index b2a02aaa3522..52ea27aa8d49 100644 --- a/chart2/source/controller/main/UndoGuard.cxx +++ b/chart2/source/controller/main/UndoGuard.cxx @@ -138,10 +138,61 @@ UndoGuardWithSelection::UndoGuardWithSelection( { } +//----------------------------------------------------------------------------- + UndoGuardWithSelection::~UndoGuardWithSelection() { if ( !isActionPosted() ) rollback(); } +//----------------------------------------------------------------------------- + +UndoContext::UndoContext( const Reference< document::XUndoManager > & i_undoManager, const ::rtl::OUString& i_undoTitle ) + :m_xUndoManager( i_undoManager ) +{ + ENSURE_OR_THROW( m_xUndoManager.is(), "invalid undo manager!" ); + m_xUndoManager->enterUndoContext( i_undoTitle ); +} + +//----------------------------------------------------------------------------- + +UndoContext::~UndoContext() +{ + m_xUndoManager->leaveUndoContext(); +} + +//----------------------------------------------------------------------------- + +HiddenUndoContext::HiddenUndoContext( const Reference< document::XUndoManager > & i_undoManager ) + :m_xUndoManager( i_undoManager ) +{ + ENSURE_OR_THROW( m_xUndoManager.is(), "invalid undo manager!" ); + try + { + m_xUndoManager->enterHiddenUndoContext(); + } + catch( const uno::Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + m_xUndoManager.clear(); + // prevents the leaveUndoContext in the dtor + } +} + +//----------------------------------------------------------------------------- + +HiddenUndoContext::~HiddenUndoContext() +{ + try + { + if ( m_xUndoManager.is() ) + m_xUndoManager->leaveUndoContext(); + } + catch( const uno::Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } +} + } // namespace chart -- cgit