diff options
author | Matthias Clasen <mclasen@redhat.com> | 2020-05-10 21:26:19 -0400 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2020-05-11 08:15:56 -0400 |
commit | d2430c70bd2166f086214880043258cf19bb3e8f (patch) | |
tree | efc20eec503846fa269780f4df2e4f1bf5932f22 /examples/application5 | |
parent | 4de4957aa34b39b313cceff760d390003795b325 (diff) | |
download | gtk+-d2430c70bd2166f086214880043258cf19bb3e8f.tar.gz |
Refresh the tutorial examples
Redo this series of examples from 2013, and adapt it to modern
way of doing things. The biggest differences are that we use
a headerbar right from the start, and don't mention the app
menu.
Fixes: #2730
Diffstat (limited to 'examples/application5')
-rw-r--r-- | examples/application5/exampleapp.c | 7 | ||||
-rw-r--r-- | examples/application5/exampleapp.gresource.xml | 2 | ||||
-rw-r--r-- | examples/application5/exampleappwin.c | 12 | ||||
-rw-r--r-- | examples/application5/gears-menu.ui (renamed from examples/application5/app-menu.ui) | 3 | ||||
-rw-r--r-- | examples/application5/window.ui | 25 |
5 files changed, 30 insertions, 19 deletions
diff --git a/examples/application5/exampleapp.c b/examples/application5/exampleapp.c index 0f01fb388a..6ab68aebc3 100644 --- a/examples/application5/exampleapp.c +++ b/examples/application5/exampleapp.c @@ -39,8 +39,6 @@ static GActionEntry app_entries[] = static void example_app_startup (GApplication *app) { - GtkBuilder *builder; - GMenuModel *app_menu; const gchar *quit_accels[2] = { "<Ctrl>Q", NULL }; G_APPLICATION_CLASS (example_app_parent_class)->startup (app); @@ -51,11 +49,6 @@ example_app_startup (GApplication *app) gtk_application_set_accels_for_action (GTK_APPLICATION (app), "app.quit", quit_accels); - - builder = gtk_builder_new_from_resource ("/org/gtk/exampleapp/app-menu.ui"); - app_menu = G_MENU_MODEL (gtk_builder_get_object (builder, "appmenu")); - gtk_application_set_app_menu (GTK_APPLICATION (app), app_menu); - g_object_unref (builder); } static void diff --git a/examples/application5/exampleapp.gresource.xml b/examples/application5/exampleapp.gresource.xml index 1c9b11821f..5a5da01ba2 100644 --- a/examples/application5/exampleapp.gresource.xml +++ b/examples/application5/exampleapp.gresource.xml @@ -2,6 +2,6 @@ <gresources> <gresource prefix="/org/gtk/exampleapp"> <file preprocess="xml-stripblanks">window.ui</file> - <file preprocess="xml-stripblanks">app-menu.ui</file> + <file preprocess="xml-stripblanks">gears-menu.ui</file> </gresource> </gresources> diff --git a/examples/application5/exampleappwin.c b/examples/application5/exampleappwin.c index 16d11f4c70..5425b44a4d 100644 --- a/examples/application5/exampleappwin.c +++ b/examples/application5/exampleappwin.c @@ -9,6 +9,7 @@ struct _ExampleAppWindow GSettings *settings; GtkWidget *stack; + GtkWidget *gears; }; G_DEFINE_TYPE (ExampleAppWindow, example_app_window, GTK_TYPE_APPLICATION_WINDOW) @@ -16,9 +17,17 @@ G_DEFINE_TYPE (ExampleAppWindow, example_app_window, GTK_TYPE_APPLICATION_WINDOW static void example_app_window_init (ExampleAppWindow *win) { + GtkBuilder *builder; + GMenuModel *menu; + gtk_widget_init_template (GTK_WIDGET (win)); - win->settings = g_settings_new ("org.gtk.exampleapp"); + builder = gtk_builder_new_from_resource ("/org/gtk/exampleapp/gears-menu.ui"); + menu = G_MENU_MODEL (gtk_builder_get_object (builder, "menu")); + gtk_menu_button_set_menu_model (GTK_MENU_BUTTON (win->gears), menu); + g_object_unref (builder); + + win->settings = g_settings_new ("org.gtk.exampleapp"); g_settings_bind (win->settings, "transition", win->stack, "transition-type", G_SETTINGS_BIND_DEFAULT); @@ -44,6 +53,7 @@ example_app_window_class_init (ExampleAppWindowClass *class) gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (class), "/org/gtk/exampleapp/window.ui"); gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (class), ExampleAppWindow, stack); + gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (class), ExampleAppWindow, gears); } ExampleAppWindow * diff --git a/examples/application5/app-menu.ui b/examples/application5/gears-menu.ui index 13bf8fd342..30e292ef9a 100644 --- a/examples/application5/app-menu.ui +++ b/examples/application5/gears-menu.ui @@ -1,5 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> <interface> - <menu id="appmenu"> + <menu id="menu"> <section> <item> <attribute name="label" translatable="yes">_Preferences</attribute> diff --git a/examples/application5/window.ui b/examples/application5/window.ui index 595df79ef0..eee9127573 100644 --- a/examples/application5/window.ui +++ b/examples/application5/window.ui @@ -1,21 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> <interface> <template class="ExampleAppWindow" parent="GtkApplicationWindow"> <property name="title" translatable="yes">Example Application</property> <property name="default-width">600</property> <property name="default-height">400</property> + <child type="titlebar"> + <object class="GtkHeaderBar" id="header"> + <property name="show-title-buttons">1</property> + <child type="title"> + <object class="GtkStackSwitcher" id="tabs"> + <property name="stack">stack</property> + </object> + </child> + <child type="end"> + <object class="GtkMenuButton" id="gears"> + <property name="direction">none</property> + </object> + </child> + </object> + </child> <child> <object class="GtkBox" id="content_box"> <property name="orientation">vertical</property> <child> - <object class="GtkHeaderBar" id="header"> - <child type="title"> - <object class="GtkStackSwitcher" id="tabs"> - <property name="stack">stack</property> - </object> - </child> - </object> - </child> - <child> <object class="GtkStack" id="stack"/> </child> </object> |