~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/FlagsSelectorDialog.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
 
 
4
 
namespace Stetic.Editor
5
 
{
6
 
        public class FlagsSelectorDialog: IDisposable
7
 
        {
8
 
                [Glade.Widget] Gtk.TreeView treeView;
9
 
                [Glade.Widget ("FlagsSelectorDialog")] Gtk.Dialog dialog;
10
 
                Gtk.ListStore store;
11
 
                Gtk.Window parent;
12
 
                uint flags;
13
 
                
14
 
                public FlagsSelectorDialog (Gtk.Window parent, EnumDescriptor enumDesc, uint flags, string title)
15
 
                {
16
 
                        this.flags = flags;
17
 
                        this.parent = parent;
18
 
 
19
 
                        Glade.XML xml = new Glade.XML (null, "stetic.glade", "FlagsSelectorDialog", null);
20
 
                        xml.Autoconnect (this);
21
 
                        
22
 
                        store = new Gtk.ListStore (typeof(bool), typeof(string), typeof(uint));
23
 
                        treeView.Model = store;
24
 
                        
25
 
                        Gtk.TreeViewColumn col = new Gtk.TreeViewColumn ();
26
 
                        
27
 
                        Gtk.CellRendererToggle tog = new Gtk.CellRendererToggle ();
28
 
                        tog.Toggled += new Gtk.ToggledHandler (OnToggled);
29
 
                        col.PackStart (tog, false);
30
 
                        col.AddAttribute (tog, "active", 0);
31
 
                        
32
 
                        Gtk.CellRendererText crt = new Gtk.CellRendererText ();
33
 
                        col.PackStart (crt, true);
34
 
                        col.AddAttribute (crt, "text", 1);
35
 
                        
36
 
                        treeView.AppendColumn (col);
37
 
                        
38
 
                        foreach (Enum value in enumDesc.Values) {
39
 
                                EnumValue eval = enumDesc[value];
40
 
                                if (eval.Label == "")
41
 
                                        continue;
42
 
                                uint val = (uint) (int) eval.Value;
43
 
                                store.AppendValues (((flags & val) != 0), eval.Label, val);
44
 
                        }
45
 
                }
46
 
                
47
 
                public int Run ()
48
 
                {
49
 
                        dialog.ShowAll ();
50
 
                        dialog.TransientFor = parent;
51
 
                        return dialog.Run ();
52
 
                }
53
 
                
54
 
                public void Dispose ()
55
 
                {
56
 
                        dialog.Destroy ();
57
 
                }
58
 
                
59
 
                void OnToggled (object s, Gtk.ToggledArgs args)
60
 
                {
61
 
                        Gtk.TreeIter iter;
62
 
                        if (!store.GetIterFromString (out iter, args.Path))
63
 
                                return;
64
 
                        
65
 
                        bool oldValue = (bool) store.GetValue (iter, 0);
66
 
                        uint flag = (uint) store.GetValue (iter, 2);
67
 
                        store.SetValue (iter, 0, !oldValue);
68
 
                        
69
 
                        if (oldValue)
70
 
                                flags &= ~flag;
71
 
                        else
72
 
                                flags |= flag;
73
 
                }
74
 
 
75
 
                public uint Value {
76
 
                        get { return flags; }
77
 
                }
78
 
        }
79
 
}