[meld: 7/8] final cleanup and minor refactor




commit 62b932b6d00ec087ea6f1c623d098736a36ea7f5
Author: Roberto Vidal <vidal roberto j gmail com>
Date:   Tue Mar 22 11:56:48 2022 +0100

    final cleanup and minor refactor

 help/C/syncpoints.page              |  8 +----
 meld/filediff.py                    | 62 +++++++++++++++++--------------------
 meld/meldwindow.py                  | 18 -----------
 meld/resources/gtk/menus.ui         | 11 -------
 meld/resources/ui/appwindow.ui      |  1 -
 meld/resources/ui/filediff-menus.ui | 12 -------
 6 files changed, 29 insertions(+), 83 deletions(-)
---
diff --git a/help/C/syncpoints.page b/help/C/syncpoints.page
index cddf5591..34c1e4ef 100644
--- a/help/C/syncpoints.page
+++ b/help/C/syncpoints.page
@@ -20,15 +20,9 @@ Synchronization points help <app>Meld</app> perform a more fine-grained comparis
 </p>
 
 <p>
-To add a synchronization point, click on a line and then right-click and select <gui style="menu">Add 
Synchronization Point</gui>. Repeat this with each file in your comparison and the synchronization points 
will match each other and TODO
+To add a synchronization point, click on a line and then right-click and select <gui style="menu">Add 
Synchronization Point</gui>. Repeat this with each file in your comparison: click on a line and then 
right-click and select <gui style="menu">Match Synchronization Point</gui>. Once every file has a 
synchronization point, they will match each other and the comparison will be updated to take them into 
account.
 </p>
 
-<note>
-  <p>
-    All actions related to synchronization points are also accessible from <gui 
style="menu">Comparison</gui>.
-  </p>
-</note>
-
 <p>
 You can add successive synchronization points and subdivide your files even further by repeating the steps 
above. Note that synchronization points are matched to each other in the order they appear in the text, which 
might not correspond to the order they were created.
 </p>
diff --git a/meld/filediff.py b/meld/filediff.py
index 14f95d6f..f6df519b 100644
--- a/meld/filediff.py
+++ b/meld/filediff.py
@@ -1419,39 +1419,38 @@ class FileDiff(Gtk.VBox, MeldDoc):
             return True
         return False
 
-    def syncpoint_action(self):
-        if self.focus_pane:
-            return self._syncpoint_action(self.textview.index(self.focus_pane))
-
     def set_syncpoint_menuitem(self, pane):
         menu_actions = {
-            SyncpointState.CAN_ADD: [
+            SyncpointAction.ADD: [
                 _("Add Synchronization Point"),
                 "view.add-sync-point"
             ],
-            SyncpointState.CAN_DELETE: [
+            SyncpointAction.DELETE: [
                 _("Remove Synchronization Point"),
                 "view.remove-sync-point"
             ],
-            SyncpointState.CAN_MOVE: [
+            SyncpointAction.MOVE: [
                 _("Move Synchronization Point"),
                 "view.add-sync-point"
             ],
-            SyncpointState.CAN_MATCH: [
+            SyncpointAction.MATCH: [
                 _("Match Synchronization Point"),
                 "view.add-sync-point"
             ],
-            SyncpointState.DISABLED: [
+            SyncpointAction.DISABLED: [
                 _("Add Synchronization Point"),
                 "view.add-sync-point"
             ],
         }
 
-        action = self._syncpoint_action(pane)
+        def get_mark():
+            return self.textbuffer[pane].get_insert()
+
+        action = self.syncpoints.action(pane, get_mark)
 
         self.set_action_enabled(
             "add-sync-point",
-            action != SyncpointState.DISABLED
+            action != SyncpointAction.DISABLED
         )
 
         label, action_id = menu_actions[action]
@@ -1469,12 +1468,6 @@ class FileDiff(Gtk.VBox, MeldDoc):
         self.popup_menu = Gtk.Menu.new_from_model(self.popup_menu_model)
         self.popup_menu.attach_to_widget(self)
 
-    def _syncpoint_action(self, pane):
-        def get_mark():
-            return self.textbuffer[pane].get_insert()
-
-        return self.syncpoints.state(pane, get_mark)
-
     def set_labels(self, labels):
         labels = labels[:self.num_panes]
         for label, buf in zip(labels, self.textbuffer):
@@ -2548,16 +2541,17 @@ class FileDiff(Gtk.VBox, MeldDoc):
 FileDiff.set_css_name('meld-file-diff')
 
 
-class SyncpointState(Enum):
-    # The state of a line when a dangling syncpoint can be moved to it
-    CAN_MOVE = "can_move"
-    # The state of a line where a dangling syncpoint sits
-    CAN_DELETE = "can_delete"
-    # The state of a line when a syncpoint can be added to match existing ones
-    CAN_MATCH = "can_match"
-    # The state of a line when a new, dangling syncpoint can be added to it
-    CAN_ADD = "can_add"
-    # The state of a line when no syncpoint action can be taken
+class SyncpointAction(Enum):
+    # A dangling syncpoint can be moved to the line
+    MOVE = "move"
+    # A dangling syncpoint sits can be remove from this line
+    DELETE = "delete"
+    # A syncpoint can be added to this line to match existing ones
+    # in other panes
+    MATCH = "match"
+    # A new, dangling syncpoint can be added to this line
+    ADD = "add"
+    # No syncpoint-related action can be taken on this line
     DISABLED = "disabled"
 
 
@@ -2633,11 +2627,11 @@ class Syncpoints:
         else:
             return self.PaneState.DANGLING
 
-    def state(self, pane_idx: int, get_mark):
+    def action(self, pane_idx: int, get_mark):
         state = self._pane_state(pane_idx)
 
         if state == self.PaneState.SHORT:
-            return SyncpointState.CAN_MATCH
+            return SyncpointAction.MATCH
 
         target = self._comparator(pane_idx, get_mark())
 
@@ -2650,13 +2644,13 @@ class Syncpoints:
             )
 
             if is_syncpoint:
-                return SyncpointState.CAN_DELETE
+                return SyncpointAction.DELETE
             else:
-                return SyncpointState.CAN_ADD
+                return SyncpointAction.ADD
 
         # state == DANGLING
         if target == self._comparator(pane_idx, points[-1]):
-            return SyncpointState.CAN_DELETE
+            return SyncpointAction.DELETE
 
         is_syncpoint = any(
             self._comparator(pane_idx, point) == target
@@ -2664,9 +2658,9 @@ class Syncpoints:
         )
 
         if is_syncpoint:
-            return SyncpointState.DISABLED
+            return SyncpointAction.DISABLED
         else:
-            return SyncpointState.CAN_MOVE
+            return SyncpointAction.MOVE
 
     class PaneState(Enum):
         # The state of a pane with all its syncpoints matched
diff --git a/meld/meldwindow.py b/meld/meldwindow.py
index e9d30dd1..49c04ee3 100644
--- a/meld/meldwindow.py
+++ b/meld/meldwindow.py
@@ -363,24 +363,6 @@ class MeldWindow(Gtk.ApplicationWindow):
             doc.scheduler.add_task(doc.auto_compare)
         return doc
 
-    @Gtk.Template.Callback()
-    def on_gear_popup_menu(self, menubutton):
-        if not menubutton.get_active():
-            return
-
-        current_page_idx = self.notebook.get_current_page()
-
-        if current_page_idx == -1:
-            return
-
-        page = self.notebook.get_nth_page(current_page_idx)
-
-        if not isinstance(page, FileDiff):
-            return
-
-        # TODO: recompute menu items
-        # action = page.syncpoint_action()
-
     def append_filediff(
             self, gfiles, *, encodings=None, merge_output=None, meta=None):
         assert len(gfiles) in (1, 2, 3)
diff --git a/meld/resources/gtk/menus.ui b/meld/resources/gtk/menus.ui
index 992f67c1..75dacf95 100644
--- a/meld/resources/gtk/menus.ui
+++ b/meld/resources/gtk/menus.ui
@@ -86,17 +86,6 @@
             <attribute name="action">view.merge-all</attribute>
           </item>
         </section>
-        <section>
-          <attribute name="id">synchronisation-section</attribute>
-          <item>
-            <attribute name="label" translatable="yes">Add Synchronization Point</attribute>
-            <attribute name="action">view.add-sync-point</attribute>
-          </item>
-          <item>
-            <attribute name="label" translatable="yes">Clear Synchronization Points</attribute>
-            <attribute name="action">view.clear-sync-point</attribute>
-          </item>
-        </section>
         <section>
           <attribute name="id">tool-section</attribute>
           <item>
diff --git a/meld/resources/ui/appwindow.ui b/meld/resources/ui/appwindow.ui
index 7b952f54..6717a3ff 100644
--- a/meld/resources/ui/appwindow.ui
+++ b/meld/resources/ui/appwindow.ui
@@ -172,7 +172,6 @@
             <property name="action-name">win.gear-menu</property>
             <property name="visible">true</property>
             <property name="can_focus">False</property>
-            <signal name="toggled" handler="on_gear_popup_menu"></signal>
             <child>
               <object class="GtkImage">
                 <property name="icon-name">open-menu-symbolic</property>
diff --git a/meld/resources/ui/filediff-menus.ui b/meld/resources/ui/filediff-menus.ui
index 00693ed0..ec1500bf 100644
--- a/meld/resources/ui/filediff-menus.ui
+++ b/meld/resources/ui/filediff-menus.ui
@@ -61,18 +61,6 @@
     </section>
     <section>
       <attribute name="id">syncpoint-section</attribute>
-      <item>
-        <attribute name="label" translatable="yes">Add Synchronization Point</attribute>
-        <attribute name="action">view.add-sync-point</attribute>
-      </item>
-      <item>
-        <attribute name="label" translatable="yes">Remove Synchronization Point</attribute>
-        <attribute name="action">view.remove-sync-point</attribute>
-      </item>
-      <item>
-        <attribute name="label" translatable="yes">Clear Synchronization Points</attribute>
-        <attribute name="action">view.clear-sync-point</attribute>
-      </item>
     </section>
   </menu>
 </interface>


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