[meld] Move undo-busy logic into UndoSequence



commit 75ec3ad50d2aa0a86750eb55851988624de72c22
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Thu Aug 13 20:19:43 2009 +1000

    Move undo-busy logic into UndoSequence

 meld/filediff.py |    8 ++++----
 meld/melddoc.py  |   14 ++------------
 meld/undo.py     |   17 +++++++++++++++++
 3 files changed, 23 insertions(+), 16 deletions(-)
---
diff --git a/meld/filediff.py b/meld/filediff.py
index 8989a62..53ea44c 100644
--- a/meld/filediff.py
+++ b/meld/filediff.py
@@ -568,16 +568,16 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
         self.undosequence.end_group()
 
     def on_text_insert_text(self, buffer, it, text, textlen):
-        if not self.undosequence_busy:
-            self.undosequence.add_action( BufferInsertionAction(buffer, it.get_offset(), text) )
+        self.undosequence.add_action(
+            BufferInsertionAction(buffer, it.get_offset(), text))
 
     def on_text_delete_range(self, buffer, it0, it1):
         text = buffer.get_text(it0, it1, 0)
         pane = self.textbuffer.index(buffer)
         assert self.deleted_lines_pending == -1
         self.deleted_lines_pending = text.count("\n")
-        if not self.undosequence_busy:
-            self.undosequence.add_action( BufferDeletionAction(buffer, it0.get_offset(), text) )
+        self.undosequence.add_action(
+            BufferDeletionAction(buffer, it0.get_offset(), text))
 
     def on_undo_checkpointed(self, undosequence, buf, checkpointed):
         self.set_buffer_modified(buf, not checkpointed)
diff --git a/meld/melddoc.py b/meld/melddoc.py
index a711fca..0c0ea7c 100644
--- a/meld/melddoc.py
+++ b/meld/melddoc.py
@@ -40,7 +40,6 @@ class MeldDoc(gobject.GObject):
     def __init__(self, prefs):
         gobject.GObject.__init__(self)
         self.undosequence = undo.UndoSequence()
-        self.undosequence_busy = 0
         self.scheduler = task.FifoScheduler()
         self.prefs = prefs
         self.prefs.notify_add(self.on_preference_changed)
@@ -73,20 +72,11 @@ class MeldDoc(gobject.GObject):
 
     def on_undo_activate(self):
         if self.undosequence.can_undo():
-            self.undosequence_busy = 1
-            try:
-                self.undosequence.undo()
-            finally:
-                self.undosequence_busy = 0
+            self.undosequence.undo()
 
     def on_redo_activate(self):
         if self.undosequence.can_redo():
-            self.undosequence_busy = 1
-            try:
-                self.undosequence.redo()
-            finally:
-                self.undosequence_busy = 0
-            self.undosequence_busy = 0
+            self.undosequence.redo()
 
     def on_refresh_activate(self, *extra):
         self.on_reload_activate(self, *extra)
diff --git a/meld/undo.py b/meld/undo.py
index ad50993..17569ed 100644
--- a/meld/undo.py
+++ b/meld/undo.py
@@ -63,6 +63,7 @@ class UndoSequence(gobject.GObject):
         self.next_redo = 0
         self.checkpoints = {}
         self.group = None
+        self.busy = False
 
     def clear(self):
         """Remove all undo and redo actions from this sequence
@@ -102,6 +103,9 @@ class UndoSequence(gobject.GObject):
         action -- A class with two callable attributes: 'undo' and 'redo'
                   which are called by this sequence during an undo or redo.
         """
+        if self.busy:
+            return
+
         if self.group is None:
             if self.checkpointed(action.buffer):
                 self.checkpoints[action.buffer][1] = self.next_redo
@@ -130,12 +134,14 @@ class UndoSequence(gobject.GObject):
         Raises an AssertionError if the sequence is not undoable.
         """
         assert self.next_redo > 0
+        self.busy = True
         buf = self.actions[self.next_redo - 1].buffer
         if self.checkpointed(buf):
             self.emit('checkpointed', buf, False)
         could_redo = self.can_redo()
         self.next_redo -= 1
         self.actions[self.next_redo].undo()
+        self.busy = False
         if not self.can_undo():
             self.emit('can-undo', 0)
         if not could_redo:
@@ -149,6 +155,7 @@ class UndoSequence(gobject.GObject):
         Raises and AssertionError if the sequence is not undoable.
         """
         assert self.next_redo < len(self.actions)
+        self.busy = True
         buf = self.actions[self.next_redo].buffer
         if self.checkpointed(buf):
             self.emit('checkpointed', buf, False)
@@ -156,6 +163,7 @@ class UndoSequence(gobject.GObject):
         a = self.actions[self.next_redo]
         self.next_redo += 1
         a.redo()
+        self.busy = False
         if not could_undo:
             self.emit('can-undo', 1)
         if not self.can_redo():
@@ -192,6 +200,9 @@ class UndoSequence(gobject.GObject):
         implemented as a pair of 'delete' and 'create' actions, but
         undoing should undo both of them.
         """
+        if self.busy:
+            return
+
         if self.group:
             self.group.begin_group() 
         else:
@@ -203,6 +214,9 @@ class UndoSequence(gobject.GObject):
         Raises an AssertionError if there was not a matching call to
         begin_group().
         """
+        if self.busy:
+            return
+
         assert self.group is not None
         if self.group.group is not None:
             self.group.end_group()
@@ -219,6 +233,9 @@ class UndoSequence(gobject.GObject):
         
         Raises an AssertionError if there was no a matching call to begin_group().
         """
+        if self.busy:
+            return
+
         assert self.group is not None
         if self.group.group is not None:
             self.group.abort_group()



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]