[shotwell] Use GtkApplication menubar, get accels for free



commit f8f42e7a7dee8cedbb115309671468a7fd1e81e0
Author: Jens Georg <mail jensge org>
Date:   Mon Nov 14 23:27:25 2016 +0100

    Use GtkApplication menubar, get accels for free
    
    Signed-off-by: Jens Georg <mail jensge org>

 src/AppWindow.vala             |    3 +++
 src/Application.vala           |    8 ++++++++
 src/Page.vala                  |   13 ++++++-------
 src/direct/DirectWindow.vala   |    3 ++-
 src/library/LibraryWindow.vala |   30 +++++-------------------------
 5 files changed, 24 insertions(+), 33 deletions(-)
---
diff --git a/src/AppWindow.vala b/src/AppWindow.vala
index 677a1c6..bdb7bd2 100644
--- a/src/AppWindow.vala
+++ b/src/AppWindow.vala
@@ -276,9 +276,12 @@ public abstract class PageWindow : Gtk.ApplicationWindow {
     }
     
     public PageWindow() {
+        Object (application: Application.get_instance().get_system_app ());
+
         // the current page needs to know when modifier keys are pressed
         add_events(Gdk.EventMask.KEY_PRESS_MASK | Gdk.EventMask.KEY_RELEASE_MASK
             | Gdk.EventMask.STRUCTURE_MASK);
+        set_show_menubar (true);
     }
     
     public Page? get_current_page() {
diff --git a/src/Application.vala b/src/Application.vala
index 21055dd..4a24fd4 100644
--- a/src/Application.vala
+++ b/src/Application.vala
@@ -29,6 +29,10 @@ public class Application {
         return fixup_raw_thumbs;
     }
 
+    public Gtk.Application get_system_app () {
+        return system_app;
+    }
+
     private bool running = false;
     private bool exiting_fired = false;
 
@@ -95,6 +99,10 @@ public class Application {
         get_instance().system_app.set_accels_for_action (action, accel);
     }
 
+    public static void set_menubar (GLib.MenuModel? model) {
+        get_instance().system_app.set_menubar (model);
+    }
+
     /**
      * @brief Signal handler for GApplication's 'command-line' signal.
      *
diff --git a/src/Page.vala b/src/Page.vala
index e02028b..d13d5c9 100644
--- a/src/Page.vala
+++ b/src/Page.vala
@@ -205,12 +205,11 @@ public abstract class Page : Gtk.ScrolledWindow {
         return event_source;
     }
 
-    private Gtk.MenuBar menubar;
-
-    public Gtk.MenuBar get_menubar() {
-        if (this.menubar == null) {
-            var model = builder.get_object ("MenuBar") as GLib.Menu;
+    private bool menubar_injected = false;
+    public GLib.MenuModel get_menubar() {
+        var model = builder.get_object ("MenuBar") as GLib.Menu;
 
+        if (!menubar_injected) {
             // Collect injected UI elements and add them to the UI manager
             InjectionGroup[] injection_groups = init_collect_injection_groups();
             foreach (InjectionGroup group in injection_groups) {
@@ -246,10 +245,10 @@ public abstract class Page : Gtk.ScrolledWindow {
                 }
             }
 
-            this.menubar = new Gtk.MenuBar.from_model (model);
+            this.menubar_injected = true;
         }
 
-        return this.menubar;
+        return model;
     }
 
     public virtual Gtk.Toolbar get_toolbar() {
diff --git a/src/direct/DirectWindow.vala b/src/direct/DirectWindow.vala
index 2a33423..e1cbf75 100644
--- a/src/direct/DirectWindow.vala
+++ b/src/direct/DirectWindow.vala
@@ -21,10 +21,11 @@ public class DirectWindow : AppWindow {
         // simple layout: menu on top, photo in center, toolbar along bottom (mimicking the
         // PhotoPage in the library, but without the sidebar)
         Gtk.Box layout = new Gtk.Box(Gtk.Orientation.VERTICAL, 0);
-        layout.pack_start(direct_photo_page.get_menubar(), false, false, 0);
         layout.pack_start(direct_photo_page, true, true, 0);
         layout.pack_end(direct_photo_page.get_toolbar(), false, false, 0);
         
+        Application.set_menubar (direct_photo_page.get_menubar ());
+
         add(layout);
     }
     
diff --git a/src/library/LibraryWindow.vala b/src/library/LibraryWindow.vala
index e6b9d11..894e61a 100644
--- a/src/library/LibraryWindow.vala
+++ b/src/library/LibraryWindow.vala
@@ -173,22 +173,7 @@ public class LibraryWindow : AppWindow {
         
         // setup search bar and add its accelerators to the window
         search_toolbar = new SearchFilterToolbar(search_actions);
-        
-/*        try {
-            File ui_file = Resources.get_ui("top.ui");
-            ui.add_ui_from_file(ui_file.get_path());
-        } catch (Error e) {
-            error(e.message);
-        }
-        
-        Gtk.MenuBar? menubar = ui.get_widget("/MenuBar") as Gtk.MenuBar;
-        layout.add(menubar);
-        
-        // We never want to invoke show_all() on the menubar since that will show empty menus,
-        // which should be hidden.
-        menubar.no_show_all = true;
-        */
-        
+
         // create the main layout & start at the Library page
         create_layout(library_branch.photos_entry.get_page());
         
@@ -1221,10 +1206,8 @@ public class LibraryWindow : AppWindow {
         
         Page current_page = get_current_page();
         if (current_page != null) {
-            var menubar = current_page.get_menubar ();
-            if (menubar != null) {
-                layout.remove (menubar);
-            }
+            set_show_menubar (false);
+            Application.set_menubar (null);
 
             Gtk.Toolbar toolbar = current_page.get_toolbar();
             if (toolbar != null)
@@ -1281,11 +1264,8 @@ public class LibraryWindow : AppWindow {
         
         page.switched_to();
 
-        var menubar = page.get_menubar ();
-        if (menubar != null) {
-            layout.pack_start (menubar, false, false);
-            menubar.show_all ();
-        }
+        Application.set_menubar (page.get_menubar ());
+        set_show_menubar (true);
         
         Gtk.Toolbar toolbar = page.get_toolbar();
         if (toolbar != null) {


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