[meld/ui-next: 5/35] filediff: Move action mode to a gprop on FileDiff



commit 301c0f2947e2ee5b8431fde519790aed8df648fe
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Mon Feb 11 08:00:51 2019 +1000

    filediff: Move action mode to a gprop on FileDiff
    
    Having this is nicer than emitting a signal, and it makes it possible to
    simply prop-bind in a future gutter implementation.

 meld/const.py    | 13 +++++++++----
 meld/filediff.py | 19 ++++++++++++-------
 2 files changed, 21 insertions(+), 11 deletions(-)
---
diff --git a/meld/const.py b/meld/const.py
index f6ae1271..9738960b 100644
--- a/meld/const.py
+++ b/meld/const.py
@@ -1,12 +1,17 @@
 
+import enum
+
 from gi.repository import GtkSource
 
 from meld.conf import _
 
-# Chunk action mode, set by filediff and used in gutterrendererchunk
-MODE_REPLACE = 0
-MODE_DELETE = 1
-MODE_INSERT = 2
+
+class ActionMode(enum.IntEnum):
+    """Action mode for chunk change actions"""
+    Replace = 0
+    Delete = 1
+    Insert = 2
+
 
 NEWLINES = {
     GtkSource.NewlineType.LF: ('\n', _("UNIX (LF)")),
diff --git a/meld/filediff.py b/meld/filediff.py
index 1899f84c..e8a92bc6 100644
--- a/meld/filediff.py
+++ b/meld/filediff.py
@@ -28,7 +28,7 @@ from gi.repository import GtkSource
 # TODO: Don't from-import whole modules
 from meld import misc
 from meld.conf import _, ui_file
-from meld.const import MODE_DELETE, MODE_INSERT, MODE_REPLACE, NEWLINES
+from meld.const import ActionMode, NEWLINES
 from meld.gutterrendererchunk import GutterRendererChunkLines
 from meld.iohelpers import prompt_save_filename
 from meld.matchers.diffutil import Differ, merged_chunk_order
@@ -177,10 +177,14 @@ class FileDiff(Gtk.VBox, MeldDoc):
     __gsignals__ = {
         'next-conflict-changed': (
             GObject.SignalFlags.RUN_FIRST, None, (bool, bool)),
-        'action-mode-changed': (
-            GObject.SignalFlags.RUN_FIRST, None, (int,)),
     }
 
+    action_mode = GObject.Property(
+        type=int,
+        nick='Action mode for chunk change actions',
+        default=ActionMode.Replace,
+    )
+
     def __init__(self, num_panes):
         super().__init__()
         # FIXME:
@@ -346,13 +350,14 @@ class FileDiff(Gtk.VBox, MeldDoc):
 
     def set_keymask(self, value):
         if value & MASK_SHIFT:
-            mode = MODE_DELETE
+            mode = ActionMode.Delete
         elif value & MASK_CTRL:
-            mode = MODE_INSERT
+            mode = ActionMode.Insert
         else:
-            mode = MODE_REPLACE
+            mode = ActionMode.Replace
         self._keymask = value
-        self.emit("action-mode-changed", mode)
+        self.action_mode = mode
+
     keymask = property(get_keymask, set_keymask)
 
     @Template.Callback()


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