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 {
35 }
36 
38 {
39  if(isTextEditActive())
40  {
41  bool bRetval(false);
42 
43  // we are in text edit mode
44  if(GetUndoActionCount() && mpLastUndoActionBeforeTextEdit != GetUndoAction())
45  {
46  // there is an undo action for text edit, trigger it
47  bRetval = EditUndoManager::Undo();
48  }
49  else
50  {
51  // no more text edit undo, end text edit
53  maEndTextEditHdl.Call(this);
55  }
56 
57  return bRetval;
58  }
59  else
60  {
61  // no undo triggered up to now, trigger local one
62  return SfxUndoManager::Undo();
63  }
64 }
65 
67 {
68  bool bRetval(false);
69 
70  if(isTextEditActive())
71  {
72  // we are in text edit mode
73  bRetval = EditUndoManager::Redo();
74  }
75 
76  if(!bRetval)
77  {
78  // no redo triggered up to now, trigger local one
79  bRetval = SfxUndoManager::Redo();
80  }
81 
82  return bRetval;
83 }
84 
86 {
87  if(isTextEditActive())
88  {
89  while(GetUndoActionCount() && mpLastUndoActionBeforeTextEdit != GetUndoAction())
90  {
91  RemoveLastUndoAction();
92  }
93 
94  // urgently needed: RemoveLastUndoAction does NOT correct the Redo stack by itself (!)
95  ClearRedo();
96  }
97  else
98  {
99  // call parent
100  EditUndoManager::Clear();
101  }
102 }
103 
105 {
106  maEndTextEditHdl = rLink;
107 
108  if(isTextEditActive())
109  {
110  // text edit start, remember last non-textedit action for later cleanup
111  mpLastUndoActionBeforeTextEdit = GetUndoActionCount() ? GetUndoAction() : nullptr;
112  }
113  else
114  {
115  // text edit ends, pop all textedit actions up to the remembered non-textedit action from the start
116  // to set back the UndoManager to the state before text edit started. If that action is already gone
117  // (due to being removed from the undo stack in the meantime), all need to be removed anyways
118  while(GetUndoActionCount() && mpLastUndoActionBeforeTextEdit != GetUndoAction())
119  {
120  RemoveLastUndoAction();
121  }
122 
123  // urgently needed: RemoveLastUndoAction does NOT correct the Redo stack by itself (!)
124  ClearRedo();
125 
126  // forget marker again
128  }
129 }
130 
132 {
133  return maEndTextEditHdl.IsSet();
134 }
135 
137 {
138  m_pDocSh = pDocShell;
139 }
140 
142 {
143  if (m_pDocSh)
144  {
145  m_pDocSh->Broadcast(SfxHint(SfxHintId::DocumentRepair));
146  }
147 }
148 
149 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Link< SdrUndoManager *, void > maEndTextEditHdl
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
virtual void Clear() override
void SetDocShell(SfxObjectShell *pDocShell)
virtual void EmptyActionsChanged() override