diff options
author | Matthias Clasen <mclasen@redhat.com> | 2013-07-20 00:21:48 -0400 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2013-07-20 23:04:47 -0400 |
commit | 8087bb7a22303064fef947fc72639fcf70ce1515 (patch) | |
tree | 6f27902fc47b4d89f831eeb125a0ede3de1d3d17 /examples/application4/exampleappwin.c | |
parent | 68025551e13eebcd8c610b104d309494a3aa973d (diff) | |
download | gtk+-8087bb7a22303064fef947fc72639fcf70ce1515.tar.gz |
Add a new example app
Add a new example to the getting started part of the docs. The focus
of this example is on 'new stuff': GtkApplication, templates, settings,
gmenu, gaction, GtkStack, GtkHeaderBar, GtkSearchBar, GtkRevealer,
GtkListBox, GtkMenuButton, etc.
It is being developed in several steps. Each step is put in a separate
directory below examples/: application1, ..., application8. This is a
little repetitive, but lets us use the code of all examples in the
documentation.
Diffstat (limited to 'examples/application4/exampleappwin.c')
-rw-r--r-- | examples/application4/exampleappwin.c | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/examples/application4/exampleappwin.c b/examples/application4/exampleappwin.c new file mode 100644 index 0000000000..52306e1fd7 --- /dev/null +++ b/examples/application4/exampleappwin.c @@ -0,0 +1,73 @@ +#include "exampleapp.h" +#include "exampleappwin.h" +#include <gtk/gtk.h> + +struct ExampleAppWindow { + GtkApplicationWindow parent; +}; + +struct ExampleAppWindowClass { + GtkApplicationWindowClass parent_class; +}; + +typedef struct ExampleAppWindowPrivate ExampleAppWindowPrivate; + +struct ExampleAppWindowPrivate { + GtkWidget *stack; +}; + +G_DEFINE_TYPE_WITH_PRIVATE(ExampleAppWindow, example_app_window, GTK_TYPE_APPLICATION_WINDOW); + +static void +example_app_window_init (ExampleAppWindow *win) +{ + gtk_widget_init_template (GTK_WIDGET (win)); +} + +static void +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_child (GTK_WIDGET_CLASS (class), ExampleAppWindowPrivate, stack); +} + +ExampleAppWindow * +example_app_window_new (ExampleApp *app) +{ + return g_object_new (EXAMPLE_APP_WINDOW_TYPE, "application", app, NULL); +} + +void +example_app_window_open (ExampleAppWindow *win, + GFile *file) +{ + ExampleAppWindowPrivate *priv = example_app_window_get_instance_private (win); + gchar *basename; + GtkWidget *scrolled, *view; + gchar *contents; + gsize length; + + 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); + + if (g_file_load_contents (file, NULL, &contents, &length, NULL, NULL)) { + GtkTextBuffer *buffer; + + buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)); + gtk_text_buffer_set_text (buffer, contents, length); + g_free (contents); + } + + g_free (basename); +} |