Added ability to order the execution of dictionary adapter behaviors.
[castle.git] / Experiments / Attic / Generator / Castle.ActiveRecord.Generator / Dialogs / GenCodeDialog.cs
blob282925bc9e20e0d1219f622f33bd7e506fa837b1
1 // Copyright 2004-2007 Castle Project - http://www.castleproject.org/
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle.ActiveRecord.Generator.Dialogs
17 using System;
18 using System.Drawing;
19 using System.Collections;
20 using System.ComponentModel;
21 using System.IO;
22 using System.Windows.Forms;
24 using Castle.ActiveRecord.Generator.Components.CodeGenerator;
26 /// <summary>
27 /// Summary description for GenCodeDialog.
28 /// </summary>
29 public class GenCodeDialog : System.Windows.Forms.Form
31 private System.Windows.Forms.GroupBox groupBox1;
32 private System.Windows.Forms.Label label1;
33 private System.Windows.Forms.TextBox ns;
34 private System.Windows.Forms.TextBox outDir;
35 private System.Windows.Forms.Label label2;
36 private System.Windows.Forms.CheckBox overwriteCheck;
37 private System.Windows.Forms.Label label3;
38 private System.Windows.Forms.FolderBrowserDialog folderBrowserDialog1;
39 private System.Windows.Forms.ComboBox languageCombo;
40 /// <summary>
41 /// Required designer variable.
42 /// </summary>
43 private System.ComponentModel.Container components = null;
45 private ICodeProviderFactory codeproviderFactory;
46 private System.Windows.Forms.Button browseButton;
47 private System.Windows.Forms.Button generateButton;
48 private System.Windows.Forms.Button closeButton;
49 private Model _model;
52 protected GenCodeDialog()
54 codeproviderFactory =
55 ServiceRegistry.Instance[ typeof(ICodeProviderFactory) ] as ICodeProviderFactory;
58 // Required for Windows Form Designer support
60 InitializeComponent();
62 languageCombo.ValueMember = "Label";
64 foreach(CodeProviderInfo info in codeproviderFactory.GetAvailableProviders())
66 languageCombo.Items.Add(info);
69 languageCombo.SelectedIndex = 0;
72 public GenCodeDialog(Model model) : this()
74 _model = model;
76 ns.Text = model.CurrentProject.Namespace;
77 outDir.Text = model.CurrentProject.LastOutDir;
78 overwriteCheck.Checked = model.CurrentProject.OverwriteFiles;
81 /// <summary>
82 /// Clean up any resources being used.
83 /// </summary>
84 protected override void Dispose( bool disposing )
86 if( disposing )
88 if(components != null)
90 components.Dispose();
93 base.Dispose( disposing );
96 #region Windows Form Designer generated code
97 /// <summary>
98 /// Required method for Designer support - do not modify
99 /// the contents of this method with the code editor.
100 /// </summary>
101 private void InitializeComponent()
103 this.groupBox1 = new System.Windows.Forms.GroupBox();
104 this.languageCombo = new System.Windows.Forms.ComboBox();
105 this.label3 = new System.Windows.Forms.Label();
106 this.overwriteCheck = new System.Windows.Forms.CheckBox();
107 this.browseButton = new System.Windows.Forms.Button();
108 this.label2 = new System.Windows.Forms.Label();
109 this.outDir = new System.Windows.Forms.TextBox();
110 this.ns = new System.Windows.Forms.TextBox();
111 this.label1 = new System.Windows.Forms.Label();
112 this.generateButton = new System.Windows.Forms.Button();
113 this.closeButton = new System.Windows.Forms.Button();
114 this.folderBrowserDialog1 = new System.Windows.Forms.FolderBrowserDialog();
115 this.groupBox1.SuspendLayout();
116 this.SuspendLayout();
118 // groupBox1
120 this.groupBox1.Controls.Add(this.languageCombo);
121 this.groupBox1.Controls.Add(this.label3);
122 this.groupBox1.Controls.Add(this.overwriteCheck);
123 this.groupBox1.Controls.Add(this.browseButton);
124 this.groupBox1.Controls.Add(this.label2);
125 this.groupBox1.Controls.Add(this.outDir);
126 this.groupBox1.Controls.Add(this.ns);
127 this.groupBox1.Controls.Add(this.label1);
128 this.groupBox1.Location = new System.Drawing.Point(16, 16);
129 this.groupBox1.Name = "groupBox1";
130 this.groupBox1.Size = new System.Drawing.Size(424, 184);
131 this.groupBox1.TabIndex = 0;
132 this.groupBox1.TabStop = false;
133 this.groupBox1.Text = "Options:";
135 // languageCombo
137 this.languageCombo.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
138 this.languageCombo.Location = new System.Drawing.Point(104, 96);
139 this.languageCombo.Name = "languageCombo";
140 this.languageCombo.Size = new System.Drawing.Size(200, 21);
141 this.languageCombo.TabIndex = 7;
143 // label3
145 this.label3.Location = new System.Drawing.Point(16, 96);
146 this.label3.Name = "label3";
147 this.label3.Size = new System.Drawing.Size(80, 23);
148 this.label3.TabIndex = 6;
149 this.label3.Text = "Language:";
150 this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
152 // overwriteCheck
154 this.overwriteCheck.Location = new System.Drawing.Point(104, 136);
155 this.overwriteCheck.Name = "overwriteCheck";
156 this.overwriteCheck.Size = new System.Drawing.Size(208, 24);
157 this.overwriteCheck.TabIndex = 5;
158 this.overwriteCheck.Text = "Overwrite existing files";
160 // browseButton
162 this.browseButton.Location = new System.Drawing.Point(368, 64);
163 this.browseButton.Name = "browseButton";
164 this.browseButton.Size = new System.Drawing.Size(32, 24);
165 this.browseButton.TabIndex = 4;
166 this.browseButton.Text = "...";
167 this.browseButton.Click += new System.EventHandler(this.button3_Click);
169 // label2
171 this.label2.Location = new System.Drawing.Point(16, 64);
172 this.label2.Name = "label2";
173 this.label2.Size = new System.Drawing.Size(80, 23);
174 this.label2.TabIndex = 3;
175 this.label2.Text = "Output dir:";
176 this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
178 // outDir
180 this.outDir.Location = new System.Drawing.Point(104, 64);
181 this.outDir.Name = "outDir";
182 this.outDir.Size = new System.Drawing.Size(256, 21);
183 this.outDir.TabIndex = 2;
184 this.outDir.Text = "";
186 // ns
188 this.ns.Location = new System.Drawing.Point(104, 32);
189 this.ns.Name = "ns";
190 this.ns.Size = new System.Drawing.Size(296, 21);
191 this.ns.TabIndex = 1;
192 this.ns.Text = "";
194 // label1
196 this.label1.Location = new System.Drawing.Point(16, 32);
197 this.label1.Name = "label1";
198 this.label1.Size = new System.Drawing.Size(80, 23);
199 this.label1.TabIndex = 0;
200 this.label1.Text = "Namespace:";
201 this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
203 // generateButton
205 this.generateButton.Location = new System.Drawing.Point(368, 216);
206 this.generateButton.Name = "generateButton";
207 this.generateButton.TabIndex = 1;
208 this.generateButton.Text = "Generate";
209 this.generateButton.Click += new System.EventHandler(this.button1_Click);
211 // closeButton
213 this.closeButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
214 this.closeButton.Location = new System.Drawing.Point(280, 216);
215 this.closeButton.Name = "closeButton";
216 this.closeButton.TabIndex = 2;
217 this.closeButton.Text = "Close";
218 this.closeButton.Click += new System.EventHandler(this.button2_Click);
220 // GenCodeDialog
222 this.AcceptButton = this.generateButton;
223 this.AutoScaleBaseSize = new System.Drawing.Size(5, 14);
224 this.CancelButton = this.closeButton;
225 this.ClientSize = new System.Drawing.Size(456, 250);
226 this.Controls.Add(this.closeButton);
227 this.Controls.Add(this.generateButton);
228 this.Controls.Add(this.groupBox1);
229 this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
230 this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
231 this.MaximizeBox = false;
232 this.Name = "GenCodeDialog";
233 this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
234 this.Text = "Generate Code Options";
235 this.groupBox1.ResumeLayout(false);
236 this.ResumeLayout(false);
239 #endregion
241 private void button3_Click(object sender, System.EventArgs e)
243 folderBrowserDialog1.SelectedPath = outDir.Text;
245 if (folderBrowserDialog1.ShowDialog(this) == DialogResult.OK)
247 outDir.Text = folderBrowserDialog1.SelectedPath;
251 private void button2_Click(object sender, System.EventArgs e)
253 DialogResult = DialogResult.Cancel;
254 Close();
257 private void button1_Click(object sender, System.EventArgs e)
259 DirectoryInfo dirInfo = new DirectoryInfo(outDir.Text);
261 if (outDir.Text == String.Empty)
263 MessageBox.Show(this, "You must specify an output directory.", "Field is required", MessageBoxButtons.OK, MessageBoxIcon.Information);
264 return;
267 if (!dirInfo.Exists)
269 if (MessageBox.Show(this, "Output directory does not exists. Create it?", "Question", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question) == DialogResult.Yes)
271 dirInfo.Create();
273 else
275 return;
279 _model.CurrentProject.CodeInfo = languageCombo.SelectedItem as CodeProviderInfo;
280 _model.CurrentProject.LastOutDir = outDir.Text;
281 _model.CurrentProject.Namespace = ns.Text;
282 _model.CurrentProject.OverwriteFiles = overwriteCheck.Checked;
284 DialogResult = DialogResult.OK;
285 Close();