forked from mono/gtk-sharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNodeViewDemo.cs
165 lines (133 loc) · 3.81 KB
/
NodeViewDemo.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
// NodeViewDemo.cs - rework of TreeViewDemo to use NodeView.
//
// Author: Mike Kestner <[email protected]>
//
// Copyright (c) 2004 Novell, Inc.
namespace GtkSamples {
using System;
using System.Reflection;
using Gtk;
public class DemoTreeNode : TreeNode {
string desc;
static int count = 0;
public DemoTreeNode (string name, string desc)
{
this.Name = name;
this.desc = desc;
count++;
}
// TreeNodeValues can come from both properties and fields
[TreeNodeValue (Column=0)]
public string Name;
[TreeNodeValue (Column=1)]
public string Description {
get { return desc; }
}
public static int Count {
get {
return count;
}
}
}
public class NodeViewDemo : Gtk.Window {
NodeStore store;
StatusDialog dialog;
public NodeViewDemo () : base ("NodeView demo")
{
DeleteEvent += new DeleteEventHandler (DeleteCB);
DefaultSize = new Gdk.Size (640,480);
ScrolledWindow sw = new ScrolledWindow ();
Add (sw);
NodeView view = new NodeView (Store);
view.HeadersVisible = true;
view.AppendColumn ("Name", new CellRendererText (), "text", 0);
view.AppendColumn ("Type", new CellRendererText (), new NodeCellDataFunc (DataCallback));
sw.Add (view);
dialog.Destroy ();
dialog = null;
}
private void DataCallback (TreeViewColumn col, CellRenderer cell, ITreeNode node)
{
(cell as CellRendererText).Text = (node as DemoTreeNode).Description;
}
StatusDialog Dialog {
get {
if (dialog == null)
dialog = new StatusDialog ();
return dialog;
}
}
void ProcessType (DemoTreeNode parent, System.Type t)
{
foreach (MemberInfo mi in t.GetMembers ())
parent.AddChild (new DemoTreeNode (mi.Name, mi.ToString ()));
}
void ProcessAssembly (DemoTreeNode parent, Assembly asm)
{
string asm_name = asm.GetName ().Name;
foreach (System.Type t in asm.GetTypes ()) {
Dialog.Update ("Loading from {0}:\n{1}", asm_name, t.ToString ());
DemoTreeNode node = new DemoTreeNode (t.Name, t.ToString ());
ProcessType (node, t);
parent.AddChild (node);
}
}
NodeStore Store {
get {
if (store == null) {
store = new NodeStore (typeof (DemoTreeNode));
foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies ()) {
Dialog.Update ("Loading {0}", asm.GetName ().Name);
DemoTreeNode node = new DemoTreeNode (asm.GetName ().Name, "Assembly");
ProcessAssembly (node, asm);
store.AddNode (node);
}
}
return store;
}
}
public static void Main (string[] args)
{
DateTime start = DateTime.Now;
Application.Init ();
Gtk.Window win = new NodeViewDemo ();
win.ShowAll ();
Console.WriteLine (DemoTreeNode.Count + " nodes created.");
Console.WriteLine ("startup time: " + DateTime.Now.Subtract (start));
Application.Run ();
}
void DeleteCB (System.Object o, DeleteEventArgs args)
{
Application.Quit ();
}
}
public class StatusDialog : Gtk.Dialog {
Label dialog_label;
public StatusDialog () : base ()
{
Title = "Loading data from assemblies...";
AddButton (Stock.Cancel, 1);
Response += new ResponseHandler (ResponseCB);
DefaultSize = new Gdk.Size (480, 100);
HBox hbox = new HBox (false, 4);
ContentArea.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 ("");
hbox.PackStart (dialog_label, false, false, 0);
ShowAll ();
}
public void Update (string format, params object[] args)
{
string text = String.Format (format, args);
dialog_label.Text = text;
while (Application.EventsPending ())
Application.RunIteration ();
}
private static void ResponseCB (object obj, ResponseArgs args)
{
Application.Quit ();
System.Environment.Exit (0);
}
}
}