[meld/ui-next] Move find and replace to GActions



commit 211eb6ec32105c2ef19fc67d4f042fc7f105c818
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Fri Mar 1 09:39:27 2019 +1000

    Move find and replace to GActions

 data/ui/meldapp-ui.xml      |  4 ----
 meld/accelerators.py        |  2 ++
 meld/dirdiff.py             |  5 +++--
 meld/filediff.py            |  6 ++++--
 meld/melddoc.py             |  6 ------
 meld/meldwindow.py          | 25 -------------------------
 meld/resources/gtk/menus.ui | 11 +++++++++++
 meld/vcview.py              |  5 +++--
 8 files changed, 23 insertions(+), 41 deletions(-)
---
diff --git a/data/ui/meldapp-ui.xml b/data/ui/meldapp-ui.xml
index 950a7d14..3460f4e6 100644
--- a/data/ui/meldapp-ui.xml
+++ b/data/ui/meldapp-ui.xml
@@ -1,9 +1,5 @@
 <ui>
   <menubar name="Menubar">
-    <menu action="EditMenu">
-      <menuitem action="Find"/>
-      <menuitem action="Replace"/>
-    </menu>
     <menu action="ChangesMenu">
       <placeholder name="ChangesActions" />
     </menu>
diff --git a/meld/accelerators.py b/meld/accelerators.py
index 08b38007..2485e7f2 100644
--- a/meld/accelerators.py
+++ b/meld/accelerators.py
@@ -4,8 +4,10 @@ from gi.repository import Gtk
 
 def register_accels(app: Gtk.Application):
     view_accels = (
+        ('view.find', '<Primary>F'),
         ('view.find-next', '<Primary>G'),
         ('view.find-previous', '<Primary><Shift>G'),
+        ('view.find-replace', '<Primary>H'),
         ('view.folder-compare', 'Return'),
         ('view.folder-copy-left', '<Alt>Left'),
         ('view.folder-copy-right', '<Alt>Right'),
diff --git a/meld/dirdiff.py b/meld/dirdiff.py
index 4efa4c9c..be78f79d 100644
--- a/meld/dirdiff.py
+++ b/meld/dirdiff.py
@@ -408,6 +408,7 @@ class DirDiff(Gtk.VBox, tree.TreeviewCommon, MeldDoc):
 
         # Manually handle GAction additions
         actions = (
+            ('find', self.action_find),
             ('folder-collapse', self.action_folder_collapse),
             ('folder-compare', self.action_diff),
             ('folder-copy-left', self.action_copy_left),
@@ -1662,7 +1663,7 @@ class DirDiff(Gtk.VBox, tree.TreeviewCommon, MeldDoc):
     def action_next_change(self, *args):
         self.next_diff(Gdk.ScrollDirection.DOWN)
 
-    def action_refresh(self, *extra):
+    def action_refresh(self, *args):
         self.on_fileentry_file_set(None)
 
     def on_delete_event(self):
@@ -1671,7 +1672,7 @@ class DirDiff(Gtk.VBox, tree.TreeviewCommon, MeldDoc):
         self.close_signal.emit(0)
         return Gtk.ResponseType.OK
 
-    def on_find_activate(self, *extra):
+    def action_find(self, *args):
         self.focus_pane.emit("start-interactive-search")
 
     def auto_compare(self):
diff --git a/meld/filediff.py b/meld/filediff.py
index e9a68fe6..073a495f 100644
--- a/meld/filediff.py
+++ b/meld/filediff.py
@@ -291,8 +291,10 @@ class FileDiff(Gtk.VBox, MeldDoc):
         actions = (
             ('add-sync-point', self.add_sync_point),
             ('clear-sync-point', self.clear_sync_points),
+            ('find', self.action_find),
             ('find-next', self.action_find_next),
             ('find-previous', self.action_find_previous),
+            ('find-replace', self.action_find_replace),
             ('format-as-patch', self.action_format_as_patch),
             ('go-to-line', self.action_go_to_line),
             ('merge-all-left', self.action_pull_all_changes_left),
@@ -1157,12 +1159,12 @@ class FileDiff(Gtk.VBox, MeldDoc):
         if sel:
             return buf.get_text(sel[0], sel[1], False)
 
-    def on_find_activate(self, *args):
+    def action_find(self, *args):
         selected_text = self.get_selected_text()
         self.findbar.start_find(
             textview=self.focus_pane, replace=False, text=selected_text)
 
-    def on_replace_activate(self, *args):
+    def action_find_replace(self, *args):
         selected_text = self.get_selected_text()
         self.findbar.start_find(
             textview=self.focus_pane, replace=True, text=selected_text)
diff --git a/meld/melddoc.py b/meld/melddoc.py
index 60ee5d0c..2cf197f4 100644
--- a/meld/melddoc.py
+++ b/meld/melddoc.py
@@ -168,12 +168,6 @@ class MeldDoc(LabeledObjectMixin, GObject.GObject):
             f.query_info_async(query_attrs, 0, GLib.PRIORITY_LOW, None,
                                open_cb, None)
 
-    def on_find_activate(self, *extra):
-        pass
-
-    def on_replace_activate(self, *extra):
-        pass
-
     def on_file_changed(self, filename):
         pass
 
diff --git a/meld/meldwindow.py b/meld/meldwindow.py
index 8e647425..edf3d5fd 100644
--- a/meld/meldwindow.py
+++ b/meld/meldwindow.py
@@ -60,14 +60,6 @@ class MeldWindow(Gtk.ApplicationWindow):
         self.init_template()
 
         actions = (
-            ("EditMenu", None, _("_Edit")),
-            ("Find", Gtk.STOCK_FIND, _("Find…"), None, _("Search for text"),
-                self.on_menu_find_activate),
-            ("Replace", Gtk.STOCK_FIND_AND_REPLACE,
-                _("_Replace…"), "<Primary>H",
-                _("Find and replace text"),
-                self.on_menu_replace_activate),
-
             ("ChangesMenu", None, _("_Changes")),
         )
         self.actiongroup = Gtk.ActionGroup(name='MainActions')
@@ -224,17 +216,6 @@ class MeldWindow(Gtk.ApplicationWindow):
             page = None
 
         self.lookup_action('close').set_enabled(bool(page))
-        if not isinstance(page, MeldDoc):
-            for action in (
-                           "Find", "Replace",
-                           ):
-                self.actiongroup.get_action(action).set_sensitive(False)
-        else:
-            for action in ("Find",):
-                self.actiongroup.get_action(action).set_sensitive(True)
-            is_filediff = isinstance(page, FileDiff)
-            for action in ("Replace",):
-                self.actiongroup.get_action(action).set_sensitive(is_filediff)
 
     def handle_current_doc_switch(self, page):
         page.on_container_switch_out_event(self.ui, self)
@@ -280,12 +261,6 @@ class MeldWindow(Gtk.ApplicationWindow):
             page = self.notebook.get_nth_page(i)
             page.on_delete_event()
 
-    def on_menu_find_activate(self, *extra):
-        self.current_doc().on_find_activate()
-
-    def on_menu_replace_activate(self, *extra):
-        self.current_doc().on_replace_activate()
-
     def on_action_fullscreen_change_state(self, action, state):
         window_state = self.get_window().get_state()
         is_full = window_state & Gdk.WindowState.FULLSCREEN
diff --git a/meld/resources/gtk/menus.ui b/meld/resources/gtk/menus.ui
index da58bfcc..959eab2e 100644
--- a/meld/resources/gtk/menus.ui
+++ b/meld/resources/gtk/menus.ui
@@ -39,6 +39,17 @@
         <attribute name="action">view.revert</attribute>
       </item>
     </section>
+    <section>
+      <attribute name="id">find-section</attribute>
+      <item>
+        <attribute name="label" translatable="yes">_Find…</attribute>
+        <attribute name="action">view.find</attribute>
+      </item>
+      <item>
+        <attribute name="label" translatable="yes">_Replace…</attribute>
+        <attribute name="action">view.find-replace</attribute>
+      </item>
+    </section>
     <section>
       <submenu>
         <attribute name="label" translatable="yes">View</attribute>
diff --git a/meld/vcview.py b/meld/vcview.py
index 7e1a78ff..f50707d0 100644
--- a/meld/vcview.py
+++ b/meld/vcview.py
@@ -201,6 +201,7 @@ class VcView(Gtk.VBox, tree.TreeviewCommon, MeldDoc):
         # Manually handle GAction additions
         actions = (
             ('compare', self.action_diff),
+            ('find', self.action_find),
             ('next-change', self.action_next_change),
             ('open-external', self.action_open_external),
             ('previous-change', self.action_previous_change),
@@ -896,10 +897,10 @@ class VcView(Gtk.VBox, tree.TreeviewCommon, MeldDoc):
     def action_next_change(self, *args):
         self.next_diff(Gdk.ScrollDirection.DOWN)
 
-    def action_refresh(self, *extra):
+    def action_refresh(self, *args):
         self.on_fileentry_file_set(self.fileentry)
 
-    def on_find_activate(self, *extra):
+    def action_find(self, *args):
         self.treeview.emit("start-interactive-search")
 
     def auto_compare(self):


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