[meld] Extract linkmap drawing methods for FileDiff subclasses



commit 516cc2576abc49d32a7d1176467387e4ede7e714
Author: Piotr Piastucki <leech miranda gmail com>
Date:   Fri Nov 6 07:23:35 2009 +0100

    Extract linkmap drawing methods for FileDiff subclasses
    
    Different file comparison modes, such as auto-merge mode, need different
    merging actions in the linkmap. This patch extracts several linkmap-related
    methods to allow easier subclassing of FileDiff.

 meld/filediff.py |   75 ++++++++++++++++++++++++++++-------------------------
 1 files changed, 40 insertions(+), 35 deletions(-)
---
diff --git a/meld/filediff.py b/meld/filediff.py
index 9e7a584..b9c470c 100644
--- a/meld/filediff.py
+++ b/meld/filediff.py
@@ -1164,17 +1164,13 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
                 buf.place_cursor(buf.get_iter_at_line(c[1]))
             self.textview[pane].scroll_to_mark(buf.get_insert(), 0.1)
 
-        #
-        # linkmap drawing
-        #
-    def on_linkmap_expose_event(self, widget, event):
-        wtotal, htotal = widget.allocation.width, widget.allocation.height
-        yoffset = widget.allocation.y
-        context = widget.window.cairo_create()
-        context.rectangle(event.area.x, event.area.y, event.area.width, event.area.height)
-        context.clip()
-        context.set_line_width(1.0)
+    def paint_pixbuf_at(self, context, pixbuf, x, y):
+        context.translate(x, y)
+        context.set_source_pixbuf(pixbuf, 0, 0)
+        context.paint()
+        context.identity_matrix()
 
+    def _linkmap_draw_icon(self, context, which, change, x, f0, t0):
         if self.keymask & MASK_SHIFT:
             pix0 = self.pixbuf_delete
             pix1 = self.pixbuf_delete
@@ -1184,6 +1180,21 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
         else: # self.keymask == 0:
             pix0 = self.pixbuf_apply0
             pix1 = self.pixbuf_apply1
+        if change in ("insert", "replace"):
+            self.paint_pixbuf_at(context, pix1, x, t0)
+        if change in ("delete", "replace"):
+            self.paint_pixbuf_at(context, pix0, 0, f0)
+
+        #
+        # linkmap drawing
+        #
+    def on_linkmap_expose_event(self, widget, event):
+        wtotal, htotal = widget.allocation.width, widget.allocation.height
+        yoffset = widget.allocation.y
+        context = widget.window.cairo_create()
+        context.rectangle(event.area.x, event.area.y, event.area.width, event.area.height)
+        context.clip()
+        context.set_line_width(1.0)
 
         which = self.linkmap.index(widget)
         pix_start = [None] * self.num_panes
@@ -1201,12 +1212,6 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
         # For bezier control points
         x_steps = [-0.5, (1. / 3) * wtotal, (2. / 3) * wtotal, wtotal + 0.5]
 
-        def paint_pixbuf_at(pixbuf, x, y):
-            context.translate(x, y)
-            context.set_source_pixbuf(pixbuf, 0, 0)
-            context.paint()
-            context.identity_matrix()
-
         for c in self.linediffer.pair_changes(which, which + 1):
             assert c[0] != "equal"
             if c[2] < visible[1] and c[4] < visible[3]: # find first visible chunk
@@ -1235,10 +1240,7 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
             context.stroke()
 
             x = wtotal-self.pixbuf_apply0.get_width()
-            if c[0] in ("insert", "replace"):
-                paint_pixbuf_at(pix1, x, t0)
-            if c[0] in ("delete", "replace"):
-                paint_pixbuf_at(pix0, 0, f0)
+            self._linkmap_draw_icon(context, which, c[0], x, f0, t0)
 
         # allow for scrollbar at end of textview
         mid = int(0.5 * self.textview[0].allocation.height) + 0.5
@@ -1250,6 +1252,23 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
     def on_linkmap_scroll_event(self, area, event):
         self.next_diff(event.direction)
 
+    def _linkmap_process_event(self, event, which, side, htotal, rect_x, pix_width, pix_height):
+        src = which + side
+        dst = which + 1 - side
+        adj = self.scrolledwindow[src].get_vadjustment()
+
+        for c in self.linediffer.pair_changes(src, dst):
+            if c[0] == "insert":
+                continue
+            h = self._line_to_pixel(src, c[1]) - adj.value
+            if h < 0: # find first visible chunk
+                continue
+            elif h > htotal: # we've gone past last visible
+                break
+            elif h < event.y and event.y < h + pix_height:
+                self.mouse_chunk = ((src, dst), (rect_x, h, pix_width, pix_height), c)
+                break
+
     def on_linkmap_button_press_event(self, area, event):
         if event.button == 1:
             self.focus_before_click = None
@@ -1276,21 +1295,7 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
                 rect_x = wtotal - pix_width
             else:
                 return True
-            src = which + side
-            dst = which + 1 - side
-            adj = self.scrolledwindow[src].get_vadjustment()
-
-            for c in self.linediffer.pair_changes(src, dst):
-                if c[0] == "insert":
-                    continue
-                h = self._line_to_pixel(src, c[1]) - adj.value
-                if h < 0: # find first visible chunk
-                    continue
-                elif h > htotal: # we've gone past last visible
-                    break
-                elif h < event.y and event.y < h + pix_height:
-                    self.mouse_chunk = ( (src,dst), (rect_x, h, pix_width, pix_height), c)
-                    break
+            self._linkmap_process_event(event, which, side, htotal, rect_x, pix_width, pix_height)
             #print self.mouse_chunk
             return True
         return False



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