20 #include <UndoManager.hxx>
22 #include <libxml/xmlwriter.h>
27 #include <drawdoc.hxx>
42 #include <osl/diagnose.h>
50 #define UNDO_ACTION_LIMIT (USHRT_MAX - 1000)
58 : m_rDrawModelAccess(rDrawModelAccess)
59 , m_rRedlineAccess(rRedlineAccess)
61 , m_xUndoNodes(xUndoNodes)
65 , m_bLockUndoNoModifiedPosition(
false)
66 , m_isAddWithIgnoreRepeat(
false)
68 , m_pDocShell(nullptr)
74 SdrUndoManager::EnableUndo(
false);
104 size_t nRet = SdrUndoManager::GetUndoActionCount(bCurrentLevel);
108 if (!nRet || !SdrUndoManager::GetUndoActionCount())
111 const SfxUndoAction* pAction = SdrUndoManager::GetUndoAction();
128 size_t nRet = SdrUndoManager::GetRedoActionCount(bCurrentLevel);
132 if (!nRet || !SdrUndoManager::GetRedoActionCount())
135 const SfxUndoAction* pAction = SdrUndoManager::GetRedoAction();
172 return IsUndoEnabled();
240 if (!SdrUndoManager::GetUndoActionCount())
244 SfxUndoAction *
const pAction( SdrUndoManager::GetUndoAction() );
245 return dynamic_cast<SwUndo*
>(pAction);
255 return SdrUndoManager::ImplClearRedo_NoLock(TopLevel);
262 SdrUndoManager::ClearAllLevels();
271 if (!IsUndoEnabled())
285 comment = pRewriter->
Apply(comment);
292 nViewShellId = pView->GetViewShellId();
294 SdrUndoManager::EnterListAction(comment, comment, static_cast<sal_uInt16>(eUndoId), nViewShellId);
302 if (!IsUndoEnabled())
310 "EndUndo(): no Undo ID, but rewriter given?");
313 (0 == SdrUndoManager::GetUndoActionCount())
314 ?
nullptr : SdrUndoManager::GetUndoAction() );
316 int const nCount = LeaveListAction();
322 auto pListAction =
dynamic_cast<SfxListUndoAction*
>(SdrUndoManager::GetUndoAction());
326 OSL_ENSURE(static_cast<SwUndoId>(pListAction->GetId()) == eUndoId,
327 "EndUndo(): given ID different from StartUndo()");
332 comment = pRewriter->
Apply(comment);
334 pListAction->SetComment(comment);
336 else if (
SwUndoId::START != static_cast<SwUndoId>(pListAction->GetId()))
346 OUString
const comment(pLastUndo->
GetComment());
347 pListAction->SetComment(comment);
351 OSL_ENSURE(
false,
"EndUndo(): no comment?");
388 pViewAction = pAction;
400 auto pTopSwAction =
dynamic_cast<const SwUndo*
>(pTopAction);
406 auto pViewSwAction =
dynamic_cast<const SwUndo*
>(pViewAction);
412 const auto& rTopInsert = *
static_cast<const SwUndoInsert*
>(pTopSwAction);
413 const auto& rViewInsert = *
static_cast<const SwUndoInsert*
>(pViewSwAction);
417 auto pRedoAction =
dynamic_cast<const SwUndo*
>(GetRedoAction(
i));
423 const auto& rRedoInsert = *
static_cast<const SwUndoInsert*
>(pRedoAction);
424 if (!rViewInsert.IsIndependent(rRedoInsert) && rRedoInsert.GetViewShellId() != nViewId)
431 if (!rViewInsert.IsIndependent(rTopInsert))
442 OUString *
const o_pStr,
SwUndoId *
const o_pId,
const SwView* pView)
const
446 if (!SdrUndoManager::GetUndoActionCount())
451 SfxUndoAction *
const pAction( SdrUndoManager::GetUndoAction() );
475 if (
auto pListAction = dynamic_cast<const SfxListUndoAction*>(pAction))
476 *o_pId =
static_cast<SwUndoId>(pListAction->GetId());
477 else if (
auto pSwAction = dynamic_cast<const SwUndo*>(pAction))
478 *o_pId = pSwAction->GetId();
488 OSL_ENSURE(!SdrUndoManager::IsInListAction(),
489 "GetUndoComments() called while in list action?");
492 const size_t nUndoCount(SdrUndoManager::GetUndoActionCount(TopLevel));
493 for (
size_t n = 0;
n < nUndoCount; ++
n)
495 OUString
const comment(
496 SdrUndoManager::GetUndoActionComment(
n, TopLevel));
497 ret.push_back(comment);
505 const SwView* pView)
const
507 if (!SdrUndoManager::GetRedoActionCount())
512 SfxUndoAction *
const pAction( SdrUndoManager::GetRedoAction() );
513 if ( pAction ==
nullptr )
538 if (
auto pListAction = dynamic_cast<const SfxListUndoAction*>(pAction))
539 *o_pId =
static_cast<SwUndoId>(pListAction->GetId());
540 else if (
auto pSwAction = dynamic_cast<const SwUndo*>(pAction))
541 *o_pId = pSwAction->GetId();
551 OSL_ENSURE(!SdrUndoManager::IsInListAction(),
552 "GetRedoComments() called while in list action?");
555 const size_t nRedoCount(SdrUndoManager::GetRedoActionCount(TopLevel));
556 for (
size_t n = 0;
n < nRedoCount; ++
n)
558 OUString
const comment(
559 SdrUndoManager::GetRedoActionComment(
n, TopLevel));
560 ret.push_back(comment);
570 if( SwUndoId::REPEAT_START <= nRepeatId && SwUndoId::REPEAT_END > nRepeatId )
583 if (SdrUndoManager::GetRedoActionCount() ||
584 SdrUndoManager::GetRedoActionCount(TopLevel))
586 OSL_ENSURE(
false,
"RemoveLastUndoAction(): there are Redo actions?");
589 if (!SdrUndoManager::GetUndoActionCount())
591 OSL_ENSURE(
false,
"RemoveLastUndoAction(): no Undo actions");
595 SdrUndoManager::RemoveLastUndoAction();
596 return dynamic_cast<SwUndo *
>(pLastUndo);
603 SwUndo *
const pUndo( dynamic_cast<SwUndo *>(pAction.get()) );
615 SdrUndoManager::AddUndoAction(std::move(pAction), bTryMerge);
630 RemoveOldestUndoAction();
639 CursorGuard(
SwEditShell & rShell,
bool const bSave)
641 , m_bSaveCursor(bSave)
648 ~CursorGuard() COVERITY_NOEXCEPT_FALSE
657 bool const m_bSaveCursor;
670 OSL_ENSURE(pEditShell,
"sw::UndoManager needs a SwEditShell!");
673 throw uno::RuntimeException();
678 bool const bSaveCursors(pEditShell->CursorsLocked());
679 CursorGuard aCursorGuard(*pEditShell, bSaveCursors);
683 pEditShell->KillPams();
684 pEditShell->SetMark();
685 pEditShell->ClearMark();
696 bRet = SdrUndoManager::UndoWithContext(context);
700 bRet = SdrUndoManager::RedoWithContext(context);
716 pEditShell->HandleUndoRedoContext(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))
797 nId =
static_cast<SwUndoId>(pListAction->GetId());
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 bool DoesGroupUndo() const override
Is Group Undo enabled?
bool impl_DoUndoRedo(UndoOrRedoType undoOrRedo, size_t nUndoOffset)
SwNodes const & GetUndoNodes() const
std::shared_ptr< SwNodes > m_xUndoNodes
Undo nodes array: content not currently in document.
bool m_isAddWithIgnoreRepeat
set the IgnoreRepeat flag on every added action
void dumpAsXml(xmlTextWriterPtr pWriter) const
virtual void SetModified()=0
Must be called manually at changes of format.
virtual bool Undo() override
virtual bool DoesDrawUndo() const override
Is Undo for Drawing objects enabled? for Draw-Undo: writer wants to handle actions on Flys on its own...
void SetDocShell(SwDocShell *pDocShell)
void SetRedlineFlags(RedlineFlags eMode)
virtual void SetUndoNoResetModified() override
Disable (re)setting the document modified flag on Undo/Redo.
size_t GetRedoActionCount(const bool bCurrentLevel=true) const override
Dialog to specify the properties of date form field.
void Invalidate(sal_uInt16 nId)
virtual bool GetLastUndoInfo(OUString *const o_pStr, SwUndoId *const o_pId, const SwView *pView=nullptr) const override
Get Id and comment of last Undo action.
virtual bool Redo() override
void SetView(SwView *pView) override
Return undo/redo info for this view.
IDocumentState & m_rState
virtual void DelAllUndoObj() override
Delete all Undo actions.
void EnableUndo(bool bEnable)
virtual bool IsUndoNoResetModified() const override
Is setting the document modified flag on Undo/Redo disabled?
virtual SwUndoComments_t GetRedoComments() const override
Get comments of Redo actions.
virtual bool Undo() override
std::vector< OUString > SwUndoComments_t
RedlineFlags GetRedlineFlags() const
bool isTextEditActive() const
void DoRepair(bool bRepair) override
Enable repair mode.
PaM is Point and Mark: a selection of the document model.
IDocumentRedlineAccess & m_rRedlineAccess
Typing one or more characters to a single paragraph.
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...
OUString Apply(const OUString &rStr) const
SwEditShell const * GetEditShell() const
bool m_bRepair
If true, then repair mode is enabled.
SfxBindings & GetBindings()
virtual void LockUndoNoModifiedPosition() override
Prevent updates to the "unmodified" state position via SetUndoNoResetModified().
static SfxViewFrame * GetNext(const SfxViewFrame &rPrev, const SfxObjectShell *pDoc=nullptr, bool bOnlyVisible=true)
virtual const SwDrawModel * GetDrawModel() const =0
Draw Model and id accessors.
virtual size_t GetUndoActionCount(const bool bCurrentLevel=true) const override
Get the number of Undo actions.
UndoManager(std::shared_ptr< SwNodes > const &pUndoNodes, IDocumentDrawModelAccess &rDrawModelAccess, IDocumentRedlineAccess &rRedlineAccess, IDocumentState &rState)
virtual void SetUndoNoModifiedPosition() override
Set the position at which the document is in the "unmodified" state to the current position in the Un...
virtual SwUndoId GetRepeatInfo(OUString *const o_pStr) const override
Get Id and comment of last Undo action, if it is Repeat capable.
ring_container GetRingContainer()
UndoStackMark m_UndoSaveMark
position in Undo-Array at which Doc was saved (and is not modified)
constexpr T & temporary(T &&x)
virtual bool IsUndoNodes(SwNodes const &rNodes) const override
virtual void DoDrawUndo(bool const bDoUndo) override
Enable/Disable Undo for Drawing objects.
virtual OUString GetRepeatComment(SfxRepeatTarget &) const
virtual SwUndoId EndUndo(SwUndoId const eUndoId, SwRewriter const *const pRewriter) override
Closes undo block.
virtual void UnLockUndoNoModifiedPosition() override
Allow updates to the "unmodified" state position via SetUndoNoResetModified().
virtual ViewShellId GetViewShellId() const
bool DoesRepair() const override
Is repair mode active?
virtual OUString GetComment() const
#define UNDO_ACTION_LIMIT
bool m_bLockUndoNoModifiedPosition
virtual void Repeat(SfxRepeatTarget &)
Get information about the current document state.
IDocumentDrawModelAccess & m_rDrawModelAccess
virtual SwUndoComments_t GetUndoComments() const override
Get comments of Undo actions.
virtual bool Redo() override
virtual void DoUndo(bool const bDoUndo) override
IDocumentUndoRedo.
virtual void AddUndoAction(std::unique_ptr< SfxUndoAction > pAction, bool bTryMerg=false) override
virtual SwUndoId StartUndo(SwUndoId const eUndoId, SwRewriter const *const pRewriter) override
Opens undo block.
virtual void EmptyActionsChanged() override
OUString GetUndoComment(SwUndoId eId)
static SfxViewFrame * GetFirst(const SfxObjectShell *pDoc=nullptr, bool bOnlyVisible=true)
virtual bool CanRepeat(SfxRepeatTarget &) const
virtual void DoGroupUndo(bool const bDoUndo) override
Enable/Disable Group Undo.
virtual RedlineFlags GetRedlineFlags() const =0
Query the currently set redline mode.
struct _xmlTextWriter * xmlTextWriterPtr
const SwView * GetView() const
SwUndo * RemoveLastUndo()
bool UndoWithOffset(size_t nUndoOffset) override
Zero offset means undoing the top undo action.
void SetUndoOffset(size_t nUndoOffset)
virtual void ClearRedo() override
Delete all Redo actions.
virtual bool Repeat(::sw::RepeatContext &rContext, sal_uInt16 const nRepeatCnt) override
N.B.
virtual bool DoesUndo() const override
Is Undo enabled?
virtual bool GetFirstRedoInfo(OUString *const o_pStr, SwUndoId *const o_pId, const SwView *pView=nullptr) const override
Get Id and comment of first Redo action.
ViewShellId GetViewShellId() const override
virtual void AppendUndo(std::unique_ptr< SwUndo > pUndo) override
Add new Undo action.
bool m_bDetectedRangeSegmentation false
virtual void ResetModified()=0