20#include <UndoManager.hxx>
22#include <libxml/xmlwriter.h>
43#include <osl/diagnose.h>
51#define UNDO_ACTION_LIMIT (USHRT_MAX - 1000)
59 : m_rDrawModelAccess(rDrawModelAccess)
60 , m_rRedlineAccess(rRedlineAccess)
62 , m_xUndoNodes(
std::move(xUndoNodes))
66 , m_bLockUndoNoModifiedPosition(false)
67 , m_isAddWithIgnoreRepeat(false)
69 , m_pDocShell(nullptr)
75 SdrUndoManager::EnableUndo(
false);
105 size_t nRet = SdrUndoManager::GetUndoActionCount(bCurrentLevel);
109 if (!nRet || !SdrUndoManager::GetUndoActionCount())
112 const SfxUndoAction* pAction = SdrUndoManager::GetUndoAction();
129 size_t nRet = SdrUndoManager::GetRedoActionCount(bCurrentLevel);
133 if (!nRet || !SdrUndoManager::GetRedoActionCount())
136 const SfxUndoAction* pAction = SdrUndoManager::GetRedoAction();
173 return IsUndoEnabled();
241 if (!SdrUndoManager::GetUndoActionCount())
245 SfxUndoAction *
const pAction( SdrUndoManager::GetUndoAction() );
246 return dynamic_cast<SwUndo*
>(pAction);
256 return SdrUndoManager::ImplClearRedo_NoLock(TopLevel);
263 SdrUndoManager::ClearAllLevels();
272 if (!IsUndoEnabled())
286 comment = pRewriter->
Apply(comment);
293 nViewShellId = pView->GetViewShellId();
295 SdrUndoManager::EnterListAction(comment, comment,
static_cast<sal_uInt16
>(eUndoId), nViewShellId);
303 if (!IsUndoEnabled())
311 "EndUndo(): no Undo ID, but rewriter given?");
314 (0 == SdrUndoManager::GetUndoActionCount())
315 ?
nullptr : SdrUndoManager::GetUndoAction() );
317 int const nCount = LeaveListAction();
323 auto pListAction =
dynamic_cast<SfxListUndoAction*
>(SdrUndoManager::GetUndoAction());
327 OSL_ENSURE(
static_cast<SwUndoId>(pListAction->GetId()) == eUndoId,
328 "EndUndo(): given ID different from StartUndo()");
333 comment = pRewriter->
Apply(comment);
335 pListAction->SetComment(comment);
347 OUString
const comment(pLastUndo->
GetComment());
348 pListAction->SetComment(comment);
352 OSL_ENSURE(
false,
"EndUndo(): no comment?");
389 pViewAction = pAction;
401 auto pTopSwAction =
dynamic_cast<const SwUndo*
>(pTopAction);
407 auto pViewSwAction =
dynamic_cast<const SwUndo*
>(pViewAction);
413 const auto& rTopInsert = *
static_cast<const SwUndoInsert*
>(pTopSwAction);
414 const auto& rViewInsert = *
static_cast<const SwUndoInsert*
>(pViewSwAction);
418 auto pRedoAction =
dynamic_cast<const SwUndo*
>(GetRedoAction(
i));
424 const auto& rRedoInsert = *
static_cast<const SwUndoInsert*
>(pRedoAction);
425 if (!rViewInsert.IsIndependent(rRedoInsert) && rRedoInsert.GetViewShellId() != nViewId)
432 if (!rViewInsert.IsIndependent(rTopInsert))
443 OUString *
const o_pStr,
SwUndoId *
const o_pId,
const SwView* pView)
const
447 if (!SdrUndoManager::GetUndoActionCount())
452 SfxUndoAction *
const pAction( SdrUndoManager::GetUndoAction() );
477 *o_pId =
static_cast<SwUndoId>(pListAction->GetId());
478 else if (
auto pSwAction =
dynamic_cast<const SwUndo*
>(pAction))
479 *o_pId = pSwAction->GetId();
489 OSL_ENSURE(!SdrUndoManager::IsInListAction(),
490 "GetUndoComments() called while in list action?");
493 const size_t nUndoCount(SdrUndoManager::GetUndoActionCount(TopLevel));
494 for (
size_t n = 0;
n < nUndoCount; ++
n)
496 OUString
const comment(
497 SdrUndoManager::GetUndoActionComment(
n, TopLevel));
498 ret.push_back(comment);
506 const SwView* pView)
const
508 if (!SdrUndoManager::GetRedoActionCount())
513 SfxUndoAction *
const pAction( SdrUndoManager::GetRedoAction() );
514 if ( pAction ==
nullptr )
540 *o_pId =
static_cast<SwUndoId>(pListAction->GetId());
541 else if (
auto pSwAction =
dynamic_cast<const SwUndo*
>(pAction))
542 *o_pId = pSwAction->GetId();
552 OSL_ENSURE(!SdrUndoManager::IsInListAction(),
553 "GetRedoComments() called while in list action?");
556 const size_t nRedoCount(SdrUndoManager::GetRedoActionCount(TopLevel));
557 for (
size_t n = 0;
n < nRedoCount; ++
n)
559 OUString
const comment(
560 SdrUndoManager::GetRedoActionComment(
n, TopLevel));
561 ret.push_back(comment);
571 if( SwUndoId::REPEAT_START <= nRepeatId && SwUndoId::REPEAT_END > nRepeatId )
584 if (SdrUndoManager::GetRedoActionCount() ||
585 SdrUndoManager::GetRedoActionCount(TopLevel))
587 OSL_ENSURE(
false,
"RemoveLastUndoAction(): there are Redo actions?");
590 if (!SdrUndoManager::GetUndoActionCount())
592 OSL_ENSURE(
false,
"RemoveLastUndoAction(): no Undo actions");
596 SdrUndoManager::RemoveLastUndoAction();
597 return dynamic_cast<SwUndo *
>(pLastUndo);
604 SwUndo *
const pUndo(
dynamic_cast<SwUndo *
>(pAction.get()) );
616 SdrUndoManager::AddUndoAction(std::move(pAction), bTryMerge);
631 RemoveOldestUndoAction();
640 CursorGuard(
SwEditShell & rShell,
bool const bSave)
642 , m_bSaveCursor(bSave)
649 ~CursorGuard() COVERITY_NOEXCEPT_FALSE
658 bool const m_bSaveCursor;
670 OSL_ENSURE(pEditShell,
"sw::UndoManager needs a SwEditShell!");
673 throw uno::RuntimeException();
679 CursorGuard aCursorGuard(*pEditShell, bSaveCursors);
696 bRet = SdrUndoManager::UndoWithContext(context);
700 bRet = SdrUndoManager::RedoWithContext(context);
749 (void)xmlTextWriterStartElement(pWriter, BAD_CAST(
"swUndoManager"));
750 SdrUndoManager::dumpAsXml(pWriter);
752 (void)xmlTextWriterStartElement(pWriter, BAD_CAST(
"m_xUndoNodes"));
754 (void)xmlTextWriterEndElement(pWriter);
756 (void)xmlTextWriterEndElement(pWriter);
773 sal_uInt16
const nRepeatCount)
775 if (SdrUndoManager::IsInListAction())
777 OSL_ENSURE(
false,
"repeat in open list action???");
780 if (!SdrUndoManager::GetUndoActionCount(TopLevel))
785 assert(pRepeatAction);
791 OUString
const comment(pRepeatAction->
GetComment());
794 if (
auto const*
const pSwAction =
dynamic_cast<SwUndo*
>(pRepeatAction))
795 nId = pSwAction->GetId();
796 else if (
auto const*
const pListAction =
dynamic_cast<SfxListUndoAction*
>(pRepeatAction))
806 nViewShellId = pView->GetViewShellId();
808 EnterListAction(comment, rcomment,
static_cast<sal_uInt16
>(
nId), nViewShellId);
819 for (sal_uInt16 nRptCnt = nRepeatCount; nRptCnt > 0; --nRptCnt)
821 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
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
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)