sysprof: wire up window menu

This commit is contained in:
Christian Hergert
2019-05-16 12:06:37 -07:00
parent ad1cfebedd
commit 8e63320a1c
4 changed files with 67 additions and 1 deletions

35
src/sysprof/gtk/menus.ui Normal file
View File

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<menu id="win-menu">
<section id="win-menu-new">
<item>
<attribute name="label" translatable="yes">New Tab</attribute>
<attribute name="action">win.new-tab</attribute>
</item>
<item>
<attribute name="label" translatable="yes">New Window</attribute>
<attribute name="action">app.new-window</attribute>
</item>
</section>
<section id="win-menu-open">
<item>
<attribute name="label" translatable="yes">Open Capture…</attribute>
<attribute name="action">app.open-capture</attribute>
</item>
</section>
<section id="win-menu-misc">
<item>
<attribute name="label" translatable="yes">Keyboard Shortcuts</attribute>
<attribute name="action">app.show-help-overlay</attribute>
</item>
<item>
<attribute name="label" translatable="yes">Help</attribute>
<attribute name="action">app.help</attribute>
</item>
<item>
<attribute name="label" translatable="yes">Quit</attribute>
<attribute name="action">app.quit</attribute>
</item>
</section>
</menu>
</interface>

View File

@ -31,6 +31,7 @@ struct _SysprofWindow
{
GtkApplicationWindow parent_instance;
SysprofNotebook *notebook;
GtkMenuButton *menu_button;
};
G_DEFINE_TYPE (SysprofWindow, sysprof_window, GTK_TYPE_APPLICATION_WINDOW)
@ -104,6 +105,19 @@ close_tab_cb (GSimpleAction *action,
sysprof_notebook_close_current (self->notebook);
}
static void
sysprof_window_constructed (GObject *object)
{
SysprofWindow *self = (SysprofWindow *)object;
GApplication *app = g_application_get_default ();
GMenu *menu;
G_OBJECT_CLASS (sysprof_window_parent_class)->constructed (object);
menu = gtk_application_get_menu_by_id (GTK_APPLICATION (app), "win-menu");
gtk_menu_button_set_menu_model (self->menu_button, G_MENU_MODEL (menu));
}
static void
sysprof_window_finalize (GObject *object)
{
@ -116,10 +130,12 @@ sysprof_window_class_init (SysprofWindowClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
object_class->constructed = sysprof_window_constructed;
object_class->finalize = sysprof_window_finalize;
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/sysprof/ui/sysprof-window.ui");
gtk_widget_class_bind_template_child (widget_class, SysprofWindow , notebook);
gtk_widget_class_bind_template_child (widget_class, SysprofWindow, menu_button);
gtk_widget_class_bind_template_child (widget_class, SysprofWindow, notebook);
g_type_ensure (SYSPROF_TYPE_PROFILER_MENU_BUTTON);
g_type_ensure (SYSPROF_TYPE_NOTEBOOK);

View File

@ -3,6 +3,7 @@
<gresource prefix="/org/gnome/sysprof">
<!-- Automatic GTK resources -->
<file>gtk/help-overlay.ui</file>
<file>gtk/menus.ui</file>
<!-- Theme overrides -->
<file compressed="true">theme/shared.css</file>

View File

@ -10,6 +10,20 @@
<property name="show-close-button">true</property>
<property name="visible">true</property>
<property name="title" translatable="yes">Sysprof</property>
<child>
<object class="GtkMenuButton" id="menu_button">
<property name="visible">true</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>
<child type="title">
<object class="GtkBox">
<property name="orientation">vertical</property>