20#include <UndoManager.hxx>
22#include <libxml/xmlwriter.h>
44#include <osl/diagnose.h>
52#define UNDO_ACTION_LIMIT (USHRT_MAX - 1000)
60 : m_rDrawModelAccess(rDrawModelAccess)
61 , m_rRedlineAccess(rRedlineAccess)
63 , m_xUndoNodes(
std::move(xUndoNodes))
67 , m_bLockUndoNoModifiedPosition(false)
68 , m_isAddWithIgnoreRepeat(false)
70 , m_pDocShell(nullptr)
76 SdrUndoManager::EnableUndo(
false);
106 size_t nRet = SdrUndoManager::GetUndoActionCount(bCurrentLevel);
110 if (!nRet || !SdrUndoManager::GetUndoActionCount())
113 const SfxUndoAction* pAction = SdrUndoManager::GetUndoAction();
130 size_t nRet = SdrUndoManager::GetRedoActionCount(bCurrentLevel);
134 if (!nRet || !SdrUndoManager::GetRedoActionCount())
137 const SfxUndoAction* pAction = SdrUndoManager::GetRedoAction();
174 return IsUndoEnabled();
242 if (!SdrUndoManager::GetUndoActionCount())
246 SfxUndoAction *
const pAction( SdrUndoManager::GetUndoAction() );
247 return dynamic_cast<SwUndo*
>(pAction);
257 return SdrUndoManager::ImplClearRedo_NoLock(TopLevel);
264 SdrUndoManager::ClearAllLevels();
273 if (!IsUndoEnabled())
287 comment = pRewriter->
Apply(comment);
294 nViewShellId = pView->GetViewShellId();
296 SdrUndoManager::EnterListAction(comment, comment,
static_cast<sal_uInt16
>(eUndoId), nViewShellId);
304 if (!IsUndoEnabled())
312 "EndUndo(): no Undo ID, but rewriter given?");
315 (0 == SdrUndoManager::GetUndoActionCount())
316 ?
nullptr : SdrUndoManager::GetUndoAction() );
318 int const nCount = LeaveListAction();
324 auto pListAction =
dynamic_cast<SfxListUndoAction*
>(SdrUndoManager::GetUndoAction());
328 OSL_ENSURE(
static_cast<SwUndoId>(pListAction->GetId()) == eUndoId,
329 "EndUndo(): given ID different from StartUndo()");
334 comment = pRewriter->
Apply(comment);
336 pListAction->SetComment(comment);
348 OUString
const comment(pLastUndo->
GetComment());
349 pListAction->SetComment(comment);
353 OSL_ENSURE(
false,
"EndUndo(): no comment?");
390 pViewAction = pAction;
402 auto pTopSwAction =
dynamic_cast<const SwUndo*
>(pTopAction);
408 auto pViewSwAction =
dynamic_cast<const SwUndo*
>(pViewAction);
414 const auto& rTopInsert = *
static_cast<const SwUndoInsert*
>(pTopSwAction);
415 const auto& rViewInsert = *
static_cast<const SwUndoInsert*
>(pViewSwAction);
419 auto pRedoAction =
dynamic_cast<const SwUndo*
>(GetRedoAction(
i));
425 const auto& rRedoInsert = *
static_cast<const SwUndoInsert*
>(pRedoAction);
426 if (!rViewInsert.IsIndependent(rRedoInsert) && rRedoInsert.GetViewShellId() != nViewId)
433 if (!rViewInsert.IsIndependent(rTopInsert))
444 OUString *
const o_pStr,
SwUndoId *
const o_pId,
const SwView* pView)
const
448 if (!SdrUndoManager::GetUndoActionCount())
453 SfxUndoAction *
const pAction( SdrUndoManager::GetUndoAction() );
478 *o_pId =
static_cast<SwUndoId>(pListAction->GetId());
479 else if (
auto pSwAction =
dynamic_cast<const SwUndo*
>(pAction))
480 *o_pId = pSwAction->GetId();
490 OSL_ENSURE(!SdrUndoManager::IsInListAction(),
491 "GetUndoComments() called while in list action?");
494 const size_t nUndoCount(SdrUndoManager::GetUndoActionCount(TopLevel));
495 for (
size_t n = 0;
n < nUndoCount; ++
n)
497 OUString
const comment(
498 SdrUndoManager::GetUndoActionComment(
n, TopLevel));
499 ret.push_back(comment);
507 const SwView* pView)
const
509 if (!SdrUndoManager::GetRedoActionCount())
514 SfxUndoAction *
const pAction( SdrUndoManager::GetRedoAction() );
515 if ( pAction ==
nullptr )
541 *o_pId =
static_cast<SwUndoId>(pListAction->GetId());
542 else if (
auto pSwAction =
dynamic_cast<const SwUndo*
>(pAction))
543 *o_pId = pSwAction->GetId();
553 OSL_ENSURE(!SdrUndoManager::IsInListAction(),
554 "GetRedoComments() called while in list action?");
557 const size_t nRedoCount(SdrUndoManager::GetRedoActionCount(TopLevel));
558 for (
size_t n = 0;
n < nRedoCount; ++
n)
560 OUString
const comment(
561 SdrUndoManager::GetRedoActionComment(
n, TopLevel));
562 ret.push_back(comment);
572 if( SwUndoId::REPEAT_START <= nRepeatId && SwUndoId::REPEAT_END > nRepeatId )
585 if (SdrUndoManager::GetRedoActionCount() ||
586 SdrUndoManager::GetRedoActionCount(TopLevel))
588 OSL_ENSURE(
false,
"RemoveLastUndoAction(): there are Redo actions?");
591 if (!SdrUndoManager::GetUndoActionCount())
593 OSL_ENSURE(
false,
"RemoveLastUndoAction(): no Undo actions");
597 SdrUndoManager::RemoveLastUndoAction();
598 return dynamic_cast<SwUndo *
>(pLastUndo);
605 SwUndo *
const pUndo(
dynamic_cast<SwUndo *
>(pAction.get()) );
617 SdrUndoManager::AddUndoAction(std::move(pAction), bTryMerge);
632 RemoveOldestUndoAction();
641 CursorGuard(
SwEditShell & rShell,
bool const bSave)
643 , m_bSaveCursor(bSave)
650 ~CursorGuard() COVERITY_NOEXCEPT_FALSE
659 bool const m_bSaveCursor;
674 OSL_ENSURE(pEditShell,
"sw::UndoManager needs a SwEditShell!");
677 throw uno::RuntimeException();
683 CursorGuard aCursorGuard(*pEditShell, bSaveCursors);
700 bRet = SdrUndoManager::UndoWithContext(context);
704 bRet = SdrUndoManager::RedoWithContext(context);
753 (void)xmlTextWriterStartElement(pWriter, BAD_CAST(
"swUndoManager"));
754 SdrUndoManager::dumpAsXml(pWriter);
756 (void)xmlTextWriterStartElement(pWriter, BAD_CAST(
"m_xUndoNodes"));
758 (void)xmlTextWriterEndElement(pWriter);
760 (void)xmlTextWriterEndElement(pWriter);
777 sal_uInt16
const nRepeatCount)
779 if (SdrUndoManager::IsInListAction())
781 OSL_ENSURE(
false,
"repeat in open list action???");
784 if (!SdrUndoManager::GetUndoActionCount(TopLevel))
789 assert(pRepeatAction);
795 OUString
const comment(pRepeatAction->
GetComment());
798 if (
auto const*
const pSwAction =
dynamic_cast<SwUndo*
>(pRepeatAction))
799 nId = pSwAction->GetId();
800 else if (
auto const*
const pListAction =
dynamic_cast<SfxListUndoAction*
>(pRepeatAction))
810 nViewShellId = pView->GetViewShellId();
812 EnterListAction(comment, rcomment,
static_cast<sal_uInt16
>(
nId), nViewShellId);
823 for (sal_uInt16 nRptCnt = nRepeatCount; nRptCnt > 0; --nRptCnt)
825 pRepeatAction->
Repeat(rContext);
virtual const SwDrawModel * GetDrawModel() const =0
Draw Model and id accessors.
virtual RedlineFlags GetRedlineFlags() const =0
Query the currently set redline mode.
Get information about the current document state.
virtual void ResetModified()=0
virtual void SetModified()=0
Must be called manually at changes of format.
void EnableUndo(bool bEnable)
virtual bool Redo() override
bool isTextEditActive() const
virtual bool Undo() override
void Invalidate(sal_uInt16 nId)
virtual void Repeat(SfxRepeatTarget &)
virtual OUString GetRepeatComment(SfxRepeatTarget &) const
virtual ViewShellId GetViewShellId() const
virtual OUString GetComment() const
virtual bool CanRepeat(SfxRepeatTarget &) const
SfxBindings & GetBindings()
static SAL_WARN_UNUSED_RESULT SfxViewFrame * GetNext(const SfxViewFrame &rPrev, const SfxObjectShell *pDoc=nullptr, bool bOnlyVisible=true)
static SAL_WARN_UNUSED_RESULT SfxViewFrame * GetFirst(const SfxObjectShell *pDoc=nullptr, bool bOnlyVisible=true)
ViewShellId GetViewShellId() const override
static SAL_WARN_UNUSED_RESULT SfxViewShell * Current()
const SwView * GetView() const
SwEditShell const * GetEditShell() const
void HandleUndoRedoContext(::sw::UndoRedoContext &rContext)
set selections to those contained in the UndoRedoContext should only be called by sw::UndoManager!
bool CursorsLocked() const
is it forbidden to modify cursors via API calls?
PaM is Point and Mark: a selection of the document model.
OUString Apply(const OUString &rStr) const
Typing one or more characters to a single paragraph.
void SetRedlineFlags(RedlineFlags eMode)
RedlineFlags GetRedlineFlags() const
SwWrtShell * GetWrtShellPtr() const
ring_container GetRingContainer()
UndoStackMark m_UndoSaveMark
position in Undo-Array at which Doc was saved (and is not modified)
virtual void DoGroupUndo(bool const bDoUndo) override
void DoRepair(bool bRepair) override
virtual void LockUndoNoModifiedPosition() override
bool DoesRepair() const override
bool IsViewUndoActionIndependent(const SwView *pView, sal_uInt16 &rOffset) const
Checks if the topmost undo action owned by pView is independent from the topmost action undo action.
virtual bool GetFirstRedoInfo(OUString *const o_pStr, SwUndoId *const o_pId, const SwView *pView=nullptr) const override
virtual void ClearRedo() override
bool m_bLockUndoNoModifiedPosition
UndoManager(std::shared_ptr< SwNodes > pUndoNodes, IDocumentDrawModelAccess &rDrawModelAccess, IDocumentRedlineAccess &rRedlineAccess, IDocumentState &rState)
virtual void SetUndoNoModifiedPosition() override
virtual bool Repeat(::sw::RepeatContext &rContext, sal_uInt16 const nRepeatCnt) override
N.B.
virtual bool DoesGroupUndo() const override
virtual void DoDrawUndo(bool const bDoUndo) override
std::shared_ptr< SwNodes > m_xUndoNodes
Undo nodes array: content not currently in document, but required for undo/redo.
virtual bool Undo() override
virtual bool IsUndoNodes(SwNodes const &rNodes) const override
SwUndo * RemoveLastUndo()
virtual bool GetLastUndoInfo(OUString *const o_pStr, SwUndoId *const o_pId, const SwView *pView=nullptr) const override
virtual bool Redo() override
bool m_bRepair
If true, then repair mode is enabled.
virtual bool DoesUndo() const override
virtual SwUndoId StartUndo(SwUndoId const eUndoId, SwRewriter const *const pRewriter) override
virtual SwUndoComments_t GetRedoComments() const override
IDocumentRedlineAccess & m_rRedlineAccess
bool m_isAddWithIgnoreRepeat
set the IgnoreRepeat flag on every added action
virtual void AddUndoAction(std::unique_ptr< SfxUndoAction > pAction, bool bTryMerg=false) override
virtual size_t GetUndoActionCount(const bool bCurrentLevel=true) const override
void SetDocShell(SwDocShell *pDocShell)
void SetView(SwView *pView) override
virtual void DoUndo(bool const bDoUndo) override
IDocumentUndoRedo.
virtual SwUndoId EndUndo(SwUndoId const eUndoId, SwRewriter const *const pRewriter) override
virtual SwUndoId GetRepeatInfo(OUString *const o_pStr) const override
bool impl_DoUndoRedo(UndoOrRedoType undoOrRedo, size_t nUndoOffset)
virtual void DelAllUndoObj() override
virtual bool IsUndoNoResetModified() const override
IDocumentDrawModelAccess & m_rDrawModelAccess
virtual SwUndoComments_t GetUndoComments() const override
virtual bool DoesDrawUndo() const override
virtual void SetUndoNoResetModified() override
virtual void UnLockUndoNoModifiedPosition() override
bool UndoWithOffset(size_t nUndoOffset) override
void dumpAsXml(xmlTextWriterPtr pWriter) const
size_t GetRedoActionCount(const bool bCurrentLevel=true) const override
virtual void EmptyActionsChanged() override
virtual void AppendUndo(std::unique_ptr< SwUndo > pUndo) override
SwNodes const & GetUndoNodes() const
IDocumentState & m_rState
void SetUndoOffset(size_t nUndoOffset)
struct _xmlTextWriter * xmlTextWriterPtr
#define UNDO_ACTION_LIMIT
constexpr T & temporary(T &&x)
Dialog to specify the properties of date form field.
std::vector< OUString > SwUndoComments_t
OUString GetUndoComment(SwUndoId eId)