From fe4fd6ee781faa7691b6211d157d6460ecfc8160 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Canek=20Pel=C3=A1ez=20Vald=C3=A9s?= Date: Tue, 9 Sep 2014 23:42:55 -0500 Subject: [PATCH] application-window: Add stack child, and implement open() method. --- src/application-window.vala | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/application-window.vala b/src/application-window.vala index 2bb3ea2..ad21853 100644 --- a/src/application-window.vala +++ b/src/application-window.vala @@ -3,11 +3,39 @@ namespace Example { [GtkTemplate (ui = "/org/gtk/exampleapp/window.ui")] public class ApplicationWindow : Gtk.ApplicationWindow { + [GtkChild] + private Gtk.Stack stack; + public ApplicationWindow (Gtk.Application application) { GLib.Object (application: application); } public void open (GLib.File file) { + var basename = file.get_basename (); + + var scrolled = new Gtk.ScrolledWindow (null, null); + scrolled.show (); + scrolled.hexpand = true; + scrolled.vexpand = true; + + var view = new Gtk.TextView (); + view.editable = false; + view.cursor_visible = false; + view.show (); + + scrolled.add (view); + stack.add_titled (scrolled, basename, basename); + + try { + uint8[] contents; + if (file.load_contents (null, out contents, null)) { + var buffer = view.get_buffer (); + buffer.set_text ((string)contents); + } + } catch (GLib.Error e) { + GLib.warning ("There was an error loading '%s': %s", + basename, e.message); + } } } } -- GitLab