LibreOffice Module sw (master)  1
docundo.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include <UndoManager.hxx>
21 
22 #include <libxml/xmlwriter.h>
23 
24 #include <doc.hxx>
25 #include <docsh.hxx>
26 #include <view.hxx>
27 #include <drawdoc.hxx>
28 #include <ndarr.hxx>
29 #include <pam.hxx>
30 #include <swundo.hxx>
31 #include <UndoCore.hxx>
32 #include <editsh.hxx>
33 #include <unobaseclass.hxx>
36 #include <IDocumentState.hxx>
37 #include <comphelper/lok.hxx>
38 #include <assert.h>
39 
40 #include <sfx2/viewfrm.hxx>
41 #include <sfx2/bindings.hxx>
42 #include <osl/diagnose.h>
43 #include <o3tl/temporary.hxx>
44 
45 #include <UndoInsert.hxx>
46 
47 using namespace ::com::sun::star;
48 
49 // the undo array should never grow beyond this limit:
50 #define UNDO_ACTION_LIMIT (USHRT_MAX - 1000)
51 
52 namespace sw {
53 
54 UndoManager::UndoManager(std::shared_ptr<SwNodes> const & xUndoNodes,
55  IDocumentDrawModelAccess & rDrawModelAccess,
56  IDocumentRedlineAccess & rRedlineAccess,
57  IDocumentState & rState)
58  : m_rDrawModelAccess(rDrawModelAccess)
59  , m_rRedlineAccess(rRedlineAccess)
60  , m_rState(rState)
61  , m_xUndoNodes(xUndoNodes)
62  , m_bGroupUndo(true)
63  , m_bDrawUndo(true)
64  , m_bRepair(false)
65  , m_bLockUndoNoModifiedPosition(false)
66  , m_isAddWithIgnoreRepeat(false)
67  , m_UndoSaveMark(MARK_INVALID)
68  , m_pDocShell(nullptr)
69  , m_pView(nullptr)
70 {
71  assert(bool(m_xUndoNodes));
72  // writer expects it to be disabled initially
73  // Undo is enabled by SwEditShell constructor
74  SdrUndoManager::EnableUndo(false);
75 }
76 
78 {
79  return *m_xUndoNodes;
80 }
81 
83 {
84  return *m_xUndoNodes;
85 }
86 
87 bool UndoManager::IsUndoNodes(SwNodes const& rNodes) const
88 {
89  return & rNodes == m_xUndoNodes.get();
90 }
91 
93 {
94  m_pDocShell = pDocShell;
95 }
96 
98 {
99  m_pView = pView;
100 }
101 
102 size_t UndoManager::GetUndoActionCount(const bool bCurrentLevel) const
103 {
104  size_t nRet = SdrUndoManager::GetUndoActionCount(bCurrentLevel);
106  return nRet;
107 
108  if (!nRet || !SdrUndoManager::GetUndoActionCount())
109  return nRet;
110 
111  const SfxUndoAction* pAction = SdrUndoManager::GetUndoAction();
112  if (!pAction)
113  return nRet;
114 
115  if (!m_bRepair)
116  {
117  // If another view created the last undo action, prevent undoing it from this view.
118  ViewShellId nViewShellId = m_pView->GetViewShellId();
119  if (pAction->GetViewShellId() != nViewShellId)
120  nRet = 0;
121  }
122 
123  return nRet;
124 }
125 
126 size_t UndoManager::GetRedoActionCount(const bool bCurrentLevel) const
127 {
128  size_t nRet = SdrUndoManager::GetRedoActionCount(bCurrentLevel);
130  return nRet;
131 
132  if (!nRet || !SdrUndoManager::GetRedoActionCount())
133  return nRet;
134 
135  const SfxUndoAction* pAction = SdrUndoManager::GetRedoAction();
136  if (!pAction)
137  return nRet;
138 
139  if (!m_bRepair)
140  {
141  // If another view created the first redo action, prevent redoing it from this view.
142  ViewShellId nViewShellId = m_pView->GetViewShellId();
143  if (pAction->GetViewShellId() != nViewShellId)
144  nRet = 0;
145  }
146 
147  return nRet;
148 }
149 
150 void UndoManager::DoUndo(bool const bDoUndo)
151 {
152  if(!isTextEditActive())
153  {
154  EnableUndo(bDoUndo);
155 
156  SwDrawModel*const pSdrModel = m_rDrawModelAccess.GetDrawModel();
157  if( pSdrModel )
158  {
159  pSdrModel->EnableUndo(bDoUndo);
160  }
161  }
162 }
163 
165 {
166  if(isTextEditActive())
167  {
168  return false;
169  }
170  else
171  {
172  return IsUndoEnabled();
173  }
174 }
175 
176 void UndoManager::DoGroupUndo(bool const bDoUndo)
177 {
178  m_bGroupUndo = bDoUndo;
179 }
180 
182 {
183  return m_bGroupUndo;
184 }
185 
186 void UndoManager::DoDrawUndo(bool const bDoUndo)
187 {
188  m_bDrawUndo = bDoUndo;
189 }
190 
192 {
193  return m_bDrawUndo;
194 }
195 
196 void UndoManager::DoRepair(bool bRepair)
197 {
198  m_bRepair = bRepair;
199 }
200 
202 {
203  return m_bRepair;
204 }
205 
207 {
208  return MARK_INVALID == m_UndoSaveMark;
209 }
210 
212 {
214  {
215  RemoveMark(m_UndoSaveMark);
217  }
218 }
219 
221 {
223  {
224  m_UndoSaveMark = MarkTopUndoAction();
225  }
226 }
227 
229 {
231 }
232 
234 {
236 }
237 
239 {
240  if (!SdrUndoManager::GetUndoActionCount())
241  {
242  return nullptr;
243  }
244  SfxUndoAction *const pAction( SdrUndoManager::GetUndoAction() );
245  return dynamic_cast<SwUndo*>(pAction);
246 }
247 
248 void UndoManager::AppendUndo(std::unique_ptr<SwUndo> pUndo)
249 {
250  AddUndoAction(std::move(pUndo));
251 }
252 
254 {
255  return SdrUndoManager::ImplClearRedo_NoLock(TopLevel);
256 }
257 
259 {
260  ::sw::UndoGuard const undoGuard(*this);
261 
262  SdrUndoManager::ClearAllLevels();
263 
265 }
266 
267 SwUndoId
269  SwRewriter const*const pRewriter)
270 {
271  if (!IsUndoEnabled())
272  {
273  return SwUndoId::EMPTY;
274  }
275 
276  SwUndoId const eUndoId( (i_eUndoId == SwUndoId::EMPTY) ? SwUndoId::START : i_eUndoId );
277 
278  assert(SwUndoId::END != eUndoId);
279  OUString comment( (SwUndoId::START == eUndoId)
280  ? OUString("??")
281  : GetUndoComment(eUndoId) );
282  if (pRewriter)
283  {
284  assert(SwUndoId::START != eUndoId);
285  comment = pRewriter->Apply(comment);
286  }
287 
288  ViewShellId nViewShellId(-1);
289  if (m_pDocShell)
290  {
291  if (const SwView* pView = m_pDocShell->GetView())
292  nViewShellId = pView->GetViewShellId();
293  }
294  SdrUndoManager::EnterListAction(comment, comment, static_cast<sal_uInt16>(eUndoId), nViewShellId);
295 
296  return eUndoId;
297 }
298 
299 SwUndoId
300 UndoManager::EndUndo(SwUndoId eUndoId, SwRewriter const*const pRewriter)
301 {
302  if (!IsUndoEnabled())
303  {
304  return SwUndoId::EMPTY;
305  }
306 
307  if ((eUndoId == SwUndoId::EMPTY) || (SwUndoId::START == eUndoId))
308  eUndoId = SwUndoId::END;
309  OSL_ENSURE(!((SwUndoId::END == eUndoId) && pRewriter),
310  "EndUndo(): no Undo ID, but rewriter given?");
311 
312  SfxUndoAction *const pLastUndo(
313  (0 == SdrUndoManager::GetUndoActionCount())
314  ? nullptr : SdrUndoManager::GetUndoAction() );
315 
316  int const nCount = LeaveListAction();
317 
318  if (nCount) // otherwise: empty list action not inserted!
319  {
320  assert(pLastUndo);
321  assert(SwUndoId::START != eUndoId);
322  auto pListAction = dynamic_cast<SfxListUndoAction*>(SdrUndoManager::GetUndoAction());
323  assert(pListAction);
324  if (SwUndoId::END != eUndoId)
325  {
326  OSL_ENSURE(static_cast<SwUndoId>(pListAction->GetId()) == eUndoId,
327  "EndUndo(): given ID different from StartUndo()");
328  // comment set by caller of EndUndo
329  OUString comment = GetUndoComment(eUndoId);
330  if (pRewriter)
331  {
332  comment = pRewriter->Apply(comment);
333  }
334  pListAction->SetComment(comment);
335  }
336  else if (SwUndoId::START != static_cast<SwUndoId>(pListAction->GetId()))
337  {
338  // comment set by caller of StartUndo: nothing to do here
339  }
340  else if (pLastUndo)
341  {
342  // comment was not set at StartUndo or EndUndo:
343  // take comment of last contained action
344  // (note that this works recursively, i.e. the last contained
345  // action may be a list action created by StartUndo/EndUndo)
346  OUString const comment(pLastUndo->GetComment());
347  pListAction->SetComment(comment);
348  }
349  else
350  {
351  OSL_ENSURE(false, "EndUndo(): no comment?");
352  }
353  }
354 
355  return eUndoId;
356 }
357 
362 bool UndoManager::IsViewUndoActionIndependent(const SwView* pView, sal_uInt16& rOffset) const
363 {
364  if (GetUndoActionCount() <= 1)
365  {
366  // Single or less undo, owned by another view.
367  return false;
368  }
369 
370  if (!pView)
371  {
372  return false;
373  }
374 
375  // Last undo action that doesn't belong to the view.
376  const SfxUndoAction* pTopAction = GetUndoAction();
377 
378  ViewShellId nViewId = pView->GetViewShellId();
379 
380  // Earlier undo action that belongs to the view, but is not the top one.
381  const SfxUndoAction* pViewAction = nullptr;
382  size_t nOffset = 0;
383  for (size_t i = 0; i < GetUndoActionCount(); ++i)
384  {
385  const SfxUndoAction* pAction = GetUndoAction(i);
386  if (pAction->GetViewShellId() == nViewId)
387  {
388  pViewAction = pAction;
389  nOffset = i;
390  break;
391  }
392  }
393 
394  if (!pViewAction)
395  {
396  // Found no earlier undo action that belongs to the view.
397  return false;
398  }
399 
400  auto pTopSwAction = dynamic_cast<const SwUndo*>(pTopAction);
401  if (!pTopSwAction || pTopSwAction->GetId() != SwUndoId::TYPING)
402  {
403  return false;
404  }
405 
406  auto pViewSwAction = dynamic_cast<const SwUndo*>(pViewAction);
407  if (!pViewSwAction || pViewSwAction->GetId() != SwUndoId::TYPING)
408  {
409  return false;
410  }
411 
412  const auto& rTopInsert = *static_cast<const SwUndoInsert*>(pTopSwAction);
413  const auto& rViewInsert = *static_cast<const SwUndoInsert*>(pViewSwAction);
414 
415  for (size_t i = 0; i < GetRedoActionCount(); ++i)
416  {
417  auto pRedoAction = dynamic_cast<const SwUndo*>(GetRedoAction(i));
418  if (!pRedoAction || pViewSwAction->GetId() != SwUndoId::TYPING)
419  {
420  return false;
421  }
422 
423  const auto& rRedoInsert = *static_cast<const SwUndoInsert*>(pRedoAction);
424  if (!rViewInsert.IsIndependent(rRedoInsert) && rRedoInsert.GetViewShellId() != nViewId)
425  {
426  // Dependent redo action and owned by another view.
427  return false;
428  }
429  }
430 
431  if (!rViewInsert.IsIndependent(rTopInsert))
432  {
433  return false;
434  }
435 
436  rOffset = nOffset;
437  return true;
438 }
439 
440 bool
442  OUString *const o_pStr, SwUndoId *const o_pId, const SwView* pView) const
443 {
444  // this is actually expected to work on the current level,
445  // but that was really not obvious from the previous implementation...
446  if (!SdrUndoManager::GetUndoActionCount())
447  {
448  return false;
449  }
450 
451  SfxUndoAction *const pAction( SdrUndoManager::GetUndoAction() );
452 
454  {
455  // If another view created the undo action, prevent undoing it from this view.
456  ViewShellId nViewShellId = pView ? pView->GetViewShellId() : m_pDocShell->GetView()->GetViewShellId();
457  // Unless we know that the other view's undo action is independent from us.
458  if (pAction->GetViewShellId() != nViewShellId
459  && !IsViewUndoActionIndependent(pView, o3tl::temporary(sal_uInt16())))
460  {
461  if (o_pId)
462  {
463  *o_pId = SwUndoId::CONFLICT;
464  }
465  return false;
466  }
467  }
468 
469  if (o_pStr)
470  {
471  *o_pStr = pAction->GetComment();
472  }
473  if (o_pId)
474  {
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();
479  else
480  *o_pId = SwUndoId::EMPTY;
481  }
482 
483  return true;
484 }
485 
487 {
488  OSL_ENSURE(!SdrUndoManager::IsInListAction(),
489  "GetUndoComments() called while in list action?");
490 
491  SwUndoComments_t ret;
492  const size_t nUndoCount(SdrUndoManager::GetUndoActionCount(TopLevel));
493  for (size_t n = 0; n < nUndoCount; ++n)
494  {
495  OUString const comment(
496  SdrUndoManager::GetUndoActionComment(n, TopLevel));
497  ret.push_back(comment);
498  }
499 
500  return ret;
501 }
502 
503 bool UndoManager::GetFirstRedoInfo(OUString *const o_pStr,
504  SwUndoId *const o_pId,
505  const SwView* pView) const
506 {
507  if (!SdrUndoManager::GetRedoActionCount())
508  {
509  return false;
510  }
511 
512  SfxUndoAction *const pAction( SdrUndoManager::GetRedoAction() );
513  if ( pAction == nullptr )
514  {
515  return false;
516  }
517 
519  {
520  // If another view created the undo action, prevent redoing it from this view.
521  ViewShellId nViewShellId = pView ? pView->GetViewShellId() : m_pDocShell->GetView()->GetViewShellId();
522  if (pAction->GetViewShellId() != nViewShellId)
523  {
524  if (o_pId)
525  {
526  *o_pId = SwUndoId::CONFLICT;
527  }
528  return false;
529  }
530  }
531 
532  if (o_pStr)
533  {
534  *o_pStr = pAction->GetComment();
535  }
536  if (o_pId)
537  {
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();
542  else
543  *o_pId = SwUndoId::EMPTY;
544  }
545 
546  return true;
547 }
548 
550 {
551  OSL_ENSURE(!SdrUndoManager::IsInListAction(),
552  "GetRedoComments() called while in list action?");
553 
554  SwUndoComments_t ret;
555  const size_t nRedoCount(SdrUndoManager::GetRedoActionCount(TopLevel));
556  for (size_t n = 0; n < nRedoCount; ++n)
557  {
558  OUString const comment(
559  SdrUndoManager::GetRedoActionComment(n, TopLevel));
560  ret.push_back(comment);
561  }
562 
563  return ret;
564 }
565 
566 SwUndoId UndoManager::GetRepeatInfo(OUString *const o_pStr) const
567 {
568  SwUndoId nRepeatId(SwUndoId::EMPTY);
569  GetLastUndoInfo(o_pStr, & nRepeatId);
570  if( SwUndoId::REPEAT_START <= nRepeatId && SwUndoId::REPEAT_END > nRepeatId )
571  {
572  return nRepeatId;
573  }
574  if (o_pStr) // not repeatable -> clear comment
575  {
576  o_pStr->clear();
577  }
578  return SwUndoId::EMPTY;
579 }
580 
582 {
583  if (SdrUndoManager::GetRedoActionCount() ||
584  SdrUndoManager::GetRedoActionCount(TopLevel))
585  {
586  OSL_ENSURE(false, "RemoveLastUndoAction(): there are Redo actions?");
587  return nullptr;
588  }
589  if (!SdrUndoManager::GetUndoActionCount())
590  {
591  OSL_ENSURE(false, "RemoveLastUndoAction(): no Undo actions");
592  return nullptr;
593  }
594  SfxUndoAction *const pLastUndo(GetUndoAction());
595  SdrUndoManager::RemoveLastUndoAction();
596  return dynamic_cast<SwUndo *>(pLastUndo);
597 }
598 
599 // SfxUndoManager
600 
601 void UndoManager::AddUndoAction(std::unique_ptr<SfxUndoAction> pAction, bool bTryMerge)
602 {
603  SwUndo *const pUndo( dynamic_cast<SwUndo *>(pAction.get()) );
604  if (pUndo)
605  {
606  if (RedlineFlags::NONE == pUndo->GetRedlineFlags())
607  {
609  }
611  {
612  pUndo->IgnoreRepeat();
613  }
614  }
615  SdrUndoManager::AddUndoAction(std::move(pAction), bTryMerge);
616  if (m_pDocShell)
617  {
619  while ( pViewFrame )
620  {
621  pViewFrame->GetBindings().Invalidate( SID_UNDO );
622  pViewFrame->GetBindings().Invalidate( SID_REDO );
623  pViewFrame = SfxViewFrame::GetNext( *pViewFrame, m_pDocShell );
624  }
625  }
626 
627  // if the undo nodes array is too large, delete some actions
628  while (UNDO_ACTION_LIMIT < sal_Int32(GetUndoNodes().Count()))
629  {
630  RemoveOldestUndoAction();
631  }
632 }
633 
634 namespace {
635 
636 class CursorGuard
637 {
638 public:
639  CursorGuard(SwEditShell & rShell, bool const bSave)
640  : m_rShell(rShell)
641  , m_bSaveCursor(bSave)
642  {
643  if (m_bSaveCursor)
644  {
645  m_rShell.Push(); // prevent modification of current cursor
646  }
647  }
648  ~CursorGuard() COVERITY_NOEXCEPT_FALSE
649  {
650  if (m_bSaveCursor)
651  {
653  }
654  }
655 private:
656  SwEditShell & m_rShell;
657  bool const m_bSaveCursor;
658 };
659 
660 }
661 
662 bool UndoManager::impl_DoUndoRedo(UndoOrRedoType undoOrRedo, size_t nUndoOffset)
663 {
664  SwDoc & rDoc(GetUndoNodes().GetDoc());
665 
666  UnoActionContext c(& rDoc); // exception-safe StartAllAction/EndAllAction
667 
668  SwEditShell *const pEditShell( rDoc.GetEditShell() );
669 
670  OSL_ENSURE(pEditShell, "sw::UndoManager needs a SwEditShell!");
671  if (!pEditShell)
672  {
673  throw uno::RuntimeException();
674  }
675 
676  // in case the model has controllers locked, the Undo should not
677  // change the view cursors!
678  bool const bSaveCursors(pEditShell->CursorsLocked());
679  CursorGuard aCursorGuard(*pEditShell, bSaveCursors);
680  if (!bSaveCursors)
681  {
682  // (in case Undo was called via API) clear the cursors:
683  pEditShell->KillPams();
684  pEditShell->SetMark();
685  pEditShell->ClearMark();
686  }
687 
688  bool bRet(false);
689 
690  ::sw::UndoRedoContext context(rDoc, *pEditShell);
691  context.SetUndoOffset(nUndoOffset);
692 
693  // N.B. these may throw!
694  if (UndoOrRedoType::Undo == undoOrRedo)
695  {
696  bRet = SdrUndoManager::UndoWithContext(context);
697  }
698  else
699  {
700  bRet = SdrUndoManager::RedoWithContext(context);
701  }
702 
703  if (bRet)
704  {
705  // if we are at the "last save" position, the document is not modified
706  if (SdrUndoManager::HasTopUndoActionMark(m_UndoSaveMark))
707  {
709  }
710  else
711  {
713  }
714  }
715 
716  pEditShell->HandleUndoRedoContext(context);
717 
718  return bRet;
719 }
720 
721 bool UndoManager::Undo() { return UndoWithOffset(0); }
722 
723 bool UndoManager::UndoWithOffset(size_t nUndoOffset)
724 {
725  if(isTextEditActive())
726  {
727  return SdrUndoManager::Undo();
728  }
729  else
730  {
731  return impl_DoUndoRedo(UndoOrRedoType::Undo, nUndoOffset);
732  }
733 }
734 
736 {
737  if(isTextEditActive())
738  {
739  return SdrUndoManager::Redo();
740  }
741  else
742  {
743  return impl_DoUndoRedo(UndoOrRedoType::Redo, /*nUndoOffset=*/0);
744  }
745 }
746 
748 {
749  (void)xmlTextWriterStartElement(pWriter, BAD_CAST("swUndoManager"));
750  SdrUndoManager::dumpAsXml(pWriter);
751 
752  (void)xmlTextWriterStartElement(pWriter, BAD_CAST("m_xUndoNodes"));
753  m_xUndoNodes->dumpAsXml(pWriter);
754  (void)xmlTextWriterEndElement(pWriter);
755 
756  (void)xmlTextWriterEndElement(pWriter);
757 }
758 
760 {
761  if (m_pDocShell)
762  {
763  m_pDocShell->Broadcast(SfxHint(SfxHintId::DocumentRepair));
764  }
765 }
766 
773  sal_uInt16 const nRepeatCount)
774 {
775  if (SdrUndoManager::IsInListAction())
776  {
777  OSL_ENSURE(false, "repeat in open list action???");
778  return false;
779  }
780  if (!SdrUndoManager::GetUndoActionCount(TopLevel))
781  {
782  return false;
783  }
784  SfxUndoAction *const pRepeatAction(GetUndoAction());
785  assert(pRepeatAction);
786  if (!pRepeatAction->CanRepeat(rContext))
787  {
788  return false;
789  }
790 
791  OUString const comment(pRepeatAction->GetComment());
792  OUString const rcomment(pRepeatAction->GetRepeatComment(rContext));
793  SwUndoId nId;
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());
798  else
799  return false;
800  if (DoesUndo())
801  {
802  ViewShellId nViewShellId(-1);
803  if (m_pDocShell)
804  {
805  if (const SwView* pView = m_pDocShell->GetView())
806  nViewShellId = pView->GetViewShellId();
807  }
808  EnterListAction(comment, rcomment, static_cast<sal_uInt16>(nId), nViewShellId);
809  }
810 
811  SwPaM* pTmp = rContext.m_pCurrentPaM;
812  for(SwPaM& rPaM : rContext.GetRepeatPaM().GetRingContainer())
813  { // iterate over ring
814  rContext.m_pCurrentPaM = &rPaM;
815  if (DoesUndo() && & rPaM != pTmp)
816  {
818  }
819  for (sal_uInt16 nRptCnt = nRepeatCount; nRptCnt > 0; --nRptCnt)
820  {
821  pRepeatAction->Repeat(rContext);
822  }
823  if (DoesUndo() && & rPaM != pTmp)
824  {
825  m_isAddWithIgnoreRepeat = false;
826  }
827  rContext.m_bDeleteRepeated = false; // reset for next PaM
828  }
829  rContext.m_pCurrentPaM = pTmp;
830 
831  if (DoesUndo())
832  {
833  LeaveListAction();
834  }
835  return true;
836 }
837 
838 } // namespace sw
839 
840 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual bool DoesGroupUndo() const override
Is Group Undo enabled?
Definition: docundo.cxx:181
bool impl_DoUndoRedo(UndoOrRedoType undoOrRedo, size_t nUndoOffset)
Definition: docundo.cxx:662
SwNodes const & GetUndoNodes() const
Definition: docundo.cxx:77
std::shared_ptr< SwNodes > m_xUndoNodes
Undo nodes array: content not currently in document.
SwUndoId
Definition: swundo.hxx:29
bool m_isAddWithIgnoreRepeat
set the IgnoreRepeat flag on every added action
void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: docundo.cxx:747
virtual void SetModified()=0
Must be called manually at changes of format.
SwPaM & GetRepeatPaM()
Definition: UndoCore.hxx:134
virtual bool Undo() override
sal_Int64 n
Definition: doc.hxx:187
sal_Int16 nId
virtual bool DoesDrawUndo() const override
Is Undo for Drawing objects enabled? for Draw-Undo: writer wants to handle actions on Flys on its own...
Definition: docundo.cxx:191
void SetDocShell(SwDocShell *pDocShell)
Definition: docundo.cxx:92
void SetRedlineFlags(RedlineFlags eMode)
Definition: undobj.hxx:120
virtual void SetUndoNoResetModified() override
Disable (re)setting the document modified flag on Undo/Redo.
Definition: docundo.cxx:211
size_t GetRedoActionCount(const bool bCurrentLevel=true) const override
Definition: docundo.cxx:126
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.
Definition: docundo.cxx:441
virtual bool Redo() override
void SetView(SwView *pView) override
Return undo/redo info for this view.
Definition: docundo.cxx:97
IDocumentState & m_rState
virtual void DelAllUndoObj() override
Delete all Undo actions.
Definition: docundo.cxx:258
void EnableUndo(bool bEnable)
virtual bool IsUndoNoResetModified() const override
Is setting the document modified flag on Undo/Redo disabled?
Definition: docundo.cxx:206
int nCount
virtual SwUndoComments_t GetRedoComments() const override
Get comments of Redo actions.
Definition: docundo.cxx:549
virtual bool Undo() override
Definition: docundo.cxx:721
std::vector< OUString > SwUndoComments_t
Definition: swundo.hxx:26
RedlineFlags GetRedlineFlags() const
Definition: undobj.hxx:119
bool isTextEditActive() const
void DoRepair(bool bRepair) override
Enable repair mode.
Definition: docundo.cxx:196
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:137
SwDocShell * m_pDocShell
IDocumentRedlineAccess & m_rRedlineAccess
Typing one or more characters to a single paragraph.
Definition: UndoInsert.hxx:41
int i
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...
Definition: docundo.cxx:362
OUString Apply(const OUString &rStr) const
Definition: SwRewriter.cxx:39
SwEditShell const * GetEditShell() const
Definition: doccorr.cxx:328
bool m_bRepair
If true, then repair mode is enabled.
Count
SfxBindings & GetBindings()
virtual void LockUndoNoModifiedPosition() override
Prevent updates to the "unmodified" state position via SetUndoNoResetModified().
Definition: docundo.cxx:228
#define MARK_INVALID
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.
Definition: docundo.cxx:102
UndoManager(std::shared_ptr< SwNodes > const &pUndoNodes, IDocumentDrawModelAccess &rDrawModelAccess, IDocumentRedlineAccess &rRedlineAccess, IDocumentState &rState)
Definition: docundo.cxx:54
virtual void SetUndoNoModifiedPosition() override
Set the position at which the document is in the "unmodified" state to the current position in the Un...
Definition: docundo.cxx:220
virtual SwUndoId GetRepeatInfo(OUString *const o_pStr) const override
Get Id and comment of last Undo action, if it is Repeat capable.
Definition: docundo.cxx:566
ring_container GetRingContainer()
Definition: ring.hxx:240
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
Definition: docundo.cxx:87
virtual void DoDrawUndo(bool const bDoUndo) override
Enable/Disable Undo for Drawing objects.
Definition: docundo.cxx:186
virtual OUString GetRepeatComment(SfxRepeatTarget &) const
virtual SwUndoId EndUndo(SwUndoId const eUndoId, SwRewriter const *const pRewriter) override
Closes undo block.
Definition: docundo.cxx:300
virtual void UnLockUndoNoModifiedPosition() override
Allow updates to the "unmodified" state position via SetUndoNoResetModified().
Definition: docundo.cxx:233
SwUndo * GetLastUndo()
Definition: docundo.cxx:238
virtual ViewShellId GetViewShellId() const
bool DoesRepair() const override
Is repair mode active?
Definition: docundo.cxx:201
virtual OUString GetComment() const
#define UNDO_ACTION_LIMIT
Definition: docundo.cxx:50
bool m_bLockUndoNoModifiedPosition
virtual void Repeat(SfxRepeatTarget &)
Get information about the current document state.
void IgnoreRepeat()
Definition: undobj.hxx:130
IDocumentDrawModelAccess & m_rDrawModelAccess
virtual SwUndoComments_t GetUndoComments() const override
Get comments of Undo actions.
Definition: docundo.cxx:486
virtual bool Redo() override
Definition: docundo.cxx:735
virtual void DoUndo(bool const bDoUndo) override
IDocumentUndoRedo.
Definition: docundo.cxx:150
virtual void AddUndoAction(std::unique_ptr< SfxUndoAction > pAction, bool bTryMerg=false) override
Definition: docundo.cxx:601
virtual SwUndoId StartUndo(SwUndoId const eUndoId, SwRewriter const *const pRewriter) override
Opens undo block.
Definition: docundo.cxx:268
virtual void EmptyActionsChanged() override
Definition: docundo.cxx:759
OUString GetUndoComment(SwUndoId eId)
Definition: undobj.cxx:271
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.
Definition: docundo.cxx:176
virtual RedlineFlags GetRedlineFlags() const =0
Query the currently set redline mode.
struct _xmlTextWriter * xmlTextWriterPtr
SwPaM * m_pCurrentPaM
Definition: UndoCore.hxx:144
const SwView * GetView() const
Definition: docsh.hxx:221
SwUndo * RemoveLastUndo()
Definition: docundo.cxx:581
bool UndoWithOffset(size_t nUndoOffset) override
Zero offset means undoing the top undo action.
Definition: docundo.cxx:723
void SetUndoOffset(size_t nUndoOffset)
Definition: UndoCore.hxx:110
virtual void ClearRedo() override
Delete all Redo actions.
Definition: docundo.cxx:253
virtual bool Repeat(::sw::RepeatContext &rContext, sal_uInt16 const nRepeatCnt) override
N.B.
Definition: docundo.cxx:772
virtual bool DoesUndo() const override
Is Undo enabled?
Definition: docundo.cxx:164
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.
Definition: docundo.cxx:503
no RedlineFlags
Definition: view.hxx:144
ViewShellId GetViewShellId() const override
virtual void AppendUndo(std::unique_ptr< SwUndo > pUndo) override
Add new Undo action.
Definition: docundo.cxx:248
bool m_bDetectedRangeSegmentation false
virtual void ResetModified()=0
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo