From 48358ccf22d115d6690aba852043ee0276d9d5b7 Mon Sep 17 00:00:00 2001 From: Mike Kestner Date: Thu, 16 Dec 2004 20:30:43 +0000 Subject: [PATCH] 2004-12-16 Mike Kestner * sample/NodeViewDemo.cs : rework of TreeViewDemo to use NodeStore. * sample/TreeViewDemo.cs : added some timing and node counting fu. 2004-12-16 Duncan Mak * gtk/Makefile.am (sources): Added NodeSelection and NodeView. * gtk/NodeSelection.cs: New file, an implementation of TreeSelection that exposes ITreeNodes instead of TreeIters. * gtk/NodeStore.cs : added internal GetIter and GetPath methods for NodeSelection. Reworked [TreeNodeValue] lookup logic. out what the Type of data the store holds. * gtk/NodeView.cs: New subclass of TreeView utilizing NodeStore and NodeSelection. * gtk/TreeIter.custom : new internal UserData prop. * gtk/TreeNodeValueAttribute.cs: Set AllowMultiple to true. * gtk/TreeView.custom: Obsoleted constructor that uses a NodeStore as parameter. NodeView should be used instead. svn path=/trunk/gtk-sharp/; revision=37845 --- ChangeLog | 20 +++ doc/en/Gtk/NodeSelection.xml | 240 ++++++++++++++++++++++++++++++++++ doc/en/Gtk/NodeView.xml | 72 ++++++++++ doc/en/Gtk/TreeView.xml | 2 +- gtk/Makefile.am | 2 + gtk/NodeSelection.cs | 135 +++++++++++++++++++ gtk/NodeStore.cs | 83 ++++++------ gtk/NodeView.cs | 64 +++++++++ gtk/TreeIter.custom | 10 ++ gtk/TreeNodeValueAttribute.cs | 11 +- gtk/TreeView.custom | 2 +- sample/Makefile.am | 6 +- sample/NodeViewDemo.cs | 164 +++++++++++++++++++++++ sample/TreeViewDemo.cs | 8 ++ 14 files changed, 763 insertions(+), 56 deletions(-) create mode 100644 doc/en/Gtk/NodeSelection.xml create mode 100644 doc/en/Gtk/NodeView.xml create mode 100644 gtk/NodeSelection.cs create mode 100644 gtk/NodeView.cs create mode 100644 sample/NodeViewDemo.cs diff --git a/ChangeLog b/ChangeLog index cdbf7d177..f0389ac41 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,23 @@ +2004-12-16 Mike Kestner + + * sample/NodeViewDemo.cs : rework of TreeViewDemo to use NodeStore. + * sample/TreeViewDemo.cs : added some timing and node counting fu. + +2004-12-16 Duncan Mak + + * gtk/Makefile.am (sources): Added NodeSelection and NodeView. + * gtk/NodeSelection.cs: New file, an implementation of + TreeSelection that exposes ITreeNodes instead of TreeIters. + * gtk/NodeStore.cs : added internal GetIter and GetPath methods for + NodeSelection. Reworked [TreeNodeValue] lookup logic. + out what the Type of data the store holds. + * gtk/NodeView.cs: New subclass of TreeView utilizing NodeStore and + NodeSelection. + * gtk/TreeIter.custom : new internal UserData prop. + * gtk/TreeNodeValueAttribute.cs: Set AllowMultiple to true. + * gtk/TreeView.custom: Obsoleted constructor that uses a NodeStore as + parameter. NodeView should be used instead. + 2004-12-16 Tambet Ingo * glib/Opaque.cs : hold a weakref in the hash, not a strong ref. diff --git a/doc/en/Gtk/NodeSelection.xml b/doc/en/Gtk/NodeSelection.xml new file mode 100644 index 000000000..eb09d398f --- /dev/null +++ b/doc/en/Gtk/NodeSelection.xml @@ -0,0 +1,240 @@ + + + + gtk-sharp + [00 24 00 00 04 80 00 00 94 00 00 00 06 02 00 00 00 24 00 00 52 53 41 31 00 04 00 00 01 00 01 00 71 EB 6C 55 75 52 9C BF 72 44 F7 A6 EA 05 62 84 F9 EA E0 3B CF F2 CC 13 2C 9C 49 0A B3 09 EA B0 B5 6B CE 44 9D F5 03 D9 C0 A8 1E 52 05 85 CD BE 70 E2 FB 90 43 4B AC 04 FA 62 22 A8 00 98 B7 A1 A7 B3 AF 99 1A 41 23 24 BB 43 25 F6 B8 65 BB 64 EB F6 D1 C2 06 D5 73 2D DF BC 70 A7 38 9E E5 3E 0C 24 6E 32 79 74 1A D0 05 03 E4 98 42 E1 9B F3 7B 19 8B 40 21 26 CB 36 89 C2 EA 64 96 A4 7C B4] + 2.0.0.0 + neutral + + + Gtk# is thread aware, but not thread safe; See the Gtk# Thread Programming for details. + + Accessing and manipulates the selected rows of a . + + + + System.Object + + + + + + + Method + + System.Boolean + + + + + + Tests if a specified node is currently selected. + a + a + + + + + + Method + + System.Boolean + + + + + + Tests if a specified path is currently selected. + a + a + + + + + + Method + + System.Void + + + + Selects all the nodes in the view. + + + + + + Method + + System.Void + + + + + + Selects a specified node in the view. + a + + + + + + Method + + System.Void + + + + + + Selects a node by path. + a + + + + + + Method + + System.Void + + + + + + + Selects all the nodes in a specified range. + a + a + + + + + + Method + + System.Void + + + + Unselects all the nodes in the view. + + + + + + Method + + System.Void + + + + + + Unselects a specified node. + a + + + + + + Method + + System.Void + + + + + + Unselects a specified node by path. + a + + + + + + Method + + System.Void + + + + + + + Unselects all the nodes in a specified range. + a + a + + + + + + Method + + System.Void + + + + + + + Unselects all the nodes in a specified range. + a + a + + + + + + Property + + Gtk.SelectionMode + + + + Selection mode currently is use. + a + + + + + + Property + + Gtk.NodeView + + + + The view associated with this selection object. + a + + + + + + Property + + Gtk.ITreeNode[] + + + + The currently selected nodes. + a + + + + + + Event + + System.EventHandler + + + + The currently selected row(s) changed. + + + + + diff --git a/doc/en/Gtk/NodeView.xml b/doc/en/Gtk/NodeView.xml new file mode 100644 index 000000000..83ea52949 --- /dev/null +++ b/doc/en/Gtk/NodeView.xml @@ -0,0 +1,72 @@ + + + + gtk-sharp + [00 24 00 00 04 80 00 00 94 00 00 00 06 02 00 00 00 24 00 00 52 53 41 31 00 04 00 00 01 00 01 00 71 EB 6C 55 75 52 9C BF 72 44 F7 A6 EA 05 62 84 F9 EA E0 3B CF F2 CC 13 2C 9C 49 0A B3 09 EA B0 B5 6B CE 44 9D F5 03 D9 C0 A8 1E 52 05 85 CD BE 70 E2 FB 90 43 4B AC 04 FA 62 22 A8 00 98 B7 A1 A7 B3 AF 99 1A 41 23 24 BB 43 25 F6 B8 65 BB 64 EB F6 D1 C2 06 D5 73 2D DF BC 70 A7 38 9E E5 3E 0C 24 6E 32 79 74 1A D0 05 03 E4 98 42 E1 9B F3 7B 19 8B 40 21 26 CB 36 89 C2 EA 64 96 A4 7C B4] + 2.0.0.0 + neutral + + + Gtk# is thread aware, but not thread safe; See the Gtk# Thread Programming for details. + + Tree and List view. + + + + Gtk.TreeView + + + + Atk.Implementor + + + GLib.IWrapper + + + System.IDisposable + + + + + + + Constructor + + + + + + Constructs a new view for a given . + a + a + + + + + + Property + + Gtk.NodeStore + + + + The store containing the view's data. + a + + + + + + Property + + Gtk.NodeSelection + + + + Used to obtain and manipulate the currently selected node(s). + a + + + + + diff --git a/doc/en/Gtk/TreeView.xml b/doc/en/Gtk/TreeView.xml index 27c44baef..881e56f64 100644 --- a/doc/en/Gtk/TreeView.xml +++ b/doc/en/Gtk/TreeView.xml @@ -1795,4 +1795,4 @@ tree_view.AppendColumn ("title", text, "text", 0); - \ No newline at end of file + diff --git a/gtk/Makefile.am b/gtk/Makefile.am index f55e58257..ceb136f09 100644 --- a/gtk/Makefile.am +++ b/gtk/Makefile.am @@ -21,7 +21,9 @@ sources = \ Application.cs \ ChildPropertyAttribute.cs \ ITreeNode.cs \ + NodeSelection.cs \ NodeStore.cs \ + NodeView.cs \ RadioActionEntry.cs \ ThreadNotify.cs \ ToggleActionEntry.cs \ diff --git a/gtk/NodeSelection.cs b/gtk/NodeSelection.cs new file mode 100644 index 000000000..4409bdcad --- /dev/null +++ b/gtk/NodeSelection.cs @@ -0,0 +1,135 @@ +// NodeSelection.cs - a TreeSelection implementation that exposes ITreeNodes +// +// Author: Duncan Mak (duncan@ximian.com) +// +// Copyright (c) 2004 Novell, Inc. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of version 2 of the Lesser GNU General +// Public License as published by the Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the +// Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +namespace Gtk { + + using System; + + public class NodeSelection { + + private TreeSelection selection; + + public event EventHandler Changed; + + internal NodeSelection (TreeSelection selection) + { + this.selection = selection; + + selection.Changed += new EventHandler (ChangedHandler); + } + + private void ChangedHandler (object o, EventArgs args) + { + if (Changed != null) + Changed (this, args); + } + + public bool NodeIsSelected (ITreeNode node) + { + return selection.IterIsSelected (NodeView.NodeStore.GetIter (node)); + } + + public bool PathIsSelected (TreePath path) + { + return selection.PathIsSelected (path); + } + + public void SelectAll () + { + selection.SelectAll (); + } + + public void SelectNode (ITreeNode node) + { + selection.SelectIter (NodeView.NodeStore.GetIter (node)); + } + + public void SelectPath (TreePath path) + { + selection.SelectPath (path); + } + + public void SelectRange (ITreeNode begin_node, ITreeNode end_node) + { + TreePath begin = NodeView.NodeStore.GetPath (begin_node); + TreePath end = NodeView.NodeStore.GetPath (end_node); + + selection.SelectRange (begin, end); + } + + public void UnselectAll () + { + selection.UnselectAll (); + } + + public void UnselectNode (ITreeNode node) + { + selection.UnselectIter (NodeView.NodeStore.GetIter (node)); + } + + public void UnselectPath (TreePath path) + { + selection.UnselectPath (path); + } + + public void UnselectRange (TreePath begin, TreePath end) + { + selection.UnselectRange (begin, end); + } + + public void UnselectRange (ITreeNode begin_node, ITreeNode end_node) + { + TreePath begin = NodeView.NodeStore.GetPath (begin_node); + TreePath end = NodeView.NodeStore.GetPath (end_node); + + selection.UnselectRange (begin, end); + } + + public SelectionMode Mode { + get { + return selection.Mode; + } + set { + selection.Mode = value; + } + } + + public NodeView NodeView { + get { + return selection.TreeView as NodeView; + } + } + + public ITreeNode[] SelectedNodes { + get { + TreeModel model; + TreePath [] paths = selection.GetSelectedRows (out model); + int length = paths.Length; + + ITreeNode [] results = new ITreeNode [length]; + + for (int i = 0; i < length; i++) + results [i] = NodeView.NodeStore.GetNode (paths [i]); + + return results; + } + } + } +} diff --git a/gtk/NodeStore.cs b/gtk/NodeStore.cs index c52f2b750..dcaee0ba1 100644 --- a/gtk/NodeStore.cs +++ b/gtk/NodeStore.cs @@ -80,7 +80,7 @@ namespace Gtk { int stamp; Hashtable node_hash = new IDHashtable (); - GLib.GType[] ctypes; + GLib.GType[] ctypes; PropertyInfo[] getters; int n_cols = 1; ArrayList nodes = new ArrayList (); @@ -120,22 +120,10 @@ namespace Gtk { IntPtr get_path_cb (int node_idx) { - TreePath path = new TreePath (); - int idx; - ITreeNode node = node_hash [node_idx] as ITreeNode; if (node == null) throw new Exception ("Invalid Node ID"); - while (node.Parent != null) { - idx = node.Parent.IndexOf (node); - if (idx < 0) throw new Exception ("Badly formed tree"); - path.PrependIndex (idx); - node = node.Parent; - } - idx = Nodes.IndexOf (node); - if (idx < 0) throw new Exception ("Node not found in Nodes list"); - path.PrependIndex (idx); - return path.Handle; + return GetPath (node).Handle; } [DllImport("libgobject-2.0-0.dll")] @@ -294,45 +282,24 @@ namespace Gtk { void ScanType (Type type) { object[] attrs = type.GetCustomAttributes (false); - foreach (object attr in attrs) { - switch (attr.ToString ()) { - case "Gtk.TreeNodeAttribute": - TreeNodeAttribute tna = attr as TreeNodeAttribute; - n_cols = tna.ColumnCount; - break; - default: - Console.WriteLine ("Unknown attr: " + attr); - break; - } - } + foreach (TreeNodeAttribute attr in type.GetCustomAttributes (typeof (TreeNodeAttribute), false)) + n_cols = attr.ColumnCount; ctypes = new GLib.GType [n_cols]; getters = new PropertyInfo [n_cols]; - MemberInfo[] info = type.GetMembers (); - foreach (MemberInfo mi in info) { - PropertyInfo pi; - object[] attr_info = mi.GetCustomAttributes (false); - foreach (object attr in attr_info) { - switch (attr.ToString ()) { - case "Gtk.TreeNodeValueAttribute": - TreeNodeValueAttribute tnva = attr as TreeNodeValueAttribute; - int col = tnva.Column; - pi = mi as PropertyInfo; - getters [col] = pi; - GLib.GType ctype = GLib.TypeConverter.LookupType (pi.PropertyType); - if (ctype == GLib.GType.Invalid) - throw new Exception ("Unknown type"); - ctypes[col] = ctype; - break; - default: - Console.WriteLine ("Unknown custom attr: " + attr); - break; - } + foreach (PropertyInfo pi in type.GetProperties ()) { + foreach (TreeNodeValueAttribute attr in pi.GetCustomAttributes (typeof (TreeNodeValueAttribute), false)) { + int col = attr.Column; + getters [col] = pi; + GLib.GType ctype = GLib.TypeConverter.LookupType (pi.PropertyType); + if (ctype == GLib.GType.Invalid) + throw new Exception ("Unknown type"); + ctypes[col] = ctype; } } } - + private IList Nodes { get { return nodes as IList; @@ -439,6 +406,30 @@ namespace Gtk { return GetNodeAtPath (path); } + internal TreePath GetPath (ITreeNode node) + { + TreePath path = new TreePath (); + int idx; + + while (node.Parent != null) { + idx = node.Parent.IndexOf (node); + if (idx < 0) throw new Exception ("Badly formed tree"); + path.PrependIndex (idx); + node = node.Parent; + } + idx = Nodes.IndexOf (node); + if (idx < 0) throw new Exception ("Node not found in Nodes list"); + path.PrependIndex (idx); + return path; + } + + internal TreeIter GetIter (ITreeNode node) + { + TreeIter iter = new TreeIter (); + iter.UserData = new IntPtr (node.ID); + return iter; + } + [DllImport("gtksharpglue-2")] static extern IntPtr gtksharp_node_store_get_type (); diff --git a/gtk/NodeView.cs b/gtk/NodeView.cs new file mode 100644 index 000000000..0550cd960 --- /dev/null +++ b/gtk/NodeView.cs @@ -0,0 +1,64 @@ +// NodeView.cs - a TreeView implementation that exposes ITreeNodes +// +// Author: Duncan Mak (duncan@ximian.com) +// +// Copyright (c) 2004 Novell, Inc. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of version 2 of the Lesser GNU General +// Public License as published by the Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the +// Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +// This file was generated by the Gtk# code generator. +// Any changes made will be lost if regenerated. + +namespace Gtk { + + using System; + using System.Collections; + using System.Reflection; + using System.Runtime.InteropServices; + + public class NodeView : TreeView { + + [DllImport("libgtk-win32-2.0-0.dll")] + static extern IntPtr gtk_tree_view_new_with_model(IntPtr model); + + NodeStore store; + + public NodeView (NodeStore store) : base (IntPtr.Zero) + { + if (GetType() != typeof (NodeView)) { + string[] names = { "model" }; + GLib.Value[] vals = { new GLib.Value (store) }; + CreateNativeObject (names, vals); + vals [0].Dispose (); + } else { + Raw = gtk_tree_view_new_with_model (store.Handle); + } + + this.store = store; + } + + public NodeStore NodeStore { + get { + return store; + } + } + + public NodeSelection NodeSelection { + get { + return new NodeSelection (Selection); + } + } + } +} diff --git a/gtk/TreeIter.custom b/gtk/TreeIter.custom index a2043477f..d0b462afb 100644 --- a/gtk/TreeIter.custom +++ b/gtk/TreeIter.custom @@ -34,3 +34,13 @@ ti._user_data2 == _user_data2 && ti._user_data3 == _user_data3; } + + internal IntPtr UserData { + get { + return _user_data; + } + set { + _user_data = value; + } + } + diff --git a/gtk/TreeNodeValueAttribute.cs b/gtk/TreeNodeValueAttribute.cs index 9e7ecabd8..464b921df 100644 --- a/gtk/TreeNodeValueAttribute.cs +++ b/gtk/TreeNodeValueAttribute.cs @@ -23,17 +23,14 @@ namespace Gtk { using System; - [AttributeUsage(AttributeTargets.Property)] + [AttributeUsage (AttributeTargets.Property, AllowMultiple = true)] public sealed class TreeNodeValueAttribute : Attribute { + int col; public int Column { - get { - return col; - } - set { - col = value; - } + get { return col; } + set { col = value; } } } } diff --git a/gtk/TreeView.custom b/gtk/TreeView.custom index 5867461c6..aebbdda9f 100644 --- a/gtk/TreeView.custom +++ b/gtk/TreeView.custom @@ -24,7 +24,7 @@ // Boston, MA 02111-1307, USA. - + [Obsolete ("Use NodeView with NodeStores")] public TreeView (NodeStore store) : base (IntPtr.Zero) { if (GetType() != typeof (TreeView)) { diff --git a/sample/Makefile.am b/sample/Makefile.am index 20d0d2f04..bd5c03782 100755 --- a/sample/Makefile.am +++ b/sample/Makefile.am @@ -32,7 +32,7 @@ VTE_TARGETS= VTE_ASSEMBLY= endif -TARGETS = custom-notebook.exe drawing-sample.exe custom-widget.exe custom-cellrenderer.exe gtk-hello-world.exe button.exe calendar.exe subclass.exe menu.exe size.exe scribble.exe scribble-xinput.exe treeviewdemo.exe managedtreeviewdemo.exe testdnd.exe actions.exe $(GNOMEVFS_TARGETS) $(GNOME_TARGETS) $(GLADE_TARGETS) $(VTE_TARGETS) +TARGETS = custom-notebook.exe drawing-sample.exe custom-widget.exe custom-cellrenderer.exe gtk-hello-world.exe button.exe calendar.exe subclass.exe menu.exe size.exe scribble.exe scribble-xinput.exe treeviewdemo.exe managedtreeviewdemo.exe nodeviewdemo.exe testdnd.exe actions.exe $(GNOMEVFS_TARGETS) $(GNOME_TARGETS) $(GLADE_TARGETS) $(VTE_TARGETS) assemblies=../glib/glib-sharp.dll ../pango/pango-sharp.dll ../atk/atk-sharp.dll ../gdk/gdk-sharp.dll ../gtk/gtk-sharp.dll $(GNOMEVFS_ASSEMBLY) $(GNOME_ASSEMBLY) $(GLADE_ASSEMBLY) $(VTE_ASSEMBLY) references=$(addprefix /r:, $(assemblies)) @@ -82,6 +82,9 @@ treeviewdemo.exe: $(srcdir)/TreeViewDemo.cs $(assemblies) managedtreeviewdemo.exe: $(srcdir)/ManagedTreeViewDemo.cs $(assemblies) $(CSC) /out:managedtreeviewdemo.exe $(references) $(srcdir)/ManagedTreeViewDemo.cs +nodeviewdemo.exe: $(srcdir)/NodeViewDemo.cs $(assemblies) + $(CSC) /out:nodeviewdemo.exe $(references) $(srcdir)/NodeViewDemo.cs + glade-viewer.exe: $(srcdir)/GladeViewer.cs $(assemblies) $(CSC) /out:glade-viewer.exe $(references) $(srcdir)/GladeViewer.cs @@ -130,6 +133,7 @@ EXTRA_DIST = \ ScribbleXInput.cs \ TreeViewDemo.cs \ ManagedTreeViewDemo.cs \ + NodeViewDemo.cs \ GladeViewer.cs \ GladeTest.cs \ test.glade \ diff --git a/sample/NodeViewDemo.cs b/sample/NodeViewDemo.cs new file mode 100644 index 000000000..b44cd2d21 --- /dev/null +++ b/sample/NodeViewDemo.cs @@ -0,0 +1,164 @@ +// NodeViewDemo.cs - rework of TreeViewDemo to use NodeView. +// +// Author: Mike Kestner +// +// Copyright (c) 2004 Novell, Inc. + +namespace GtkSamples { + + using System; + using System.Reflection; + using Gtk; + + [TreeNode (ColumnCount=2)] + public class DemoTreeNode : TreeNode { + + string name; + string desc; + static int count = 0; + + public DemoTreeNode (string name, string desc) + { + this.name = name; + this.desc = desc; + count++; + } + + [TreeNodeValue (Column=0)] + public string Name { + get { return 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 (), "text", 1); + + sw.Add (view); + + dialog.Destroy (); + dialog = null; + } + + 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); + 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 (""); + 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); + } + } +} diff --git a/sample/TreeViewDemo.cs b/sample/TreeViewDemo.cs index 0e77f1084..2b3a04118 100644 --- a/sample/TreeViewDemo.cs +++ b/sample/TreeViewDemo.cs @@ -14,9 +14,12 @@ namespace GtkSamples { private static TreeStore store = null; private static Dialog dialog = null; private static Label dialog_label = null; + private static int count = 0; public TreeViewDemo () { + DateTime start = DateTime.Now; + Application.Init (); PopulateStore (); @@ -42,6 +45,8 @@ namespace GtkSamples { win.ShowAll (); + Console.WriteLine (count + " nodes added."); + Console.WriteLine ("Startup time: " + DateTime.Now.Subtract (start)); Application.Run (); } @@ -49,6 +54,7 @@ namespace GtkSamples { { foreach (MemberInfo mi in t.GetMembers ()) { store.AppendValues (parent, mi.Name, mi.ToString ()); + count++; } } @@ -59,6 +65,7 @@ namespace GtkSamples { 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 ()); + count++; ProcessType (iter, t); } } @@ -75,6 +82,7 @@ namespace GtkSamples { UpdateDialog ("Loading {0}", asm.GetName ().Name); TreeIter iter = store.AppendValues (asm.GetName ().Name, "Assembly"); + count++; ProcessAssembly (iter, asm); } }