2002-08-10 23:40:20 +00:00
|
|
|
// TreeView.cs - Fun TreeView demo
|
|
|
|
//
|
|
|
|
// Author: Kristian Rietveld <kris@gtk.org>
|
|
|
|
//
|
|
|
|
// (c) 2002 Kristian Rietveld
|
|
|
|
|
|
|
|
namespace GtkSamples {
|
|
|
|
using System;
|
|
|
|
using System.Reflection;
|
|
|
|
|
|
|
|
using Gtk;
|
|
|
|
|
|
|
|
public class TreeViewDemo {
|
|
|
|
private static TreeStore store = null;
|
2002-08-31 20:37:52 +00:00
|
|
|
private static Dialog dialog = null;
|
|
|
|
private static Label dialog_label = null;
|
2004-12-16 20:30:43 +00:00
|
|
|
private static int count = 0;
|
2003-07-22 23:58:07 +00:00
|
|
|
|
|
|
|
public TreeViewDemo ()
|
|
|
|
{
|
2004-12-16 20:30:43 +00:00
|
|
|
DateTime start = DateTime.Now;
|
|
|
|
|
2003-07-22 23:58:07 +00:00
|
|
|
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;
|
2004-12-07 19:03:55 +00:00
|
|
|
tv.EnableSearch = false;
|
2003-07-22 23:58:07 +00:00
|
|
|
|
|
|
|
tv.AppendColumn ("Name", new CellRendererText (), "text", 0);
|
|
|
|
tv.AppendColumn ("Type", new CellRendererText (), "text", 1);
|
|
|
|
|
|
|
|
sw.Add (tv);
|
|
|
|
|
|
|
|
dialog.Destroy ();
|
|
|
|
dialog = null;
|
|
|
|
|
|
|
|
win.ShowAll ();
|
|
|
|
|
2004-12-16 20:30:43 +00:00
|
|
|
Console.WriteLine (count + " nodes added.");
|
|
|
|
Console.WriteLine ("Startup time: " + DateTime.Now.Subtract (start));
|
2003-07-22 23:58:07 +00:00
|
|
|
Application.Run ();
|
|
|
|
}
|
2002-08-10 23:40:20 +00:00
|
|
|
|
2003-02-24 08:04:42 +00:00
|
|
|
private static void ProcessType (TreeIter parent, System.Type t)
|
2002-08-10 23:40:20 +00:00
|
|
|
{
|
2003-07-22 23:58:07 +00:00
|
|
|
foreach (MemberInfo mi in t.GetMembers ()) {
|
2003-05-19 07:18:52 +00:00
|
|
|
store.AppendValues (parent, mi.Name, mi.ToString ());
|
2004-12-16 20:30:43 +00:00
|
|
|
count++;
|
2002-08-10 23:40:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void ProcessAssembly (TreeIter parent, Assembly asm)
|
|
|
|
{
|
2002-08-31 20:37:52 +00:00
|
|
|
string asm_name = asm.GetName ().Name;
|
2002-08-10 23:40:20 +00:00
|
|
|
|
2003-02-24 08:04:42 +00:00
|
|
|
foreach (System.Type t in asm.GetTypes ()) {
|
2002-08-31 20:37:52 +00:00
|
|
|
UpdateDialog ("Loading from {0}:\n{1}", asm_name, t.ToString ());
|
2003-05-19 07:18:52 +00:00
|
|
|
TreeIter iter = store.AppendValues (parent, t.Name, t.ToString ());
|
2004-12-16 20:30:43 +00:00
|
|
|
count++;
|
2002-08-10 23:40:20 +00:00
|
|
|
ProcessType (iter, t);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void PopulateStore ()
|
|
|
|
{
|
|
|
|
if (store != null)
|
|
|
|
return;
|
|
|
|
|
2003-05-19 07:18:52 +00:00
|
|
|
store = new TreeStore (typeof (string), typeof (string));
|
2002-08-10 23:40:20 +00:00
|
|
|
|
|
|
|
foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies ()) {
|
|
|
|
|
2002-08-31 20:37:52 +00:00
|
|
|
UpdateDialog ("Loading {0}", asm.GetName ().Name);
|
|
|
|
|
2003-05-19 07:18:52 +00:00
|
|
|
TreeIter iter = store.AppendValues (asm.GetName ().Name, "Assembly");
|
2004-12-16 20:30:43 +00:00
|
|
|
count++;
|
2002-08-10 23:40:20 +00:00
|
|
|
ProcessAssembly (iter, asm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void Main (string[] args)
|
|
|
|
{
|
2003-07-22 23:58:07 +00:00
|
|
|
new TreeViewDemo ();
|
2002-08-10 23:40:20 +00:00
|
|
|
}
|
|
|
|
|
2002-09-24 00:32:59 +00:00
|
|
|
private static void DeleteCB (System.Object o, DeleteEventArgs args)
|
2002-08-10 23:40:20 +00:00
|
|
|
{
|
|
|
|
Application.Quit ();
|
|
|
|
}
|
2002-08-31 20:37:52 +00:00
|
|
|
|
|
|
|
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);
|
2003-07-22 23:58:07 +00:00
|
|
|
dialog.SetDefaultSize (480, 100);
|
2002-08-31 20:37:52 +00:00
|
|
|
|
2011-02-10 00:23:18 +00:00
|
|
|
Box vbox = dialog.ContentArea;
|
2002-08-31 20:37:52 +00:00
|
|
|
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);
|
|
|
|
}
|
2002-08-10 23:40:20 +00:00
|
|
|
}
|
|
|
|
}
|