summaryrefslogtreecommitdiff
path: root/examples/application9
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/application9
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/application9')
-rw-r--r--examples/application9/README1
-rw-r--r--examples/application9/app-menu.ui16
-rw-r--r--examples/application9/exampleapp.c7
-rw-r--r--examples/application9/exampleapp.gresource.xml1
-rw-r--r--examples/application9/exampleappwin.c15
-rw-r--r--examples/application9/gears-menu.ui11
-rw-r--r--examples/application9/prefs.ui14
-rw-r--r--examples/application9/window.ui66
8 files changed, 59 insertions, 72 deletions
diff --git a/examples/application9/README b/examples/application9/README
new file mode 100644
index 0000000000..4b43848ff7
--- /dev/null
+++ b/examples/application9/README
@@ -0,0 +1 @@
+Step 9: Using properties
diff --git a/examples/application9/app-menu.ui b/examples/application9/app-menu.ui
deleted file mode 100644
index 13bf8fd342..0000000000
--- a/examples/application9/app-menu.ui
+++ /dev/null
@@ -1,16 +0,0 @@
-<interface>
- <menu id="appmenu">
- <section>
- <item>
- <attribute name="label" translatable="yes">_Preferences</attribute>
- <attribute name="action">app.preferences</attribute>
- </item>
- </section>
- <section>
- <item>
- <attribute name="label" translatable="yes">_Quit</attribute>
- <attribute name="action">app.quit</attribute>
- </item>
- </section>
- </menu>
-</interface>
diff --git a/examples/application9/exampleapp.c b/examples/application9/exampleapp.c
index 64a3ceb100..8ac0ebd529 100644
--- a/examples/application9/exampleapp.c
+++ b/examples/application9/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/application9/exampleapp.gresource.xml b/examples/application9/exampleapp.gresource.xml
index ace59c8bb7..c40f6419b7 100644
--- a/examples/application9/exampleapp.gresource.xml
+++ b/examples/application9/exampleapp.gresource.xml
@@ -2,7 +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>
<file preprocess="xml-stripblanks">prefs.ui</file>
</gresource>
diff --git a/examples/application9/exampleappwin.c b/examples/application9/exampleappwin.c
index 725ee67df1..c585094f4c 100644
--- a/examples/application9/exampleappwin.c
+++ b/examples/application9/exampleappwin.c
@@ -9,10 +9,10 @@ struct _ExampleAppWindow
GSettings *settings;
GtkWidget *stack;
+ GtkWidget *gears;
GtkWidget *search;
GtkWidget *searchbar;
GtkWidget *searchentry;
- GtkWidget *gears;
GtkWidget *sidebar;
GtkWidget *words;
GtkWidget *lines;
@@ -168,6 +168,12 @@ example_app_window_init (ExampleAppWindow *win)
GAction *action;
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",
@@ -185,11 +191,6 @@ example_app_window_init (ExampleAppWindow *win)
g_signal_connect (win->sidebar, "notify::reveal-child",
G_CALLBACK (words_changed), 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);
-
action = g_settings_create_action (win->settings, "show-words");
g_action_map_add_action (G_ACTION_MAP (win), action);
g_object_unref (action);
@@ -224,10 +225,10 @@ example_app_window_class_init (ExampleAppWindowClass *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);
gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (class), ExampleAppWindow, search);
gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (class), ExampleAppWindow, searchbar);
gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (class), ExampleAppWindow, searchentry);
- gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (class), ExampleAppWindow, gears);
gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (class), ExampleAppWindow, words);
gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (class), ExampleAppWindow, sidebar);
gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (class), ExampleAppWindow, lines);
diff --git a/examples/application9/gears-menu.ui b/examples/application9/gears-menu.ui
index 0b3d15e1be..d16d93a8ab 100644
--- a/examples/application9/gears-menu.ui
+++ b/examples/application9/gears-menu.ui
@@ -1,3 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
<interface>
<menu id="menu">
<section>
@@ -9,6 +10,16 @@
<attribute name="label" translatable="yes">_Lines</attribute>
<attribute name="action">win.show-lines</attribute>
</item>
+ <item>
+ <attribute name="label" translatable="yes">_Preferences</attribute>
+ <attribute name="action">app.preferences</attribute>
+ </item>
+ </section>
+ <section>
+ <item>
+ <attribute name="label" translatable="yes">_Quit</attribute>
+ <attribute name="action">app.quit</attribute>
+ </item>
</section>
</menu>
</interface>
diff --git a/examples/application9/prefs.ui b/examples/application9/prefs.ui
index 9551758c8f..c4cfcb621a 100644
--- a/examples/application9/prefs.ui
+++ b/examples/application9/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/application9/window.ui b/examples/application9/window.ui
index 59f6e8c71a..29af168d26 100644
--- a/examples/application9/window.ui
+++ b/examples/application9/window.ui
@@ -4,44 +4,42 @@
<property name="title" translatable="yes">Example Application</property>
<property name="default-width">600</property>
<property name="default-height">400</property>
- <child>
- <object class="GtkBox" id="content_box">
- <property name="orientation">vertical</property>
+ <child type="titlebar">
+ <object class="GtkHeaderBar" id="header">
+ <property name="show-title-buttons">1</property>
<child>
- <object class="GtkHeaderBar" id="header">
- <child>
- <object class="GtkLabel" id="lines_label">
- <property name="visible">0</property>
- <property name="label" translatable="yes">Lines:</property>
- </object>
- </child>
- <child>
- <object class="GtkLabel" id="lines">
- <property name="visible">0</property>
- </object>
- </child>
- <child type="title">
- <object class="GtkStackSwitcher" id="tabs">
- <property name="stack">stack</property>
- </object>
- </child>
- <child type="end">
- <object class="GtkToggleButton" id="search">
- <property name="sensitive">0</property>
- <property name="icon-name">edit-find-symbolic</property>
- </object>
- </child>
- <child type="end">
- <object class="GtkMenuButton" id="gears">
- <property name="direction">none</property>
- <style>
- <class name="image-button"/>
- </style>
- </object>
- </child>
+ <object class="GtkLabel" id="lines_label">
+ <property name="visible">0</property>
+ <property name="label" translatable="yes">Lines:</property>
</object>
</child>
<child>
+ <object class="GtkLabel" id="lines">
+ <property name="visible">0</property>
+ </object>
+ </child>
+ <child type="title">
+ <object class="GtkStackSwitcher" id="tabs">
+ <property name="stack">stack</property>
+ </object>
+ </child>
+ <child type="end">
+ <object class="GtkToggleButton" id="search">
+ <property name="sensitive">0</property>
+ <property name="icon-name">edit-find-symbolic</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="GtkSearchBar" id="searchbar">
<child>
<object class="GtkSearchEntry" id="searchentry">