Mercurial > fife-parpg
comparison clients/editor/plugins/HistoryManager.py @ 256:e893afb4963b
* Fixed HistoryManager to work with linear undo
* Set UndoManager to use branched mode by default
author | cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Mon, 08 Jun 2009 16:57:39 +0000 |
parents | 51cc05d862f2 |
children | 043d71a192b5 |
comparison
equal
deleted
inserted
replaced
255:51cc05d862f2 | 256:e893afb4963b |
---|---|
90 self.gui.addChild(self.scrollarea) | 90 self.gui.addChild(self.scrollarea) |
91 self.scrollarea.addChild(self.list) | 91 self.scrollarea.addChild(self.list) |
92 | 92 |
93 self.gui.position_technique = "right:center" | 93 self.gui.position_technique = "right:center" |
94 | 94 |
95 def _linearUndo(self, target): | |
96 mapview = self.editor.getActiveMapView() | |
97 if mapview is None: | |
98 return | |
99 | |
100 undomanager = mapview.getController().getUndoManager() | |
101 current_item = undomanager.current_item | |
102 | |
103 # Redo? | |
104 item = current_item | |
105 count = 0 | |
106 while item is not None: | |
107 if item == target: | |
108 undomanager.redo(count) | |
109 break | |
110 count += 1 | |
111 item = item.next | |
112 | |
113 else: | |
114 # Undo? | |
115 count = 0 | |
116 item = current_item | |
117 while item is not None: | |
118 if item == target: | |
119 undomanager.undo(count) | |
120 break | |
121 count += 1 | |
122 item = item.previous | |
123 | |
124 else: | |
125 print "HistoryManager: Didn't find target item!" | |
126 | |
127 # Select the current item, important to see if the undo/redo didn't work as expected | |
128 self.update() | |
129 | |
130 | |
95 def _itemSelected(self): | 131 def _itemSelected(self): |
96 mapview = self.editor.getActiveMapView() | 132 mapview = self.editor.getActiveMapView() |
97 if mapview is None: | 133 if mapview is None: |
98 return | 134 return |
99 | 135 |
100 undomanager = mapview.getController().getUndoManager() | 136 undomanager = mapview.getController().getUndoManager() |
101 | 137 |
102 stackitem = self.list.selected_item.item | 138 stackitem = self.list.selected_item.item |
103 if stackitem == undomanager.current_item: | 139 if stackitem == undomanager.current_item: |
104 #print "Selected current item" | 140 return |
141 | |
142 if undomanager.getBranchMode() is False: | |
143 self._linearUndo(stackitem) | |
105 return | 144 return |
106 | 145 |
107 searchlist = [] | 146 searchlist = [] |
108 searchlist2 = [] | 147 searchlist2 = [] |
109 parent = stackitem | 148 parent = stackitem |
190 while item is not None: | 229 while item is not None: |
191 listitem = _ListItem(u" "*indention + branchstr + " " + item.object.name, item, parent) | 230 listitem = _ListItem(u" "*indention + branchstr + " " + item.object.name, item, parent) |
192 items.append(listitem) | 231 items.append(listitem) |
193 branchnr = -1 | 232 branchnr = -1 |
194 | 233 |
195 for branch in item._branches: | 234 for branch in item.getBranches(): |
196 branchnr += 1 | 235 branchnr += 1 |
197 if branchnr == 0: | 236 if branchnr == 0: |
198 continue | 237 continue |
199 | 238 |
200 items.extend(self.recursiveUpdate(branch, indention+2, listitem, str(branchnr))) | 239 items.extend(self.recursiveUpdate(branch, indention+2, listitem, str(branchnr))) |
201 | 240 |
202 if len(item._branches) > 0: | 241 if self.undomanager.getBranchMode(): |
203 item = item._branches[0] | 242 if len(item._branches) > 0: |
204 else: | 243 item = item._branches[0] |
205 break | 244 else: |
206 #item = item.next | 245 break |
246 else: item = item.next | |
207 | 247 |
208 return items | 248 return items |
209 | 249 |
210 def update(self): | 250 def update(self): |
211 mapview = self.editor.getActiveMapView() | 251 mapview = self.editor.getActiveMapView() |