LibreOffice Module svl (master) 1
Public Member Functions | Static Public Attributes | Protected Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
SfxUndoManager Class Reference

#include <undo.hxx>

Public Member Functions

 SfxUndoManager (size_t nMaxUndoActionCount=20)
 
virtual ~SfxUndoManager ()
 
void SetMaxUndoActionCount (size_t nMaxUndoActionCount)
 
size_t GetMaxUndoActionCount () const
 
virtual void AddUndoAction (std::unique_ptr< SfxUndoAction > pAction, bool bTryMerg=false)
 
virtual size_t GetUndoActionCount (bool const i_currentLevel=CurrentLevel) const
 
OUString GetUndoActionComment (size_t nNo=0, bool const i_currentLevel=CurrentLevel) const
 
SfxUndoActionGetUndoAction (size_t nNo=0) const
 
OUString GetUndoActionsInfo () const
 Get info about all undo actions (comment, view shell id, etc.) More...
 
virtual size_t GetRedoActionCount (bool const i_currentLevel=CurrentLevel) const
 
OUString GetRedoActionComment (size_t nNo=0, bool const i_currentLevel=CurrentLevel) const
 
SfxUndoActionGetRedoAction (size_t nNo=0) const
 
OUString GetRedoActionsInfo () const
 Get info about all redo actions (comment, view shell id, etc.) More...
 
virtual bool Undo ()
 
virtual bool Redo ()
 
virtual void Clear ()
 Clears both the Redo and the Undo stack. More...
 
virtual void ClearRedo ()
 Clears the Redo stack. More...
 
void Reset ()
 leaves any possible open list action (<member>IsInListAction</member>), and clears both the Undo and the Redo stack. More...
 
bool IsDoing () const
 determines whether an Undo or Redo is currently running More...
 
size_t GetRepeatActionCount () const
 
OUString GetRepeatActionComment (SfxRepeatTarget &rTarget) const
 
bool Repeat (SfxRepeatTarget &rTarget)
 
bool CanRepeat (SfxRepeatTarget &rTarget) const
 
virtual void EnterListAction (const OUString &rComment, const OUString &rRepeatComment, sal_uInt16 nId, ViewShellId nViewShellId)
 Inserts a ListUndoAction and sets its UndoArray as current. More...
 
size_t LeaveListAction ()
 Leaves the list action entered with EnterListAction. More...
 
size_t LeaveAndMergeListAction ()
 Leaves the list action entered with EnterListAction, and forcefully merges the previous action on the stack into the newly created list action. More...
 
bool IsInListAction () const
 determines whether we're within a ListAction context, i.e. a LeaveListAction/LeaveAndMergeListAction call is pending More...
 
size_t GetListActionDepth () const
 Determines how many nested list actions are currently open. More...
 
void RemoveLastUndoAction ()
 Clears the redo stack and removes the top undo action. More...
 
void EnableUndo (bool bEnable)
 enables (true) or disables (false) recording of undo actions More...
 
bool IsUndoEnabled () const
 returns true if undo is currently enabled. More...
 
void AddUndoListener (SfxUndoListener &i_listener)
 Adds a new listener to be notified about changes in the UndoManager's state. More...
 
void RemoveUndoListener (SfxUndoListener &i_listener)
 
bool IsEmptyActions () const
 
UndoStackMark MarkTopUndoAction ()
 marks the current top-level element of the Undo stack, and returns a unique ID for it More...
 
void RemoveMark (UndoStackMark const i_mark)
 removes a mark given by its ID. More...
 
bool HasTopUndoActionMark (UndoStackMark const i_mark)
 determines whether the top action on the Undo stack has a given mark More...
 
void RemoveOldestUndoAction ()
 removes the oldest Undo actions from the stack More...
 
void dumpAsXml (xmlTextWriterPtr pWriter) const
 

Static Public Attributes

static bool const CurrentLevel = true
 
static bool const TopLevel = false
 

Protected Member Functions

bool UndoWithContext (SfxUndoContext &i_context)
 
bool RedoWithContext (SfxUndoContext &i_context)
 
void ImplClearRedo_NoLock (bool const i_currentLevel)
 
void ClearAllLevels ()
 clears all undo actions on the current level, plus all undo actions on superordinate levels, as soon as those levels are reached. More...
 
virtual void EmptyActionsChanged ()
 

Private Member Functions

size_t ImplLeaveListAction (const bool i_merge, ::svl::undo::impl::UndoManagerGuard &i_guard)
 
bool ImplAddUndoAction_NoNotify (std::unique_ptr< SfxUndoAction > pAction, bool bTryMerge, bool bClearRedo, ::svl::undo::impl::UndoManagerGuard &i_guard)
 
void ImplClearRedo (::svl::undo::impl::UndoManagerGuard &i_guard, bool const i_currentLevel)
 
void ImplClearUndo (::svl::undo::impl::UndoManagerGuard &i_guard)
 
void ImplClearCurrentLevel_NoNotify (::svl::undo::impl::UndoManagerGuard &i_guard)
 
size_t ImplGetRedoActionCount_Lock (bool const i_currentLevel=CurrentLevel) const
 
bool ImplIsUndoEnabled_Lock () const
 
bool ImplIsInListAction_Lock () const
 
void ImplEnableUndo_Lock (bool const i_enable)
 
bool ImplUndo (SfxUndoContext *i_contextOrNull)
 
bool ImplRedo (SfxUndoContext *i_contextOrNull)
 
void ImplCheckEmptyActions ()
 
bool ImplIsEmptyActions () const
 

Private Attributes

std::unique_ptr< SfxUndoManager_Datam_xData
 

Friends

class ::svl::undo::impl::LockGuard
 

Detailed Description

Definition at line 189 of file undo.hxx.

Constructor & Destructor Documentation

◆ SfxUndoManager()

SfxUndoManager::SfxUndoManager ( size_t  nMaxUndoActionCount = 20)

Definition at line 339 of file undo.cxx.

References ImplIsEmptyActions(), and m_xData.

◆ ~SfxUndoManager()

SfxUndoManager::~SfxUndoManager ( )
virtual

Definition at line 346 of file undo.cxx.

Member Function Documentation

◆ AddUndoAction()

void SfxUndoManager::AddUndoAction ( std::unique_ptr< SfxUndoAction pAction,
bool  bTryMerg = false 
)
virtual

◆ AddUndoListener()

void SfxUndoManager::AddUndoListener ( SfxUndoListener i_listener)

Adds a new listener to be notified about changes in the UndoManager's state.

Definition at line 898 of file undo.cxx.

References m_xData.

◆ CanRepeat()

bool SfxUndoManager::CanRepeat ( SfxRepeatTarget &  rTarget) const

Definition at line 886 of file undo.cxx.

References m_xData, and rTarget.

◆ Clear()

void SfxUndoManager::Clear ( )
virtual

Clears both the Redo and the Undo stack.

Will assert and bail out when called while within a list action (<member>IsInListAction</member>).

Definition at line 435 of file undo.cxx.

References SfxUndoListener::cleared(), ImplClearCurrentLevel_NoNotify(), ImplIsInListAction_Lock(), m_xData, and SAL_WARN_IF.

◆ ClearAllLevels()

void SfxUndoManager::ClearAllLevels ( )
protected

clears all undo actions on the current level, plus all undo actions on superordinate levels, as soon as those levels are reached.

If no list action is active currently, i.e. we're on the top level already, this method is equivalent to ->Clear.

Otherwise, the Undo actions on the current level are removed. Upon leaving the current list action, all undo actions on the then-current level are removed, too. This is continued until the top level is reached.

Definition at line 448 of file undo.cxx.

References SfxUndoListener::cleared(), ImplClearCurrentLevel_NoNotify(), ImplIsInListAction_Lock(), and m_xData.

◆ ClearRedo()

void SfxUndoManager::ClearRedo ( )
virtual

Clears the Redo stack.

Will assert and bail out when called while within a list action (<member>IsInListAction</member>).

Definition at line 471 of file undo.cxx.

References CurrentLevel, ImplClearRedo_NoLock(), IsInListAction(), and SAL_WARN_IF.

◆ dumpAsXml()

void SfxUndoManager::dumpAsXml ( xmlTextWriterPtr  pWriter) const

◆ EmptyActionsChanged()

void SfxUndoManager::EmptyActionsChanged ( )
protectedvirtual

Definition at line 1262 of file undo.cxx.

Referenced by ImplCheckEmptyActions().

◆ EnableUndo()

void SfxUndoManager::EnableUndo ( bool  bEnable)

enables (true) or disables (false) recording of undo actions

If undo actions are added while undo is disabled, they are deleted. Disabling undo does not clear the current undo buffer!

Multiple calls to EnableUndo are not cumulative. That is, calling EnableUndo( false ) twice, and then calling EnableUndo( true ) means that Undo is enable afterwards.

Definition at line 351 of file undo.cxx.

References ImplEnableUndo_Lock(), and m_xData.

◆ EnterListAction()

void SfxUndoManager::EnterListAction ( const OUString &  rComment,
const OUString &  rRepeatComment,
sal_uInt16  nId,
ViewShellId  nViewShellId 
)
virtual

Inserts a ListUndoAction and sets its UndoArray as current.

Definition at line 916 of file undo.cxx.

References ImplAddUndoAction_NoNotify(), ImplIsUndoEnabled_Lock(), SfxUndoListener::listActionEntered(), m_xData, and nId.

◆ GetListActionDepth()

size_t SfxUndoManager::GetListActionDepth ( ) const

Determines how many nested list actions are currently open.

Definition at line 951 of file undo.cxx.

References m_xData, and SfxUndoArray::pFatherUndoArray.

◆ GetMaxUndoActionCount()

size_t SfxUndoManager::GetMaxUndoActionCount ( ) const

Definition at line 413 of file undo.cxx.

References m_xData.

◆ GetRedoAction()

SfxUndoAction * SfxUndoManager::GetRedoAction ( size_t  nNo = 0) const

Definition at line 758 of file undo.cxx.

References m_xData, SfxUndoArray::maUndoActions, and SfxUndoArray::nCurUndoAction.

◆ GetRedoActionComment()

OUString SfxUndoManager::GetRedoActionComment ( size_t  nNo = 0,
bool const  i_currentLevel = CurrentLevel 
) const

Definition at line 771 of file undo.cxx.

References m_xData, SfxUndoArray::maUndoActions, and SfxUndoArray::nCurUndoAction.

◆ GetRedoActionCount()

size_t SfxUndoManager::GetRedoActionCount ( bool const  i_currentLevel = CurrentLevel) const
virtual

Definition at line 744 of file undo.cxx.

References ImplGetRedoActionCount_Lock(), and m_xData.

Referenced by dumpAsXml(), and GetRedoActionsInfo().

◆ GetRedoActionsInfo()

OUString SfxUndoManager::GetRedoActionsInfo ( ) const

Get info about all redo actions (comment, view shell id, etc.)

Definition at line 1221 of file undo.cxx.

References GetRedoActionCount(), i, lcl_ActionToJson(), m_xData, SfxUndoArray::maUndoActions, nCount, SfxUndoArray::nCurUndoAction, and nIndex.

◆ GetRepeatActionComment()

OUString SfxUndoManager::GetRepeatActionComment ( SfxRepeatTarget &  rTarget) const

Definition at line 862 of file undo.cxx.

References m_xData, and rTarget.

◆ GetRepeatActionCount()

size_t SfxUndoManager::GetRepeatActionCount ( ) const

Definition at line 855 of file undo.cxx.

References m_xData.

◆ GetUndoAction()

SfxUndoAction * SfxUndoManager::GetUndoAction ( size_t  nNo = 0) const

Definition at line 619 of file undo.cxx.

References m_xData.

◆ GetUndoActionComment()

OUString SfxUndoManager::GetUndoActionComment ( size_t  nNo = 0,
bool const  i_currentLevel = CurrentLevel 
) const

Definition at line 606 of file undo.cxx.

References m_xData, SfxUndoArray::maUndoActions, and SfxUndoArray::nCurUndoAction.

◆ GetUndoActionCount()

size_t SfxUndoManager::GetUndoActionCount ( bool const  i_currentLevel = CurrentLevel) const
virtual

Definition at line 598 of file undo.cxx.

References m_xData, and SfxUndoArray::nCurUndoAction.

Referenced by dumpAsXml(), and GetUndoActionsInfo().

◆ GetUndoActionsInfo()

OUString SfxUndoManager::GetUndoActionsInfo ( ) const

Get info about all undo actions (comment, view shell id, etc.)

Definition at line 1204 of file undo.cxx.

References GetUndoActionCount(), i, lcl_ActionToJson(), m_xData, SfxUndoArray::maUndoActions, and SfxUndoArray::nCurUndoAction.

◆ HasTopUndoActionMark()

bool SfxUndoManager::HasTopUndoActionMark ( UndoStackMark const  i_mark)

determines whether the top action on the Undo stack has a given mark

Definition at line 1119 of file undo.cxx.

References MarkedUndoAction::aMarks, and m_xData.

◆ ImplAddUndoAction_NoNotify()

bool SfxUndoManager::ImplAddUndoAction_NoNotify ( std::unique_ptr< SfxUndoAction pAction,
bool  bTryMerge,
bool  bClearRedo,
::svl::undo::impl::UndoManagerGuard i_guard 
)
private

◆ ImplCheckEmptyActions()

void SfxUndoManager::ImplCheckEmptyActions ( )
private

◆ ImplClearCurrentLevel_NoNotify()

void SfxUndoManager::ImplClearCurrentLevel_NoNotify ( ::svl::undo::impl::UndoManagerGuard i_guard)
private

Definition at line 418 of file undo.cxx.

References ImplCheckEmptyActions(), m_xData, and MARK_INVALID.

Referenced by Clear(), ClearAllLevels(), LeaveListAction(), and Reset().

◆ ImplClearRedo()

void SfxUndoManager::ImplClearRedo ( ::svl::undo::impl::UndoManagerGuard i_guard,
bool const  i_currentLevel 
)
private

◆ ImplClearRedo_NoLock()

void SfxUndoManager::ImplClearRedo_NoLock ( bool const  i_currentLevel)
protected

Definition at line 464 of file undo.cxx.

References ImplClearRedo(), and m_xData.

Referenced by ClearRedo().

◆ ImplClearUndo()

void SfxUndoManager::ImplClearUndo ( ::svl::undo::impl::UndoManagerGuard i_guard)
private

Definition at line 503 of file undo.cxx.

References ImplCheckEmptyActions(), and m_xData.

Referenced by ImplUndo().

◆ ImplEnableUndo_Lock()

void SfxUndoManager::ImplEnableUndo_Lock ( bool const  i_enable)
private

◆ ImplGetRedoActionCount_Lock()

size_t SfxUndoManager::ImplGetRedoActionCount_Lock ( bool const  i_currentLevel = CurrentLevel) const
private

◆ ImplIsEmptyActions()

bool SfxUndoManager::ImplIsEmptyActions ( ) const
inlineprivate

Definition at line 1247 of file undo.cxx.

References m_xData.

Referenced by ImplCheckEmptyActions(), ImplLeaveListAction(), IsEmptyActions(), and SfxUndoManager().

◆ ImplIsInListAction_Lock()

bool SfxUndoManager::ImplIsInListAction_Lock ( ) const
private

◆ ImplIsUndoEnabled_Lock()

bool SfxUndoManager::ImplIsUndoEnabled_Lock ( ) const
private

Definition at line 374 of file undo.cxx.

References m_xData.

Referenced by EnterListAction(), ImplAddUndoAction_NoNotify(), ImplLeaveListAction(), IsUndoEnabled(), and Reset().

◆ ImplLeaveListAction()

size_t SfxUndoManager::ImplLeaveListAction ( const bool  i_merge,
::svl::undo::impl::UndoManagerGuard i_guard 
)
private

◆ ImplRedo()

bool SfxUndoManager::ImplRedo ( SfxUndoContext i_contextOrNull)
private

◆ ImplUndo()

bool SfxUndoManager::ImplUndo ( SfxUndoContext i_contextOrNull)
private

◆ IsDoing()

bool SfxUndoManager::IsDoing ( ) const

determines whether an Undo or Redo is currently running

Definition at line 652 of file undo.cxx.

References m_xData.

Referenced by ImplRedo(), and ImplUndo().

◆ IsEmptyActions()

bool SfxUndoManager::IsEmptyActions ( ) const

Definition at line 1240 of file undo.cxx.

References ImplIsEmptyActions(), and m_xData.

◆ IsInListAction()

bool SfxUndoManager::IsInListAction ( ) const

determines whether we're within a ListAction context, i.e. a LeaveListAction/LeaveAndMergeListAction call is pending

Definition at line 938 of file undo.cxx.

References ImplIsInListAction_Lock(), and m_xData.

Referenced by ClearRedo(), MarkTopUndoAction(), RemoveOldestUndoAction(), and Reset().

◆ IsUndoEnabled()

bool SfxUndoManager::IsUndoEnabled ( ) const

returns true if undo is currently enabled.

This returns false if undo was disabled using EnableUndo( false ) and also during the runtime of the Undo() and Redo() methods.

Definition at line 367 of file undo.cxx.

References ImplIsUndoEnabled_Lock(), and m_xData.

◆ LeaveAndMergeListAction()

size_t SfxUndoManager::LeaveAndMergeListAction ( )

Leaves the list action entered with EnterListAction, and forcefully merges the previous action on the stack into the newly created list action.

Say you have an Undo action A on the stack, then call EnterListAction, followed by one or more calls to AddUndoAction, followed by a call to LeaveAndMergeListAction. In opposite to LeaveListAction, your Undo stack will now still contain one undo action: the newly created list action, whose first child is the original A, whose other children are those you added via AddUndoAction, and whose comment is the same as the comment of A.

Effectively, this means that all actions added between EnterListAction and LeaveAndMergeListAction are hidden from the user.

Returns
the number of the sub actions in the list which has just been left. Note that in case no such actions exist, the list action does not contribute to the Undo stack, but is silently removed.

Definition at line 987 of file undo.cxx.

References ImplLeaveListAction(), and m_xData.

◆ LeaveListAction()

size_t SfxUndoManager::LeaveListAction ( )

Leaves the list action entered with EnterListAction.

Returns
the number of the sub actions in the list which has just been left. Note that in case no such actions exist, the list action does not contribute to the Undo stack, but is silently removed.

Definition at line 967 of file undo.cxx.

References SfxUndoListener::cleared(), ImplClearCurrentLevel_NoNotify(), ImplIsInListAction_Lock(), ImplLeaveListAction(), m_xData, and nCount.

◆ MarkTopUndoAction()

UndoStackMark SfxUndoManager::MarkTopUndoAction ( )

marks the current top-level element of the Undo stack, and returns a unique ID for it

Definition at line 1068 of file undo.cxx.

References IsInListAction(), m_xData, and SAL_WARN_IF.

◆ Redo()

bool SfxUndoManager::Redo ( )
virtual

Definition at line 784 of file undo.cxx.

References ImplRedo().

◆ RedoWithContext()

bool SfxUndoManager::RedoWithContext ( SfxUndoContext i_context)
protected

Definition at line 790 of file undo.cxx.

References ImplRedo().

◆ RemoveLastUndoAction()

void SfxUndoManager::RemoveLastUndoAction ( )

Clears the redo stack and removes the top undo action.

clears the redo stack and removes the top undo action

Definition at line 631 of file undo.cxx.

References ENSURE_OR_RETURN_VOID, ImplCheckEmptyActions(), m_xData, and nPos.

◆ RemoveMark()

void SfxUndoManager::RemoveMark ( UndoStackMark const  i_mark)

removes a mark given by its ID.

After the call, the mark ID is invalid.

Definition at line 1089 of file undo.cxx.

References MarkedUndoAction::aMarks, i, m_xData, MARK_INVALID, and SAL_WARN.

◆ RemoveOldestUndoAction()

void SfxUndoManager::RemoveOldestUndoAction ( )

removes the oldest Undo actions from the stack

Definition at line 1136 of file undo.cxx.

References ImplCheckEmptyActions(), IsInListAction(), and m_xData.

◆ RemoveUndoListener()

void SfxUndoManager::RemoveUndoListener ( SfxUndoListener i_listener)

Definition at line 905 of file undo.cxx.

References m_xData.

◆ Repeat()

bool SfxUndoManager::Repeat ( SfxRepeatTarget &  rTarget)

Definition at line 870 of file undo.cxx.

References SfxUndoAction::CanRepeat(), m_xData, SfxUndoAction::Repeat(), and rTarget.

◆ Reset()

void SfxUndoManager::Reset ( void  )

leaves any possible open list action (<member>IsInListAction</member>), and clears both the Undo and the Redo stack.

Effectively, calling this method is equivalent to while ( IsInListAction() ) LeaveListAction();, followed by Clear(). The only difference to this calling sequence is that Reset is an atomic operation, also resulting in only one notification.

Definition at line 479 of file undo.cxx.

References ImplClearCurrentLevel_NoNotify(), ImplEnableUndo_Lock(), ImplIsUndoEnabled_Lock(), ImplLeaveListAction(), IsInListAction(), m_xData, and SfxUndoListener::resetAll().

◆ SetMaxUndoActionCount()

void SfxUndoManager::SetMaxUndoActionCount ( size_t  nMaxUndoActionCount)

Definition at line 379 of file undo.cxx.

References ImplCheckEmptyActions(), m_xData, and nPos.

◆ Undo()

bool SfxUndoManager::Undo ( )
virtual

Definition at line 659 of file undo.cxx.

References ImplUndo().

◆ UndoWithContext()

bool SfxUndoManager::UndoWithContext ( SfxUndoContext i_context)
protected

Definition at line 665 of file undo.cxx.

References ImplUndo().

Friends And Related Function Documentation

◆ ::svl::undo::impl::LockGuard

friend class ::svl::undo::impl::LockGuard
friend

Definition at line 339 of file undo.hxx.

Member Data Documentation

◆ CurrentLevel

bool const SfxUndoManager::CurrentLevel = true
static

◆ m_xData

std::unique_ptr< SfxUndoManager_Data > SfxUndoManager::m_xData
private

◆ TopLevel

bool const SfxUndoManager::TopLevel = false
static

Definition at line 195 of file undo.hxx.

Referenced by ImplClearRedo().


The documentation for this class was generated from the following files: