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

« back to all changes in this revision

Viewing changes to src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Dialogs/CombineEntryFeatureSelector.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
 
// CombineEntryFeatureSelector.cs
2
 
//
3
 
// Author:
4
 
//   Lluis Sanchez Gual <lluis@novell.com>
5
 
//
6
 
// Copyright (c) 2007 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
 
 
29
 
using System;
30
 
using System.Collections.Generic;
31
 
using Gtk;
32
 
using MonoDevelop.Ide.Templates;
33
 
using MonoDevelop.Projects;
34
 
using MonoDevelop.Core;
35
 
using MonoDevelop.Core.Gui;
36
 
 
37
 
namespace MonoDevelop.Ide.Gui.Dialogs
38
 
{
39
 
        [System.ComponentModel.Category("MonoDevelop.Ide")]
40
 
        [System.ComponentModel.ToolboxItem(true)]
41
 
        public partial class CombineEntryFeatureSelector : Gtk.Bin
42
 
        {
43
 
                List<ISolutionItemFeature> selectedFeatures = new List<ISolutionItemFeature> ();
44
 
                List<Gtk.Widget> selectedEditors = new List<Gtk.Widget> ();
45
 
                SolutionItem entry;
46
 
                SolutionFolder parentCombine;
47
 
                VBox box = new VBox ();
48
 
                Gdk.Cursor handCursor;
49
 
                
50
 
                public CombineEntryFeatureSelector ()
51
 
                {
52
 
                        this.Build();
53
 
                        handCursor = new Gdk.Cursor (Gdk.CursorType.Hand1);
54
 
                        box.Spacing = 6;
55
 
                        box.BorderWidth = 3;
56
 
                        box.Show ();
57
 
                }
58
 
                
59
 
                public void Fill (SolutionFolder parentCombine, SolutionItem entry, ISolutionItemFeature[] features)
60
 
                {
61
 
                        selectedFeatures.Clear ();
62
 
                        selectedEditors.Clear ();
63
 
                        
64
 
                        this.entry = entry;
65
 
                        this.parentCombine = parentCombine;
66
 
                        
67
 
                        foreach (Gtk.Widget w in box.Children) {
68
 
                                box.Remove (w);
69
 
                                w.Destroy ();
70
 
                        }
71
 
                        // Show enabled features at the beginning
72
 
                        foreach (ISolutionItemFeature feature in features)
73
 
                                if (feature.IsEnabled (parentCombine, entry)) {
74
 
                                        Gtk.Widget editor = AddFeature (feature);
75
 
                                        selectedFeatures.Add (feature);
76
 
                                        selectedEditors.Add (editor);
77
 
                                }
78
 
                        foreach (ISolutionItemFeature feature in features)
79
 
                                if (!feature.IsEnabled (parentCombine, entry))
80
 
                                        AddFeature (feature);
81
 
                        
82
 
                        if (box.Children.Length == 0) {
83
 
                                // No features
84
 
                                Label lab = new Label ();
85
 
                                lab.Xalign = 0;
86
 
                                lab.Text = GettextCatalog.GetString ("There are no additional features available for this project.");
87
 
                                box.PackStart (lab, false, false, 0);
88
 
                                lab.Show ();
89
 
                        }
90
 
                        scrolled.AddWithViewport (box);
91
 
                }
92
 
                
93
 
                Gtk.Widget AddFeature (ISolutionItemFeature feature)
94
 
                {
95
 
                        Gtk.HBox cbox = new Gtk.HBox ();
96
 
                        CheckButton check = null;
97
 
                        
98
 
                        Label fl = new Label ();
99
 
                        fl.Wrap = true;
100
 
                        fl.WidthRequest = 630;
101
 
                        fl.Markup = "<b>" + feature.Title + "</b>\n<small>" + feature.Description + "</small>";
102
 
                        bool enabledByDefault = feature.IsEnabled (parentCombine, entry);
103
 
 
104
 
                        if (enabledByDefault) {
105
 
                                Alignment al = new Alignment (0,0,0,0);
106
 
                                al.SetPadding (6,6,6,6);
107
 
                                al.Add (fl);
108
 
                                cbox.PackStart (al, false, false, 0);
109
 
                        }
110
 
                        else {
111
 
                                check = new CheckButton ();
112
 
                                check.Image = fl;
113
 
                                cbox.PackStart (check, false, false, 0);
114
 
                                check.ModifyBg (StateType.Prelight, Style.MidColors [(int)StateType.Normal]);
115
 
                                check.BorderWidth = 3;
116
 
                        }
117
 
                        EventBox eb = new EventBox ();
118
 
                        if (!enabledByDefault) {
119
 
                                eb.Realized += delegate {
120
 
                                        eb.GdkWindow.Cursor = handCursor;
121
 
                                };
122
 
                        }
123
 
                        eb.ModifyBg (StateType.Normal, Style.MidColors[(int)StateType.Normal]);
124
 
                        eb.Add (cbox);
125
 
                        eb.ShowAll ();
126
 
                        box.PackStart (eb, false, false, 0);
127
 
                        
128
 
                        HBox fbox = new HBox ();
129
 
                        Gtk.Widget editor = feature.CreateFeatureEditor (parentCombine, entry);
130
 
                        if (editor != null) {
131
 
                                Label sp = new Label ("");
132
 
                                sp.WidthRequest = 24;
133
 
                                sp.Show ();
134
 
                                fbox.PackStart (sp, false, false, 0);
135
 
                                editor.Show ();
136
 
                                fbox.PackStart (editor, false, false, 0);
137
 
                                box.PackStart (fbox, false, false, 0);
138
 
                        }
139
 
                        
140
 
                        if (check != null) {
141
 
                                ISolutionItemFeature f = feature;
142
 
                                check.Toggled += delegate {
143
 
                                        OnClickFeature (f, check, fbox, editor);
144
 
                                };
145
 
                        } else {
146
 
                                fbox.Show ();
147
 
                        }
148
 
                        return editor;
149
 
                }
150
 
                
151
 
                void OnClickFeature (ISolutionItemFeature feature, CheckButton check, HBox fbox, Gtk.Widget editor)
152
 
                {
153
 
                        if (editor != null)
154
 
                                fbox.Visible = check.Active;
155
 
                        if (check.Active) {
156
 
                                selectedFeatures.Add (feature);
157
 
                                selectedEditors.Add (editor);
158
 
                        } else {
159
 
                                selectedFeatures.Remove (feature);
160
 
                                selectedEditors.Remove (editor);
161
 
                        }
162
 
                }
163
 
                
164
 
                public bool Validate ()
165
 
                {
166
 
                        for (int n=0; n<selectedFeatures.Count; n++) {
167
 
                                ISolutionItemFeature pf = selectedFeatures [n];
168
 
                                string msg = pf.Validate (parentCombine, entry, selectedEditors [n]);
169
 
                                if (!string.IsNullOrEmpty (msg)) {
170
 
                                        msg = pf.Title + ": " + msg;
171
 
                                        MessageService.ShowError ((Gtk.Window)this.Toplevel, msg);
172
 
                                        return false;
173
 
                                }
174
 
                        }
175
 
                        return true;
176
 
                }
177
 
                
178
 
                public void ApplyFeatures ()
179
 
                {
180
 
                        for (int n=0; n<selectedFeatures.Count; n++) {
181
 
                                try {
182
 
                                        ISolutionItemFeature pf = selectedFeatures [n];
183
 
                                        pf.ApplyFeature (parentCombine, entry, selectedEditors [n]);
184
 
                                }
185
 
                                catch (Exception ex) {
186
 
                                        MessageService.ShowException (ex);
187
 
                                }
188
 
                        }
189
 
                }
190
 
                
191
 
                protected override void OnDestroyed ()
192
 
                {
193
 
                        if (handCursor != null) {
194
 
                                handCursor.Dispose ();
195
 
                                handCursor = null;
196
 
                        }
197
 
                        base.OnDestroyed ();
198
 
                }
199
 
 
200
 
        }
201
 
}