~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to src/core/MonoDevelop.Ide/MonoDevelop.Ide.Projects.OptionPanels/PortableRuntimeOptionsPanel.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
63
63
        [System.ComponentModel.ToolboxItem(true)]
64
64
        public partial class PortableRuntimeOptionsPanelWidget : Gtk.Bin
65
65
        {
 
66
                static TargetFramework NetPortableProfile1;
 
67
                static TargetFramework NetPortableProfile2;
 
68
                static TargetFramework NetPortableProfile3;
 
69
                static TargetFramework NetPortableProfile4;
 
70
 
 
71
                Dictionary<CheckButton, List<TargetFramework>> checkboxes = new Dictionary<CheckButton, List<TargetFramework>> ();
 
72
                Dictionary<CheckButton, ComboBox> comboboxes = new Dictionary<CheckButton, ComboBox> ();
66
73
                PortableDotNetProject project;
 
74
                TargetFramework target;
 
75
 
 
76
                static void InitProfiles ()
 
77
                {
 
78
                        // Profile 1 (.NETFramework + Silverlight + WindowsPhone + Xbox)
 
79
                        NetPortableProfile1 = Runtime.SystemAssemblyService.GetTargetFramework (new TargetFrameworkMoniker (".NETPortable", "4.0", "Profile1"));
 
80
                        SupportedFramework NetFramework = new SupportedFramework (NetPortableProfile1, ".NETFramework", ".NET Framework", "*", new Version (4, 0), "4");
 
81
                        SupportedFramework Silverlight = new SupportedFramework (NetPortableProfile1, "Silverlight", "Silverlight", "", new Version (4, 0), "4");
 
82
                        SupportedFramework WindowsPhone = new SupportedFramework (NetPortableProfile1, "Silverlight", "Windows Phone", "WindowsPhone*", new Version (4, 0), "7");
 
83
                        SupportedFramework Xbox = new SupportedFramework (NetPortableProfile1, "Xbox", "Xbox 360", "*", new Version (4, 0), "");
 
84
                        
 
85
                        NetPortableProfile1.SupportedFrameworks.Add (NetFramework);
 
86
                        NetPortableProfile1.SupportedFrameworks.Add (Silverlight);
 
87
                        NetPortableProfile1.SupportedFrameworks.Add (WindowsPhone);
 
88
                        NetPortableProfile1.SupportedFrameworks.Add (Xbox);
 
89
 
 
90
                        // Profile 2 (.NETFramework + Silverlight + WindowsPhone)
 
91
                        NetPortableProfile2 = Runtime.SystemAssemblyService.GetTargetFramework (new TargetFrameworkMoniker (".NETPortable", "4.0", "Profile2"));
 
92
                        NetFramework = new SupportedFramework (NetPortableProfile2, ".NETFramework", ".NET Framework", "*", new Version (4, 0), "4");
 
93
                        Silverlight = new SupportedFramework (NetPortableProfile2, "Silverlight", "Silverlight", "", new Version (4, 0), "4");
 
94
                        WindowsPhone = new SupportedFramework (NetPortableProfile2, "Silverlight", "Windows Phone", "WindowsPhone*", new Version (4, 0), "7");
 
95
                        
 
96
                        NetPortableProfile2.SupportedFrameworks.Add (NetFramework);
 
97
                        NetPortableProfile2.SupportedFrameworks.Add (Silverlight);
 
98
                        NetPortableProfile2.SupportedFrameworks.Add (WindowsPhone);
 
99
 
 
100
                        // Profile 3 (.NETFramework + Silverlight)
 
101
                        NetPortableProfile3 = Runtime.SystemAssemblyService.GetTargetFramework (new TargetFrameworkMoniker (".NETPortable", "4.0", "Profile3"));
 
102
                        NetFramework = new SupportedFramework (NetPortableProfile3, ".NETFramework", ".NET Framework", "*", new Version (4, 0), "4");
 
103
                        Silverlight = new SupportedFramework (NetPortableProfile3, "Silverlight", "Silverlight", "", new Version (4, 0), "4");
 
104
                        
 
105
                        NetPortableProfile3.SupportedFrameworks.Add (NetFramework);
 
106
                        NetPortableProfile3.SupportedFrameworks.Add (Silverlight);
 
107
 
 
108
                        // Profile 4 (Silverlight + WindowsPhone)
 
109
                        NetPortableProfile4 = Runtime.SystemAssemblyService.GetTargetFramework (new TargetFrameworkMoniker (".NETPortable", "4.0", "Profile4"));
 
110
                        Silverlight = new SupportedFramework (NetPortableProfile4, "Silverlight", "Silverlight", "", new Version (4, 0), "4");
 
111
                        WindowsPhone = new SupportedFramework (NetPortableProfile4, "Silverlight", "Windows Phone", "WindowsPhone*", new Version (4, 0), "7");
 
112
 
 
113
                        NetPortableProfile4.SupportedFrameworks.Add (Silverlight);
 
114
                        NetPortableProfile4.SupportedFrameworks.Add (WindowsPhone);
 
115
                }
67
116
                
68
117
                public PortableRuntimeOptionsPanelWidget (PortableDotNetProject project, IEnumerable<ItemConfiguration> configurations)
69
118
                {
 
119
                        this.target = project.TargetFramework;
70
120
                        this.project = project;
71
121
                        this.Build ();
72
 
                        
73
 
                        SortedDictionary<string, List<Framework>> options = new SortedDictionary<string, List<Framework>> ();
74
 
                        
 
122
 
 
123
                        // Aggregate all SupportedFrameworks from .NETPortable TargetFrameworks
 
124
                        SortedDictionary<string, List<SupportedFramework>> frameworks = new SortedDictionary<string, List<SupportedFramework>> ();
 
125
                        foreach (var fx in GetPortableTargetFrameworks ()) {
 
126
                                foreach (var sfx in fx.SupportedFrameworks) {
 
127
                                        List<SupportedFramework> list;
 
128
                                        
 
129
                                        if (!frameworks.TryGetValue (sfx.DisplayName, out list)) {
 
130
                                                list = new List<SupportedFramework> ();
 
131
                                                frameworks.Add (sfx.DisplayName, list);
 
132
                                        }
 
133
                                        
 
134
                                        list.Add (sfx);
 
135
                                }
 
136
                        }
 
137
 
 
138
                        // Now create a list of config options from our supported frameworks
 
139
                        var options = new List<SortedDictionary<string, List<TargetFramework>>> ();
 
140
                        foreach (var fx in frameworks) {
 
141
                                var dict = new SortedDictionary<string, List<TargetFramework>> ();
 
142
                                List<SupportedFramework> versions = fx.Value;
 
143
                                List<TargetFramework> targets;
 
144
                                string label;
 
145
 
 
146
                                foreach (var sfx in versions) {
 
147
                                        if (!string.IsNullOrEmpty (sfx.MinimumVersionDisplayName))
 
148
                                                label = sfx.DisplayName + " " + sfx.MinimumVersionDisplayName;
 
149
                                        else
 
150
                                                label = sfx.DisplayName;
 
151
 
 
152
                                        if (!dict.TryGetValue (label, out targets)) {
 
153
                                                targets = new List<TargetFramework> ();
 
154
                                                dict.Add (label, targets);
 
155
                                        }
 
156
 
 
157
                                        targets.Add (sfx.TargetFramework);
 
158
                                }
 
159
 
 
160
                                options.Add (dict);
 
161
                        }
 
162
 
 
163
                        // Add multi-option combo boxes first
 
164
                        foreach (var opt in options) {
 
165
                                if (opt.Count > 1)
 
166
                                        AddMultiOptionCombo (opt);
 
167
                        }
 
168
 
 
169
                        // Now add the single-option check boxes
 
170
                        foreach (var opt in options) {
 
171
                                if (opt.Count == 1) {
 
172
                                        var kvp = opt.FirstOrDefault ();
 
173
 
 
174
                                        AddSingleOptionCheckbox (kvp.Key, kvp.Value);
 
175
                                }
 
176
                        }
 
177
                }
 
178
 
 
179
                IEnumerable<TargetFramework> GetPortableTargetFrameworks ()
 
180
                {
 
181
                        int count = 0;
 
182
 
75
183
                        foreach (var fx in Runtime.SystemAssemblyService.GetTargetFrameworks ()) {
76
184
                                if (fx.Hidden || fx.Id.Identifier != ".NETPortable" || !project.TargetRuntime.IsInstalled (fx))
77
185
                                        continue;
78
 
                                
79
 
                                foreach (var sfx in fx.SupportedFrameworks) {
80
 
                                        List<Framework> list;
81
 
                                        
82
 
                                        if (!options.TryGetValue (sfx.DisplayName, out list)) {
83
 
                                                list = new List<Framework> ();
84
 
                                                options.Add (sfx.DisplayName, list);
85
 
                                        }
86
 
                                        
87
 
                                        list.Add (sfx);
88
 
                                }
89
 
                        }
90
 
                        
91
 
                        foreach (var opt in options) {
92
 
                                var alignment = new Alignment (0.0f, 0.5f, 1.0f, 1.0f) { LeftPadding = 18 };
93
 
                                List<Framework> versions = opt.Value;
94
 
                                CheckButton check;
95
 
                                
96
 
                                // FIXME: VS11 introduces comboboxes for some of these... which I suspect will need to sort based on version
97
 
                                //versions.Sort (CompareFrameworksByVersion);
98
 
                                check = new CheckButton (versions[0].DisplayName + " " + versions[0].MinimumVersionDisplayName);
99
 
                                check.Sensitive = false; // Desensitize until we support changing these values...
100
 
                                foreach (var ver in versions) {
101
 
                                        if (ver.TargetFramework == project.TargetFramework) {
102
 
                                                check.Active = true;
103
 
                                                break;
104
 
                                        }
105
 
                                }
106
 
                                check.Show ();
107
 
                                
108
 
                                alignment.Add (check);
109
 
                                alignment.Show ();
110
 
                                
111
 
                                vbox1.PackStart (alignment, false, false, 0);
112
 
                        }
113
 
                }
114
 
                
115
 
                static int CompareFrameworksByVersion (Framework fx1, Framework fx2)
116
 
                {
117
 
                        if (fx1.MinimumVersion < fx2.MinimumVersion)
118
 
                                return -1;
119
 
                        
120
 
                        if (fx1.MinimumVersion > fx2.MinimumVersion)
121
 
                                return 1;
122
 
                        
123
 
                        if (fx1.MaximumVersion < fx2.MaximumVersion)
124
 
                                return -1;
125
 
                        
126
 
                        if (fx1.MaximumVersion > fx2.MaximumVersion)
127
 
                                return 1;
128
 
                        
129
 
                        return 0;
 
186
 
 
187
                                yield return fx;
 
188
                                count++;
 
189
                        }
 
190
 
 
191
                        if (count > 0)
 
192
                                yield break;
 
193
 
 
194
                        if (NetPortableProfile1 == null)
 
195
                                InitProfiles ();
 
196
 
 
197
                        yield return NetPortableProfile1;
 
198
                        yield return NetPortableProfile2;
 
199
                        yield return NetPortableProfile3;
 
200
                        yield return NetPortableProfile4;
 
201
                }
 
202
 
 
203
                void AddMultiOptionCombo (SortedDictionary<string, List<TargetFramework>> options)
 
204
                {
 
205
                        var alignment = new Alignment (0.0f, 0.5f, 1.0f, 1.0f) { LeftPadding = 18 };
 
206
                        var model = new ListStore (new Type[] { typeof (string), typeof (object) });
 
207
                        var renderer = new CellRendererText ();
 
208
                        var combo = new ComboBox (model);
 
209
                        var check = new CheckButton ();
 
210
                        List<TargetFramework> targets;
 
211
                        var hbox = new HBox ();
 
212
                        int current = 0;
 
213
                        int active = -1;
 
214
                        string label;
 
215
 
 
216
                        foreach (var kvp in options) {
 
217
                                label = kvp.Key;
 
218
 
 
219
                                if (current + 1 < options.Count)
 
220
                                        label += " or later";
 
221
 
 
222
                                targets = kvp.Value;
 
223
                                if (active == -1) {
 
224
                                        foreach (var target in targets) {
 
225
                                                if (target.Id.Equals (project.TargetFramework.Id)) {
 
226
                                                        active = current;
 
227
                                                        break;
 
228
                                                }
 
229
                                        }
 
230
                                }
 
231
 
 
232
                                model.AppendValues (label, targets);
 
233
                                current++;
 
234
                        }
 
235
 
 
236
                        combo.PackStart (renderer, true);
 
237
                        combo.AddAttribute (renderer, "text", 0);
 
238
 
 
239
                        check.Show ();
 
240
                        combo.Show ();
 
241
 
 
242
                        if (active != -1) {
 
243
                                combo.Active = active;
 
244
                                check.Active = true;
 
245
                        } else {
 
246
                                check.Active = false;
 
247
                                combo.Active = 0;
 
248
                        }
 
249
 
 
250
                        combo.Changed += (sender, e) => {
 
251
                                if (check.Active)
 
252
                                        TargetFrameworkChanged (check, combo);
 
253
                        };
 
254
                        check.Toggled += (sender, e) => {
 
255
                                TargetFrameworkChanged (check, combo);
 
256
                        };
 
257
 
 
258
                        comboboxes.Add (check, combo);
 
259
 
 
260
                        hbox.PackStart (check, false, false, 0);
 
261
                        hbox.PackStart (combo, false, true, 0);
 
262
                        hbox.Show ();
 
263
 
 
264
                        alignment.Add (hbox);
 
265
                        alignment.Show ();
 
266
 
 
267
                        vbox1.PackStart (alignment, false, false, 0);
 
268
                }
 
269
 
 
270
                void AddSingleOptionCheckbox (string label, List<TargetFramework> targetFrameworks)
 
271
                {
 
272
                        var alignment = new Alignment (0.0f, 0.5f, 1.0f, 1.0f) { LeftPadding = 18 };
 
273
                        var check = new CheckButton (label);
 
274
 
 
275
                        foreach (var fx in targetFrameworks) {
 
276
                                if (fx.Id.Equals (project.TargetFramework.Id)) {
 
277
                                        check.Active = true;
 
278
                                        break;
 
279
                                }
 
280
                        }
 
281
 
 
282
                        check.Toggled += (sender, e) => {
 
283
                                TargetFrameworkChanged (check, targetFrameworks);
 
284
                        };
 
285
 
 
286
                        checkboxes.Add (check, targetFrameworks);
 
287
 
 
288
                        check.Show ();
 
289
                        alignment.Add (check);
 
290
                        alignment.Show ();
 
291
 
 
292
                        vbox1.PackStart (alignment, false, false, 0);
 
293
                }
 
294
 
 
295
                List<TargetFramework> GetTargetFrameworks (ComboBox combo)
 
296
                {
 
297
                        TreeIter iter;
 
298
 
 
299
                        if (!combo.GetActiveIter (out iter))
 
300
                                return new List<TargetFramework> ();
 
301
 
 
302
                        return (List<TargetFramework>) combo.Model.GetValue (iter, 1);
 
303
                }
 
304
 
 
305
                TargetFramework GetTargetFramework (CheckButton checkbox, List<TargetFramework> initial)
 
306
                {
 
307
                        var list = new List<TargetFramework> (initial);
 
308
                        int nchecked = 0;
 
309
 
 
310
                        foreach (var kvp in comboboxes) {
 
311
                                var combo = kvp.Value;
 
312
                                var check = kvp.Key;
 
313
 
 
314
                                if (check.Active)
 
315
                                        nchecked++;
 
316
 
 
317
                                if (!check.Active || check == checkbox)
 
318
                                        continue;
 
319
 
 
320
                                var filtered = new List<TargetFramework> ();
 
321
                                foreach (var target in GetTargetFrameworks (combo)) {
 
322
                                        if (list.Contains (target))
 
323
                                                filtered.Add (target);
 
324
                                }
 
325
                                list = filtered;
 
326
                        }
 
327
 
 
328
                        foreach (var kvp in checkboxes) {
 
329
                                var targets = kvp.Value;
 
330
                                var check = kvp.Key;
 
331
 
 
332
                                if (check.Active)
 
333
                                        nchecked++;
 
334
                                
 
335
                                if (!check.Active || check == checkbox)
 
336
                                        continue;
 
337
                                
 
338
                                var filtered = new List<TargetFramework> ();
 
339
                                foreach (var target in targets) {
 
340
                                        if (list.Contains (target))
 
341
                                                filtered.Add (target);
 
342
                                }
 
343
                                list = filtered;
 
344
                        }
 
345
 
 
346
                        // Choose the TargetFramework with the smallest subset of supported frameworks
 
347
                        TargetFramework smallest = this.target;
 
348
                        int min = Int32.MaxValue;
 
349
 
 
350
                        foreach (var target in list) {
 
351
                                if (target.SupportedFrameworks.Count < min) {
 
352
                                        min = target.SupportedFrameworks.Count;
 
353
                                        smallest = target;
 
354
                                }
 
355
                        }
 
356
 
 
357
                        return smallest;
 
358
                }
 
359
 
 
360
                void TargetFrameworkChanged (CheckButton check, List<TargetFramework> targetFrameworks)
 
361
                {
 
362
                        if (!check.Active)
 
363
                                targetFrameworks = new List<TargetFramework> (GetPortableTargetFrameworks ());
 
364
 
 
365
                        target = GetTargetFramework (check, targetFrameworks);
 
366
                }
 
367
 
 
368
                void TargetFrameworkChanged (CheckButton check, ComboBox combo)
 
369
                {
 
370
                        List<TargetFramework> targetFrameworks;
 
371
 
 
372
                        if (!check.Active)
 
373
                                targetFrameworks = new List<TargetFramework> (GetPortableTargetFrameworks ());
 
374
                        else
 
375
                                targetFrameworks = GetTargetFrameworks (combo);
 
376
 
 
377
                        target = GetTargetFramework (check, targetFrameworks);
130
378
                }
131
379
                
132
380
                public void Store ()
133
381
                {
134
 
                        // no-op for now, until we figure out the logic for setting the target framework based on the checkboxes enabled...
 
382
                        if (target != null && target != project.TargetFramework) {
 
383
                                project.TargetFramework = target;
 
384
                                IdeApp.ProjectOperations.Save (project);
 
385
                        }
135
386
                }
136
387
        }
137
388
}