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



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

    Move Stop to a GAction

 data/ui/meldapp-ui.xml      |  2 --
 meld/accelerators.py        |  1 +
 meld/melddoc.py             |  2 +-
 meld/meldwindow.py          | 16 ++++++++--------
 meld/resources/gtk/menus.ui |  5 +++++
 5 files changed, 15 insertions(+), 11 deletions(-)
---
diff --git a/data/ui/meldapp-ui.xml b/data/ui/meldapp-ui.xml
index 50b5fdb5..b38a7a0f 100644
--- a/data/ui/meldapp-ui.xml
+++ b/data/ui/meldapp-ui.xml
@@ -44,14 +44,12 @@
       <separator/>
       <placeholder name="ViewDocSpecificPlaceholder" />
       <separator/>
-      <menuitem action="Stop" />
       <menuitem action="Refresh" />
     </menu>
   </menubar>
 
   <toolbar action="Toolbar">
     <placeholder name="GeneralActions" />
-    <toolitem action="Stop"/>
     <separator/>
     <placeholder name="SpecialActions" />
     <separator/>
diff --git a/meld/accelerators.py b/meld/accelerators.py
index 222d02c1..0861ce14 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")),
+        ("win.stop", "Escape"),
     )
     for (name, accel) in view_accels:
         accel = accel if isinstance(accel, tuple) else (accel,)
diff --git a/meld/melddoc.py b/meld/melddoc.py
index 0f185e54..d5509d09 100644
--- a/meld/melddoc.py
+++ b/meld/melddoc.py
@@ -111,7 +111,7 @@ class MeldDoc(LabeledObjectMixin, GObject.GObject):
         """Get the comparison type and URI(s) being compared"""
         pass
 
-    def on_action_cancel(self, *args):
+    def action_stop(self, *args):
         if self.scheduler.tasks_pending():
             self.scheduler.remove_task(self.scheduler.get_current_task())
 
diff --git a/meld/meldwindow.py b/meld/meldwindow.py
index 235e80c2..e413b669 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")),
-            ("Stop", Gtk.STOCK_STOP, None, "Escape",
-                _("Stop the current action"),
-                self.on_toolbar_stop_clicked),
             ("Refresh", Gtk.STOCK_REFRESH, None, "<Primary>R",
                 _("Refresh the view"),
                 self.on_menu_refresh_activate),
@@ -149,7 +146,6 @@ class MeldWindow(Gtk.ApplicationWindow):
             accel_group.connect(keyval, mask, 0, callback)
 
         # Initialise sensitivity for important actions
-        self.actiongroup.get_action("Stop").set_sensitive(False)
         self._update_page_action_sensitivity()
 
         self.appvbox.pack_start(self.menubar, False, True, 0)
@@ -168,6 +164,7 @@ class MeldWindow(Gtk.ApplicationWindow):
         actions = (
             ("close", self.on_menu_close_activate),
             ("new-tab", self.on_action_new_tab_activate),
+            ("stop", self.action_stop),
         )
         for name, callback in actions:
             action = Gio.SimpleAction.new(name, None)
@@ -185,6 +182,9 @@ class MeldWindow(Gtk.ApplicationWindow):
             action.connect('change-state', callback)
             self.add_action(action)
 
+        # Initialise sensitivity for important actions
+        self.lookup_action('stop').set_enabled(False)
+
         # Fake out the spinner on Windows. See Gitlab issue #133.
         if os.name == 'nt':
             for attr in ('stop', 'hide', 'show', 'start'):
@@ -245,14 +245,14 @@ class MeldWindow(Gtk.ApplicationWindow):
             self.spinner.hide()
             self.spinner.set_tooltip_text("")
             self.idle_hooked = None
-            self.actiongroup.get_action("Stop").set_sensitive(False)
+            self.lookup_action('stop').set_enabled(False)
         return pending
 
     def on_scheduler_runnable(self, sched):
         if not self.idle_hooked:
             self.spinner.show()
             self.spinner.start()
-            self.actiongroup.get_action("Stop").set_sensitive(True)
+            self.lookup_action('stop').set_enabled(True)
             self.idle_hooked = GLib.idle_add(self.on_idle)
 
     @Template.Callback()
@@ -448,8 +448,8 @@ class MeldWindow(Gtk.ApplicationWindow):
     def on_open_external(self, *args):
         self.current_doc().open_external()
 
-    def on_toolbar_stop_clicked(self, *args):
-        self.current_doc().on_action_cancel()
+    def action_stop(self, *args):
+        self.current_doc().action_stop()
 
     def page_removed(self, page, status):
         if hasattr(page, 'scheduler'):
diff --git a/meld/resources/gtk/menus.ui b/meld/resources/gtk/menus.ui
index b1a0755c..fcc676a7 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">Stop</attribute>
+        <attribute name="action">win.stop</attribute>
+        <attribute name="verb-icon">process-stop-symbolic</attribute>
+      </item>
       <item>
         <attribute name="label" translatable="yes">Fullscreen</attribute>
         <attribute name="action">win.fullscreen</attribute>


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