~ubuntu-branches/ubuntu/natty/monodevelop/natty

« back to all changes in this revision

Viewing changes to src/core/MonoDevelop.Ide/MonoDevelop.Components.PropertyGrid.Editors/FlagsSelectorDialog.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2010-07-05 13:00:05 UTC
  • mfrom: (1.2.8 upstream) (1.3.9 experimental)
  • Revision ID: james.westby@ubuntu.com-20100705130005-d6hp4k5gcn1xkj8c
Tags: 2.4+dfsg-1ubuntu1
* debian/patches/remove_support_for_moonlight.patch,
  debian/patches/dont_add_moonlight_to_core_addins.patch,
  debian/control:
  + Enable support for Moonlight
* debian/rules:
  + Ensure Moonlight addin isn't shipped in main MonoDevelop package by
    mistake

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// FlagsSelectorDialog.cs
 
3
//
 
4
// Author:
 
5
//   Lluis Sanchez Gual
 
6
//
 
7
// Copyright (C) 2007 Novell, Inc (http://www.novell.com)
 
8
//
 
9
// Permission is hereby granted, free of charge, to any person obtaining
 
10
// a copy of this software and associated documentation files (the
 
11
// "Software"), to deal in the Software without restriction, including
 
12
// without limitation the rights to use, copy, modify, merge, publish,
 
13
// distribute, sublicense, and/or sell copies of the Software, and to
 
14
// permit persons to whom the Software is furnished to do so, subject to
 
15
// the following conditions:
 
16
// 
 
17
// The above copyright notice and this permission notice shall be
 
18
// included in all copies or substantial portions of the Software.
 
19
// 
 
20
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 
21
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 
22
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 
23
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 
24
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 
25
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 
26
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
27
//
 
28
 
 
29
using System;
 
30
 
 
31
namespace MonoDevelop.Components.PropertyGrid.PropertyEditors
 
32
{
 
33
        public class FlagsSelectorDialog: IDisposable
 
34
        {
 
35
                Gtk.TreeView treeView;
 
36
                Gtk.Dialog dialog;
 
37
                Gtk.ListStore store;
 
38
                Gtk.Window parent;
 
39
                ulong flags;
 
40
                
 
41
                public FlagsSelectorDialog (Gtk.Window parent, Type enumDesc, ulong flags, string title)
 
42
                {
 
43
                        this.flags = flags;
 
44
                        this.parent = parent;
 
45
 
 
46
                        Gtk.ScrolledWindow sc = new Gtk.ScrolledWindow ();
 
47
                        sc.HscrollbarPolicy = Gtk.PolicyType.Automatic;
 
48
                        sc.VscrollbarPolicy = Gtk.PolicyType.Automatic;
 
49
                        sc.ShadowType = Gtk.ShadowType.In;
 
50
                        sc.BorderWidth = 6;
 
51
                        
 
52
                        treeView = new Gtk.TreeView ();
 
53
                        sc.Add (treeView);
 
54
                        
 
55
                        dialog = new Gtk.Dialog ();
 
56
                        dialog.VBox.Add (sc);
 
57
                        dialog.AddButton (Gtk.Stock.Cancel, Gtk.ResponseType.Cancel);
 
58
                        dialog.AddButton (Gtk.Stock.Ok, Gtk.ResponseType.Ok);
 
59
                        
 
60
                        store = new Gtk.ListStore (typeof(bool), typeof(string), typeof(ulong));
 
61
                        treeView.Model = store;
 
62
                        treeView.HeadersVisible = false;
 
63
                        
 
64
                        Gtk.TreeViewColumn col = new Gtk.TreeViewColumn ();
 
65
                        
 
66
                        Gtk.CellRendererToggle tog = new Gtk.CellRendererToggle ();
 
67
                        tog.Toggled += new Gtk.ToggledHandler (OnToggled);
 
68
                        col.PackStart (tog, false);
 
69
                        col.AddAttribute (tog, "active", 0);
 
70
                        
 
71
                        Gtk.CellRendererText crt = new Gtk.CellRendererText ();
 
72
                        col.PackStart (crt, true);
 
73
                        col.AddAttribute (crt, "text", 1);
 
74
                        
 
75
                        treeView.AppendColumn (col);
 
76
                        
 
77
                        foreach (object value in System.Enum.GetValues (enumDesc)) {
 
78
                                ulong val = Convert.ToUInt64 (value);
 
79
                                store.AppendValues (((flags & val) != 0), value.ToString (), val);
 
80
                        }
 
81
                }
 
82
                
 
83
                public int Run ()
 
84
                {
 
85
                        dialog.DefaultWidth = 500;
 
86
                        dialog.DefaultHeight = 400;
 
87
                        dialog.ShowAll ();
 
88
                        return MonoDevelop.Ide.MessageService.RunCustomDialog (dialog, parent);
 
89
                }
 
90
                
 
91
                public void Dispose ()
 
92
                {
 
93
                        dialog.Destroy ();
 
94
                }
 
95
                
 
96
                void OnToggled (object s, Gtk.ToggledArgs args)
 
97
                {
 
98
                        Gtk.TreeIter iter;
 
99
                        if (!store.GetIterFromString (out iter, args.Path))
 
100
                                return;
 
101
                        
 
102
                        bool oldValue = (bool) store.GetValue (iter, 0);
 
103
                        ulong flag = (ulong) store.GetValue (iter, 2);
 
104
                        store.SetValue (iter, 0, !oldValue);
 
105
                        
 
106
                        if (oldValue)
 
107
                                flags &= ~flag;
 
108
                        else
 
109
                                flags |= flag;
 
110
                }
 
111
 
 
112
                public ulong Value {
 
113
                        get { return flags; }
 
114
                }
 
115
        }
 
116
}