[meld] Improve state skipping logic, and avoid order comparisons between types
- From: Kai Willadsen <kaiw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [meld] Improve state skipping logic, and avoid order comparisons between types
- Date: Fri, 30 Nov 2012 19:30:07 +0000 (UTC)
commit c8a2c1b5f00528b387b7f8543f306265d8bd08d3
Author: Kai Willadsen <kai willadsen gmail com>
Date: Sat Oct 27 13:04:02 2012 +1000
Improve state skipping logic, and avoid order comparisons between types
There were problems with our previous state-calculation skipping logic
where calculation was not correctly skipped in cases where the previous
and/or next differences were None. In particular, this would cause
problems in Python 3, where comparisons between unequal types are not
allowed.
meld/dirdiff.py | 36 ++++++++++++++++++++++++++----------
meld/vcview.py | 35 +++++++++++++++++++++++++----------
2 files changed, 51 insertions(+), 20 deletions(-)
---
diff --git a/meld/dirdiff.py b/meld/dirdiff.py
index 847415b..66c5723 100644
--- a/meld/dirdiff.py
+++ b/meld/dirdiff.py
@@ -630,6 +630,7 @@ class DirDiff(melddoc.MeldDoc, gnomeglade.Component):
self.treeview[0].expand_to_path(path)
yield _("[%s] Done") % self.label_text
self.actiongroup.get_action("Hide").set_sensitive(True)
+ self.scheduler.add_task(self.on_treeview_cursor_changed)
def _show_tree_wide_errors(self, invalid_filenames, shadowed_entries):
header = _("Multiple errors occurred while scanning this folder")
@@ -816,6 +817,12 @@ class DirDiff(melddoc.MeldDoc, gnomeglade.Component):
cursor_path, cursor_col = self.treeview[pane].get_cursor()
if not cursor_path:
self.emit("next-diff-changed", False, False)
+ self.current_path = cursor_path
+ return
+
+ # If invoked directly rather than through a callback, we always check
+ if not args:
+ skip = False
else:
try:
old_cursor = self.model.get_iter(self.current_path)
@@ -823,17 +830,26 @@ class DirDiff(melddoc.MeldDoc, gnomeglade.Component):
# An invalid path gives ValueError; None gives a TypeError
skip = False
else:
+ # We can skip recalculation if the new cursor is between
+ # the previous/next bounds, and we weren't on a changed row
state = self.model.get_state(old_cursor, 0)
- # We can skip recalculation if the new cursor is between the
- # previous/next bounds, and we weren't on a changed row
- skip = state in (tree.STATE_NORMAL, tree.STATE_EMPTY) and \
- self.prev_path < cursor_path < self.next_path
-
- if not skip:
- prev, next = self.model._find_next_prev_diff(cursor_path)
- self.prev_path, self.next_path = prev, next
- have_next_diffs = (prev is not None, next is not None)
- self.emit("next-diff-changed", *have_next_diffs)
+ if state not in (tree.STATE_NORMAL, tree.STATE_EMPTY):
+ skip = False
+ else:
+ if self.prev_path is None and self.next_path is None:
+ skip = True
+ elif self.prev_path is None:
+ skip = cursor_path < self.next_path
+ elif self.next_path is None:
+ skip = self.prev_path < cursor_path
+ else:
+ skip = self.prev_path < cursor_path < self.next_path
+
+ if not skip:
+ prev, next = self.model._find_next_prev_diff(cursor_path)
+ self.prev_path, self.next_path = prev, next
+ have_next_diffs = (prev is not None, next is not None)
+ self.emit("next-diff-changed", *have_next_diffs)
self.current_path = cursor_path
paths = self._get_selected_paths(pane)
diff --git a/meld/vcview.py b/meld/vcview.py
index 31ef142..486ee99 100644
--- a/meld/vcview.py
+++ b/meld/vcview.py
@@ -714,6 +714,12 @@ class VcView(melddoc.MeldDoc, gnomeglade.Component):
cursor_path, cursor_col = self.treeview.get_cursor()
if not cursor_path:
self.emit("next-diff-changed", False, False)
+ self.current_path = cursor_path
+ return
+
+ # If invoked directly rather than through a callback, we always check
+ if not args:
+ skip = False
else:
try:
old_cursor = self.model.get_iter(self.current_path)
@@ -721,17 +727,26 @@ class VcView(melddoc.MeldDoc, gnomeglade.Component):
# An invalid path gives ValueError; None gives a TypeError
skip = False
else:
+ # We can skip recalculation if the new cursor is between
+ # the previous/next bounds, and we weren't on a changed row
state = self.model.get_state(old_cursor, 0)
- # We can skip recalculation if the new cursor is between the
- # previous/next bounds, and we weren't on a changed row
- skip = state in (tree.STATE_NORMAL, tree.STATE_EMPTY) and \
- self.prev_path < cursor_path < self.next_path
-
- if not skip:
- prev, next = self.model._find_next_prev_diff(cursor_path)
- self.prev_path, self.next_path = prev, next
- have_next_diffs = (prev is not None, next is not None)
- self.emit("next-diff-changed", *have_next_diffs)
+ if state not in (tree.STATE_NORMAL, tree.STATE_EMPTY):
+ skip = False
+ else:
+ if self.prev_path is None and self.next_path is None:
+ skip = True
+ elif self.prev_path is None:
+ skip = cursor_path < self.next_path
+ elif self.next_path is None:
+ skip = self.prev_path < cursor_path
+ else:
+ skip = self.prev_path < cursor_path < self.next_path
+
+ if not skip:
+ prev, next = self.model._find_next_prev_diff(cursor_path)
+ self.prev_path, self.next_path = prev, next
+ have_next_diffs = (prev is not None, next is not None)
+ self.emit("next-diff-changed", *have_next_diffs)
self.current_path = cursor_path
def next_diff(self, direction):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]