2
using System.Collections;
4
namespace Stetic.Editor {
6
public class Enumeration: PropertyEditorCell
8
protected override string GetValueText ()
13
EnumDescriptor enm = Registry.LookupEnum (Property.PropertyType.FullName);
14
EnumValue ev = enm [(Enum)Value];
21
protected override IPropertyEditor CreateEditor (Gdk.Rectangle cell_area, Gtk.StateType state)
23
return new EnumerationEditor ();
27
public class EnumerationEditor : Gtk.HBox, IPropertyEditor {
30
Gtk.ComboBoxEntry combo;
34
public EnumerationEditor () : base (false, 0)
38
public void Initialize (PropertyDescriptor prop)
40
if (!prop.PropertyType.IsEnum)
41
throw new ApplicationException ("Enumeration editor does not support editing values of type " + prop.PropertyType);
43
ebox = new Gtk.EventBox ();
45
PackStart (ebox, true, true, 0);
47
combo = Gtk.ComboBoxEntry.NewText ();
48
combo.Changed += combo_Changed;
49
combo.Entry.IsEditable = false;
50
combo.Entry.HasFrame = false;
51
combo.Entry.HeightRequest = combo.SizeRequest ().Height; // The combo does not set the entry to the correct size when it does not have a frame
55
tips = new Gtk.Tooltips ();
57
enm = Registry.LookupEnum (prop.PropertyType.FullName);
58
foreach (Enum value in enm.Values)
59
combo.AppendText (enm[value].Label);
62
public void AttachObject (object obj)
66
public override void Dispose ()
74
return enm.Values[combo.Active];
77
int i = Array.IndexOf (enm.Values, (Enum)value);
83
public event EventHandler ValueChanged;
85
void combo_Changed (object o, EventArgs args)
87
if (ValueChanged != null)
88
ValueChanged (this, EventArgs.Empty);
89
EnumValue value = enm[(Enum)Value];
91
tips.SetTip (ebox, value.Description, value.Description);
93
tips.SetTip (ebox, null, null);