diff options
author | Frank Schoenheit [fs] <frank.schoenheit@oracle.com> | 2010-11-30 09:25:41 +0100 |
---|---|---|
committer | Frank Schoenheit [fs] <frank.schoenheit@oracle.com> | 2010-11-30 09:25:41 +0100 |
commit | 6877464dd7203ee78ded1eabd9a29298d2953cd6 (patch) | |
tree | 77d745e862b427cc0259db0e72061aef4152d486 /svl | |
parent | c93023f2ad77f399a065f907ab840b22be1ddca3 (diff) |
undoapi: introduced an (optional) SfxUndoContext for SfxUndoAction::Undo/Redo
Diffstat (limited to 'svl')
-rw-r--r-- | svl/inc/svl/undo.hxx | 27 | ||||
-rw-r--r-- | svl/source/undo/undo.cxx | 62 |
2 files changed, 85 insertions, 4 deletions
diff --git a/svl/inc/svl/undo.hxx b/svl/inc/svl/undo.hxx index fb1ae16a01d8..b1bec6332f61 100644 --- a/svl/inc/svl/undo.hxx +++ b/svl/inc/svl/undo.hxx @@ -35,6 +35,7 @@ #include <boost/scoped_ptr.hpp> #include <vector> +#include <memory> //==================================================================== @@ -47,6 +48,14 @@ public: //==================================================================== +class SVL_DLLPUBLIC SfxUndoContext +{ +public: + virtual ~SfxUndoContext() = 0; +}; + +//==================================================================== + class SVL_DLLPUBLIC SfxUndoAction { BOOL bLinked; @@ -58,7 +67,9 @@ public: virtual BOOL IsLinked(); virtual void SetLinked( BOOL bIsLinked = TRUE ); virtual void Undo(); + virtual void UndoWithContext( SfxUndoContext& i_context ); virtual void Redo(); + virtual void RedoWithContext( SfxUndoContext& i_context ); virtual void Repeat(SfxRepeatTarget&); virtual BOOL CanRepeat(SfxRepeatTarget&) const; @@ -163,7 +174,9 @@ class SVL_DLLPUBLIC SfxListUndoAction : public SfxUndoAction, public SfxUndoArra SfxListUndoAction( const UniString &rComment, const UniString rRepeatComment, USHORT Id, SfxUndoArray *pFather); virtual void Undo(); + virtual void UndoWithContext( SfxUndoContext& i_context ); virtual void Redo(); + virtual void RedoWithContext( SfxUndoContext& i_context ); virtual void Repeat(SfxRepeatTarget&); virtual BOOL CanRepeat(SfxRepeatTarget&) const; @@ -382,6 +395,20 @@ public: */ void RemoveOldestUndoActions( USHORT const i_count ); +protected: + /** retrieve the context for a to-be-executed Undo or Redo operation + + This method is called immediately before an SfxUndoAction is undo or redone. If a derived class provides a non-<NULL/> + context here, it is passed to SfxUndoAction's UndoWithContext resp. RedoWithContext. If no context is provided, + the SfxUndoAction's normal Undo/Redo is called. + + The method is called with the UndoManager's mutex locked. + + The default implementation of the method returns a <NULL/> context. + */ + virtual ::std::auto_ptr< SfxUndoContext > + GetUndoContext(); + private: USHORT ImplLeaveListAction( const bool i_merge, ::svl::undo::impl::UndoManagerGuard& i_guard ); bool ImplAddUndoAction_NoNotify( SfxUndoAction* pAction, BOOL bTryMerge, ::svl::undo::impl::UndoManagerGuard& i_guard ); diff --git a/svl/source/undo/undo.cxx b/svl/source/undo/undo.cxx index 13588b234a62..480fb2e8026a 100644 --- a/svl/source/undo/undo.cxx +++ b/svl/source/undo/undo.cxx @@ -61,6 +61,12 @@ SfxRepeatTarget::~SfxRepeatTarget() //------------------------------------------------------------------------ +SfxUndoContext::~SfxUndoContext() +{ +} + +//------------------------------------------------------------------------ + BOOL SfxUndoAction::IsLinked() { return bLinked; @@ -123,7 +129,6 @@ XubString SfxUndoAction::GetRepeatComment(SfxRepeatTarget&) const //------------------------------------------------------------------------ - void SfxUndoAction::Undo() { // die sind nur konzeptuell pure virtual @@ -132,6 +137,14 @@ void SfxUndoAction::Undo() //------------------------------------------------------------------------ +void SfxUndoAction::UndoWithContext( SfxUndoContext& i_context ) +{ + (void)i_context; + Undo(); +} + +//------------------------------------------------------------------------ + void SfxUndoAction::Redo() { // die sind nur konzeptuell pure virtual @@ -140,6 +153,14 @@ void SfxUndoAction::Redo() //------------------------------------------------------------------------ +void SfxUndoAction::RedoWithContext( SfxUndoContext& i_context ) +{ + (void)i_context; + Redo(); +} + +//------------------------------------------------------------------------ + void SfxUndoAction::Repeat(SfxRepeatTarget&) { // die sind nur konzeptuell pure virtual @@ -730,10 +751,14 @@ BOOL SfxUndoManager::Undo() const String sActionComment = pAction->GetComment(); try { - // clear the guard/mutex before calling into the SfxUndoAction - this can be a extension-implemented UNO component + ::std::auto_ptr< SfxUndoContext > pUndoContext( GetUndoContext() ); + // clear the guard/mutex before calling into the SfxUndoAction - this can be an extension-implemented UNO component // nowadays ... aGuard.clear(); - pAction->Undo(); + if ( pUndoContext.get() != NULL ) + pAction->UndoWithContext( *pUndoContext ); + else + pAction->Undo(); aGuard.reset(); } catch( ... ) @@ -813,10 +838,14 @@ BOOL SfxUndoManager::Redo() const String sActionComment = pAction->GetComment(); try { + ::std::auto_ptr< SfxUndoContext > pUndoContext( GetUndoContext() ); // clear the guard/mutex before calling into the SfxUndoAction - this can be a extension-implemented UNO component // nowadays ... aGuard.clear(); - pAction->Redo(); + if ( pUndoContext.get() != NULL ) + pAction->RedoWithContext( *pUndoContext ); + else + pAction->Redo(); aGuard.reset(); } catch( ... ) @@ -1160,6 +1189,13 @@ void SfxUndoManager::RemoveOldestUndoActions( USHORT const i_count ) //------------------------------------------------------------------------ +::std::auto_ptr< SfxUndoContext > SfxUndoManager::GetUndoContext() +{ + return ::std::auto_ptr< SfxUndoContext >(); +} + +//------------------------------------------------------------------------ + USHORT SfxListUndoAction::GetId() const { return nId; @@ -1213,6 +1249,15 @@ void SfxListUndoAction::Undo() //------------------------------------------------------------------------ +void SfxListUndoAction::UndoWithContext( SfxUndoContext& i_context ) +{ + for(INT16 i=nCurUndoAction-1;i>=0;i--) + aUndoActions[i].pAction->UndoWithContext( i_context ); + nCurUndoAction=0; +} + +//------------------------------------------------------------------------ + void SfxListUndoAction::Redo() { for(USHORT i=nCurUndoAction;i<aUndoActions.size();i++) @@ -1222,6 +1267,15 @@ void SfxListUndoAction::Redo() //------------------------------------------------------------------------ +void SfxListUndoAction::RedoWithContext( SfxUndoContext& i_context ) +{ + for(USHORT i=nCurUndoAction;i<aUndoActions.size();i++) + aUndoActions[i].pAction->RedoWithContext( i_context ); + nCurUndoAction = USHORT( aUndoActions.size() ); +} + +//------------------------------------------------------------------------ + void SfxListUndoAction::Repeat(SfxRepeatTarget&rTarget) { for(USHORT i=0;i<nCurUndoAction;i++) |