1
// ****************************************************************
2
// Copyright 2011, Charlie Poole
3
// This is free software licensed under the NUnit license. You may
4
// obtain a copy of the license at http://nunit.org
5
// ****************************************************************
9
using System.Collections;
10
using System.ComponentModel;
11
using System.Windows.Forms;
17
/// Displays a dialog for creation of a new configuration.
18
/// The dialog collects and validates the name and the
19
/// name of a configuration to be copied and then adds the
20
/// new configuration to the project.
22
/// A DialogResult of DialogResult.OK indicates that the
23
/// configuration was added successfully.
25
public class AddConfigurationDialog : NUnitFormBase
27
#region Instance variables
29
private NUnitProject project;
30
private string configurationName;
31
private string copyConfigurationName;
33
private System.Windows.Forms.Button okButton;
34
private System.Windows.Forms.Button cancelButton;
35
private System.Windows.Forms.TextBox configurationNameTextBox;
36
private System.Windows.Forms.Label label1;
37
private System.Windows.Forms.Label label2;
38
private System.Windows.Forms.ComboBox configurationComboBox;
41
/// Required designer variable.
43
private System.ComponentModel.Container components = null;
47
#region Construction and Disposal
49
public AddConfigurationDialog( NUnitProject project )
51
InitializeComponent();
52
this.project = project;
56
/// Clean up any resources being used.
58
protected override void Dispose( bool disposing )
62
if(components != null)
67
base.Dispose( disposing );
72
#region Windows Form Designer generated code
74
/// Required method for Designer support - do not modify
75
/// the contents of this method with the code editor.
77
private void InitializeComponent()
79
this.configurationNameTextBox = new System.Windows.Forms.TextBox();
80
this.okButton = new System.Windows.Forms.Button();
81
this.cancelButton = new System.Windows.Forms.Button();
82
this.configurationComboBox = new System.Windows.Forms.ComboBox();
83
this.label1 = new System.Windows.Forms.Label();
84
this.label2 = new System.Windows.Forms.Label();
87
// configurationNameTextBox
89
this.configurationNameTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
90
| System.Windows.Forms.AnchorStyles.Right)));
91
this.configurationNameTextBox.Location = new System.Drawing.Point(16, 24);
92
this.configurationNameTextBox.Name = "configurationNameTextBox";
93
this.configurationNameTextBox.Size = new System.Drawing.Size(254, 22);
94
this.configurationNameTextBox.TabIndex = 0;
95
this.configurationNameTextBox.Text = "";
99
this.okButton.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
100
this.okButton.Location = new System.Drawing.Point(50, 120);
101
this.okButton.Name = "okButton";
102
this.okButton.Size = new System.Drawing.Size(76, 23);
103
this.okButton.TabIndex = 1;
104
this.okButton.Text = "OK";
105
this.okButton.Click += new System.EventHandler(this.okButton_Click);
109
this.cancelButton.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
110
this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
111
this.cancelButton.Location = new System.Drawing.Point(155, 120);
112
this.cancelButton.Name = "cancelButton";
113
this.cancelButton.TabIndex = 2;
114
this.cancelButton.Text = "Cancel";
116
// configurationComboBox
118
this.configurationComboBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
119
| System.Windows.Forms.AnchorStyles.Right)));
120
this.configurationComboBox.ItemHeight = 16;
121
this.configurationComboBox.Location = new System.Drawing.Point(16, 80);
122
this.configurationComboBox.Name = "configurationComboBox";
123
this.configurationComboBox.Size = new System.Drawing.Size(256, 24);
124
this.configurationComboBox.TabIndex = 3;
128
this.label1.Location = new System.Drawing.Point(16, 8);
129
this.label1.Name = "label1";
130
this.label1.Size = new System.Drawing.Size(248, 16);
131
this.label1.TabIndex = 4;
132
this.label1.Text = "Configuration Name:";
136
this.label2.Location = new System.Drawing.Point(16, 63);
137
this.label2.Name = "label2";
138
this.label2.Size = new System.Drawing.Size(240, 17);
139
this.label2.TabIndex = 5;
140
this.label2.Text = "Copy Settings From:";
142
// AddConfigurationDialog
144
this.AcceptButton = this.okButton;
145
this.CancelButton = this.cancelButton;
146
this.ClientSize = new System.Drawing.Size(280, 149);
147
this.Controls.Add(this.label2);
148
this.Controls.Add(this.label1);
149
this.Controls.Add(this.configurationComboBox);
150
this.Controls.Add(this.cancelButton);
151
this.Controls.Add(this.okButton);
152
this.Controls.Add(this.configurationNameTextBox);
153
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
154
this.Name = "AddConfigurationDialog";
155
this.ShowInTaskbar = false;
156
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
157
this.Text = "New Configuration";
158
this.Load += new System.EventHandler(this.ConfigurationNameDialog_Load);
159
this.ResumeLayout(false);
166
public string ConfigurationName
168
get { return configurationName; }
171
public string CopyConfigurationName
173
get { return copyConfigurationName; }
180
private void ConfigurationNameDialog_Load(object sender, System.EventArgs e)
182
configurationComboBox.Items.Add( "<none>" );
183
configurationComboBox.SelectedIndex = 0;
185
foreach( ProjectConfig config in project.Configs )
187
int index = configurationComboBox.Items.Add( config.Name );
188
if ( config.Name == project.ActiveConfigName )
189
configurationComboBox.SelectedIndex = index;
193
private void okButton_Click(object sender, System.EventArgs e)
195
configurationName = configurationNameTextBox.Text;
197
if ( configurationName == string.Empty )
199
MessageDisplay.Error("No configuration name provided");
203
if ( project.Configs.Contains( configurationName ) )
205
MessageDisplay.Error("A configuration with that name already exists");
209
// ToDo: Move more of this to project
210
ProjectConfig newConfig = new ProjectConfig( configurationName );
212
copyConfigurationName = null;
213
if ( configurationComboBox.SelectedIndex > 0 )
215
copyConfigurationName = (string)configurationComboBox.SelectedItem;
216
ProjectConfig copyConfig = project.Configs[copyConfigurationName];
217
if ( copyConfig != null )
218
foreach( string assembly in copyConfig.Assemblies )
219
newConfig.Assemblies.Add( assembly );
222
project.Configs.Add( newConfig );
223
DialogResult = DialogResult.OK;
1
// ****************************************************************
2
// Copyright 2011, Charlie Poole
3
// This is free software licensed under the NUnit license. You may
4
// obtain a copy of the license at http://nunit.org
5
// ****************************************************************
9
using System.Collections;
10
using System.ComponentModel;
11
using System.Windows.Forms;
17
/// Displays a dialog for creation of a new configuration.
18
/// The dialog collects and validates the name and the
19
/// name of a configuration to be copied and then adds the
20
/// new configuration to the project.
22
/// A DialogResult of DialogResult.OK indicates that the
23
/// configuration was added successfully.
25
public class AddConfigurationDialog : NUnitFormBase
27
#region Instance variables
29
private NUnitProject project;
30
private string configurationName;
31
private string copyConfigurationName;
33
private System.Windows.Forms.Button okButton;
34
private System.Windows.Forms.Button cancelButton;
35
private System.Windows.Forms.TextBox configurationNameTextBox;
36
private System.Windows.Forms.Label label1;
37
private System.Windows.Forms.Label label2;
38
private System.Windows.Forms.ComboBox configurationComboBox;
41
/// Required designer variable.
43
private System.ComponentModel.Container components = null;
47
#region Construction and Disposal
49
public AddConfigurationDialog( NUnitProject project )
51
InitializeComponent();
52
this.project = project;
56
/// Clean up any resources being used.
58
protected override void Dispose( bool disposing )
62
if(components != null)
67
base.Dispose( disposing );
72
#region Windows Form Designer generated code
74
/// Required method for Designer support - do not modify
75
/// the contents of this method with the code editor.
77
private void InitializeComponent()
79
this.configurationNameTextBox = new System.Windows.Forms.TextBox();
80
this.okButton = new System.Windows.Forms.Button();
81
this.cancelButton = new System.Windows.Forms.Button();
82
this.configurationComboBox = new System.Windows.Forms.ComboBox();
83
this.label1 = new System.Windows.Forms.Label();
84
this.label2 = new System.Windows.Forms.Label();
87
// configurationNameTextBox
89
this.configurationNameTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
90
| System.Windows.Forms.AnchorStyles.Right)));
91
this.configurationNameTextBox.Location = new System.Drawing.Point(16, 24);
92
this.configurationNameTextBox.Name = "configurationNameTextBox";
93
this.configurationNameTextBox.Size = new System.Drawing.Size(254, 22);
94
this.configurationNameTextBox.TabIndex = 0;
95
this.configurationNameTextBox.Text = "";
99
this.okButton.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
100
this.okButton.Location = new System.Drawing.Point(50, 120);
101
this.okButton.Name = "okButton";
102
this.okButton.Size = new System.Drawing.Size(76, 23);
103
this.okButton.TabIndex = 1;
104
this.okButton.Text = "OK";
105
this.okButton.Click += new System.EventHandler(this.okButton_Click);
109
this.cancelButton.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
110
this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
111
this.cancelButton.Location = new System.Drawing.Point(155, 120);
112
this.cancelButton.Name = "cancelButton";
113
this.cancelButton.TabIndex = 2;
114
this.cancelButton.Text = "Cancel";
116
// configurationComboBox
118
this.configurationComboBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
119
| System.Windows.Forms.AnchorStyles.Right)));
120
this.configurationComboBox.ItemHeight = 16;
121
this.configurationComboBox.Location = new System.Drawing.Point(16, 80);
122
this.configurationComboBox.Name = "configurationComboBox";
123
this.configurationComboBox.Size = new System.Drawing.Size(256, 24);
124
this.configurationComboBox.TabIndex = 3;
128
this.label1.Location = new System.Drawing.Point(16, 8);
129
this.label1.Name = "label1";
130
this.label1.Size = new System.Drawing.Size(248, 16);
131
this.label1.TabIndex = 4;
132
this.label1.Text = "Configuration Name:";
136
this.label2.Location = new System.Drawing.Point(16, 63);
137
this.label2.Name = "label2";
138
this.label2.Size = new System.Drawing.Size(240, 17);
139
this.label2.TabIndex = 5;
140
this.label2.Text = "Copy Settings From:";
142
// AddConfigurationDialog
144
this.AcceptButton = this.okButton;
145
this.CancelButton = this.cancelButton;
146
this.ClientSize = new System.Drawing.Size(280, 149);
147
this.Controls.Add(this.label2);
148
this.Controls.Add(this.label1);
149
this.Controls.Add(this.configurationComboBox);
150
this.Controls.Add(this.cancelButton);
151
this.Controls.Add(this.okButton);
152
this.Controls.Add(this.configurationNameTextBox);
153
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
154
this.Name = "AddConfigurationDialog";
155
this.ShowInTaskbar = false;
156
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
157
this.Text = "New Configuration";
158
this.Load += new System.EventHandler(this.ConfigurationNameDialog_Load);
159
this.ResumeLayout(false);
166
public string ConfigurationName
168
get { return configurationName; }
171
public string CopyConfigurationName
173
get { return copyConfigurationName; }
180
private void ConfigurationNameDialog_Load(object sender, System.EventArgs e)
182
configurationComboBox.Items.Add( "<none>" );
183
configurationComboBox.SelectedIndex = 0;
185
foreach( ProjectConfig config in project.Configs )
187
int index = configurationComboBox.Items.Add( config.Name );
188
if ( config.Name == project.ActiveConfigName )
189
configurationComboBox.SelectedIndex = index;
193
private void okButton_Click(object sender, System.EventArgs e)
195
configurationName = configurationNameTextBox.Text;
197
if ( configurationName == string.Empty )
199
MessageDisplay.Error("No configuration name provided");
203
if ( project.Configs.Contains( configurationName ) )
205
MessageDisplay.Error("A configuration with that name already exists");
209
// ToDo: Move more of this to project
210
ProjectConfig newConfig = new ProjectConfig( configurationName );
212
copyConfigurationName = null;
213
if ( configurationComboBox.SelectedIndex > 0 )
215
copyConfigurationName = (string)configurationComboBox.SelectedItem;
216
ProjectConfig copyConfig = project.Configs[copyConfigurationName];
217
if ( copyConfig != null )
218
foreach( string assembly in copyConfig.Assemblies )
219
newConfig.Assemblies.Add( assembly );
222
project.Configs.Add( newConfig );
223
DialogResult = DialogResult.OK;