mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-11-05 16:20:10 +00:00
cda60c3c40
We rename the gtk_widget_class_bind_template_child{_internal} macros by appending a _private to their name. Otherwise, it would be too magic to pass the 'public' names as arguments, but affect a member of the Private struct. At the same time, Add two new macros with the old names, gtk_widget_class_bind_template_child{_internal} that operate on members of the instance struct.
79 lines
2.1 KiB
C
79 lines
2.1 KiB
C
#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_template_child_private (GTK_WIDGET_CLASS (class), ExampleAppWindow, 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;
|
|
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);
|
|
|
|
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);
|
|
}
|