1 namespace Castle
.ActiveRecord
.Generator
.Dialogs
5 using System
.CodeDom
.Compiler
;
8 using System
.Collections
;
9 using System
.ComponentModel
;
10 using System
.Windows
.Forms
;
12 using Castle
.ActiveRecord
.Generator
.Components
.CodeGenerator
;
13 using Castle
.ActiveRecord
.Generator
.Components
.Database
;
16 /// Summary description for CodePreviewDialog.
18 public class CodePreviewDialog
: System
.Windows
.Forms
.Form
20 private System
.Windows
.Forms
.PictureBox pictureBox1
;
21 private System
.Windows
.Forms
.RichTextBox richTextBox1
;
22 private System
.Windows
.Forms
.ComboBox language
;
24 /// Required designer variable.
26 private System
.ComponentModel
.Container components
= null;
28 private ICodeProviderFactory codeproviderFactory
;
29 private System
.Windows
.Forms
.Button button1
;
30 private CodeTypeDeclaration typeDecl
;
33 public CodePreviewDialog()
36 // Required for Windows Form Designer support
38 InitializeComponent();
41 // TODO: Add any constructor code after InitializeComponent call
45 public CodePreviewDialog(IActiveRecordDescriptor descriptor
) : this()
48 ServiceRegistry
.Instance
[ typeof(ICodeProviderFactory
) ] as ICodeProviderFactory
;
49 ICodeDomGenerator codeDomGen
=
50 ServiceRegistry
.Instance
[ typeof(ICodeDomGenerator
) ] as ICodeDomGenerator
;
52 typeDecl
= codeDomGen
.Generate(descriptor
);
54 language
.ValueMember
= "Label";
56 foreach(CodeProviderInfo info
in codeproviderFactory
.GetAvailableProviders())
58 language
.Items
.Add(info
);
61 language
.SelectedIndex
= 0;
65 /// Clean up any resources being used.
67 protected override void Dispose( bool disposing
)
71 if(components
!= null)
76 base.Dispose( disposing
);
79 #region Windows Form Designer generated code
81 /// Required method for Designer support - do not modify
82 /// the contents of this method with the code editor.
84 private void InitializeComponent()
86 this.pictureBox1
= new System
.Windows
.Forms
.PictureBox();
87 this.button1
= new System
.Windows
.Forms
.Button();
88 this.language
= new System
.Windows
.Forms
.ComboBox();
89 this.richTextBox1
= new System
.Windows
.Forms
.RichTextBox();
90 this.pictureBox1
.SuspendLayout();
95 this.pictureBox1
.Controls
.Add(this.button1
);
96 this.pictureBox1
.Controls
.Add(this.language
);
97 this.pictureBox1
.Dock
= System
.Windows
.Forms
.DockStyle
.Bottom
;
98 this.pictureBox1
.Location
= new System
.Drawing
.Point(0, 344);
99 this.pictureBox1
.Name
= "pictureBox1";
100 this.pictureBox1
.Size
= new System
.Drawing
.Size(616, 50);
101 this.pictureBox1
.TabIndex
= 0;
102 this.pictureBox1
.TabStop
= false;
106 this.button1
.Anchor
= System
.Windows
.Forms
.AnchorStyles
.Right
;
107 this.button1
.DialogResult
= System
.Windows
.Forms
.DialogResult
.Cancel
;
108 this.button1
.Location
= new System
.Drawing
.Point(500, 12);
109 this.button1
.Name
= "button1";
110 this.button1
.TabIndex
= 4;
111 this.button1
.Text
= "Close";
115 this.language
.DropDownStyle
= System
.Windows
.Forms
.ComboBoxStyle
.DropDownList
;
116 this.language
.Location
= new System
.Drawing
.Point(16, 12);
117 this.language
.Name
= "language";
118 this.language
.TabIndex
= 1;
119 this.language
.SelectedIndexChanged
+= new System
.EventHandler(this.language_SelectedIndexChanged
);
123 this.richTextBox1
.DetectUrls
= false;
124 this.richTextBox1
.Dock
= System
.Windows
.Forms
.DockStyle
.Fill
;
125 this.richTextBox1
.Font
= new System
.Drawing
.Font("Lucida Console", 9.75F
, System
.Drawing
.FontStyle
.Regular
, System
.Drawing
.GraphicsUnit
.Point
, ((System
.Byte
)(0)));
126 this.richTextBox1
.ForeColor
= System
.Drawing
.Color
.Navy
;
127 this.richTextBox1
.Location
= new System
.Drawing
.Point(0, 0);
128 this.richTextBox1
.Name
= "richTextBox1";
129 this.richTextBox1
.ReadOnly
= true;
130 this.richTextBox1
.Size
= new System
.Drawing
.Size(616, 344);
131 this.richTextBox1
.TabIndex
= 3;
132 this.richTextBox1
.Text
= "";
136 this.AutoScaleBaseSize
= new System
.Drawing
.Size(5, 14);
137 this.ClientSize
= new System
.Drawing
.Size(616, 394);
138 this.Controls
.Add(this.richTextBox1
);
139 this.Controls
.Add(this.pictureBox1
);
140 this.Font
= new System
.Drawing
.Font("Tahoma", 8.25F
, System
.Drawing
.FontStyle
.Regular
, System
.Drawing
.GraphicsUnit
.Point
, ((System
.Byte
)(0)));
141 this.Name
= "CodePreviewDialog";
142 this.Text
= "Preview";
143 this.pictureBox1
.ResumeLayout(false);
144 this.ResumeLayout(false);
149 private void language_SelectedIndexChanged(object sender
, System
.EventArgs e
)
151 CodeProviderInfo info
= (CodeProviderInfo
) language
.SelectedItem
;
153 CodeDomProvider provider
= codeproviderFactory
.GetProvider( info
);
155 StringWriter writer
= new StringWriter();
156 CodeGeneratorOptions opts
= new CodeGeneratorOptions();
157 opts
.BracingStyle
= "C";
158 opts
.BlankLinesBetweenMembers
= true;
160 provider
.CreateGenerator().GenerateCodeFromType(typeDecl
, writer
, opts
);
162 richTextBox1
.Text
= writer
.GetStringBuilder().ToString();