From d2430c70bd2166f086214880043258cf19bb3e8f Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sun, 10 May 2020 21:26:19 -0400 Subject: 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 --- examples/application5/exampleappwin.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'examples/application5/exampleappwin.c') 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 * -- cgit v1.2.1