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

« back to all changes in this revision

Viewing changes to src/addins/MonoDevelop.GtkCore/lib/stetic/libsteticui/WidgetTreeCombo.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 Gtk;
4
 
 
5
 
namespace Stetic
6
 
{
7
 
        internal class WidgetTreeCombo: Button
8
 
        {
9
 
                Label label;
10
 
                Image image;
11
 
                Stetic.Wrapper.Widget rootWidget;
12
 
                Stetic.IProject project;
13
 
                Stetic.Wrapper.Widget selection;
14
 
                WidgetTreePopup popup;
15
 
                
16
 
                public WidgetTreeCombo ()
17
 
                {
18
 
                        label = new Label ();
19
 
                        image = new Gtk.Image ();
20
 
                        
21
 
                        HBox bb = new HBox ();
22
 
                        bb.PackStart (image, false, false, 3);
23
 
                        bb.PackStart (label, true, true, 3);
24
 
                        label.Xalign = 0;
25
 
                        label.HeightRequest = 18;
26
 
                        bb.PackStart (new VSeparator (), false, false, 1);
27
 
                        bb.PackStart (new Arrow (ArrowType.Down, ShadowType.None), false, false, 1);
28
 
                        Child = bb;
29
 
                        this.WidthRequest = 300;
30
 
                        Sensitive = false;
31
 
                }
32
 
                
33
 
                public override void Dispose ()
34
 
                {
35
 
                        if (popup != null)
36
 
                                popup.Destroy ();
37
 
                        base.Dispose ();
38
 
                }
39
 
 
40
 
                
41
 
                public Stetic.Wrapper.Widget RootWidget {
42
 
                        get { return rootWidget; }
43
 
                        set {
44
 
                                rootWidget = value;
45
 
                                Sensitive = rootWidget != null;
46
 
                                if (rootWidget != null)
47
 
                                        project = rootWidget.Project;
48
 
                                Update ();
49
 
                        }
50
 
                }
51
 
                
52
 
                public void SetSelection (Stetic.Wrapper.Widget widget) 
53
 
                {
54
 
                        selection = widget;
55
 
                        Update ();
56
 
                }
57
 
                
58
 
                void Update ()
59
 
                {
60
 
                        if (selection != null) {
61
 
                                label.Text = selection.Wrapped.Name;
62
 
                                image.Pixbuf = selection.ClassDescriptor.Icon.ScaleSimple (16, 16, Gdk.InterpType.Bilinear);
63
 
                                image.Show ();
64
 
                        } else {
65
 
                                label.Text = "             ";
66
 
                                image.Hide ();
67
 
                        }
68
 
                }
69
 
                
70
 
                protected override void OnPressed ()
71
 
                {
72
 
                        base.OnPressed ();
73
 
                        if (popup == null) {
74
 
                                popup = new WidgetTreePopup (project);
75
 
                                popup.WidgetActivated += OnPopupActivated;
76
 
                                popup.SetDefaultSize (Allocation.Width, 500);
77
 
                        }
78
 
                        else if (popup.Visible) {
79
 
                                popup.Hide ();
80
 
                                return;
81
 
                        }
82
 
                        
83
 
                        int x, y;
84
 
                        ParentWindow.GetOrigin (out x, out y);
85
 
                        x += Allocation.X;
86
 
                        y += Allocation.Y + Allocation.Height;
87
 
                        
88
 
                        popup.Fill (RootWidget.Wrapped);
89
 
                        popup.Move (x, y);
90
 
                        popup.ShowAll ();
91
 
                }
92
 
                
93
 
                protected override bool OnFocusOutEvent (Gdk.EventFocus evnt)
94
 
                {
95
 
                        if (popup != null)
96
 
                                popup.Hide ();
97
 
                        return base.OnFocusOutEvent (evnt);
98
 
                }
99
 
 
100
 
                
101
 
                void OnPopupActivated (object s, EventArgs a)
102
 
                {
103
 
                        popup.Hide ();
104
 
                        Stetic.Wrapper.Widget wrapper = Stetic.Wrapper.Widget.Lookup (popup.Selection);
105
 
                        GLib.Timeout.Add (10, delegate {
106
 
                                wrapper.Select ();
107
 
                                return false;
108
 
                        });
109
 
                }
110
 
        }
111
 
        
112
 
        class WidgetTreePopup: Window
113
 
        {
114
 
                TreeView tree;
115
 
                TreeStore store;
116
 
                Gtk.Widget selection;
117
 
                Stetic.IProject project;
118
 
                
119
 
                public event EventHandler WidgetActivated;
120
 
                
121
 
                public WidgetTreePopup (Stetic.IProject project): base (WindowType.Popup)
122
 
                {
123
 
                        this.project = project;
124
 
                        Gtk.Frame frame = new Frame ();
125
 
                        frame.ShadowType = Gtk.ShadowType.Out;
126
 
                        Add (frame);
127
 
                        
128
 
                        Gtk.ScrolledWindow sc = new ScrolledWindow ();
129
 
                        sc.VscrollbarPolicy = PolicyType.Automatic;
130
 
                        sc.HscrollbarPolicy = PolicyType.Automatic;
131
 
                        frame.Add (sc);
132
 
                        
133
 
                        tree = new TreeView ();
134
 
                        store = new TreeStore (typeof(Gdk.Pixbuf), typeof(string), typeof(Widget));
135
 
                        tree.Model = store;
136
 
                        tree.HeadersVisible = false;
137
 
                        
138
 
                        TreeViewColumn col = new TreeViewColumn ();
139
 
                        CellRendererPixbuf cr = new CellRendererPixbuf ();
140
 
                        col.PackStart (cr, false);
141
 
                        col.AddAttribute (cr, "pixbuf", 0);
142
 
                        
143
 
                        CellRendererText tr = new CellRendererText ();
144
 
                        col.PackStart (tr, true);
145
 
                        col.AddAttribute (tr, "markup", 1);
146
 
                        
147
 
                        tree.AppendColumn (col);
148
 
                        
149
 
                        tree.ButtonReleaseEvent += OnButtonRelease;
150
 
                        tree.RowActivated += OnButtonRelease;
151
 
                        sc.Add (tree);
152
 
                        tree.GrabFocus ();
153
 
                        
154
 
                }
155
 
                
156
 
                public void Fill (Gtk.Widget widget)
157
 
                {
158
 
                        store.Clear ();
159
 
                        Fill (TreeIter.Zero, widget);
160
 
                }
161
 
                
162
 
                public void Fill (TreeIter iter, Gtk.Widget widget)
163
 
                {
164
 
                        Stetic.Wrapper.Widget wrapper = Stetic.Wrapper.Widget.Lookup (widget);
165
 
                        if (wrapper == null) return;
166
 
                        
167
 
                        if (!wrapper.Unselectable) {
168
 
                                
169
 
                                Gdk.Pixbuf icon = wrapper.ClassDescriptor.Icon.ScaleSimple (16, 16, Gdk.InterpType.Bilinear);
170
 
                                string txt;
171
 
                                if (widget == project.Selection)
172
 
                                        txt = "<b>" + GLib.Markup.EscapeText (widget.Name) + "</b>";
173
 
                                else
174
 
                                        txt = GLib.Markup.EscapeText (widget.Name);
175
 
                                
176
 
                                if (!iter.Equals (TreeIter.Zero))
177
 
                                        iter = store.AppendValues (iter, icon, txt, widget);
178
 
                                else
179
 
                                        iter = store.AppendValues (icon, txt, widget);
180
 
                        }
181
 
                        
182
 
                        Gtk.Container cc = widget as Gtk.Container;
183
 
                        if (cc != null && wrapper.ClassDescriptor.AllowChildren) {
184
 
                                foreach (Gtk.Widget child in cc.Children)
185
 
                                        Fill (iter, child);
186
 
                        }
187
 
                        if (widget == project.Selection) {
188
 
                                tree.ExpandToPath (store.GetPath (iter));
189
 
                                tree.ExpandRow (store.GetPath (iter), false);
190
 
                                tree.Selection.SelectIter (iter);
191
 
                        }
192
 
                }
193
 
                
194
 
                public Gtk.Widget Selection {
195
 
                        get { return selection; }
196
 
                }
197
 
                
198
 
                void OnButtonRelease (object s, EventArgs a)
199
 
                {
200
 
                        NotifyActivated ();
201
 
                }
202
 
                
203
 
                void NotifyActivated ()
204
 
                {
205
 
                        TreeIter iter;
206
 
                        if (!tree.Selection.GetSelected (out iter))
207
 
                                return;
208
 
                        selection = (Gtk.Widget) store.GetValue (iter, 2);
209
 
                        if (WidgetActivated != null)
210
 
                                WidgetActivated (this, EventArgs.Empty);
211
 
                }
212
 
        }
213
 
}