2
* EnumEditor.cs - Visual editor for Enumerations
4
* Part of PropertyGrid - A Gtk# widget that displays and allows
5
* editing of all of an object's public properties
8
* Michael Hutchinson <m.j.hutchinson@gmail.com>
10
* Copyright (C) 2005 Michael Hutchinson
12
* This sourcecode is licenced under The MIT License:
14
* Permission is hereby granted, free of charge, to any person obtaining
15
* a copy of this software and associated documentation files (the
16
* "Software"), to deal in the Software without restriction, including
17
* without limitation the rights to use, copy, modify, merge, publish,
18
* distribute, sublicense, and/or sell copies of the Software, and to permit
19
* persons to whom the Software is furnished to do so, subject to the
20
* following conditions:
22
* The above copyright notice and this permission notice shall be included in
23
* all copies or substantial portions of the Software.
25
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
26
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
28
* NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
29
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
30
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
31
* USE OR OTHER DEALINGS IN THE SOFTWARE.
35
using System.ComponentModel;
37
using System.Collections;
38
using MonoDevelop.DesignerSupport.PropertyGrid;
40
namespace MonoDevelop.DesignerSupport.PropertyGrid.PropertyEditors
43
[PropertyEditorType(typeof(System.Enum))]
44
public class EnumEditor : BaseEditor
48
public EnumEditor (GridRow parentRow)
51
if (!parentRow.PropertyDescriptor.PropertyType.IsEnum)
52
throw new Exception ("property is not an enum");
55
public override bool InPlaceEdit {
59
public override Widget GetDisplayWidget ()
61
return base.StringValue (parentRow.PropertyDescriptor.Converter.ConvertToString (parentRow.PropertyValue));
64
public override Gtk.Widget GetEditWidget ()
66
namestore = new ListStore (typeof(string));
67
ComboBox combo = new ComboBox (namestore);
68
CellRenderer rdr = new CellRendererText ();
69
combo.PackStart (rdr, true);
70
combo.AddAttribute (rdr, "text", 0);
72
Array values = System.Enum.GetValues (parentRow.PropertyDescriptor.PropertyType);
74
foreach (object s in values) {
75
string str = parentRow.PropertyDescriptor.Converter.ConvertToString (s);
76
TreeIter t = namestore.AppendValues (str);
77
if (str == parentRow.PropertyDescriptor.Converter.ConvertToString (parentRow.PropertyValue))
78
combo.SetActiveIter (t);
81
combo.Changed += new EventHandler (combo_Changed);
82
combo.Destroyed += new EventHandler (combo_Destroyed);
86
void combo_Destroyed (object sender, EventArgs e)
91
void combo_Changed (object sender, EventArgs e)
94
((ComboBox) sender).GetActiveIter(out t);
95
parentRow.PropertyValue = parentRow.PropertyDescriptor.Converter.ConvertFromString ((string) namestore.GetValue (t, 0));
98
public override bool DialogueEdit {