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>
|
2005-08-30 Mike Kestner <mkestner@novell.com>
|
||||||
|
|
||||||
* gdk/Event.cs : add some null guarding to GetEvent.
|
* gdk/Event.cs : add some null guarding to GetEvent.
|
||||||
|
|
|
@ -92,8 +92,8 @@ namespace Gtk {
|
||||||
|
|
||||||
Hashtable node_hash = new IDHashtable ();
|
Hashtable node_hash = new IDHashtable ();
|
||||||
GLib.GType[] ctypes;
|
GLib.GType[] ctypes;
|
||||||
PropertyInfo[] getters;
|
MemberInfo [] getters;
|
||||||
int n_cols = 1;
|
int n_cols;
|
||||||
bool list_only = false;
|
bool list_only = false;
|
||||||
ArrayList nodes = new ArrayList ();
|
ArrayList nodes = new ArrayList ();
|
||||||
TreeModelIfaceDelegates tree_model_iface;
|
TreeModelIfaceDelegates tree_model_iface;
|
||||||
|
@ -150,7 +150,11 @@ namespace Gtk {
|
||||||
if (node == null)
|
if (node == null)
|
||||||
return;
|
return;
|
||||||
g_value_init (ref val, ctypes [col].Val);
|
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;
|
val.Val = col_val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -293,19 +297,34 @@ namespace Gtk {
|
||||||
|
|
||||||
void ScanType (Type type)
|
void ScanType (Type type)
|
||||||
{
|
{
|
||||||
foreach (TreeNodeAttribute attr in type.GetCustomAttributes (typeof (TreeNodeAttribute), false)) {
|
TreeNodeAttribute tna = (TreeNodeAttribute) Attribute.GetCustomAttribute (type, typeof (TreeNodeAttribute), false);
|
||||||
n_cols = attr.ColumnCount;
|
if (tna != null)
|
||||||
list_only = attr.ListOnly;
|
list_only = tna.ListOnly;
|
||||||
}
|
|
||||||
|
|
||||||
ctypes = new GLib.GType [n_cols];
|
ArrayList minfos = new ArrayList ();
|
||||||
getters = new PropertyInfo [n_cols];
|
|
||||||
|
|
||||||
foreach (PropertyInfo pi in type.GetProperties ()) {
|
foreach (PropertyInfo pi in type.GetProperties ())
|
||||||
foreach (TreeNodeValueAttribute attr in pi.GetCustomAttributes (typeof (TreeNodeValueAttribute), false)) {
|
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];
|
||||||
|
|
||||||
|
foreach (MemberInfo mi in minfos) {
|
||||||
|
foreach (TreeNodeValueAttribute attr in mi.GetCustomAttributes (typeof (TreeNodeValueAttribute), false)) {
|
||||||
int col = attr.Column;
|
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)]
|
[AttributeUsage(AttributeTargets.Class)]
|
||||||
public sealed class TreeNodeAttribute : Attribute {
|
public sealed class TreeNodeAttribute : Attribute {
|
||||||
int col_count;
|
|
||||||
bool list_only;
|
bool list_only;
|
||||||
|
|
||||||
|
[Obsolete ("This is no longer needed; it gets detected by Gtk#")]
|
||||||
public int ColumnCount {
|
public int ColumnCount {
|
||||||
get {
|
get { return 0; }
|
||||||
return col_count;
|
set { }
|
||||||
}
|
|
||||||
set {
|
|
||||||
col_count = value;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool ListOnly {
|
public bool ListOnly {
|
||||||
|
|
|
@ -23,7 +23,7 @@ namespace Gtk {
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
[AttributeUsage (AttributeTargets.Property, AllowMultiple = true)]
|
[AttributeUsage (AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = true)]
|
||||||
public sealed class TreeNodeValueAttribute : Attribute {
|
public sealed class TreeNodeValueAttribute : Attribute {
|
||||||
|
|
||||||
int col;
|
int col;
|
||||||
|
|
|
@ -10,24 +10,20 @@ namespace GtkSamples {
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using Gtk;
|
using Gtk;
|
||||||
|
|
||||||
[TreeNode (ColumnCount=2)]
|
|
||||||
public class DemoTreeNode : TreeNode {
|
public class DemoTreeNode : TreeNode {
|
||||||
|
|
||||||
string name;
|
|
||||||
string desc;
|
string desc;
|
||||||
static int count = 0;
|
static int count = 0;
|
||||||
|
|
||||||
public DemoTreeNode (string name, string desc)
|
public DemoTreeNode (string name, string desc)
|
||||||
{
|
{
|
||||||
this.name = name;
|
this.Name = name;
|
||||||
this.desc = desc;
|
this.desc = desc;
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TreeNodeValues can come from both properties and fields
|
||||||
[TreeNodeValue (Column=0)]
|
[TreeNodeValue (Column=0)]
|
||||||
public string Name {
|
public string Name;
|
||||||
get { return name; }
|
|
||||||
}
|
|
||||||
|
|
||||||
[TreeNodeValue (Column=1)]
|
[TreeNodeValue (Column=1)]
|
||||||
public string Description {
|
public string Description {
|
||||||
|
|
Loading…
Add table
Reference in a new issue