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

« back to all changes in this revision

Viewing changes to src/core/MonoDevelop.Projects.Gui/MonoDevelop.Projects.Gui.Dialogs/MultiConfigItemOptionsPanel.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
// MultiConfigItemOptionsPanel.cs
 
2
//
 
3
// Author:
 
4
//   Lluis Sanchez Gual <lluis@novell.com>
 
5
//
 
6
// Copyright (c) 2008 Novell, Inc (http://www.novell.com)
 
7
//
 
8
// Permission is hereby granted, free of charge, to any person obtaining a copy
 
9
// of this software and associated documentation files (the "Software"), to deal
 
10
// in the Software without restriction, including without limitation the rights
 
11
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 
12
// copies of the Software, and to permit persons to whom the Software is
 
13
// furnished to do so, subject to the following conditions:
 
14
//
 
15
// The above copyright notice and this permission notice shall be included in
 
16
// all copies or substantial portions of the Software.
 
17
//
 
18
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
19
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
20
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 
21
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 
22
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 
23
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 
24
// THE SOFTWARE.
 
25
//
 
26
//
 
27
 
 
28
using System;
 
29
using System.Collections.Generic;
 
30
using System.Collections.ObjectModel;
 
31
using MonoDevelop.Core;
 
32
using MonoDevelop.Core.Gui.Dialogs;
 
33
 
 
34
namespace MonoDevelop.Projects.Gui.Dialogs
 
35
{
 
36
        public abstract class MultiConfigItemOptionsPanel: ItemOptionsPanel, IOptionsPanel
 
37
        {
 
38
                MultiConfigItemOptionsDialog dialog;
 
39
                Gtk.ComboBox configCombo;
 
40
                Gtk.ComboBox platformCombo;
 
41
                List<ItemConfiguration> currentConfigs = new List<ItemConfiguration> ();
 
42
                List<string> platforms = new List<string> ();
 
43
                Gtk.Widget panelWidget;
 
44
                
 
45
                bool loading;
 
46
                bool widgetCreated;
 
47
                bool allowMixedConfigurations;
 
48
                int lastConfigSelection = -1;
 
49
                int lastPlatformSelection = -1;
 
50
                
 
51
                internal ConfigurationData ConfigurationData {
 
52
                        get { return dialog.ConfigurationData; }
 
53
                }
 
54
                
 
55
                public override void Initialize (OptionsDialog dialog, object dataObject)
 
56
                {
 
57
                        base.Initialize (dialog, dataObject);
 
58
                        this.dialog = dialog as MultiConfigItemOptionsDialog;
 
59
                        if (this.dialog == null)
 
60
                                throw new System.InvalidOperationException ("MultiConfigItemOptionsPanel can only be used in options dialogs of type MultiConfigItemOptionsDialog. Panel type: " + GetType ());
 
61
                        this.dialog.ConfigurationData.ConfigurationsChanged += OnConfigurationsChanged;
 
62
                }
 
63
                
 
64
                
 
65
                
 
66
                public ItemConfiguration CurrentConfiguration {
 
67
                        get {
 
68
                                if (allowMixedConfigurations)
 
69
                                        throw new System.InvalidOperationException ("The options panel is working in multiple configuration selection mode (AllowMixedConfigurations=true). Use the property CurrentConfigurations to get the list of all selected configurations.");
 
70
                                return currentConfigs [0];
 
71
                        }
 
72
                }
 
73
 
 
74
                public ItemConfiguration[] CurrentConfigurations {
 
75
                        get {
 
76
                                if (!allowMixedConfigurations)
 
77
                                        throw new System.InvalidOperationException ("The options panel is working in single configuration selection mode (AllowMixedConfigurations=false). Use the property CurrentConfiguration to get the selected configuration.");
 
78
                                return currentConfigs.ToArray ();
 
79
                        }
 
80
                }
 
81
 
 
82
                // Set to true to allow the user changing data of several configurations
 
83
                // at the same time
 
84
                public bool AllowMixedConfigurations {
 
85
                        get {
 
86
                                return allowMixedConfigurations;
 
87
                        }
 
88
                        set {
 
89
                                allowMixedConfigurations = value;
 
90
                                if (widgetCreated) {
 
91
                                        FillConfigurations ();
 
92
                                        UpdateSelection ();
 
93
                                }
 
94
                        }
 
95
                }
 
96
                
 
97
                Gtk.Widget IOptionsPanel.CreatePanelWidget ()
 
98
                {
 
99
                        Gtk.VBox cbox = new Gtk.VBox (false, 6);
 
100
                        Gtk.HBox combosBox = new Gtk.HBox (false, 6);
 
101
                        cbox.PackStart (combosBox, false, false, 0);
 
102
                        combosBox.PackStart (new Gtk.Label (GettextCatalog.GetString ("Configuration:")), false, false, 0);
 
103
                        configCombo = Gtk.ComboBox.NewText ();
 
104
                        combosBox.PackStart (configCombo, false, false, 0);
 
105
                        combosBox.PackStart (new Gtk.Label (GettextCatalog.GetString ("Platform:")), false, false, 0);
 
106
                        platformCombo = Gtk.ComboBox.NewText ();
 
107
                        combosBox.PackStart (platformCombo, false, false, 0);
 
108
                        cbox.PackStart (new Gtk.HSeparator (), false, false, 0);
 
109
                        cbox.ShowAll ();
 
110
                        
 
111
                        cbox.Shown += OnPageShown;
 
112
                        
 
113
                        lastConfigSelection = -1;
 
114
                        lastPlatformSelection = -1;
 
115
                        
 
116
                        FillConfigurations ();
 
117
                        UpdateSelection ();
 
118
                        
 
119
                        configCombo.Changed += OnConfigChanged;
 
120
                        platformCombo.Changed += OnConfigChanged;
 
121
                        
 
122
                        bool oldMixed = allowMixedConfigurations;
 
123
                        Gtk.Widget child = CreatePanelWidget ();
 
124
                        
 
125
                        //HACK: work around bug 469427 - broken themes match on widget names
 
126
                        if (child.Name.IndexOf ("Panel") > 0)
 
127
                                child.Name = child.Name.Replace ("Panel", "_");
 
128
                        
 
129
                        cbox.PackStart (child, true, true, 0);
 
130
                        
 
131
                        if (allowMixedConfigurations != oldMixed) {
 
132
                                // If mixed mode has changed, update the configuration list
 
133
                                FillConfigurations ();
 
134
                                UpdateSelection ();
 
135
                        }
 
136
                        widgetCreated = true;
 
137
                        panelWidget = cbox;
 
138
                        
 
139
                        if (currentConfigs.Count > 0) {
 
140
                                panelWidget.Sensitive = true;
 
141
                                LoadConfigData ();
 
142
                        }
 
143
                        else
 
144
                                panelWidget.Sensitive = false;
 
145
                        
 
146
                        return cbox;
 
147
                }
 
148
                
 
149
                void FillConfigurations ()
 
150
                {
 
151
                        loading = true;
 
152
                        ((Gtk.ListStore)configCombo.Model).Clear ();
 
153
                        
 
154
                        if (allowMixedConfigurations)
 
155
                                configCombo.AppendText (GettextCatalog.GetString ("All Configurations"));
 
156
                        
 
157
                        foreach (ItemConfiguration config in dialog.ConfigurationData.Configurations)
 
158
                                configCombo.AppendText (config.Name);
 
159
                        
 
160
                        loading = false;
 
161
                }
 
162
                
 
163
                void FillPlatforms ()
 
164
                {
 
165
                        loading = true;
 
166
                        
 
167
                        ((Gtk.ListStore)platformCombo.Model).Clear ();
 
168
                        platforms.Clear ();
 
169
 
 
170
                        string configName = null;
 
171
                        if (!allowMixedConfigurations || configCombo.Active > 0) {
 
172
                                int i = configCombo.Active;
 
173
                                if (allowMixedConfigurations)
 
174
                                        i--;
 
175
                                ItemConfiguration config = dialog.ConfigurationData.Configurations [i];
 
176
                                configName = config.Name;
 
177
                        }
 
178
 
 
179
                        foreach (ItemConfiguration config in dialog.ConfigurationData.Configurations) {
 
180
                                if ((configName == null || config.Name == configName) && !platforms.Contains (config.Platform)) {
 
181
                                        platforms.Add (config.Platform);
 
182
                                        if (config.Platform.Length > 0)
 
183
                                                platformCombo.AppendText (config.Platform);
 
184
                                        else
 
185
                                                platformCombo.AppendText (GettextCatalog.GetString ("Any CPU"));
 
186
                                }
 
187
                        }
 
188
                        loading = false;
 
189
                }
 
190
                
 
191
                void OnConfigChanged (object s, EventArgs a)
 
192
                {
 
193
                        if (loading)
 
194
                                return;
 
195
                        
 
196
                        if (!ValidateChanges ()) {
 
197
                                loading = true;
 
198
                                configCombo.Active = lastConfigSelection;
 
199
                                platformCombo.Active = lastPlatformSelection;
 
200
                                loading = false;
 
201
                                return;
 
202
                        }
 
203
                        
 
204
                        if (s == configCombo) {
 
205
                                FillPlatforms ();
 
206
                                SelectPlatform (dialog.CurrentPlatform);
 
207
                        }
 
208
                        
 
209
                        UpdateCurrentConfiguration ();
 
210
                }
 
211
 
 
212
                void UpdateCurrentConfiguration ()
 
213
                {
 
214
                        lastConfigSelection = configCombo.Active;
 
215
                        lastPlatformSelection = platformCombo.Active;
 
216
                        
 
217
                        if (widgetCreated)
 
218
                                ApplyChanges ();
 
219
                        
 
220
                        currentConfigs.Clear ();
 
221
                        
 
222
                        string configName = dialog.CurrentConfig = configCombo.ActiveText;
 
223
                        if (configName == GettextCatalog.GetString ("All Configurations"))
 
224
                                configName = null;
 
225
                        
 
226
                        string platform = dialog.CurrentPlatform = platformCombo.ActiveText;
 
227
                        if (platform == GettextCatalog.GetString ("Any CPU"))
 
228
                                platform = string.Empty;
 
229
                        
 
230
                        foreach (ItemConfiguration config in dialog.ConfigurationData.Configurations) {
 
231
                                if ((configName == null || config.Name == configName) && config.Platform == platform)
 
232
                                        currentConfigs.Add (config);
 
233
                        }
 
234
                        
 
235
                        if (widgetCreated && currentConfigs.Count > 0) {
 
236
                                panelWidget.Sensitive = true;
 
237
                                LoadConfigData ();
 
238
                        } else if (widgetCreated)
 
239
                                panelWidget.Sensitive = false;
 
240
                }
 
241
                
 
242
                void OnConfigurationsChanged (object s, EventArgs a)
 
243
                {
 
244
                        if (!widgetCreated)
 
245
                                return;
 
246
                        FillConfigurations ();
 
247
                        UpdateSelection ();
 
248
                }
 
249
                
 
250
                void UpdateSelection ()
 
251
                {
 
252
                        SelectConfiguration (dialog.CurrentConfig);
 
253
                        if (lastConfigSelection != configCombo.Active)
 
254
                                FillPlatforms ();
 
255
 
 
256
                        SelectPlatform (dialog.CurrentPlatform);
 
257
                        if (lastConfigSelection != configCombo.Active || lastPlatformSelection != platformCombo.Active)
 
258
                                UpdateCurrentConfiguration ();
 
259
                }
 
260
                
 
261
                void OnPageShown (object s, EventArgs a)
 
262
                {
 
263
                        UpdateSelection ();
 
264
                }
 
265
                
 
266
                void SelectConfiguration (string config)
 
267
                {
 
268
                        loading = true;
 
269
                        
 
270
                        Gtk.TreeIter it;
 
271
                        if (configCombo.Model.GetIterFirst (out it)) {
 
272
                                do {
 
273
                                        if (config == (string) configCombo.Model.GetValue (it, 0)) {
 
274
                                                configCombo.SetActiveIter (it);
 
275
                                                break;
 
276
                                        }
 
277
                                }
 
278
                                while (configCombo.Model.IterNext (ref it));
 
279
                        }
 
280
                        
 
281
                        if (configCombo.Active == -1)
 
282
                                configCombo.Active = 0;
 
283
                        
 
284
                        loading = false;
 
285
                }
 
286
                
 
287
                void SelectPlatform (string platform)
 
288
                {
 
289
                        loading = true;
 
290
                        
 
291
                        Gtk.TreeIter it;
 
292
                        if (platformCombo.Model.GetIterFirst (out it)) {
 
293
                                do {
 
294
                                        if (platform == (string) platformCombo.Model.GetValue (it, 0)) {
 
295
                                                platformCombo.SetActiveIter (it);
 
296
                                                break;
 
297
                                        }
 
298
                                }
 
299
                                while (platformCombo.Model.IterNext (ref it));
 
300
                        }
 
301
                        
 
302
                        if (platformCombo.Active == -1)
 
303
                                platformCombo.Active = 0;
 
304
                        
 
305
                        loading = false;
 
306
                }
 
307
                
 
308
                void IOptionsPanel.ApplyChanges ()
 
309
                {
 
310
                        ApplyChanges ();
 
311
                }
 
312
                
 
313
                public abstract void LoadConfigData ();
 
314
        }
 
315
}