LibreOffice Module svx (master)  1
sdrundomanager.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 <svx/sdrundomanager.hxx>
21 #include <sfx2/objsh.hxx>
22 #include <svl/hint.hxx>
23 
25  : EditUndoManager(20 /*nMaxUndoActionCount*/)
26  , maEndTextEditHdl()
27  , mpLastUndoActionBeforeTextEdit(nullptr)
28  , mbEndTextEditTriggeredFromUndo(false)
29  , m_pDocSh(nullptr)
30 {
31 }
32 
34 
36 {
37  if (isTextEditActive())
38  {
39  bool bRetval(false);
40 
41  // we are in text edit mode
42  if (GetUndoActionCount() && mpLastUndoActionBeforeTextEdit != GetUndoAction())
43  {
44  // there is an undo action for text edit, trigger it
45  bRetval = EditUndoManager::Undo();
46  }
47  else
48  {
49  // no more text edit undo, end text edit
51  maEndTextEditHdl.Call(this);
53  }
54 
55  return bRetval;
56  }
57  else
58  {
59  // no undo triggered up to now, trigger local one
60  return SfxUndoManager::Undo();
61  }
62 }
63 
65 {
66  bool bRetval(false);
67 
68  if (isTextEditActive())
69  {
70  // we are in text edit mode
71  bRetval = EditUndoManager::Redo();
72  }
73 
74  if (!bRetval)
75  {
76  // no redo triggered up to now, trigger local one
77  bRetval = SfxUndoManager::Redo();
78  }
79 
80  return bRetval;
81 }
82 
84 {
85  if (isTextEditActive())
86  {
87  while (GetUndoActionCount() && mpLastUndoActionBeforeTextEdit != GetUndoAction())
88  {
89  RemoveLastUndoAction();
90  }
91 
92  // urgently needed: RemoveLastUndoAction does NOT correct the Redo stack by itself (!)
93  ClearRedo();
94  }
95  else
96  {
97  // call parent
98  EditUndoManager::Clear();
99  }
100 }
101 
103 {
104  maEndTextEditHdl = rLink;
105 
106  if (isTextEditActive())
107  {
108  // text edit start, remember last non-textedit action for later cleanup
109  mpLastUndoActionBeforeTextEdit = GetUndoActionCount() ? GetUndoAction() : nullptr;
110  }
111  else
112  {
113  // text edit ends, pop all textedit actions up to the remembered non-textedit action from the start
114  // to set back the UndoManager to the state before text edit started. If that action is already gone
115  // (due to being removed from the undo stack in the meantime), all need to be removed anyways
116  while (GetUndoActionCount() && mpLastUndoActionBeforeTextEdit != GetUndoAction())
117  {
118  RemoveLastUndoAction();
119  }
120 
121  // urgently needed: RemoveLastUndoAction does NOT correct the Redo stack by itself (!)
122  ClearRedo();
123 
124  // forget marker again
126  }
127 }
128 
130 
131 void SdrUndoManager::SetDocShell(SfxObjectShell* pDocShell) { m_pDocSh = pDocShell; }
132 
134 {
135  if (m_pDocSh)
136  {
137  m_pDocSh->Broadcast(SfxHint(SfxHintId::DocumentRepair));
138  }
139 }
140 
141 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SfxUndoAction * mpLastUndoActionBeforeTextEdit
virtual bool Undo() override
react depending on edit mode and if no more undo is possible
virtual bool Redo() override
virtual bool Undo()
virtual bool Redo()
bool isTextEditActive() const
virtual ~SdrUndoManager() override
bool mbEndTextEditTriggeredFromUndo
void SetEndTextEditHdl(const Link< SdrUndoManager *, void > &rLink)
SfxObjectShell * m_pDocSh
Link< SdrUndoManager *, void > maEndTextEditHdl
virtual void Clear() override
void SetDocShell(SfxObjectShell *pDocShell)
virtual void EmptyActionsChanged() override