[meld/deprecation-cleanup: 14/48] meldwindow: Add simple HeaderBar for the ex-application menu to live in



commit 1fdd537e1326ed4e97e0897ee4950e831be68c08
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Fri Nov 30 11:50:16 2018 +1000

    meldwindow: Add simple HeaderBar for the ex-application menu to live in
    
    Ideally we'd move a bunch of our UI there, but at this point we just
    want to meet the GNOME goal of removing application menu usage, and this
    seems like the easiest and most future-proof option.

 data/ui/application.ui |  2 +-
 data/ui/meldapp.ui     | 23 +++++++++++++++++++++++
 meld/meldapp.py        |  5 -----
 meld/meldwindow.py     | 13 +++++++++++++
 4 files changed, 37 insertions(+), 6 deletions(-)
---
diff --git a/data/ui/application.ui b/data/ui/application.ui
index d4a6c14e..3ea321dd 100644
--- a/data/ui/application.ui
+++ b/data/ui/application.ui
@@ -44,7 +44,7 @@ Josef Vybíral</property>
       </object>
     </child>
   </object>
-  <menu id="app-menu">
+  <menu id="gear-menu">
     <section>
       <item>
         <attribute name="label" translatable="yes">_Preferences</attribute>
diff --git a/data/ui/meldapp.ui b/data/ui/meldapp.ui
index 56a2d56f..a2f39958 100644
--- a/data/ui/meldapp.ui
+++ b/data/ui/meldapp.ui
@@ -7,6 +7,29 @@
     <property name="title" translatable="yes">Meld</property>
     <property name="icon_name">org.gnome.meld</property>
     <signal name="delete-event" handler="on_delete_event" swapped="no"/>
+
+    <child type="titlebar">
+      <object class="GtkHeaderBar" id="header_bar">
+        <property name="show-close-button">true</property>
+        <property name="visible">true</property>
+        <child>
+          <object class="GtkMenuButton" id="gear_menu_button">
+            <property name="visible">true</property>
+            <property name="can_focus">False</property>
+            <child>
+              <object class="GtkImage">
+                <property name="icon-name">open-menu-symbolic</property>
+                <property name="visible">true</property>
+              </object>
+            </child>
+          </object>
+          <packing>
+            <property name="pack-type">end</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+
     <child>
       <object class="GtkVBox" id="appvbox">
         <property name="visible">True</property>
diff --git a/meld/meldapp.py b/meld/meldapp.py
index aac8b550..0bf28715 100644
--- a/meld/meldapp.py
+++ b/meld/meldapp.py
@@ -65,11 +65,6 @@ class MeldApp(Gtk.Application):
             action.connect('activate', callback)
             self.add_action(action)
 
-        # TODO: Should not be necessary but Builder doesn't understand Menus
-        builder = meld.ui.util.get_builder("application.ui")
-        menu = builder.get_object("app-menu")
-        self.set_app_menu(menu)
-        # self.set_menubar()
         self.new_window()
 
     def do_activate(self):
diff --git a/meld/meldwindow.py b/meld/meldwindow.py
index 4d66a281..ce98dca8 100644
--- a/meld/meldwindow.py
+++ b/meld/meldwindow.py
@@ -251,6 +251,7 @@ class MeldWindow(Component):
         self.ui.ensure_update()
         self.diff_handler = None
         self.undo_handlers = tuple()
+        self.widget.connect('realize', self.on_realize)
         self.widget.connect('focus_in_event', self.on_focus_change)
         self.widget.connect('focus_out_event', self.on_focus_change)
 
@@ -262,6 +263,18 @@ class MeldWindow(Component):
         shortcut_window = builder.get_object("shortcuts-meld")
         self.widget.set_help_overlay(shortcut_window)
 
+    def on_realize(self, user_data):
+        # FIXME: Ideally this would be in do_realize, and we'd get the menu
+        # from resources, but MeldWindow would need to be a real GtkWindow
+        # subclass, and we'd need to... have resources.
+        builder = meld.ui.util.get_builder("application.ui")
+        menu = builder.get_object("gear-menu")
+        self.gear_menu_button.set_popover(
+            Gtk.Popover.new_from_model(self.gear_menu_button, menu))
+
+        app = self.widget.get_application()
+        meld.ui.util.extract_accels_from_menu(menu, app)
+
     def _on_recentmenu_map(self, recentmenu):
         for imagemenuitem in recentmenu.get_children():
             imagemenuitem.set_tooltip_text(imagemenuitem.get_label())


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