[meld] Initial very dubious UI for sync points, and associated fixes



commit 3a12bff38241ad2338bdb479a5b438e06d29b952
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Sun Mar 24 12:29:30 2013 +1000

    Initial very dubious UI for sync points, and associated fixes

 data/ui/filediff-ui.xml |    5 +++++
 meld/diffutil.py        |   14 ++++++++++----
 meld/filediff.py        |   20 ++++++++++++++++++++
 meld/matchers.py        |    8 ++++----
 4 files changed, 39 insertions(+), 8 deletions(-)
---
diff --git a/data/ui/filediff-ui.xml b/data/ui/filediff-ui.xml
index d9bf54c..b47faa7 100644
--- a/data/ui/filediff-ui.xml
+++ b/data/ui/filediff-ui.xml
@@ -13,6 +13,11 @@
         <menuitem action="MakePatch"/>
       </placeholder>
     </menu>
+    <menu action="EditMenu">
+      <placeholder name="EditActionsPlaceholder">
+        <menuitem action="SplitDiff"/>
+      </placeholder>
+    </menu>
     <menu action="ChangesMenu">
       <placeholder name="ChangesActions">
         <menuitem action="PrevConflict"/>
diff --git a/meld/diffutil.py b/meld/diffutil.py
index fd9f707..b5750d4 100644
--- a/meld/diffutil.py
+++ b/meld/diffutil.py
@@ -16,11 +16,10 @@
 ### Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
 ### USA.
 
-import difflib
-
 import gobject
 
-from .matchers import DiffChunk, MyersSequenceMatcher
+from .matchers import DiffChunk, MyersSequenceMatcher, \
+    SyncPointMyersSequenceMatcher
 
 
 opcode_reverse = {
@@ -70,6 +69,7 @@ class Differ(gobject.GObject):
     }
 
     _matcher = MyersSequenceMatcher
+    _sync_matcher = SyncPointMyersSequenceMatcher
 
     def __init__(self):
         # Internally, diffs are stored from text1 -> text0 and text1 -> text2.
@@ -77,6 +77,7 @@ class Differ(gobject.GObject):
         self.num_sequences = 0
         self.seqlength = [0, 0, 0]
         self.diffs = [[], []]
+        self.syncpoints = []
         self.conflicts = []
         self._old_merge_cache = set()
         self._changed_chunks = tuple()
@@ -454,7 +455,12 @@ class Differ(gobject.GObject):
         self.seqlength = [len(s) for s in sequences]
 
         for i in range(self.num_sequences - 1):
-            matcher = self._matcher(None, sequences[1], sequences[i*2])
+            if self.syncpoints:
+                matcher = self._sync_matcher(None,
+                                             sequences[1], sequences[i * 2],
+                                             syncpoints=self.syncpoints[i])
+            else:
+                matcher = self._matcher(None, sequences[1], sequences[i * 2])
             work = matcher.initialise()
             while next(work) is None:
                 yield None
diff --git a/meld/filediff.py b/meld/filediff.py
index aa23baa..6b77133 100644
--- a/meld/filediff.py
+++ b/meld/filediff.py
@@ -208,6 +208,7 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
         self._scroll_lock = False
         self.linediffer = self.differ()
         self.linediffer.ignore_blanks = self.prefs.ignore_blank_lines
+        self.syncpoints = []
         self.in_nested_textview_gutter_expose = False
         self._cached_match = CachedSequenceMatcher()
         self.anim_source_id = [None for buf in self.textbuffer]
@@ -217,6 +218,10 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
 
         actions = (
             ("MakePatch", None, _("Format as patch..."), None, _("Create a patch using differences between 
files"), self.make_patch),
+            ("SplitDiff", None, _("Add change synchronization point"), None,
+                _("Add a manual point for synchronization of changes between "
+                  "files"),
+                self.add_sync_point),
             ("PrevConflict", None, _("Previous conflict"), "<Ctrl>I", _("Go to the previous conflict"), 
lambda x: self.on_next_conflict(gtk.gdk.SCROLL_UP)),
             ("NextConflict", None, _("Next conflict"), "<Ctrl>K", _("Go to the next conflict"), lambda x: 
self.on_next_conflict(gtk.gdk.SCROLL_DOWN)),
             ("PushLeft",  gtk.STOCK_GO_BACK,    _("Push to left"),    "<Alt>Left", _("Push current change to 
the left"), lambda x: self.push_change(-1)),
@@ -1761,3 +1766,18 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
         anim = TextviewLineAnimation(mark0, mark1, rgba0, rgba1, 0.5)
         self.animating_chunks[src].append(anim)
 
+    def add_sync_point(self, action):
+        syncpoints = []
+        cursor_it = self.textbuffer[1].get_iter_at_mark(
+            self.textbuffer[1].get_insert())
+        middle_line = cursor_it.get_line()
+
+        others = (0, 2) if self.num_panes == 3 else (0,)
+        for i in others:
+            buf = self.textbuffer[i]
+            cursor_it = buf.get_iter_at_mark(buf.get_insert())
+            cursor_line = cursor_it.get_line()
+            syncpoints.append([middle_line, cursor_line])
+
+        self.linediffer.syncpoints = [syncpoints]
+        self.refresh_comparison()
diff --git a/meld/matchers.py b/meld/matchers.py
index 23e2944..8b9fa27 100644
--- a/meld/matchers.py
+++ b/meld/matchers.py
@@ -381,14 +381,13 @@ class SyncPointMyersSequenceMatcher(MyersSequenceMatcher):
                 ai = aj
                 bi = bj
             if ai < len(self.a) or bi < len(self.b):
-                chunks.append((ai, bi,
-                               self.a[ai:len(self.a)],
-                               self.b[bi:len(self.b)]))
+                chunks.append((ai, bi, self.a[ai:], self.b[bi:]))
+
             self.matching_blocks = []
             for ai, bi, a, b in chunks:
                 matcher = MyersSequenceMatcher(self.isjunk, a, b)
                 for i in matcher.initialise():
-                    yield i
+                    yield None
                 blocks = matcher.get_matching_blocks()
                 l = len(self.matching_blocks) - 1
                 if l >= 0 and len(blocks) > 1:
@@ -402,3 +401,4 @@ class SyncPointMyersSequenceMatcher(MyersSequenceMatcher):
                 for x, y, l in blocks[:-1]:
                     self.matching_blocks.append((ai + x, bi + y, l))
             self.matching_blocks.append((len(self.a), len(self.b), 0))
+            yield 1


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