~ubuntu-branches/ubuntu/intrepid/monodevelop/intrepid

« back to all changes in this revision

Viewing changes to Extras/MonoDevelop.DesignerSupport/MonoDevelop.DesignerSupport.PropertyGrid.Editors/EnumEditor.cs

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Dröge
  • Date: 2007-07-16 13:29:54 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20070716132954-pzjpp1tbvotxw30v
Tags: 0.14+dfsg-1ubuntu1
* Sync with Debian, remaining changes:
  + debian/control:
    - Build depend on firefox-dev, depend on firefox.
    - Adjust Maintainer field.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* 
2
 
 * EnumEditor.cs - Visual editor for Enumerations
3
 
 * 
4
 
 * Part of PropertyGrid - A Gtk# widget that displays and allows 
5
 
 * editing of all of an object's public properties 
6
 
 * 
7
 
 * Authors: 
8
 
 *  Michael Hutchinson <m.j.hutchinson@gmail.com>
9
 
 *  
10
 
 * Copyright (C) 2005 Michael Hutchinson
11
 
 *
12
 
 * This sourcecode is licenced under The MIT License:
13
 
 * 
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:
21
 
 * 
22
 
 * The above copyright notice and this permission notice shall be included in
23
 
 * all copies or substantial portions of the Software.
24
 
 *
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.
32
 
 */
33
 
 
34
 
using System;
35
 
using System.ComponentModel;
36
 
using Gtk;
37
 
using System.Collections;
38
 
using MonoDevelop.DesignerSupport.PropertyGrid;
39
 
 
40
 
namespace MonoDevelop.DesignerSupport.PropertyGrid.PropertyEditors
41
 
{
42
 
 
43
 
        [PropertyEditorType(typeof(System.Enum))]
44
 
        public class EnumEditor : BaseEditor
45
 
        {
46
 
                ListStore namestore;
47
 
 
48
 
                public EnumEditor (GridRow parentRow)
49
 
                        : base (parentRow)
50
 
                {
51
 
                        if (!parentRow.PropertyDescriptor.PropertyType.IsEnum)
52
 
                                throw new Exception ("property is not an enum");
53
 
                }
54
 
 
55
 
                public override bool InPlaceEdit {
56
 
                        get { return true; }
57
 
                }
58
 
 
59
 
                public override Widget GetDisplayWidget ()
60
 
                {
61
 
                        return base.StringValue (parentRow.PropertyDescriptor.Converter.ConvertToString (parentRow.PropertyValue));
62
 
                }
63
 
 
64
 
                public override Gtk.Widget GetEditWidget ()
65
 
                {
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);
71
 
 
72
 
                        Array values = System.Enum.GetValues (parentRow.PropertyDescriptor.PropertyType);
73
 
 
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);
79
 
                        }
80
 
 
81
 
                        combo.Changed += new EventHandler (combo_Changed);
82
 
                        combo.Destroyed += new EventHandler (combo_Destroyed);
83
 
                        return combo;
84
 
                }
85
 
 
86
 
                void combo_Destroyed (object sender, EventArgs e)
87
 
                {
88
 
                        namestore.Dispose ();
89
 
                }
90
 
 
91
 
                void combo_Changed (object sender, EventArgs e)
92
 
                {
93
 
                        TreeIter t;
94
 
                        ((ComboBox) sender).GetActiveIter(out t);
95
 
                        parentRow.PropertyValue = parentRow.PropertyDescriptor.Converter.ConvertFromString ((string) namestore.GetValue (t, 0));
96
 
                }
97
 
 
98
 
                public override bool DialogueEdit {
99
 
                        get { return false; }
100
 
                }
101
 
}
102
 
}