<para>In this step, we make our application show the content of
all the files that it is given on the commandline.</para>
- <para>To this end, we add a private struct to our application
+ <para>To this end, we add a member to the struct in application
window subclass and keep a reference to the #GtkStack there.
- The gtk_widget_class_bind_template_child_private() function
+ The first member of the struct should be the parent type from
+ which the class is derived. Here, ExampleAppWindow is derived
+ from GtkApplicationWindow.
+ The gtk_widget_class_bind_template_child() function
arranges things so that after instantiating the template, the
- @stack member of the private struct will point to the widget of
+ @stack member of the struct will point to the widget of
the same name from the template.</para>
<informalexample>
<programlisting><![CDATA[
...
-struct _ExampleAppWindowPrivate
+struct _ExampleAppWindow
{
+ GtkApplicationWindow parent;
+
GtkWidget *stack;
};
-G_DEFINE_TYPE_WITH_PRIVATE(ExampleAppWindow, example_app_window, GTK_TYPE_APPLICATION_WINDOW);
+G_DEFINE_TYPE (ExampleAppWindow, example_app_window, GTK_TYPE_APPLICATION_WINDOW)
...
{
gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (class),
"/org/gtk/exampleapp/window.ui");
- gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (class), ExampleAppWindow, stack);
+ gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (class), ExampleAppWindow, stack);
}
...
example_app_window_open (ExampleAppWindow *win,
GFile *file)
{
- ExampleAppWindowPrivate *priv;
gchar *basename;
GtkWidget *scrolled, *view;
gchar *contents;
gsize length;
- priv = example_app_window_get_instance_private (win);
basename = g_file_get_basename (file);
scrolled = gtk_scrolled_window_new (NULL, NULL);
- gtk_widget_show (scrolled);
gtk_widget_set_hexpand (scrolled, TRUE);
gtk_widget_set_vexpand (scrolled, TRUE);
view = gtk_text_view_new ();
gtk_text_view_set_editable (GTK_TEXT_VIEW (view), FALSE);
gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (view), FALSE);
- gtk_widget_show (view);
gtk_container_add (GTK_CONTAINER (scrolled), view);
- gtk_stack_add_titled (GTK_STACK (priv->stack), scrolled, basename, basename);
+ gtk_stack_add_titled (GTK_STACK (win->stack), scrolled, basename, basename);
if (g_file_load_contents (file, NULL, &contents, &length, NULL, NULL))
{
static void
example_app_window_init (ExampleAppWindow *win)
{
- ExampleAppWindowPrivate *priv;
-
- priv = example_app_window_get_instance_private (win);
gtk_widget_init_template (GTK_WIDGET (win));
- priv->settings = g_settings_new ("org.gtk.exampleapp");
+ win->settings = g_settings_new ("org.gtk.exampleapp");
- g_settings_bind (priv->settings, "transition",
- priv->stack, "transition-type",
+ g_settings_bind (win->settings, "transition",
+ win->stack, "transition-type",
G_SETTINGS_BIND_DEFAULT);
}
search_text_changed (GtkEntry *entry,
ExampleAppWindow *win)
{
- ExampleAppWindowPrivate *priv;
const gchar *text;
GtkWidget *tab;
GtkWidget *view;
if (text[0] == '\0')
return;
- priv = example_app_window_get_instance_private (win);
-
- tab = gtk_stack_get_visible_child (GTK_STACK (priv->stack));
+ tab = gtk_stack_get_visible_child (GTK_STACK (win->stack));
view = gtk_bin_get_child (GTK_BIN (tab));
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
{
...
- action = (GAction*) g_property_action_new ("show-lines", priv->lines, "visible");
+ action = (GAction*) g_property_action_new ("show-lines", win->lines, "visible");
g_action_map_add_action (G_ACTION_MAP (win), action);
g_object_unref (action);
- g_object_bind_property (priv->lines, "visible",
- priv->lines_label, "visible",
+ g_object_bind_property (win->lines, "visible",
+ win->lines_label, "visible",
G_BINDING_DEFAULT);
}