[shotwell/wip/gtk4: 86/94] Handle menu bar ourselves




commit 7048d8be214af5e30bc9de7835bdc2529f02cabb
Author: Jens Georg <mail jensge org>
Date:   Thu Apr 21 10:23:53 2022 +0200

    Handle menu bar ourselves

 src/AppWindow.vala             | 28 ++++++++++++++++++++++++++++
 src/Application.vala           |  4 ----
 src/FullscreenWindow.vala      |  3 ---
 src/PageWindow.vala            |  3 ---
 src/direct/DirectWindow.vala   |  2 +-
 src/library/LibraryWindow.vala |  6 ++----
 6 files changed, 31 insertions(+), 15 deletions(-)
---
diff --git a/src/AppWindow.vala b/src/AppWindow.vala
index eef1ade5..9fd98235 100644
--- a/src/AppWindow.vala
+++ b/src/AppWindow.vala
@@ -17,6 +17,10 @@ public abstract class AppWindow : PageWindow {
     
     private static FullscreenWindow fullscreen_window = null;
     private static CommandManager command_manager = null;
+
+    private Gtk.Box content_box = new Gtk.Box(Gtk.Orientation.VERTICAL, 0);
+    private Gtk.PopoverMenuBar menu_bar;
+    private Gtk.Revealer menu_revealer = new Gtk.Revealer();
     
     // the AppWindow maintains its own UI manager because the first UIManager an action group is
     // added to is the one that claims its accelerators
@@ -24,9 +28,33 @@ public abstract class AppWindow : PageWindow {
     protected int pos_x = 0;
     protected int pos_y = 0;
     
+    public new void set_child(Gtk.Widget child) {
+        content_box.append(child);
+    }
+
+    public void set_menubar(GLib.MenuModel? menu_model) {
+        // TODO: Obey Gtk.Settings:gtk-shell-shows-menubar
+        if (menu_model == null) {
+            menu_revealer.set_reveal_child(false);
+            menu_revealer.set_child(null);
+            menu_bar = null;
+
+            return;
+        }
+
+        menu_bar = new Gtk.PopoverMenuBar.from_model(menu_model);
+        menu_revealer.set_child(menu_bar);
+        menu_revealer.set_reveal_child(true);
+    }
+
     protected AppWindow() {
         base();
 
+        menu_revealer.vexpand = false;
+        menu_revealer.hexpand = true;
+        content_box.append(menu_revealer);
+        base.set_child(content_box);
+
         // although there are multiple AppWindow types, only one may exist per-process
         assert(instance == null);
         instance = this;
diff --git a/src/Application.vala b/src/Application.vala
index a52e0313..de156aaf 100644
--- a/src/Application.vala
+++ b/src/Application.vala
@@ -99,10 +99,6 @@ 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 'activate' signal.
      *
diff --git a/src/FullscreenWindow.vala b/src/FullscreenWindow.vala
index 39ee13ea..2c6d4be0 100644
--- a/src/FullscreenWindow.vala
+++ b/src/FullscreenWindow.vala
@@ -103,9 +103,6 @@ public class FullscreenWindow : PageWindow {
 
         // Toolbar steals keyboard focus from page, put it back again
         page.grab_focus ();
-
-        // Do not show menubar in fullscreen
-        set_show_menubar (false);
     }
 
     public void disable_toolbar_dismissal() {
diff --git a/src/PageWindow.vala b/src/PageWindow.vala
index fd4a7ea0..ea6c5be2 100644
--- a/src/PageWindow.vala
+++ b/src/PageWindow.vala
@@ -16,9 +16,6 @@ public abstract class PageWindow : Gtk.ApplicationWindow {
     protected PageWindow() {
         Object(application: Application.get_instance().get_system_app());
 
-        // the current page needs to know when modifier keys are pressed
-        set_show_menubar(true);
-
         notify["maximized"].connect(synthesize_configure_event);
         notify["default-width"].connect(synthesize_configure_event);
         notify["default-height"].connect(synthesize_configure_event);
diff --git a/src/direct/DirectWindow.vala b/src/direct/DirectWindow.vala
index 2cf575e7..f4dc7f8d 100644
--- a/src/direct/DirectWindow.vala
+++ b/src/direct/DirectWindow.vala
@@ -26,7 +26,7 @@ public class DirectWindow : AppWindow {
         layout.prepend(direct_photo_page);
         layout.append(direct_photo_page.get_toolbar());
         
-        Application.set_menubar (direct_photo_page.get_menubar ());
+        set_menubar(direct_photo_page.get_menubar ());
 
         set_child(layout);
 
diff --git a/src/library/LibraryWindow.vala b/src/library/LibraryWindow.vala
index 62d3216c..21beaa46 100644
--- a/src/library/LibraryWindow.vala
+++ b/src/library/LibraryWindow.vala
@@ -1144,8 +1144,7 @@ public class LibraryWindow : AppWindow {
         
         Page current_page = get_current_page();
         if (current_page != null) {
-            set_show_menubar (false);
-            Application.set_menubar (null);
+            set_menubar(null);
 
             var toolbar = current_page.get_toolbar();
             if (toolbar != null)
@@ -1202,8 +1201,7 @@ public class LibraryWindow : AppWindow {
         
         page.switched_to();
 
-        Application.set_menubar (page.get_menubar ());
-        set_show_menubar (true);
+        set_menubar (page.get_menubar ());
         var old = get_settings().gtk_shell_shows_menubar;
         get_settings().gtk_shell_shows_menubar = !old;
         get_settings().gtk_shell_shows_menubar = old;


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