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

« back to all changes in this revision

Viewing changes to src/addins/MonoDevelop.GtkCore/lib/stetic/libstetic/editor/WidgetSelector.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
 
 
2
 
using System;
3
 
using System.Collections;
4
 
using Gtk;
5
 
using Gdk;
6
 
 
7
 
namespace Stetic.Editor
8
 
{
9
 
        public class WidgetSelector: ComboBox, IPropertyEditor
10
 
        {
11
 
                Gtk.Widget obj;
12
 
                ListStore store;
13
 
                Hashtable widgets = new Hashtable ();
14
 
                
15
 
                public void Initialize (PropertyDescriptor descriptor)
16
 
                {
17
 
                        store = new ListStore (typeof(Pixbuf), typeof(string));
18
 
                        Model = store;
19
 
                        store.SetSortColumnId (1, SortType.Ascending);
20
 
                        CellRendererPixbuf crp = new CellRendererPixbuf ();
21
 
                        CellRendererText crt = new CellRendererText ();
22
 
                        PackStart (crp, false);
23
 
                        PackStart (crt, true);
24
 
                        SetAttributes (crp, "pixbuf", 0);
25
 
                        SetAttributes (crt, "text", 1);
26
 
                }
27
 
                
28
 
                public void AttachObject (object obj)
29
 
                {
30
 
                        this.obj = obj as Gtk.Widget;
31
 
                        FillWidgets ();
32
 
                }
33
 
                
34
 
                void FillWidgets ()
35
 
                {
36
 
                        store.Clear ();
37
 
                        widgets.Clear ();
38
 
                        
39
 
                        Stetic.Wrapper.Widget widget = Stetic.Wrapper.Widget.Lookup (obj);
40
 
                        if (widget == null)
41
 
                                return;
42
 
                                
43
 
                        while (!widget.IsTopLevel)
44
 
                                widget = widget.ParentWrapper;
45
 
                        
46
 
                        store.AppendValues (null, "(None)");
47
 
                        FillWidgets (widget, 0);
48
 
                }
49
 
                
50
 
                void FillWidgets (Stetic.Wrapper.Widget widget, int level)
51
 
                {
52
 
                        if (!widget.Unselectable) {
53
 
                                TreeIter iter = store.AppendValues (widget.ClassDescriptor.Icon, widget.Wrapped.Name);
54
 
                                widgets [widget.Wrapped.Name] = iter;
55
 
                        }
56
 
                        Gtk.Container cont = widget.Wrapped as Gtk.Container;
57
 
                        if (cont != null && widget.ClassDescriptor.AllowChildren) {
58
 
                                foreach (Gtk.Widget child in cont.AllChildren) {
59
 
                                        Stetic.Wrapper.Widget cwidget = Stetic.Wrapper.Widget.Lookup (child);
60
 
                                        if (cwidget != null)
61
 
                                                FillWidgets (cwidget, level+1);
62
 
                                }
63
 
                        }
64
 
                }
65
 
                
66
 
                
67
 
                public object Value {
68
 
                        get {
69
 
                                if (Active <= 0)
70
 
                                        return null;
71
 
                                else {
72
 
                                        TreeIter iter;
73
 
                                        if (!GetActiveIter (out iter))
74
 
                                                return null;
75
 
                                        return (string) store.GetValue (iter, 1);
76
 
                                }
77
 
                        }
78
 
                        set {
79
 
                                if (value == null)
80
 
                                        Active = 0;
81
 
                                else if (widgets.Contains ((string) value)) {
82
 
                                        TreeIter iter = (TreeIter) widgets [value];
83
 
                                        SetActiveIter (iter);
84
 
                                }
85
 
                        }
86
 
                }
87
 
                
88
 
                protected override void OnChanged ()
89
 
                {
90
 
                        base.OnChanged ();
91
 
                        if (ValueChanged != null)
92
 
                                ValueChanged (this, EventArgs.Empty);
93
 
                }
94
 
 
95
 
                // To be fired when the edited value changes.
96
 
                public event EventHandler ValueChanged;
97
 
        }
98
 
}