Commit f8f42e7a authored by Jens Georg's avatar Jens Georg

Use GtkApplication menubar, get accels for free

Signed-off-by: Jens Georg's avatarJens Georg <mail@jensge.org>
parent 17c8587e
......@@ -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() {
......
......@@ -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.
*
......
......@@ -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() {
......
......@@ -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);
}
......
......@@ -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) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment