~ubuntu-branches/ubuntu/saucy/monodevelop/saucy-proposed

« back to all changes in this revision

Viewing changes to src/addins/NUnit/Gui/NUnitOptionsPanel.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2010-09-10 16:54:48 UTC
  • mfrom: (19.1.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20100910165448-0rybfk25zd4o9431
Tags: 2.4+dfsg-2
* debian/patches/inject_Mono.Debugger.Soft_source.patch,
  debian/patches/use_system_Mono.Debugger.Soft.patch,
  debian/control:
  + Build against system Soft Debugger, since we now have a new
    enough Mono to match MonoDevelop's required API

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
using System.Collections;
33
33
 
34
34
using MonoDevelop.Core;
35
 
using MonoDevelop.Core.Gui.Components;
36
35
using MonoDevelop.Components;
37
 
using MonoDevelop.Core.Gui.Dialogs;
 
36
using MonoDevelop.Ide.Gui.Dialogs;
38
37
using Gtk;
39
38
 
40
39
namespace MonoDevelop.NUnit
41
40
{
42
41
        public class NUnitOptionsPanel : OptionsPanel
43
42
        {
44
 
                
45
 
                sealed class NUnitOptionsWidget : GladeWidgetExtract
46
 
                {
47
 
                        // Gtk Controls
48
 
                        [Glade.Widget] Gtk.TreeView categoryTree;
49
 
                        [Glade.Widget] CheckButton useParentCheck;
50
 
                        [Glade.Widget] RadioButton noFilterRadio;
51
 
                        [Glade.Widget] RadioButton includeRadio;
52
 
                        [Glade.Widget] RadioButton excludeRadio;
53
 
                        [Glade.Widget] Button addButton;
54
 
                        [Glade.Widget] Button removeButton;
55
 
                        TreeStore store;
56
 
                        TreeViewColumn textColumn;
57
 
                        
58
 
                        UnitTest test;
59
 
                        string config;
60
 
                        NUnitCategoryOptions options;
61
 
                        NUnitCategoryOptions localOptions;
62
 
 
63
 
                        public NUnitOptionsWidget (Properties customizationObject) : base ("nunit.glade", "NUnitOptions")
64
 
                        {
65
 
                                test =  ((Properties)customizationObject).Get<UnitTest> ("UnitTest");
66
 
                                config =  ((Properties)customizationObject).Get<string> ("Config");
67
 
                                options = localOptions = (NUnitCategoryOptions) test.GetOptions (typeof(NUnitCategoryOptions), config);
68
 
                                
69
 
                                store = new TreeStore (typeof(string));
70
 
                                categoryTree.Model = store;
71
 
                                categoryTree.HeadersVisible = false;
72
 
                                
73
 
                                CellRendererText tr = new CellRendererText ();
74
 
                                tr.Editable = true;
75
 
                                tr.Edited += new EditedHandler (OnCategoryEdited);
76
 
                                textColumn = new TreeViewColumn ();
77
 
                                textColumn.Title = GettextCatalog.GetString ("Category");
78
 
                                textColumn.PackStart (tr, false);
79
 
                                textColumn.AddAttribute (tr, "text", 0);
80
 
                                textColumn.Expand = true;
81
 
                                categoryTree.AppendColumn (textColumn);
82
 
                                
83
 
                                if (test.Parent != null)
84
 
                                        useParentCheck.Active = !test.HasOptions (typeof(NUnitCategoryOptions), config);
85
 
                                else {
86
 
                                        useParentCheck.Active = false;
87
 
                                        useParentCheck.Sensitive = false;
88
 
                                }
89
 
                                
90
 
                                if (!options.EnableFilter)
91
 
                                        noFilterRadio.Active = true;
92
 
                                else if (options.Exclude)
93
 
                                        excludeRadio.Active = true;
94
 
                                else
95
 
                                        includeRadio.Active = true;
96
 
 
97
 
                                Fill ();
98
 
                                
99
 
                                noFilterRadio.Toggled += new EventHandler (OnFilterToggled);
100
 
                                includeRadio.Toggled += new EventHandler (OnFilterToggled);
101
 
                                excludeRadio.Toggled += new EventHandler (OnFilterToggled);
102
 
                                useParentCheck.Toggled += new EventHandler (OnToggledUseParent);
103
 
                                addButton.Clicked += new EventHandler (OnAddCategory);
104
 
                                removeButton.Clicked += new EventHandler (OnRemoveCategory);
105
 
                        }
106
 
                        
107
 
                        void Fill ()
108
 
                        {
109
 
                                noFilterRadio.Sensitive = !useParentCheck.Active;
110
 
                                includeRadio.Sensitive = !useParentCheck.Active;
111
 
                                excludeRadio.Sensitive = !useParentCheck.Active;
112
 
                                categoryTree.Sensitive = !useParentCheck.Active && !noFilterRadio.Active;
113
 
                                removeButton.Sensitive = !useParentCheck.Active && !noFilterRadio.Active;
114
 
                                addButton.Sensitive = !useParentCheck.Active && !noFilterRadio.Active;
115
 
                                
116
 
                                store.Clear ();
117
 
                                foreach (string cat in options.Categories)
118
 
                                        store.AppendValues (cat);
119
 
                        }
120
 
                        
121
 
                        void OnToggledUseParent (object sender, EventArgs args)
122
 
                        {
123
 
                                if (useParentCheck.Active)
124
 
                                        options = (NUnitCategoryOptions) test.Parent.GetOptions (typeof(NUnitCategoryOptions), config);
125
 
                                else
126
 
                                        options = localOptions;
127
 
 
128
 
                                if (!options.EnableFilter)
129
 
                                        noFilterRadio.Active = true;
130
 
                                else if (options.Exclude)
131
 
                                        excludeRadio.Active = true;
132
 
                                else
133
 
                                        includeRadio.Active = true;
134
 
 
135
 
                                Fill ();
136
 
                        }
137
 
                        
138
 
                        void OnFilterToggled (object sender, EventArgs args)
139
 
                        {
140
 
                                options.EnableFilter = !noFilterRadio.Active;
141
 
                                options.Exclude = excludeRadio.Active;
142
 
                                Fill ();
143
 
                        }
144
 
 
145
 
                        void OnAddCategory (object sender, EventArgs args)
146
 
                        {
147
 
                                TreeIter it = store.AppendValues ("");
148
 
                                categoryTree.SetCursor (store.GetPath (it), textColumn, true);
149
 
                        }
150
 
 
151
 
                        void OnRemoveCategory (object sender, EventArgs args)
152
 
                        {
153
 
                                Gtk.TreeModel foo;
154
 
                                Gtk.TreeIter iter;
155
 
                                if (!categoryTree.Selection.GetSelected (out foo, out iter))
156
 
                                        return;
157
 
                                string old = (string) store.GetValue (iter, 0);
158
 
                                options.Categories.Remove (old);
159
 
                                store.Remove (ref iter);
160
 
                        }
161
 
 
162
 
                        void OnCategoryEdited (object sender, EditedArgs args)
163
 
                        {
164
 
                                TreeIter iter;
165
 
                                if (!store.GetIter (out iter, new TreePath (args.Path)))
166
 
                                        return;
167
 
                                
168
 
                                string old = (string) store.GetValue (iter, 0);
169
 
                                if (args.NewText.Length == 0) {
170
 
                                        options.Categories.Remove (old);
171
 
                                        store.Remove (ref iter);
172
 
                                } else {
173
 
                                        int i = options.Categories.IndexOf (old);
174
 
                                        if (i == -1)
175
 
                                                options.Categories.Add (args.NewText);
176
 
                                        else
177
 
                                                options.Categories [i] = args.NewText;
178
 
                                        store.SetValue (iter, 0, args.NewText);
179
 
                                }
180
 
                        }
181
 
 
182
 
                        public void Store (Properties customizationObject)
183
 
                        {
184
 
                                if (useParentCheck.Active)
185
 
                                        test.ResetOptions (typeof(NUnitCategoryOptions), config);
186
 
                                else
187
 
                                        test.SetOptions (options, config);
188
 
                        }
189
 
                }
190
 
                
191
43
                NUnitOptionsWidget widget;
192
44
                
193
45
                public override Widget CreatePanelWidget ()
201
53
                        widget.Store ((Properties) DataObject);
202
54
                }
203
55
        }
 
56
        
 
57
        partial class NUnitOptionsWidget: Gtk.Bin
 
58
        {
 
59
                TreeStore store;
 
60
                TreeViewColumn textColumn;
 
61
                
 
62
                UnitTest test;
 
63
                string config;
 
64
                NUnitCategoryOptions options;
 
65
                NUnitCategoryOptions localOptions;
 
66
 
 
67
                public NUnitOptionsWidget (Properties customizationObject)
 
68
                {
 
69
                        Build ();
 
70
                        test =  ((Properties)customizationObject).Get<UnitTest> ("UnitTest");
 
71
                        config =  ((Properties)customizationObject).Get<string> ("Config");
 
72
                        options = localOptions = (NUnitCategoryOptions) test.GetOptions (typeof(NUnitCategoryOptions), config);
 
73
                        
 
74
                        store = new TreeStore (typeof(string));
 
75
                        categoryTree.Model = store;
 
76
                        categoryTree.HeadersVisible = false;
 
77
                        
 
78
                        CellRendererText tr = new CellRendererText ();
 
79
                        tr.Editable = true;
 
80
                        tr.Edited += new EditedHandler (OnCategoryEdited);
 
81
                        textColumn = new TreeViewColumn ();
 
82
                        textColumn.Title = GettextCatalog.GetString ("Category");
 
83
                        textColumn.PackStart (tr, false);
 
84
                        textColumn.AddAttribute (tr, "text", 0);
 
85
                        textColumn.Expand = true;
 
86
                        categoryTree.AppendColumn (textColumn);
 
87
                        
 
88
                        if (test.Parent != null)
 
89
                                useParentCheck.Active = !test.HasOptions (typeof(NUnitCategoryOptions), config);
 
90
                        else {
 
91
                                useParentCheck.Active = false;
 
92
                                useParentCheck.Sensitive = false;
 
93
                        }
 
94
                        
 
95
                        if (!options.EnableFilter)
 
96
                                noFilterRadio.Active = true;
 
97
                        else if (options.Exclude)
 
98
                                excludeRadio.Active = true;
 
99
                        else
 
100
                                includeRadio.Active = true;
 
101
 
 
102
                        Fill ();
 
103
                        
 
104
                        noFilterRadio.Toggled += new EventHandler (OnFilterToggled);
 
105
                        includeRadio.Toggled += new EventHandler (OnFilterToggled);
 
106
                        excludeRadio.Toggled += new EventHandler (OnFilterToggled);
 
107
                        useParentCheck.Toggled += new EventHandler (OnToggledUseParent);
 
108
                        addButton.Clicked += new EventHandler (OnAddCategory);
 
109
                        removeButton.Clicked += new EventHandler (OnRemoveCategory);
 
110
                }
 
111
                
 
112
                void Fill ()
 
113
                {
 
114
                        noFilterRadio.Sensitive = !useParentCheck.Active;
 
115
                        includeRadio.Sensitive = !useParentCheck.Active;
 
116
                        excludeRadio.Sensitive = !useParentCheck.Active;
 
117
                        categoryTree.Sensitive = !useParentCheck.Active && !noFilterRadio.Active;
 
118
                        removeButton.Sensitive = !useParentCheck.Active && !noFilterRadio.Active;
 
119
                        addButton.Sensitive = !useParentCheck.Active && !noFilterRadio.Active;
 
120
                        
 
121
                        store.Clear ();
 
122
                        foreach (string cat in options.Categories)
 
123
                                store.AppendValues (cat);
 
124
                }
 
125
                
 
126
                void OnToggledUseParent (object sender, EventArgs args)
 
127
                {
 
128
                        if (useParentCheck.Active)
 
129
                                options = (NUnitCategoryOptions) test.Parent.GetOptions (typeof(NUnitCategoryOptions), config);
 
130
                        else
 
131
                                options = localOptions;
 
132
 
 
133
                        if (!options.EnableFilter)
 
134
                                noFilterRadio.Active = true;
 
135
                        else if (options.Exclude)
 
136
                                excludeRadio.Active = true;
 
137
                        else
 
138
                                includeRadio.Active = true;
 
139
 
 
140
                        Fill ();
 
141
                }
 
142
                
 
143
                void OnFilterToggled (object sender, EventArgs args)
 
144
                {
 
145
                        options.EnableFilter = !noFilterRadio.Active;
 
146
                        options.Exclude = excludeRadio.Active;
 
147
                        Fill ();
 
148
                }
 
149
 
 
150
                void OnAddCategory (object sender, EventArgs args)
 
151
                {
 
152
                        TreeIter it = store.AppendValues ("");
 
153
                        categoryTree.SetCursor (store.GetPath (it), textColumn, true);
 
154
                }
 
155
 
 
156
                void OnRemoveCategory (object sender, EventArgs args)
 
157
                {
 
158
                        Gtk.TreeModel foo;
 
159
                        Gtk.TreeIter iter;
 
160
                        if (!categoryTree.Selection.GetSelected (out foo, out iter))
 
161
                                return;
 
162
                        string old = (string) store.GetValue (iter, 0);
 
163
                        options.Categories.Remove (old);
 
164
                        store.Remove (ref iter);
 
165
                }
 
166
 
 
167
                void OnCategoryEdited (object sender, EditedArgs args)
 
168
                {
 
169
                        TreeIter iter;
 
170
                        if (!store.GetIter (out iter, new TreePath (args.Path)))
 
171
                                return;
 
172
                        
 
173
                        string old = (string) store.GetValue (iter, 0);
 
174
                        if (args.NewText.Length == 0) {
 
175
                                options.Categories.Remove (old);
 
176
                                store.Remove (ref iter);
 
177
                        } else {
 
178
                                int i = options.Categories.IndexOf (old);
 
179
                                if (i == -1)
 
180
                                        options.Categories.Add (args.NewText);
 
181
                                else
 
182
                                        options.Categories [i] = args.NewText;
 
183
                                store.SetValue (iter, 0, args.NewText);
 
184
                        }
 
185
                }
 
186
 
 
187
                public void Store (Properties customizationObject)
 
188
                {
 
189
                        if (useParentCheck.Active)
 
190
                                test.ResetOptions (typeof(NUnitCategoryOptions), config);
 
191
                        else
 
192
                                test.SetOptions (options, config);
 
193
                }
 
194
        }
204
195
}
205
196