[meld] Simplify handling of update during nested undo



commit 7aa4c304a84ff3989318a0820ca7db9685e2b1c9
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Sun Aug 14 08:08:10 2011 +1000

    Simplify handling of update during nested undo

 meld/filediff.py |    5 +----
 meld/undo.py     |   11 ++++++-----
 2 files changed, 7 insertions(+), 9 deletions(-)
---
diff --git a/meld/filediff.py b/meld/filediff.py
index 68b6cb1..fef2539 100644
--- a/meld/filediff.py
+++ b/meld/filediff.py
@@ -252,7 +252,6 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
         self._scroll_lock = False
         self.linediffer = self.differ()
         self.linediffer.ignore_blanks = self.prefs.ignore_blank_lines
-        self.in_nested_action = False
         self.in_nested_textview_gutter_expose = False
         self._inline_cache = set()
         self._cached_match = CachedSequenceMatcher()
@@ -832,12 +831,10 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
         # text buffer undo/redo
         #
     def on_textbuffer__begin_user_action(self, *buffer):
-        self.in_nested_action = True
         self.undosequence.begin_group()
 
     def on_textbuffer__end_user_action(self, *buffer):
         self.undosequence.end_group()
-        self.in_nested_action = False
         self.update_highlighting()
 
     def on_text_insert_text(self, buf, it, text, textlen):
@@ -1161,7 +1158,7 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
             self.set_files([None] * self.num_panes)
 
     def update_highlighting(self):
-        if not self.in_nested_action:
+        if not self.undosequence.in_grouped_action():
             self.scheduler.add_task(self._update_highlighting().next)
 
     def _update_highlighting(self):
diff --git a/meld/undo.py b/meld/undo.py
index 1ce925d..6ea744d 100644
--- a/meld/undo.py
+++ b/meld/undo.py
@@ -1,4 +1,5 @@
 ### Copyright (C) 2002-2006 Stephen Kennedy <stevek gnome org>
+### Copyright (C) 2010-2011 Kai Willadsen <kai willadsen gmail com>
 
 ### This program is free software; you can redistribute it and/or modify
 ### it under the terms of the GNU General Public License as published by
@@ -76,9 +77,7 @@ class UndoSequence(gobject.GObject):
 
         Raises an AssertionError if a group is in progress.
         """
-
-        if hasattr(self, "group"):
-            assert self.group is None
+        assert self.group is None
         if self.can_undo():
             self.emit('can-undo', 0)
         if self.can_redo():
@@ -86,7 +85,6 @@ class UndoSequence(gobject.GObject):
         self.actions = []
         self.next_redo = 0
         self.checkpoints = {}
-        self.group = None
 
     def can_undo(self):
         """Return if an undo is possible.
@@ -200,7 +198,7 @@ class UndoSequence(gobject.GObject):
     def begin_group(self):
         """Group several actions into a single logical action.
 
-        Whey you Wrap several calls to add_action() inside begin_group()
+        When you wrap several calls to add_action() inside begin_group()
         and end_group(), all the intervening actions are considered
         one logical action. For instance a 'replace' action may be
         implemented as a pair of 'delete' and 'create' actions, but
@@ -248,3 +246,6 @@ class UndoSequence(gobject.GObject):
         else:
             self.group = None
 
+    def in_grouped_action(self):
+        return self.group is not None
+



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