CMS 3D CMS Logo

UndoEvent.py
Go to the documentation of this file.
1 
3  LABEL = ""
4 
5  def __init__(self):
6  pass
7 
8  def undo(self):
9  """ Undos this event.
10  """
11  raise NotImplementedError
12 
13  def redo(self):
14  """ Repeats this event.
15  """
16  raise NotImplementedError
17 
18  def combine(self, otherUndoEvent):
19  """ Combines this event with another event of the same kind.
20 
21  If the combination was successfull True or otherwise False will be returned.
22  """
23  return False
24 
25  def description(self):
26  """ Returns a string with more detailed explanation of what this event does
27 
28  E.g. what exactly was dragged, moved or which values changed.
29  """
30  return ""
31 
32  def setLastSavedState(self, flag):
33  """ Sets the last saved state flag.
34 
35  If the flag is True, this UndoEvent represents the first action
36  after saving the file for the last time.
37  """
38  self._lastSavedStateFlag = flag
39 
40  def isLastSavedState(self):
41  """ Returns the last saved state flag, see setLastSavedState().
42  """
43  if hasattr(self, "_lastSavedStateFlag"):
44  return self._lastSavedStateFlag
45  return False
46 
47  def dump(self, prefix="undo"):
48  print prefix, ": ", self.LABEL, self.isLastSavedState()
49 
50 
52  """ This UndoEvent holds a list of UndoEvents whose redo() and undo() are invoked at the same time
53  when the corresponding function of this event is invoked.
54  """
55 
56  LABEL = "Multiple actions"
57 
58  def __init__(self, listOfUndoEvents, label=None):
59  UndoEvent.__init__(self)
60  self._undoEvents = listOfUndoEvents
61  if label:
62  self.LABEL = label
63  if len(self._undoEvents) == 1:
64  self.LABEL = self._undoEvents[0].LABEL
65 
66  labels = []
67  for event in self._undoEvents:
68  if not event.LABEL in labels:
69  labels.append(event.LABEL)
70  if len(labels) > 0:
71  self.LABEL += " (%s)" % ", ".join(labels)
72 
73  def undo(self):
74  for event in self._undoEvents:
75  event.undo()
76 
77  def redo(self):
78  # undo event list comes sorted so that it will work for undo
79  # if events depend on each other its important to reverse order for redo()
80  for event in reversed(self._undoEvents):
81  event.redo()
82 
83  def dump(self, prefix="undo"):
84  UndoEvent.dump(self, prefix)
85  for event in self._undoEvents:
86  event.dump(" " + prefix)
87 
def combine(self, otherUndoEvent)
Definition: UndoEvent.py:18
def setLastSavedState(self, flag)
Definition: UndoEvent.py:32
def dump(self, prefix="undo")
Definition: UndoEvent.py:47
def __init__(self, listOfUndoEvents, label=None)
Definition: UndoEvent.py:58
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
def dump(self, prefix="undo")
Definition: UndoEvent.py:83