summaryrefslogtreecommitdiff
path: root/examples/application6
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2020-05-10 21:26:19 -0400
committerMatthias Clasen <mclasen@redhat.com>2020-05-11 08:15:56 -0400
commitd2430c70bd2166f086214880043258cf19bb3e8f (patch)
treeefc20eec503846fa269780f4df2e4f1bf5932f22 /examples/application6
parent4de4957aa34b39b313cceff760d390003795b325 (diff)
downloadgtk+-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/application6')
-rw-r--r--examples/application6/exampleapp.c7
-rw-r--r--examples/application6/exampleapp.gresource.xml2
-rw-r--r--examples/application6/exampleappwin.c11
-rw-r--r--examples/application6/gears-menu.ui (renamed from examples/application6/app-menu.ui)3
-rw-r--r--examples/application6/prefs.ui14
-rw-r--r--examples/application6/window.ui25
6 files changed, 37 insertions, 25 deletions
diff --git a/examples/application6/exampleapp.c b/examples/application6/exampleapp.c
index 64a3ceb100..8ac0ebd529 100644
--- a/examples/application6/exampleapp.c
+++ b/examples/application6/exampleapp.c
@@ -46,8 +46,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);
@@ -58,11 +56,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/application6/exampleapp.gresource.xml b/examples/application6/exampleapp.gresource.xml
index 797688586b..c40f6419b7 100644
--- a/examples/application6/exampleapp.gresource.xml
+++ b/examples/application6/exampleapp.gresource.xml
@@ -2,7 +2,7 @@
<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>
<file preprocess="xml-stripblanks">prefs.ui</file>
</gresource>
</gresources>
diff --git a/examples/application6/exampleappwin.c b/examples/application6/exampleappwin.c
index 16d11f4c70..7f332181ea 100644
--- a/examples/application6/exampleappwin.c
+++ b/examples/application6/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,7 +17,16 @@ 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));
+
+ 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",
@@ -44,6 +54,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/application6/app-menu.ui b/examples/application6/gears-menu.ui
index 13bf8fd342..30e292ef9a 100644
--- a/examples/application6/app-menu.ui
+++ b/examples/application6/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/application6/prefs.ui b/examples/application6/prefs.ui
index 9551758c8f..c4cfcb621a 100644
--- a/examples/application6/prefs.ui
+++ b/examples/application6/prefs.ui
@@ -4,16 +4,16 @@
<property name="title" translatable="yes">Preferences</property>
<property name="resizable">0</property>
<property name="modal">1</property>
- <child internal-child="vbox">
- <object class="GtkBox" id="vbox">
+ <child internal-child="content_area">
+ <object class="GtkBox" id="content_area">
<child>
<object class="GtkGrid" id="grid">
- <property name="margin-start">6</property>
- <property name="margin-end">6</property>
- <property name="margin-top">6</property>
- <property name="margin-bottom">6</property>
+ <property name="margin-start">12</property>
+ <property name="margin-end">12</property>
+ <property name="margin-top">12</property>
+ <property name="margin-bottom">12</property>
<property name="row-spacing">12</property>
- <property name="column-spacing">6</property>
+ <property name="column-spacing">12</property>
<child>
<object class="GtkLabel" id="fontlabel">
<property name="label">_Font:</property>
diff --git a/examples/application6/window.ui b/examples/application6/window.ui
index 595df79ef0..eee9127573 100644
--- a/examples/application6/window.ui
+++ b/examples/application6/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>