~ubuntu-branches/ubuntu/oneiric/monodevelop/oneiric-updates

« back to all changes in this revision

Viewing changes to src/addins/MonoDevelop.GtkCore/libstetic/editor/Enumeration.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2009-02-18 08:40:51 UTC
  • mfrom: (1.2.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20090218084051-gh8m6ukvokbwj7cf
Tags: 1.9.2+dfsg-1ubuntu1
* Merge from Debian Experimental (LP: #330519), remaining Ubuntu changes:
  + debian/control:
    - Update for Gnome# 2.24
    - Add libmono-cairo1.0-cil to build-deps to fool pkg-config check

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
using System;
 
2
using System.Collections;
 
3
 
 
4
namespace Stetic.Editor {
 
5
 
 
6
        public class Enumeration: PropertyEditorCell
 
7
        {
 
8
                protected override string GetValueText ()
 
9
                {
 
10
                        if (Value == null)
 
11
                                return "";
 
12
 
 
13
                        EnumDescriptor enm = Registry.LookupEnum (Property.PropertyType.FullName);
 
14
                        EnumValue ev = enm [(Enum)Value];
 
15
                        if (ev != null)
 
16
                                return ev.Label;
 
17
                        else
 
18
                                return "";
 
19
                }
 
20
                
 
21
                protected override IPropertyEditor CreateEditor (Gdk.Rectangle cell_area, Gtk.StateType state)
 
22
                {
 
23
                        return new EnumerationEditor ();
 
24
                }
 
25
        }
 
26
        
 
27
        public class EnumerationEditor : Gtk.HBox, IPropertyEditor {
 
28
 
 
29
                Gtk.EventBox ebox;
 
30
                Gtk.ComboBoxEntry combo;
 
31
                Gtk.Tooltips tips;
 
32
                EnumDescriptor enm;
 
33
 
 
34
                public EnumerationEditor () : base (false, 0)
 
35
                {
 
36
                }
 
37
                
 
38
                public void Initialize (PropertyDescriptor prop)
 
39
                {
 
40
                        if (!prop.PropertyType.IsEnum)
 
41
                                throw new ApplicationException ("Enumeration editor does not support editing values of type " + prop.PropertyType);
 
42
                                
 
43
                        ebox = new Gtk.EventBox ();
 
44
                        ebox.Show ();
 
45
                        PackStart (ebox, true, true, 0);
 
46
 
 
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
 
52
                        combo.Show ();
 
53
                        ebox.Add (combo);
 
54
 
 
55
                        tips = new Gtk.Tooltips ();
 
56
 
 
57
                        enm = Registry.LookupEnum (prop.PropertyType.FullName);
 
58
                        foreach (Enum value in enm.Values)
 
59
                                combo.AppendText (enm[value].Label);
 
60
                }
 
61
 
 
62
                public void AttachObject (object obj)
 
63
                {
 
64
                }
 
65
                
 
66
                public override void Dispose ()
 
67
                {
 
68
                        tips.Destroy ();
 
69
                        base.Dispose ();
 
70
                }
 
71
 
 
72
                public object Value {
 
73
                        get {
 
74
                                return enm.Values[combo.Active];
 
75
                        }
 
76
                        set {
 
77
                                int i = Array.IndexOf (enm.Values, (Enum)value);
 
78
                                if (i != -1)
 
79
                                        combo.Active = i;
 
80
                        }
 
81
                }
 
82
 
 
83
                public event EventHandler ValueChanged;
 
84
 
 
85
                void combo_Changed (object o, EventArgs args)
 
86
                {
 
87
                        if (ValueChanged != null)
 
88
                                ValueChanged (this, EventArgs.Empty);
 
89
                        EnumValue value = enm[(Enum)Value];
 
90
                        if (value != null)
 
91
                                tips.SetTip (ebox, value.Description, value.Description);
 
92
                        else
 
93
                                tips.SetTip (ebox, null, null);
 
94
                }
 
95
        }
 
96
}