[gnome-news] application: Migrate to Primary Menu



commit 56a97929acd50967db6581d4528828184ac2c9df
Author: Christopher Davis <brainblasted disroot org>
Date:   Mon Jan 21 01:57:46 2019 -0500

    application: Migrate to Primary Menu
    
    As per https://gitlab.gnome.org/GNOME/Initiatives/issues/4,
    we are retiring the Shell App Menu in favor of an in-window
    Primary Menu.

 data/gtk/menus.ui        |   9 +-
 data/ui/headerbar.ui     | 239 +++++++++++++++++++++++++++--------------------
 gnomenews/application.py |   2 +
 gnomenews/toolbar.py     |   6 ++
 4 files changed, 147 insertions(+), 109 deletions(-)
---
diff --git a/data/gtk/menus.ui b/data/gtk/menus.ui
index 659d969..e796e70 100644
--- a/data/gtk/menus.ui
+++ b/data/gtk/menus.ui
@@ -1,16 +1,11 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface domain="gnome-news">
-  <menu id="app-menu">
+  <menu id="primary-menu">
     <section>
       <item>
-        <attribute name="label" translatable="yes">About</attribute>
+        <attribute name="label" translatable="yes">About News</attribute>
         <attribute name="action">app.about</attribute>
       </item>
-      <item>
-        <attribute name="label" translatable="yes">Quit</attribute>
-        <attribute name="action">app.quit</attribute>
-        <attribute name="accel">&lt;Primary&gt;q</attribute>
-      </item>
     </section>
   </menu>
 </interface>
diff --git a/data/ui/headerbar.ui b/data/ui/headerbar.ui
index 63f26ba..c89bc8b 100644
--- a/data/ui/headerbar.ui
+++ b/data/ui/headerbar.ui
@@ -1,32 +1,35 @@
 <?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.22.0 -->
 <interface domain="gnome-news">
-  <!-- interface-requires gtk+ 3.10 -->
+  <requires lib="gtk+" version="3.12"/>
   <object class="GtkPopover" id="add-popover">
     <property name="visible">True</property>
     <property name="can_focus">False</property>
-    <property name="valign">center</property>
-    <property name="sensitive">True</property>
     <property name="tooltip_text" translatable="yes">Add a new feed</property>
+    <property name="valign">center</property>
     <child>
       <object class="GtkBox" id="add-box">
         <property name="visible">True</property>
         <property name="can_focus">False</property>
         <property name="valign">center</property>
-        <property name="sensitive">True</property>
         <property name="orientation">vertical</property>
-        <property name="margin">10</property>
         <property name="spacing">6</property>
         <child>
           <object class="GtkLabel" id="add-box-enter-address-label">
             <property name="visible">True</property>
-            <property name="can-focus">False</property>
+            <property name="can_focus">False</property>
             <property name="halign">start</property>
-            <property name="hexpand">true</property>
+            <property name="hexpand">True</property>
             <property name="label" translatable="yes">Enter feed address to add</property>
             <style>
               <class name="dim-label"/>
             </style>
           </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">0</property>
+          </packing>
         </child>
         <child>
           <object class="GtkBox" id="add-entry-box">
@@ -36,22 +39,28 @@
             <child>
               <object class="GtkEntry" id="new-url">
                 <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="width_chars">30</property>
                 <property name="input_purpose">url</property>
-                <property name="width-chars">30</property>
               </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">0</property>
+              </packing>
             </child>
             <child>
               <object class="GtkStack" id="add-button-stack">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
-                <property name="vhomogeneous">True</property>
                 <property name="interpolate_size">True</property>
                 <child>
                   <object class="GtkButton" id="add-button">
+                    <property name="label" translatable="yes">Add</property>
                     <property name="visible">True</property>
-                    <property name="can_focus">False</property>
                     <property name="sensitive">False</property>
-                    <property name="label" translatable="yes">Add</property>
+                    <property name="can_focus">False</property>
+                    <property name="receives_default">False</property>
                     <style>
                       <class name="suggested-action"/>
                     </style>
@@ -64,200 +73,226 @@
                   <object class="GtkSpinner">
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
-                    <property name="active">True</property>
-                    <property name="valign">center</property>
                     <property name="halign">start</property>
+                    <property name="valign">center</property>
+                    <property name="active">True</property>
                   </object>
                   <packing>
                     <property name="name">spinner</property>
+                    <property name="position">1</property>
                   </packing>
                 </child>
               </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">1</property>
+              </packing>
             </child>
           </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">1</property>
+          </packing>
         </child>
         <child>
           <object class="GtkLabel" id="add-box-already-subscribed-label">
-            <property name="visible">False</property>
-            <property name="can-focus">False</property>
+            <property name="can_focus">False</property>
             <property name="halign">start</property>
             <property name="label" translatable="yes">You are already subscribed to that feed!</property>
           </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">2</property>
+          </packing>
         </child>
       </object>
     </child>
   </object>
-  <menu id="selection-menu">
-    <section>
-      <item>
-        <attribute name="label" translatable="yes">Select All</attribute>
-        <attribute name="action">win.selectAll</attribute>
-        <attribute name="accel">&lt;Primary&gt;a</attribute>
-      </item>
-      <item>
-        <attribute name="label" translatable="yes">Select None</attribute>
-        <attribute name="action">win.selectNone</attribute>
-      </item>
-    </section>
-  </menu>
-  <object class="GtkMenuButton" id="selection-menu-button">
-    <property name="menu-model">selection-menu</property>
+  <object class="GtkHeaderBar" id="header-bar">
     <property name="visible">True</property>
-    <property name="can-focus">True</property>
-    <property name="relief">none</property>
-    <property name="can-focus">False</property>
+    <property name="can_focus">False</property>
+    <property name="vexpand">False</property>
+    <property name="show_close_button">True</property>
     <child>
-      <object class="GtkBox" id="selection-menu-button-box">
+      <object class="GtkMenuButton" id="primary-menu-button">
         <property name="visible">True</property>
-        <property name="can-focus">False</property>
-        <property name="orientation">horizontal</property>
-        <property name="spacing">6</property>
-        <child>
-          <object class="GtkLabel" id="selection-menu-button-label">
-            <property name="visible">True</property>
-            <property name="can-focus">False</property>
-            <property name="label" translatable="yes">Click on items to select them</property>
-          </object>
-          <packing>
-            <property name="pack-type">start</property>
-            <property name="position">0</property>
-          </packing>
-        </child>
+        <property name="can_focus">True</property>
+        <property name="receives_default">True</property>
+        <property name="valign">center</property>
         <child>
-          <object class="GtkArrow" id="selection-menu-button-arrow">
+          <object class="GtkImage">
             <property name="visible">True</property>
-            <property name="can-focus">False</property>
-            <property name="arrow-type">down</property>
-            <property name="shadow-type">none</property>
+            <property name="can_focus">False</property>
+            <property name="icon_name">open-menu-symbolic</property>
           </object>
-          <packing>
-            <property name="pack-type">start</property>
-            <property name="position">1</property>
-          </packing>
         </child>
+        <style>
+          <class name="image-button"/>
+        </style>
       </object>
+      <packing>
+        <property name="pack_type">end</property>
+      </packing>
     </child>
-    <style>
-      <class name="selection-menu"/>
-    </style>
-  </object>
-  <object class="GtkHeaderBar" id="header-bar">
-    <property name="visible">True</property>
-    <property name="vexpand">False</property>
-    <property name="show_close_button">True</property>
     <child>
       <object class="GtkButton" id="starred-button">
         <property name="can_focus">False</property>
-        <property name="valign">center</property>
-        <property name="sensitive">True</property>
+        <property name="receives_default">False</property>
         <property name="tooltip_text" translatable="yes">Mark this article as starred</property>
-        <style>
-          <class name="image-button"/>
-        </style>
+        <property name="valign">center</property>
         <child>
           <object class="GtkImage" id="starred-button-image">
             <property name="visible">True</property>
             <property name="can_focus">False</property>
-            <property name="icon-name">non-starred-symbolic</property>
-            <property name="icon-size">1</property>
+            <property name="icon_name">non-starred-symbolic</property>
+            <property name="icon_size">1</property>
           </object>
         </child>
+        <style>
+          <class name="image-button"/>
+        </style>
       </object>
       <packing>
         <property name="pack_type">end</property>
+        <property name="position">1</property>
       </packing>
     </child>
     <child>
       <object class="GtkToggleButton" id="search-button">
         <property name="visible">True</property>
         <property name="can_focus">False</property>
-        <property name="valign">center</property>
-        <property name="sensitive">True</property>
+        <property name="receives_default">False</property>
         <property name="tooltip_text" translatable="yes">Search</property>
-        <style>
-          <class name="image-button"/>
-        </style>
+        <property name="valign">center</property>
         <child>
           <object class="GtkImage" id="search-button-image">
             <property name="visible">True</property>
             <property name="can_focus">False</property>
-            <property name="icon-name">edit-find-symbolic</property>
-            <property name="icon-size">1</property>
+            <property name="icon_name">edit-find-symbolic</property>
+            <property name="icon_size">1</property>
           </object>
         </child>
+        <style>
+          <class name="image-button"/>
+        </style>
       </object>
       <packing>
         <property name="pack_type">end</property>
+        <property name="position">2</property>
       </packing>
     </child>
     <child>
       <object class="GtkToggleButton" id="select-button">
         <property name="can_focus">False</property>
-        <property name="valign">center</property>
-        <property name="sensitive">True</property>
+        <property name="receives_default">False</property>
         <property name="tooltip_text" translatable="yes">Select</property>
-        <style>
-          <class name="image-button"/>
-        </style>
+        <property name="valign">center</property>
         <child>
           <object class="GtkImage" id="select-button-image">
             <property name="visible">True</property>
             <property name="can_focus">False</property>
-            <property name="icon-name">object-select-symbolic</property>
-            <property name="icon-size">1</property>
+            <property name="icon_name">object-select-symbolic</property>
+            <property name="icon_size">1</property>
           </object>
         </child>
+        <style>
+          <class name="image-button"/>
+        </style>
       </object>
       <packing>
         <property name="pack_type">end</property>
+        <property name="position">3</property>
       </packing>
     </child>
     <child>
       <object class="GtkMenuButton" id="add-toggle-button">
         <property name="visible">True</property>
         <property name="can_focus">False</property>
-        <property name="valign">center</property>
-        <property name="sensitive">True</property>
-        <property name="use_popover">True</property>
+        <property name="receives_default">False</property>
         <property name="tooltip_text" translatable="yes">Add a new feed</property>
-        <style>
-              <class name="image-button"/>
-        </style>
+        <property name="valign">center</property>
         <child>
           <object class="GtkImage" id="add-button-image">
             <property name="visible">True</property>
             <property name="can_focus">False</property>
-            <property name="icon-name">list-add-symbolic</property>
-            <property name="icon-size">1</property>
+            <property name="icon_name">list-add-symbolic</property>
+            <property name="icon_size">1</property>
           </object>
         </child>
+        <style>
+          <class name="image-button"/>
+        </style>
       </object>
       <packing>
-        <property name="pack_type">start</property>
+        <property name="position">4</property>
       </packing>
     </child>
     <child>
       <object class="GtkButton" id="back-button">
         <property name="visible">True</property>
         <property name="can_focus">False</property>
-        <property name="valign">center</property>
-        <property name="sensitive">True</property>
+        <property name="receives_default">False</property>
         <property name="tooltip_text" translatable="yes">Back</property>
-        <style>
-              <class name="image-button"/>
-        </style>
+        <property name="valign">center</property>
         <child>
           <object class="GtkImage" id="back-button-image">
             <property name="visible">True</property>
             <property name="can_focus">False</property>
-            <property name="icon-name">go-previous-symbolic</property>
-            <property name="icon-size">1</property>
+            <property name="icon_name">go-previous-symbolic</property>
+            <property name="icon_size">1</property>
           </object>
         </child>
+        <style>
+          <class name="image-button"/>
+        </style>
       </object>
       <packing>
-        <property name="pack_type">start</property>
+        <property name="position">5</property>
       </packing>
     </child>
   </object>
+  <object class="GtkMenuButton" id="selection-menu-button">
+    <property name="visible">True</property>
+    <property name="can_focus">False</property>
+    <property name="receives_default">False</property>
+    <property name="relief">none</property>
+    <child>
+      <object class="GtkBox" id="selection-menu-button-box">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="spacing">6</property>
+        <child>
+          <object class="GtkLabel" id="selection-menu-button-label">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="label" translatable="yes">Click on items to select them</property>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkArrow" id="selection-menu-button-arrow">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="arrow_type">down</property>
+            <property name="shadow_type">none</property>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+    <style>
+      <class name="selection-menu"/>
+    </style>
+  </object>
 </interface>
diff --git a/gnomenews/application.py b/gnomenews/application.py
index 91bb63d..273ad5d 100644
--- a/gnomenews/application.py
+++ b/gnomenews/application.py
@@ -68,6 +68,8 @@ class Application(Gtk.Application):
             action.connect("activate", getattr(self, action_name))
             self.add_action(action)
 
+        self.set_accels_for_action("app.quit", ["<Primary>q"])
+
         Gtk.Application.do_startup(self)
 
     @log
diff --git a/gnomenews/toolbar.py b/gnomenews/toolbar.py
index cd4a8a9..eea0fbd 100644
--- a/gnomenews/toolbar.py
+++ b/gnomenews/toolbar.py
@@ -77,6 +77,12 @@ class Toolbar(GObject.GObject):
         self._starred_button.connect('clicked', self._toggle_starred)
         self.starred = False
 
+        # Primary menu
+        self._ui.add_from_resource('/org/gnome/News/gtk/menus.ui')
+        self._primary_menu_model = self._ui.get_object('primary-menu')
+        self._primary_menu_button = self._ui.get_object('primary-menu-button')
+        self._primary_menu_button.set_menu_model(self._primary_menu_model)
+
         self.set_state(ToolbarState.MAIN)
 
         self._stack_switcher.show()


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