# HG changeset patch # User cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222 # Date 1244480259 0 # Node ID e893afb4963be28063b3a7157f11d8ac81b64310 # Parent 51cc05d862f2adf7ccdd1e65ff90238e2f640e7b * Fixed HistoryManager to work with linear undo * Set UndoManager to use branched mode by default diff -r 51cc05d862f2 -r e893afb4963b clients/editor/plugins/HistoryManager.py --- a/clients/editor/plugins/HistoryManager.py Mon Jun 08 16:00:02 2009 +0000 +++ b/clients/editor/plugins/HistoryManager.py Mon Jun 08 16:57:39 2009 +0000 @@ -92,6 +92,42 @@ self.gui.position_technique = "right:center" + def _linearUndo(self, target): + mapview = self.editor.getActiveMapView() + if mapview is None: + return + + undomanager = mapview.getController().getUndoManager() + current_item = undomanager.current_item + + # Redo? + item = current_item + count = 0 + while item is not None: + if item == target: + undomanager.redo(count) + break + count += 1 + item = item.next + + else: + # Undo? + count = 0 + item = current_item + while item is not None: + if item == target: + undomanager.undo(count) + break + count += 1 + item = item.previous + + else: + print "HistoryManager: Didn't find target item!" + + # Select the current item, important to see if the undo/redo didn't work as expected + self.update() + + def _itemSelected(self): mapview = self.editor.getActiveMapView() if mapview is None: @@ -101,7 +137,10 @@ stackitem = self.list.selected_item.item if stackitem == undomanager.current_item: - #print "Selected current item" + return + + if undomanager.getBranchMode() is False: + self._linearUndo(stackitem) return searchlist = [] @@ -192,18 +231,19 @@ items.append(listitem) branchnr = -1 - for branch in item._branches: + for branch in item.getBranches(): branchnr += 1 if branchnr == 0: continue items.extend(self.recursiveUpdate(branch, indention+2, listitem, str(branchnr))) - if len(item._branches) > 0: - item = item._branches[0] - else: - break - #item = item.next + if self.undomanager.getBranchMode(): + if len(item._branches) > 0: + item = item._branches[0] + else: + break + else: item = item.next return items diff -r 51cc05d862f2 -r e893afb4963b clients/editor/scripts/undomanager.py --- a/clients/editor/scripts/undomanager.py Mon Jun 08 16:00:02 2009 +0000 +++ b/clients/editor/scripts/undomanager.py Mon Jun 08 16:57:39 2009 +0000 @@ -32,7 +32,8 @@ # Adds an action to the undomanager undocallback = lambda: doSomethingElse() redocallback = lambda: doSomething() - action = UndoObject("Did something", "Something was done somewhere in the program.", "icon.png") + description = "Something was done somewhere in the program." + action = UndoObject(undocallback, redocallback, "Did something", description, "icon.png") undomanager.addAction(action) def doLotOfActions(): @@ -48,9 +49,9 @@ undomanager.undo() """ - def __init__(self, branchedMode = False): + def __init__(self, branchedMode = True): self._groups = [] - self._branched_mode = False + self._branched_mode = branchedMode def warn(msg): print "Warning: ",msg