Mercurial > fife-parpg
changeset 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 | f2195628947b |
files | clients/editor/plugins/HistoryManager.py clients/editor/scripts/undomanager.py |
diffstat | 2 files changed, 51 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- 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
--- 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