2005-09-02 Ben Maurer <bmaurer@ximian.com>
* sample/NodeViewDemo.cs: take advantage of the stuff below * gtk/TreeNodeValueAttribute.cs: Allow on props * gtk/TreeNodeAttribute.cs: Obsolete column count * gtk/NodeStore.cs: Change this to not need the TreeNodeAttribute column count. Handle fields as well as properties. svn path=/trunk/gtk-sharp/; revision=49374
This commit is contained in:
parent
06c4a3811f
commit
85eee0cb43
5 changed files with 55 additions and 33 deletions
11
ChangeLog
11
ChangeLog
|
@ -1,3 +1,14 @@
|
|||
2005-09-02 Ben Maurer <bmaurer@ximian.com>
|
||||
|
||||
* sample/NodeViewDemo.cs: take advantage of the stuff below
|
||||
|
||||
* gtk/TreeNodeValueAttribute.cs: Allow on props
|
||||
|
||||
* gtk/TreeNodeAttribute.cs: Obsolete column count
|
||||
|
||||
* gtk/NodeStore.cs: Change this to not need the TreeNodeAttribute
|
||||
column count. Handle fields as well as properties.
|
||||
|
||||
2005-08-30 Mike Kestner <mkestner@novell.com>
|
||||
|
||||
* gdk/Event.cs : add some null guarding to GetEvent.
|
||||
|
|
|
@ -92,8 +92,8 @@ namespace Gtk {
|
|||
|
||||
Hashtable node_hash = new IDHashtable ();
|
||||
GLib.GType[] ctypes;
|
||||
PropertyInfo[] getters;
|
||||
int n_cols = 1;
|
||||
MemberInfo [] getters;
|
||||
int n_cols;
|
||||
bool list_only = false;
|
||||
ArrayList nodes = new ArrayList ();
|
||||
TreeModelIfaceDelegates tree_model_iface;
|
||||
|
@ -150,7 +150,11 @@ namespace Gtk {
|
|||
if (node == null)
|
||||
return;
|
||||
g_value_init (ref val, ctypes [col].Val);
|
||||
object col_val = getters[col].GetValue (node, null);
|
||||
object col_val;
|
||||
if (getters [col] is PropertyInfo)
|
||||
col_val = ((PropertyInfo) getters [col]).GetValue (node, null);
|
||||
else
|
||||
col_val = ((FieldInfo) getters [col]).GetValue (node);
|
||||
val.Val = col_val;
|
||||
}
|
||||
|
||||
|
@ -293,19 +297,34 @@ namespace Gtk {
|
|||
|
||||
void ScanType (Type type)
|
||||
{
|
||||
foreach (TreeNodeAttribute attr in type.GetCustomAttributes (typeof (TreeNodeAttribute), false)) {
|
||||
n_cols = attr.ColumnCount;
|
||||
list_only = attr.ListOnly;
|
||||
}
|
||||
TreeNodeAttribute tna = (TreeNodeAttribute) Attribute.GetCustomAttribute (type, typeof (TreeNodeAttribute), false);
|
||||
if (tna != null)
|
||||
list_only = tna.ListOnly;
|
||||
|
||||
ArrayList minfos = new ArrayList ();
|
||||
|
||||
foreach (PropertyInfo pi in type.GetProperties ())
|
||||
foreach (TreeNodeValueAttribute attr in pi.GetCustomAttributes (typeof (TreeNodeValueAttribute), false))
|
||||
minfos.Add (pi);
|
||||
|
||||
foreach (FieldInfo fi in type.GetFields ())
|
||||
foreach (TreeNodeValueAttribute attr in fi.GetCustomAttributes (typeof (TreeNodeValueAttribute), false))
|
||||
minfos.Add (fi);
|
||||
|
||||
ctypes = new GLib.GType [minfos.Count];
|
||||
getters = new MemberInfo [minfos.Count];
|
||||
|
||||
ctypes = new GLib.GType [n_cols];
|
||||
getters = new PropertyInfo [n_cols];
|
||||
|
||||
foreach (PropertyInfo pi in type.GetProperties ()) {
|
||||
foreach (TreeNodeValueAttribute attr in pi.GetCustomAttributes (typeof (TreeNodeValueAttribute), false)) {
|
||||
foreach (MemberInfo mi in minfos) {
|
||||
foreach (TreeNodeValueAttribute attr in mi.GetCustomAttributes (typeof (TreeNodeValueAttribute), false)) {
|
||||
int col = attr.Column;
|
||||
getters [col] = pi;
|
||||
ctypes[col] = (GLib.GType) pi.PropertyType;
|
||||
|
||||
if (getters [col] != null)
|
||||
throw new Exception ("You have two TreeNodeValueAttributes with the same column");
|
||||
|
||||
getters [col] = mi;
|
||||
Type t = mi is PropertyInfo ? ((PropertyInfo) mi).PropertyType
|
||||
: ((FieldInfo) mi).FieldType;
|
||||
ctypes [col] = (GLib.GType) t;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,16 +25,12 @@ namespace Gtk {
|
|||
|
||||
[AttributeUsage(AttributeTargets.Class)]
|
||||
public sealed class TreeNodeAttribute : Attribute {
|
||||
int col_count;
|
||||
bool list_only;
|
||||
|
||||
|
||||
[Obsolete ("This is no longer needed; it gets detected by Gtk#")]
|
||||
public int ColumnCount {
|
||||
get {
|
||||
return col_count;
|
||||
}
|
||||
set {
|
||||
col_count = value;
|
||||
}
|
||||
get { return 0; }
|
||||
set { }
|
||||
}
|
||||
|
||||
public bool ListOnly {
|
||||
|
|
|
@ -23,7 +23,7 @@ namespace Gtk {
|
|||
|
||||
using System;
|
||||
|
||||
[AttributeUsage (AttributeTargets.Property, AllowMultiple = true)]
|
||||
[AttributeUsage (AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = true)]
|
||||
public sealed class TreeNodeValueAttribute : Attribute {
|
||||
|
||||
int col;
|
||||
|
|
|
@ -10,25 +10,21 @@ namespace GtkSamples {
|
|||
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.Name = name;
|
||||
this.desc = desc;
|
||||
count++;
|
||||
}
|
||||
|
||||
[TreeNodeValue (Column=0)]
|
||||
public string Name {
|
||||
get { return name; }
|
||||
}
|
||||
|
||||
|
||||
// TreeNodeValues can come from both properties and fields
|
||||
[TreeNodeValue (Column=0)]
|
||||
public string Name;
|
||||
|
||||
[TreeNodeValue (Column=1)]
|
||||
public string Description {
|
||||
get { return desc; }
|
||||
|
|
Loading…
Add table
Reference in a new issue