1
// CombineEntryFeatureSelector.cs
4
// Lluis Sanchez Gual <lluis@novell.com>
6
// Copyright (c) 2007 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
30
using System.Collections.Generic;
32
using MonoDevelop.Ide.Templates;
33
using MonoDevelop.Projects;
34
using MonoDevelop.Core;
35
using MonoDevelop.Core.Gui;
37
namespace MonoDevelop.Ide.Gui.Dialogs
39
[System.ComponentModel.Category("MonoDevelop.Ide")]
40
[System.ComponentModel.ToolboxItem(true)]
41
public partial class CombineEntryFeatureSelector : Gtk.Bin
43
List<ISolutionItemFeature> selectedFeatures = new List<ISolutionItemFeature> ();
44
List<Gtk.Widget> selectedEditors = new List<Gtk.Widget> ();
46
SolutionFolder parentCombine;
47
VBox box = new VBox ();
48
Gdk.Cursor handCursor;
50
public CombineEntryFeatureSelector ()
53
handCursor = new Gdk.Cursor (Gdk.CursorType.Hand1);
59
public void Fill (SolutionFolder parentCombine, SolutionItem entry, ISolutionItemFeature[] features)
61
selectedFeatures.Clear ();
62
selectedEditors.Clear ();
65
this.parentCombine = parentCombine;
67
foreach (Gtk.Widget w in box.Children) {
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);
78
foreach (ISolutionItemFeature feature in features)
79
if (!feature.IsEnabled (parentCombine, entry))
82
if (box.Children.Length == 0) {
84
Label lab = new Label ();
86
lab.Text = GettextCatalog.GetString ("There are no additional features available for this project.");
87
box.PackStart (lab, false, false, 0);
90
scrolled.AddWithViewport (box);
93
Gtk.Widget AddFeature (ISolutionItemFeature feature)
95
Gtk.HBox cbox = new Gtk.HBox ();
96
CheckButton check = null;
98
Label fl = new Label ();
100
fl.WidthRequest = 630;
101
fl.Markup = "<b>" + feature.Title + "</b>\n<small>" + feature.Description + "</small>";
102
bool enabledByDefault = feature.IsEnabled (parentCombine, entry);
104
if (enabledByDefault) {
105
Alignment al = new Alignment (0,0,0,0);
106
al.SetPadding (6,6,6,6);
108
cbox.PackStart (al, false, false, 0);
111
check = new CheckButton ();
113
cbox.PackStart (check, false, false, 0);
114
check.ModifyBg (StateType.Prelight, Style.MidColors [(int)StateType.Normal]);
115
check.BorderWidth = 3;
117
EventBox eb = new EventBox ();
118
if (!enabledByDefault) {
119
eb.Realized += delegate {
120
eb.GdkWindow.Cursor = handCursor;
123
eb.ModifyBg (StateType.Normal, Style.MidColors[(int)StateType.Normal]);
126
box.PackStart (eb, false, false, 0);
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;
134
fbox.PackStart (sp, false, false, 0);
136
fbox.PackStart (editor, false, false, 0);
137
box.PackStart (fbox, false, false, 0);
141
ISolutionItemFeature f = feature;
142
check.Toggled += delegate {
143
OnClickFeature (f, check, fbox, editor);
151
void OnClickFeature (ISolutionItemFeature feature, CheckButton check, HBox fbox, Gtk.Widget editor)
154
fbox.Visible = check.Active;
156
selectedFeatures.Add (feature);
157
selectedEditors.Add (editor);
159
selectedFeatures.Remove (feature);
160
selectedEditors.Remove (editor);
164
public bool Validate ()
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);
178
public void ApplyFeatures ()
180
for (int n=0; n<selectedFeatures.Count; n++) {
182
ISolutionItemFeature pf = selectedFeatures [n];
183
pf.ApplyFeature (parentCombine, entry, selectedEditors [n]);
185
catch (Exception ex) {
186
MessageService.ShowException (ex);
191
protected override void OnDestroyed ()
193
if (handCursor != null) {
194
handCursor.Dispose ();