From fe7973b7a80589e544fe8850e9b10687d9ca3d2b Mon Sep 17 00:00:00 2001 From: John Luke Date: Fri, 18 Jul 2003 17:23:36 +0000 Subject: [PATCH] 2003-07-17 John Luke * en/Gtk/TreeView.xml: add TreeViewDemo example * en/Pango/Weight.xml: remove trailing "n" svn path=/trunk/gtk-sharp/; revision=16409 --- doc/ChangeLog | 5 ++ doc/en/Gtk/TreeView.xml | 126 +++++++++++++++++++++++++++++++++++++++- doc/en/Pango/Weight.xml | 2 +- 3 files changed, 130 insertions(+), 3 deletions(-) diff --git a/doc/ChangeLog b/doc/ChangeLog index 7496dd1d5..54aec0cf6 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,8 @@ +2003-07-17 John Luke + + * en/Gtk/TreeView.xml: add TreeViewDemo example + * en/Pango/Weight.xml: remove trailing "n" + 2003-07-18 Duncan Mak * en/Pango/Alignment.xml: diff --git a/doc/en/Gtk/TreeView.xml b/doc/en/Gtk/TreeView.xml index 725f3be8e..548fa0d79 100644 --- a/doc/en/Gtk/TreeView.xml +++ b/doc/en/Gtk/TreeView.xml @@ -51,6 +51,7 @@ variable. Should you render it as a string of "True" or "False", "On" or "Off", or should you render it as a checkbox? + A simple list: using System; @@ -97,7 +98,128 @@ public class TreeViewSample { } } - + + A more advanced example: + + +using System; +using System.Reflection; +using Gtk; +using GtkSharp; + +public class TreeViewDemo { + private static TreeStore store = null; + private static Dialog dialog = null; + private static Label dialog_label = null; + + public TreeViewDemo () + { + Application.Init (); + PopulateStore (); + + Window win = new Window ("TreeView demo"); + win.DeleteEvent += new DeleteEventHandler (DeleteCB); + win.SetDefaultSize (640,480); + + ScrolledWindow sw = new ScrolledWindow (); + win.Add (sw); + + TreeView tv = new TreeView (store); + tv.HeadersVisible = true; + + tv.AppendColumn ("Name", new CellRendererText (), "text", 0); + tv.AppendColumn ("Type", new CellRendererText (), "text", 1); + + sw.Add (tv); + + dialog.Destroy (); + dialog = null; + + win.ShowAll (); + + Application.Run (); + } + + private static void ProcessType (TreeIter parent, System.Type t) + { + foreach (MemberInfo mi in t.GetMembers ()) { + store.AppendValues (parent, mi.Name, mi.ToString ()); + } + } + + private static void ProcessAssembly (TreeIter parent, Assembly asm) + { + string asm_name = asm.GetName ().Name; + + foreach (System.Type t in asm.GetTypes ()) { + UpdateDialog ("Loading from {0}:\n{1}", asm_name, t.ToString ()); + TreeIter iter = store.AppendValues (parent, t.Name, t.ToString ()); + ProcessType (iter, t); + } + } + + private static void PopulateStore () + { + if (store != null) + return; + + store = new TreeStore (typeof (string), typeof (string)); + + foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies ()) { + + UpdateDialog ("Loading {0}", asm.GetName ().Name); + + TreeIter iter = store.AppendValues (asm.GetName ().Name, "Assembly"); + ProcessAssembly (iter, asm); + } + } + + public static void Main (string[] args) + { + new TreeViewDemo (); + } + + private static void DeleteCB (System.Object o, DeleteEventArgs args) + { + Application.Quit (); + } + + private static void UpdateDialog (string format, params object[] args) + { + string text = String.Format (format, args); + + if (dialog == null) + { + dialog = new Dialog (); + dialog.Title = "Loading data from assemblies..."; + dialog.AddButton (Stock.Cancel, 1); + dialog.Response += new ResponseHandler (ResponseCB); + dialog.SetDefaultSize (480, 100); + + VBox vbox = dialog.VBox; + HBox hbox = new HBox (false, 4); + vbox.PackStart (hbox, true, true, 0); + + Gtk.Image icon = new Gtk.Image (Stock.DialogInfo, IconSize.Dialog); + hbox.PackStart (icon, false, false, 0); + dialog_label = new Label (text); + hbox.PackStart (dialog_label, false, false, 0); + dialog.ShowAll (); + } else { + dialog_label.Text = text; + while (Application.EventsPending ()) + Application.RunIteration (); + } + } + + private static void ResponseCB (object obj, ResponseArgs args) + { + Application.Quit (); + System.Environment.Exit (0); + } +} + + @@ -1279,4 +1401,4 @@ public class TreeViewSample { - \ No newline at end of file + diff --git a/doc/en/Pango/Weight.xml b/doc/en/Pango/Weight.xml index f194ddacf..f28a1bd57 100644 --- a/doc/en/Pango/Weight.xml +++ b/doc/en/Pango/Weight.xml @@ -116,4 +116,4 @@ -n \ No newline at end of file +