[meld/ui-next] Move Refresh to a GAction



commit cd3199fcb10ab6ffc6e69d5c8b037dec4e8a84e1
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Fri Feb 22 10:53:57 2019 +1000

    Move Refresh to a GAction
    
    This change also *looks* like it's removing the sensitivity handling for
    Refresh, but actually we don't need it any more. Because the Refresh
    action is handled by the views and is always enabled, the mere presence
    of the action is enough for setting sensitivity.

 data/ui/meldapp-ui.xml      |  2 --
 meld/accelerators.py        |  1 +
 meld/dirdiff.py             |  3 ++-
 meld/filediff.py            |  3 ++-
 meld/melddoc.py             |  3 ---
 meld/meldwindow.py          | 24 +++---------------------
 meld/resources/gtk/menus.ui |  5 +++++
 meld/vcview.py              |  3 ++-
 8 files changed, 15 insertions(+), 29 deletions(-)
---
diff --git a/data/ui/meldapp-ui.xml b/data/ui/meldapp-ui.xml
index b38a7a0f..64628a15 100644
--- a/data/ui/meldapp-ui.xml
+++ b/data/ui/meldapp-ui.xml
@@ -43,8 +43,6 @@
       <menu action="FileFilters" />
       <separator/>
       <placeholder name="ViewDocSpecificPlaceholder" />
-      <separator/>
-      <menuitem action="Refresh" />
     </menu>
   </menubar>
 
diff --git a/meld/accelerators.py b/meld/accelerators.py
index 0861ce14..6a4d8fa1 100644
--- a/meld/accelerators.py
+++ b/meld/accelerators.py
@@ -6,6 +6,7 @@ def register_accels(app: Gtk.Application):
     view_accels = (
         ("view.next-change", ("<Alt>Down", "<Alt>KP_Down", "<Primary>D")),
         ("view.previous-change", ("<Alt>Up", "<Alt>KP_Up", "<Primary>E")),
+        ("view.refresh", ("<control>R", "F5")),
         ("win.stop", "Escape"),
     )
     for (name, accel) in view_accels:
diff --git a/meld/dirdiff.py b/meld/dirdiff.py
index 5f8ff84b..23059d68 100644
--- a/meld/dirdiff.py
+++ b/meld/dirdiff.py
@@ -414,6 +414,7 @@ class DirDiff(Gtk.VBox, tree.TreeviewCommon, MeldDoc):
         actions = (
             ('next-change', self.action_next_change),
             ('previous-change', self.action_previous_change),
+            ('refresh', self.action_refresh),
         )
         self.view_action_group = Gio.SimpleActionGroup()
         for name, callback in actions:
@@ -1693,7 +1694,7 @@ class DirDiff(Gtk.VBox, tree.TreeviewCommon, MeldDoc):
     def action_next_change(self, *args):
         self.next_diff(Gdk.ScrollDirection.DOWN)
 
-    def on_refresh_activate(self, *extra):
+    def action_refresh(self, *extra):
         self.on_fileentry_file_set(None)
 
     def on_delete_event(self):
diff --git a/meld/filediff.py b/meld/filediff.py
index e9f8439a..2d44c896 100644
--- a/meld/filediff.py
+++ b/meld/filediff.py
@@ -280,6 +280,7 @@ class FileDiff(Gtk.VBox, MeldDoc):
         actions = (
             ('next-change', self.action_next_change),
             ('previous-change', self.action_previous_change),
+            ('refresh', self.action_refresh),
         )
         for name, callback in actions:
             action = Gio.SimpleAction.new(name, None)
@@ -1904,7 +1905,7 @@ class FileDiff(Gtk.VBox, MeldDoc):
         encodings = [b.data.encoding for b in buffers]
         self.set_files(gfiles, encodings=encodings)
 
-    def on_refresh_activate(self, *extra):
+    def action_refresh(self, *extra):
         self.refresh_comparison()
 
     def queue_draw(self, junk=None):
diff --git a/meld/melddoc.py b/meld/melddoc.py
index d5509d09..2a9007de 100644
--- a/meld/melddoc.py
+++ b/meld/melddoc.py
@@ -178,9 +178,6 @@ class MeldDoc(LabeledObjectMixin, GObject.GObject):
     def open_external(self):
         pass
 
-    def on_refresh_activate(self, *extra):
-        pass
-
     def on_find_activate(self, *extra):
         pass
 
diff --git a/meld/meldwindow.py b/meld/meldwindow.py
index e413b669..d10f05c4 100644
--- a/meld/meldwindow.py
+++ b/meld/meldwindow.py
@@ -106,9 +106,6 @@ class MeldWindow(Gtk.ApplicationWindow):
             ("FileStatus", None, _("File Status")),
             ("VcStatus", None, _("Version Status")),
             ("FileFilters", None, _("File Filters")),
-            ("Refresh", Gtk.STOCK_REFRESH, None, "<Primary>R",
-                _("Refresh the view"),
-                self.on_menu_refresh_activate),
         )
         self.actiongroup = Gtk.ActionGroup(name='MainActions')
         self.actiongroup.set_translation_domain("meld")
@@ -135,19 +132,6 @@ class MeldWindow(Gtk.ApplicationWindow):
         self.toolbar.get_style_context().add_class(
             Gtk.STYLE_CLASS_PRIMARY_TOOLBAR)
 
-        # Alternate keybindings for a few commands.
-        extra_accels = (
-            ("F5", self.on_menu_refresh_activate),
-        )
-
-        accel_group = self.ui.get_accel_group()
-        for accel, callback in extra_accels:
-            keyval, mask = Gtk.accelerator_parse(accel)
-            accel_group.connect(keyval, mask, 0, callback)
-
-        # Initialise sensitivity for important actions
-        self._update_page_action_sensitivity()
-
         self.appvbox.pack_start(self.menubar, False, True, 0)
         self.toolbar_holder.pack_start(self.toolbar, True, True, 0)
 
@@ -184,6 +168,7 @@ class MeldWindow(Gtk.ApplicationWindow):
 
         # Initialise sensitivity for important actions
         self.lookup_action('stop').set_enabled(False)
+        self._update_page_action_sensitivity()
 
         # Fake out the spinner on Windows. See Gitlab issue #133.
         if os.name == 'nt':
@@ -286,10 +271,10 @@ class MeldWindow(Gtk.ApplicationWindow):
         if not isinstance(page, MeldDoc):
             for action in ("Cut", "Copy", "Paste",
                            "Find", "FindNext", "FindPrevious", "Replace",
-                           "Refresh", "GoToLine"):
+                           "GoToLine"):
                 self.actiongroup.get_action(action).set_sensitive(False)
         else:
-            for action in ("Find", "Refresh"):
+            for action in ("Find",):
                 self.actiongroup.get_action(action).set_sensitive(True)
             is_filediff = isinstance(page, FileDiff)
             for action in ("Cut", "Copy", "Paste", "FindNext", "FindPrevious",
@@ -391,9 +376,6 @@ class MeldWindow(Gtk.ApplicationWindow):
     def on_menu_redo_activate(self, *extra):
         self.current_doc().on_redo_activate()
 
-    def on_menu_refresh_activate(self, *extra):
-        self.current_doc().on_refresh_activate()
-
     def on_menu_find_activate(self, *extra):
         self.current_doc().on_find_activate()
 
diff --git a/meld/resources/gtk/menus.ui b/meld/resources/gtk/menus.ui
index fcc676a7..d0030b06 100644
--- a/meld/resources/gtk/menus.ui
+++ b/meld/resources/gtk/menus.ui
@@ -3,6 +3,11 @@
   <menu id="gear-menu">
     <section>
       <attribute name="display-hint">horizontal-buttons</attribute>
+      <item>
+        <attribute name="label" translatable="yes">Refresh</attribute>
+        <attribute name="action">view.refresh</attribute>
+        <attribute name="verb-icon">view-refresh-symbolic</attribute>
+      </item>
       <item>
         <attribute name="label" translatable="yes">Stop</attribute>
         <attribute name="action">win.stop</attribute>
diff --git a/meld/vcview.py b/meld/vcview.py
index 24175334..d983af90 100644
--- a/meld/vcview.py
+++ b/meld/vcview.py
@@ -197,6 +197,7 @@ class VcView(Gtk.VBox, tree.TreeviewCommon, MeldDoc):
         actions = (
             ('next-change', self.action_next_change),
             ('previous-change', self.action_previous_change),
+            ('refresh', self.action_refresh),
         )
         self.view_action_group = Gio.SimpleActionGroup()
         for name, callback in actions:
@@ -884,7 +885,7 @@ class VcView(Gtk.VBox, tree.TreeviewCommon, MeldDoc):
     def action_next_change(self, *args):
         self.next_diff(Gdk.ScrollDirection.DOWN)
 
-    def on_refresh_activate(self, *extra):
+    def action_refresh(self, *extra):
         self.on_fileentry_file_set(self.fileentry)
 
     def on_find_activate(self, *extra):


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