[meld] filediff: Refactor next_diff to be usable for all diff traversals
- From: Kai Willadsen <kaiw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [meld] filediff: Refactor next_diff to be usable for all diff traversals
- Date: Sun, 14 Dec 2014 20:51:29 +0000 (UTC)
commit d06b0b249ce7be8865e1b15ce647786b2f7b516f
Author: Kai Willadsen <kai willadsen gmail com>
Date: Mon Dec 1 07:43:54 2014 +1000
filediff: Refactor next_diff to be usable for all diff traversals
data/ui/filediff.ui | 4 +-
meld/filediff.py | 74 +++++++++++++++++++++++++-------------------------
2 files changed, 39 insertions(+), 39 deletions(-)
---
diff --git a/data/ui/filediff.ui b/data/ui/filediff.ui
index 02e9610..c0103db 100644
--- a/data/ui/filediff.ui
+++ b/data/ui/filediff.ui
@@ -43,7 +43,7 @@
<object class="GtkAction" id="PrevConflict">
<property name="label" translatable="yes">Previous Conflict</property>
<property name="tooltip" translatable="yes">Go to the previous conflict</property>
- <signal name="activate" handler="on_next_conflict(Gdk.ScrollDirection.UP)" swapped="no"/>
+ <signal name="activate" handler="action_previous_conflict" swapped="no"/>
</object>
<accelerator key="I" modifiers="GDK_CONTROL_MASK"/>
</child>
@@ -51,7 +51,7 @@
<object class="GtkAction" id="NextConflict">
<property name="label" translatable="yes">Next Conflict</property>
<property name="tooltip" translatable="yes">Go to the next conflict</property>
- <signal name="activate" handler="on_next_conflict(Gdk.ScrollDirection.DOWN)" swapped="no"/>
+ <signal name="activate" handler="action_next_conflict" swapped="no"/>
</object>
<accelerator key="K" modifiers="GDK_CONTROL_MASK"/>
</child>
diff --git a/meld/filediff.py b/meld/filediff.py
index 61dd4e7..d06a553 100644
--- a/meld/filediff.py
+++ b/meld/filediff.py
@@ -517,20 +517,44 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
self.actiongroup.get_action("PrevConflict").set_sensitive(have_prev)
self.actiongroup.get_action("NextConflict").set_sensitive(have_next)
- def on_next_conflict(self, direction):
- if direction == Gdk.ScrollDirection.DOWN:
- target = self.cursor.next_conflict
- else: # direction == Gdk.ScrollDirection.UP
- target = self.cursor.prev_conflict
-
+ def go_to_chunk(self, target, pane=None, centered=False):
if target is None:
return
- buf = self.textbuffer[self.cursor.pane]
- chunk = self.linediffer.get_chunk(target, self.cursor.pane)
- buf.place_cursor(buf.get_iter_at_line(chunk[1]))
- self.textview[self.cursor.pane].scroll_to_mark(
- buf.get_insert(), 0.1, True, 0.5, 0.5)
+ if pane is None:
+ pane = self._get_focused_pane()
+ if pane == -1:
+ pane = 1 if len(self.textview) > 1 else 0
+
+ chunk = self.linediffer.get_chunk(target, pane)
+ if not chunk:
+ return
+
+ # Warp the cursor to the first line of the chunk
+ buf = self.textbuffer[pane]
+ if self.cursor.line != chunk[1]:
+ buf.place_cursor(buf.get_iter_at_line(chunk[1]))
+
+ tolerance = 0.0 if centered else 0.2
+ self.textview[pane].scroll_to_mark(
+ buf.get_insert(), tolerance, True, 0.5, 0.5)
+
+ def next_diff(self, direction, centered=False):
+ target = (self.cursor.next if direction == Gdk.ScrollDirection.DOWN
+ else self.cursor.prev)
+ go_to_chunk(target, centered=centered)
+
+ def action_previous_conflict(self, *args):
+ self.go_to_chunk(self.cursor.prev_conflict, self.cursor.pane)
+
+ def action_next_conflict(self, *args):
+ self.go_to_chunk(self.cursor.next_conflict, self.cursor.pane)
+
+ def action_previous_diff(self, *args):
+ self.go_to_chunk(self.cursor.prev)
+
+ def action_next_diff(self, *args):
+ self.go_to_chunk(self.cursor.next)
def push_change(self, direction):
src = self._get_focused_pane()
@@ -1138,7 +1162,8 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
if self.cursor.next is not None:
self.scheduler.add_task(
- lambda: self.next_diff(Gdk.ScrollDirection.DOWN, True), True)
+ lambda: self.go_to_chunk(self.cursor.next, centered=True),
+ True)
else:
buf = self.textbuffer[1 if self.num_panes > 1 else 0]
self.on_cursor_position_changed(buf, None, True)
@@ -1848,31 +1873,6 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
self.queue_draw()
self.recompute_label()
- def next_diff(self, direction, centered=False):
- target = (self.cursor.next if direction == Gdk.ScrollDirection.DOWN
- else self.cursor.prev)
- if target is None:
- return
-
- pane = self._get_focused_pane()
- if pane == -1:
- if len(self.textview) > 1:
- pane = 1
- else:
- pane = 0
-
- chunk = self.linediffer.get_chunk(target, pane)
- if not chunk:
- return
-
- # Warp the cursor to the first line of next chunk
- buf = self.textbuffer[pane]
- if self.cursor.line != chunk[1]:
- buf.place_cursor(buf.get_iter_at_line(chunk[1]))
- tolerance = 0.0 if centered else 0.2
- self.textview[pane].scroll_to_mark(
- buf.get_insert(), tolerance, True, 0.5, 0.5)
-
def copy_chunk(self, src, dst, chunk, copy_up):
b0, b1 = self.textbuffer[src], self.textbuffer[dst]
start = b0.get_iter_at_line_or_eof(chunk[1])
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]