-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathCSharpGenerator.cs
More file actions
260 lines (229 loc) · 11.8 KB
/
CSharpGenerator.cs
File metadata and controls
260 lines (229 loc) · 11.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
using System;
using System.Globalization;
using System.Text;
using System.Windows.Forms;
namespace InfoBox.Designer.CodeGeneration
{
/// <summary>
/// C# code generator for InformationBox calls
/// </summary>
public class CSharpGenerator : ICodeGenerator
{
#region ICodeGenerator Members
/// <summary>
/// Generates a single method call to display an InfoBox.
/// </summary>
/// <param name="behavior">The behavior.</param>
/// <param name="text">The text.</param>
/// <param name="title">The title.</param>
/// <param name="buttons">The buttons.</param>
/// <param name="button1Text">The button1 text.</param>
/// <param name="button2Text">The button2 text.</param>
/// <param name="button3Text">The button3 text.</param>
/// <param name="icon">The icon.</param>
/// <param name="iconFileName">Name of the icon file.</param>
/// <param name="defaultButton">The default button.</param>
/// <param name="buttonsLayout">The buttons layout.</param>
/// <param name="autoSize">The autosize parameters</param>
/// <param name="position">The position.</param>
/// <param name="showHelp">if set to <c>true</c> [show help].</param>
/// <param name="helpFile">The help file.</param>
/// <param name="helpTopic">The help topic.</param>
/// <param name="navigator">The navigator.</param>
/// <param name="checkState">The state of the checkbox.</param>
/// <param name="doNotShowAgainText">If not null, the value will replace the default text for the "Do not show again" checkbox.</param>
/// <param name="style">The style.</param>
/// <param name="useAutoClose">if set to <c>true</c> [use auto close].</param>
/// <param name="autoClose">The auto-close parameters.</param>
/// <param name="design">The design.</param>
/// <param name="fontParameters">The font parameters.</param>
/// <param name="titleStyle">The title style.</param>
/// <param name="titleIconFileName">Filename of the title icon .</param>
/// <param name="opacity">The opacity.</param>
/// <param name="order">The order.</param>
/// <param name="sound">The sound.</param>
/// <returns></returns>
public string GenerateSingleCall(InformationBoxBehavior behavior,
string text,
string title,
InformationBoxButtons buttons,
string button1Text,
string button2Text,
string button3Text,
InformationBoxIcon icon,
string iconFileName,
InformationBoxDefaultButton defaultButton,
InformationBoxButtonsLayout buttonsLayout,
InformationBoxAutoSizeMode autoSize,
InformationBoxPosition position,
bool showHelp,
string helpFile,
string helpTopic,
HelpNavigator navigator,
InformationBoxCheckBox checkState,
string doNotShowAgainText,
InformationBoxStyle style,
bool useAutoClose,
AutoCloseParameters autoClose,
DesignParameters design,
FontParameters fontParameters,
InformationBoxTitleIconStyle titleStyle,
string titleIconFileName,
InformationBoxOpacity opacity,
InformationBoxOrder order,
InformationBoxSound sound)
{
StringBuilder codeBuilder = new StringBuilder();
if (checkState == 0)
{
codeBuilder.AppendFormat("InformationBox.Show(\"{0}\", ", text.Replace(Environment.NewLine, "\\n"));
}
else
{
codeBuilder.Append("CheckState doNotShowState = CheckState.Indeterminate;");
codeBuilder.Append(Environment.NewLine);
codeBuilder.AppendFormat("InformationBox.Show(\"{0}\", out doNotShowState, ", text.Replace(Environment.NewLine, "\\n"));
}
if (!String.IsNullOrEmpty(title))
{
codeBuilder.AppendFormat("title: \"{0}\", ", title);
}
if (buttons != InformationBoxButtons.OK)
{
codeBuilder.AppendFormat("buttons: InformationBoxButtons.{0}, ", buttons);
}
if (buttons == InformationBoxButtons.OKCancelUser1 ||
buttons == InformationBoxButtons.User1User2 ||
buttons == InformationBoxButtons.YesNoUser1)
{
codeBuilder.AppendFormat("customButtons: new string[] {{ \"{0}\", \"{1}\" }}, ", button1Text, button2Text);
}
else if (buttons == InformationBoxButtons.User1User2User3)
{
codeBuilder.AppendFormat("customButtons: new string[] {{ \"{0}\", \"{1}\", \"{2}\" }}, ", button1Text, button2Text, button3Text);
}
if (icon != InformationBoxIcon.None)
{
codeBuilder.AppendFormat("icon: InformationBoxIcon.{0}, ", icon);
}
if (!String.IsNullOrEmpty(iconFileName))
{
codeBuilder.AppendFormat("customIcon: new System.Drawing.Icon(@\"{0}\"), ", iconFileName);
}
if (defaultButton != InformationBoxDefaultButton.Button1)
{
codeBuilder.AppendFormat("defaultButton: InformationBoxDefaultButton.{0}, ", defaultButton);
}
if (buttonsLayout != InformationBoxButtonsLayout.GroupMiddle)
{
codeBuilder.AppendFormat("buttonsLayout: InformationBoxButtonsLayout.{0}, ", buttonsLayout);
}
if (autoSize != InformationBoxAutoSizeMode.None)
{
codeBuilder.AppendFormat("autoSizeMode: InformationBoxAutoSizeMode.{0}, ", autoSize);
}
if (sound != InformationBoxSound.Default)
{
codeBuilder.AppendFormat("sound: InformationBoxSound.{0}, ", sound);
}
if (position != InformationBoxPosition.CenterOnParent)
{
codeBuilder.AppendFormat("position: InformationBoxPosition.{0}, ", position);
}
if (showHelp)
{
codeBuilder.Append("showHelpButton: true, ");
}
if (!String.IsNullOrEmpty(helpFile))
{
codeBuilder.AppendFormat("helpFile: @\"{0}\", ", helpFile);
}
if (navigator != 0)
{
codeBuilder.AppendFormat("helpNavigator: HelpNavigator.{0}, ", navigator);
}
if (!String.IsNullOrEmpty(helpTopic))
{
codeBuilder.AppendFormat("helpTopic: \"{0}\", ", helpTopic);
}
if (checkState != 0)
{
codeBuilder.Append("showDoNotShowAgainCheckBox: InformationBoxCheckBox.Show");
if ((checkState & InformationBoxCheckBox.Checked) == InformationBoxCheckBox.Checked)
{
codeBuilder.Append(" | InformationBoxCheckBox.Checked");
}
if ((checkState & InformationBoxCheckBox.RightAligned) == InformationBoxCheckBox.RightAligned)
{
codeBuilder.Append(" | InformationBoxCheckBox.RightAligned");
}
codeBuilder.Append(", ");
}
if (doNotShowAgainText != null)
{
codeBuilder.AppendFormat("doNotShowAgainText: \"{0}\", ", doNotShowAgainText);
}
if (style != InformationBoxStyle.Standard)
{
codeBuilder.AppendFormat("style: InformationBoxStyle.{0}, ", style);
}
if (order != InformationBoxOrder.Default)
{
codeBuilder.AppendFormat("order: InformationBoxOrder.{0}, ", order);
}
if (useAutoClose)
{
if (autoClose.Seconds == AutoCloseParameters.Default.Seconds &&
autoClose.DefaultButton == InformationBoxDefaultButton.Button1 &&
autoClose.Result == InformationBoxResult.None)
{
codeBuilder.Append("autoClose: AutoCloseParameters.Default, ");
}
else
{
if (autoClose.Mode == AutoCloseDefinedParameters.Button)
{
codeBuilder.AppendFormat("autoClose: new AutoCloseParameters({0}, InformationBoxDefaultButton.{1}), ", autoClose.Seconds, autoClose.DefaultButton);
}
else if (autoClose.Mode == AutoCloseDefinedParameters.Result)
{
codeBuilder.AppendFormat("autoClose: new AutoCloseParameters({0}, InformationBoxResult.{1}), ", autoClose.Seconds, autoClose.Result);
}
else
{
codeBuilder.AppendFormat("autoClose: new AutoCloseParameters({0}), ", autoClose.Seconds);
}
}
}
if (null != design)
{
codeBuilder.AppendFormat(CultureInfo.InvariantCulture, "design: new DesignParameters(System.Drawing.Color.FromArgb({0},{1},{2}), System.Drawing.Color.FromArgb({3},{4},{5})), ", design.FormBackColor.R, design.FormBackColor.G, design.FormBackColor.B, design.BarsBackColor.R, design.BarsBackColor.G, design.BarsBackColor.B);
}
if (null != fontParameters && fontParameters.MessageFont != null)
{
codeBuilder.AppendFormat(CultureInfo.InvariantCulture, "fontParameters: new FontParameters(new System.Drawing.Font(\"{0}\", {1}F)), ",
fontParameters.MessageFont.Name, fontParameters.MessageFont.Size);
}
if (titleStyle == InformationBoxTitleIconStyle.Custom)
{
codeBuilder.AppendFormat(CultureInfo.InvariantCulture, "titleIcon: new InformationBoxTitleIcon(@\"{0}\"), ", titleIconFileName);
}
else if (titleStyle == InformationBoxTitleIconStyle.SameAsBox)
{
codeBuilder.Append("titleStyle: InformationBoxTitleIconStyle.SameAsBox, ");
}
if (behavior == InformationBoxBehavior.Modeless)
{
codeBuilder.Append("behavior: InformationBoxBehavior.Modeless, ");
}
if (opacity != InformationBoxOpacity.NoFade)
{
codeBuilder.AppendFormat("opacity: InformationBoxOpacity.{0}, ", opacity);
}
codeBuilder[codeBuilder.Length - 2] = ')';
codeBuilder[codeBuilder.Length - 1] = ';';
return codeBuilder.ToString().Replace("\"\"", "System.String.Empty");
}
#endregion
}
}