The appmenu-related GtkApplication apis are going away.
startup (GApplication *app)
{
GtkBuilder *builder;
- GMenuModel *appmenu;
- GMenuModel *menubar;
G_APPLICATION_CLASS (demo_application_parent_class)->startup (app);
builder = gtk_builder_new ();
gtk_builder_add_from_resource (builder, "/application_demo/menus.ui", NULL);
- appmenu = (GMenuModel *)gtk_builder_get_object (builder, "appmenu");
- menubar = (GMenuModel *)gtk_builder_get_object (builder, "menubar");
-
- gtk_application_set_app_menu (GTK_APPLICATION (app), appmenu);
- gtk_application_set_menubar (GTK_APPLICATION (app), menubar);
+ gtk_application_set_menubar (GTK_APPLICATION (app),
+ G_MENU_MODEL (gtk_builder_get_object (builder, "menubar")));
g_object_unref (builder);
}
window = (DemoApplicationWindow *)g_object_new (demo_application_window_get_type (),
"application", app,
+ "show-menubar", TRUE,
NULL);
if (content)
gtk_text_buffer_set_text (window->buffer, content, -1);
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<interface>
- <menu id="appmenu">
- <section>
- <item>
- <attribute name="label" translatable="yes">About</attribute>
- <attribute name="action">app.about</attribute>
- </item>
- </section>
- <section>
- <item>
- <attribute name="label" translatable="yes">_Quit</attribute>
- <attribute name="action">app.quit</attribute>
- <attribute name="accel"><Control>q</attribute>
- </item>
- </section>
- </menu>
-</interface>
<gresources>
<gresource prefix="/ui">
<file preprocess="xml-stripblanks">main.ui</file>
- <file preprocess="xml-stripblanks">appmenu.ui</file>
</gresource>
<gresource prefix="/application_demo">
<file>application.c</file>
}
-static void
-startup (GApplication *app)
-{
- GtkBuilder *builder;
- GMenuModel *appmenu;
- const char *ids[] = { "appmenu", NULL };
-
- builder = gtk_builder_new ();
- gtk_builder_add_objects_from_resource (builder, "/ui/appmenu.ui", ids, NULL);
-
- appmenu = (GMenuModel *)gtk_builder_get_object (builder, "appmenu");
-
- gtk_application_set_app_menu (GTK_APPLICATION (app), appmenu);
-
- g_object_unref (builder);
-}
-
static void
row_activated_cb (GtkWidget *tree_view,
GtkTreePath *path,
g_application_add_main_option (G_APPLICATION (app), "list", 0, 0, G_OPTION_ARG_NONE, "List examples", NULL);
g_application_add_main_option (G_APPLICATION (app), "autoquit", 0, 0, G_OPTION_ARG_NONE, "Quit after a delay", NULL);
- g_signal_connect (app, "startup", G_CALLBACK (startup), NULL);
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
g_signal_connect (app, "command-line", G_CALLBACK (command_line), NULL);
g_signal_connect (app, "handle-local-options", G_CALLBACK (local_options), NULL);
<?xml version="1.0" encoding="UTF-8"?>
<interface>
- <menu id="appmenu">
- <section>
- <item>
- <attribute name="label" translatable="yes">_New</attribute>
- <attribute name="action">app.new</attribute>
- <attribute name="accel"><Control>n</attribute>
- </item>
- <item>
- <attribute name="label" translatable="yes">_Open</attribute>
- <attribute name="action">app.open</attribute>
- </item>
- <item>
- <attribute name="label" translatable="yes">_Save</attribute>
- <attribute name="action">app.save</attribute>
- <attribute name="accel"><Control>s</attribute>
- </item>
- <item>
- <attribute name="label" translatable="yes">Save _As...</attribute>
- <attribute name="action">app.save-as</attribute>
- <attribute name="accel"><Control>s</attribute>
- </item>
- </section>
- <section>
- <item>
- <attribute name="label" translatable="yes">_Quit</attribute>
- <attribute name="action">app.quit</attribute>
- <attribute name="accel"><Control>q</attribute>
- </item>
- </section>
- </menu>
<menu id="menubar">
<submenu>
- <attribute name="label" translatable="yes">_Preferences</attribute>
+ <attribute name="label" translatable="yes">_Application</attribute>
+ <section>
+ <item>
+ <attribute name="label" translatable="yes">_New</attribute>
+ <attribute name="action">app.new</attribute>
+ <attribute name="accel"><Control>n</attribute>
+ </item>
+ <item>
+ <attribute name="label" translatable="yes">_Open</attribute>
+ <attribute name="action">app.open</attribute>
+ </item>
+ <item>
+ <attribute name="label" translatable="yes">_Save</attribute>
+ <attribute name="action">app.save</attribute>
+ <attribute name="accel"><Control>s</attribute>
+ </item>
+ <item>
+ <attribute name="label" translatable="yes">Save _As...</attribute>
+ <attribute name="action">app.save-as</attribute>
+ <attribute name="accel"><Control>s</attribute>
+ </item>
+ </section>
+ <section>
+ <item>
+ <attribute name="label" translatable="yes">_Quit</attribute>
+ <attribute name="action">app.quit</attribute>
+ <attribute name="accel"><Control>q</attribute>
+ </item>
+ </section>
+ </submenu>
+ <submenu>
+ <attribute name="label" translatable="yes">_File</attribute>
<section>
<item>
<attribute name="label" translatable="yes">_Prefer Dark Theme</attribute>