1
// MultiConfigItemOptionsPanel.cs
4
// Lluis Sanchez Gual <lluis@novell.com>
6
// Copyright (c) 2008 Novell, Inc (http://www.novell.com)
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:
15
// The above copyright notice and this permission notice shall be included in
16
// all copies or substantial portions of the Software.
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
29
using System.Collections.Generic;
30
using System.Collections.ObjectModel;
31
using MonoDevelop.Core;
32
using MonoDevelop.Core.Gui.Dialogs;
34
namespace MonoDevelop.Projects.Gui.Dialogs
36
public abstract class MultiConfigItemOptionsPanel: ItemOptionsPanel, IOptionsPanel
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;
47
bool allowMixedConfigurations;
48
int lastConfigSelection = -1;
49
int lastPlatformSelection = -1;
51
internal ConfigurationData ConfigurationData {
52
get { return dialog.ConfigurationData; }
55
public override void Initialize (OptionsDialog dialog, object dataObject)
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;
66
public ItemConfiguration CurrentConfiguration {
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];
74
public ItemConfiguration[] CurrentConfigurations {
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 ();
82
// Set to true to allow the user changing data of several configurations
84
public bool AllowMixedConfigurations {
86
return allowMixedConfigurations;
89
allowMixedConfigurations = value;
91
FillConfigurations ();
97
Gtk.Widget IOptionsPanel.CreatePanelWidget ()
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);
111
cbox.Shown += OnPageShown;
113
lastConfigSelection = -1;
114
lastPlatformSelection = -1;
116
FillConfigurations ();
119
configCombo.Changed += OnConfigChanged;
120
platformCombo.Changed += OnConfigChanged;
122
bool oldMixed = allowMixedConfigurations;
123
Gtk.Widget child = CreatePanelWidget ();
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", "_");
129
cbox.PackStart (child, true, true, 0);
131
if (allowMixedConfigurations != oldMixed) {
132
// If mixed mode has changed, update the configuration list
133
FillConfigurations ();
136
widgetCreated = true;
139
if (currentConfigs.Count > 0) {
140
panelWidget.Sensitive = true;
144
panelWidget.Sensitive = false;
149
void FillConfigurations ()
152
((Gtk.ListStore)configCombo.Model).Clear ();
154
if (allowMixedConfigurations)
155
configCombo.AppendText (GettextCatalog.GetString ("All Configurations"));
157
foreach (ItemConfiguration config in dialog.ConfigurationData.Configurations)
158
configCombo.AppendText (config.Name);
163
void FillPlatforms ()
167
((Gtk.ListStore)platformCombo.Model).Clear ();
170
string configName = null;
171
if (!allowMixedConfigurations || configCombo.Active > 0) {
172
int i = configCombo.Active;
173
if (allowMixedConfigurations)
175
ItemConfiguration config = dialog.ConfigurationData.Configurations [i];
176
configName = config.Name;
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);
185
platformCombo.AppendText (GettextCatalog.GetString ("Any CPU"));
191
void OnConfigChanged (object s, EventArgs a)
196
if (!ValidateChanges ()) {
198
configCombo.Active = lastConfigSelection;
199
platformCombo.Active = lastPlatformSelection;
204
if (s == configCombo) {
206
SelectPlatform (dialog.CurrentPlatform);
209
UpdateCurrentConfiguration ();
212
void UpdateCurrentConfiguration ()
214
lastConfigSelection = configCombo.Active;
215
lastPlatformSelection = platformCombo.Active;
220
currentConfigs.Clear ();
222
string configName = dialog.CurrentConfig = configCombo.ActiveText;
223
if (configName == GettextCatalog.GetString ("All Configurations"))
226
string platform = dialog.CurrentPlatform = platformCombo.ActiveText;
227
if (platform == GettextCatalog.GetString ("Any CPU"))
228
platform = string.Empty;
230
foreach (ItemConfiguration config in dialog.ConfigurationData.Configurations) {
231
if ((configName == null || config.Name == configName) && config.Platform == platform)
232
currentConfigs.Add (config);
235
if (widgetCreated && currentConfigs.Count > 0) {
236
panelWidget.Sensitive = true;
238
} else if (widgetCreated)
239
panelWidget.Sensitive = false;
242
void OnConfigurationsChanged (object s, EventArgs a)
246
FillConfigurations ();
250
void UpdateSelection ()
252
SelectConfiguration (dialog.CurrentConfig);
253
if (lastConfigSelection != configCombo.Active)
256
SelectPlatform (dialog.CurrentPlatform);
257
if (lastConfigSelection != configCombo.Active || lastPlatformSelection != platformCombo.Active)
258
UpdateCurrentConfiguration ();
261
void OnPageShown (object s, EventArgs a)
266
void SelectConfiguration (string config)
271
if (configCombo.Model.GetIterFirst (out it)) {
273
if (config == (string) configCombo.Model.GetValue (it, 0)) {
274
configCombo.SetActiveIter (it);
278
while (configCombo.Model.IterNext (ref it));
281
if (configCombo.Active == -1)
282
configCombo.Active = 0;
287
void SelectPlatform (string platform)
292
if (platformCombo.Model.GetIterFirst (out it)) {
294
if (platform == (string) platformCombo.Model.GetValue (it, 0)) {
295
platformCombo.SetActiveIter (it);
299
while (platformCombo.Model.IterNext (ref it));
302
if (platformCombo.Active == -1)
303
platformCombo.Active = 0;
308
void IOptionsPanel.ApplyChanges ()
313
public abstract void LoadConfigData ();