[meld/ui-next] meldwindow: Move fullscreen to GAction and app menu



commit b33ac6a90f15412f7dd157c68a21687d1230be67
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Mon Jan 28 10:41:47 2019 +1000

    meldwindow: Move fullscreen to GAction and app menu

 data/ui/meldapp-ui.xml      |  1 -
 meld/meldwindow.py          | 22 ++++++++++++++--------
 meld/resources/gtk/menus.ui |  9 +++++++++
 3 files changed, 23 insertions(+), 9 deletions(-)
---
diff --git a/data/ui/meldapp-ui.xml b/data/ui/meldapp-ui.xml
index efbb6d42..e16758fd 100644
--- a/data/ui/meldapp-ui.xml
+++ b/data/ui/meldapp-ui.xml
@@ -36,7 +36,6 @@
     </menu>
     <menu action="ViewMenu">
       <placeholder name="ViewBarPlaceholder" />
-      <menuitem action="Fullscreen" />
       <separator/>
       <placeholder name="ViewUtilityPlaceholder" />
       <separator/>
diff --git a/meld/meldwindow.py b/meld/meldwindow.py
index 4366a5a1..78e1d592 100644
--- a/meld/meldwindow.py
+++ b/meld/meldwindow.py
@@ -119,15 +119,9 @@ class MeldWindow(Gtk.ApplicationWindow):
                 _("Refresh the view"),
                 self.on_menu_refresh_activate),
         )
-        toggleactions = (
-            ("Fullscreen", None, _("Fullscreen"), "F11",
-                _("View the comparison in fullscreen"),
-                self.on_action_fullscreen_toggled, False),
-        )
         self.actiongroup = Gtk.ActionGroup(name='MainActions')
         self.actiongroup.set_translation_domain("meld")
         self.actiongroup.add_actions(actions)
-        self.actiongroup.add_toggle_actions(toggleactions)
 
         recent_action = Gtk.RecentAction(
             name="Recent",  label=_("Open Recent"),
@@ -190,6 +184,17 @@ class MeldWindow(Gtk.ApplicationWindow):
             action.connect('activate', callback)
             self.add_action(action)
 
+        state_actions = (
+            (
+                "fullscreen", self.on_action_fullscreen_change_state,
+                GLib.Variant.new_boolean(False)
+            ),
+        )
+        for (name, callback, state) in state_actions:
+            action = Gio.SimpleAction.new_stateful(name, None, state)
+            action.connect('change-state', callback)
+            self.add_action(action)
+
         # Fake out the spinner on Windows. See Gitlab issue #133.
         if os.name == 'nt':
             for attr in ('stop', 'hide', 'show', 'start'):
@@ -447,10 +452,11 @@ class MeldWindow(Gtk.ApplicationWindow):
         elif isinstance(widget, Gtk.TextView):
             widget.emit("paste-clipboard")
 
-    def on_action_fullscreen_toggled(self, widget):
+    def on_action_fullscreen_change_state(self, action, state):
         window_state = self.get_window().get_state()
         is_full = window_state & Gdk.WindowState.FULLSCREEN
-        if widget.get_active() and not is_full:
+        action.set_state(state)
+        if state and not is_full:
             self.fullscreen()
         elif is_full:
             self.unfullscreen()
diff --git a/meld/resources/gtk/menus.ui b/meld/resources/gtk/menus.ui
index 464ca0e7..b1a0755c 100644
--- a/meld/resources/gtk/menus.ui
+++ b/meld/resources/gtk/menus.ui
@@ -1,6 +1,15 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
   <menu id="gear-menu">
+    <section>
+      <attribute name="display-hint">horizontal-buttons</attribute>
+      <item>
+        <attribute name="label" translatable="yes">Fullscreen</attribute>
+        <attribute name="action">win.fullscreen</attribute>
+        <attribute name="verb-icon">view-fullscreen-symbolic</attribute>
+        <attribute name="accel">F11</attribute>
+      </item>
+    </section>
     <section>
       <submenu>
         <attribute name="label" translatable="yes">View</attribute>


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