This repository has been archived by the owner on Dec 18, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Form1.cs
358 lines (319 loc) · 13.2 KB
/
Form1.cs
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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.CodeDom.Compiler;
using System.Diagnostics;
using Microsoft.CSharp;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using FastColoredTextBoxNS;
using VX_Library;
using System.Text.RegularExpressions;
using System.IO;
namespace VoltDev
{
public partial class Form1 : Form
{
private string filePath = "";
protected override CreateParams CreateParams
{
get
{
const int CS_DROPSHADOW = 0x20000;
CreateParams cp = base.CreateParams;
cp.ClassStyle |= CS_DROPSHADOW;
return cp;
}
}
protected static readonly Platform platformType = PlatformType.GetOperationSystemPlatform();
//styles
public readonly Style CommentStyle = new TextStyle(Brushes.DarkGreen, null, FontStyle.Regular);
public readonly Style LawnGreenStyle = new TextStyle(Brushes.ForestGreen, null, FontStyle.Regular);
public readonly Style LightBlueStyle = new TextStyle(Brushes.DodgerBlue, null, FontStyle.Regular);
public readonly Style HardBlueStyle = new TextStyle(Brushes.Blue, null, FontStyle.Regular);
public readonly Style AquaStyle = new TextStyle(Brushes.MediumAquamarine, null, FontStyle.Regular);
public readonly Style NameStyle = new TextStyle(null, null, FontStyle.Underline);
public readonly Style ClosedStyle = new TextStyle(null, null, FontStyle.Strikeout);
public readonly Style YellowStyle = new TextStyle(Brushes.Yellow, null, FontStyle.Regular);
public readonly Style BlackBGStyle = new TextStyle(null, Brushes.Black, FontStyle.Regular);
public readonly Style RedStyle = new TextStyle(Brushes.DarkRed, null, FontStyle.Regular);
public readonly Style MaroonStyle = new TextStyle(Brushes.Chocolate, null, FontStyle.Regular); //string
public Form1()
{
InitializeComponent();
SwitchStripsTheme.DarkTheme(panel2.Controls,Color.FromArgb(20,20,20),Color.FromArgb(28,28,28));
}
public const int WM_NCLBUTTONDOWN = 0xA1;
public const int HT_CAPTION = 0x2;
[System.Runtime.InteropServices.DllImportAttribute("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
[System.Runtime.InteropServices.DllImportAttribute("user32.dll")]
public static extern bool ReleaseCapture();
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
ReleaseCapture();
SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
}
}
public static RegexOptions RegexCompiledOption
{
get
{
if (platformType == Platform.X86)
return RegexOptions.Compiled;
else
return RegexOptions.None;
}
}
private void InitVoltExSyntax()
{
fastColoredTextBox1.RightBracket2 = '[';
fastColoredTextBox1.LeftBracket2 = ']';
fastColoredTextBox1.BracketsHighlightStrategy = BracketsHighlightStrategy.Strategy2;
fastColoredTextBox1.AutoIndentCharsPatterns = @"
^\s*[\w\.]+(\s\w+)?\s*(?<range>=)\s*(?<range>[^;]+);
^\s*(case|default)\s*[^:]*(?<range>:)\s*(?<range>[^;]+);";
}
private void fastColoredTextBox1_TextChanged(object sender, TextChangedEventArgs e)
{
//clear
e.ChangedRange.ClearStyle(CommentStyle, LightBlueStyle, AquaStyle, HardBlueStyle,
LawnGreenStyle, YellowStyle, NameStyle);
e.ChangedRange.ClearFoldingMarkers();
//HIGHLIGHT------------------------------------------------
e.ChangedRange.SetStyle(CommentStyle, @"#.*$");
e.ChangedRange.SetStyle(YellowStyle, @"\b(plugin|event|on_start|config)\b");
e.ChangedRange.SetStyle(YellowStyle, @"\b(change|print|use|storage|message|save|load|
run|render|console)\b");
//e.ChangedRange.SetStyle(AquaStyle, @"\b()\s+(?<range>[\w_]+?)\b");
e.ChangedRange.SetStyle(LightBlueStyle, @"\b(new|object|label|lb|button|bt|progressbar|pbar|
richtextbox|rtb|textbox|tb|panel|pn|treeview|tview
webbrowser|browser|function|end)\b");
e.ChangedRange.SetStyle(LawnGreenStyle, @"\b\d+[\.]?\d*([eE]\-?\d+)?[lLdDfF]?\b|\b0x[a-fA-F\d]+\b");
e.ChangedRange.SetStyle(MaroonStyle, @"""""|"".*?[^\\]""");
//e.ChangedRange.SetStyle(NameStyle, @"\b()\s+(?<range>[\w_]+?)\b");
//block of code
e.ChangedRange.ClearFoldingMarkers();
e.ChangedRange.SetFoldingMarkers(@"#block\b", @"#endblock\b");
}
private void RefreshSyntax()
{
string data = fastColoredTextBox1.Text;
fastColoredTextBox1.Clear();
fastColoredTextBox1.Text = data;
}
private void Save()
{
if(filePath!="")
{
StreamWriter sw = new StreamWriter(filePath);
sw.Write(fastColoredTextBox1.Text);
sw.Close();
}
else
{
SaveDlg();
}
}
private void SaveDlg()
{
SaveFileDialog sfg = new SaveFileDialog();
sfg.Filter = "VX File|*.vx|Text File|*.txt|Any File|*.*";
if (sfg.ShowDialog()==DialogResult.OK)
{
StreamWriter sw = new StreamWriter(sfg.FileName);
sw.Write(fastColoredTextBox1.Text);
sw.Close();
filePath = sfg.FileName;
}
}
private void OpenDlg()
{
OpenFileDialog sfg = new OpenFileDialog();
sfg.Filter = "VX File|*.vx|Text File|*.txt|Any File|*.*";
if(sfg.ShowDialog()==DialogResult.OK)
{
StreamReader sr = new StreamReader(sfg.FileName);
fastColoredTextBox1.Text = sr.ReadToEnd();
sr.Close();
filePath = sfg.FileName;
}
}
private void button1_Click(object sender, EventArgs e)
{
if(fastColoredTextBox1.Text.Replace(" ","")=="")
{
Application.Exit();
}
else
{
DialogResult mb = MessageBox.Show("Do you want to save file?","Saving", MessageBoxButtons.YesNoCancel);
if(mb==DialogResult.Yes)
{
Save();
Application.Exit();
}
else if(mb==DialogResult.Cancel)
{
}
else
{
Application.Exit();
}
}
}
private void findToolStripMenuItem_Click(object sender, EventArgs e)
{
fastColoredTextBox1.ShowFindDialog();
}
private void goToToolStripMenuItem_Click(object sender, EventArgs e)
{
fastColoredTextBox1.ShowGoToDialog();
}
private void endToolStripMenuItem_Click(object sender, EventArgs e)
{
fastColoredTextBox1.GoEnd();
}
private void fastColoredTextBox1_AutoIndentNeeded(object sender, AutoIndentEventArgs e)
{
}
private void openFileToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenDlg();
}
private void fromFileToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenDlg();
}
private void clearToolStripMenuItem_Click(object sender, EventArgs e)
{
DialogResult msg = MessageBox.Show("Are you sure?", "Deleting code", MessageBoxButtons.YesNo);
if (msg == DialogResult.Yes)
fastColoredTextBox1.Clear();
}
private void saveFileToolStripMenuItem_Click(object sender, EventArgs e)
{
Save();
}
private void saveFileAsToolStripMenuItem_Click(object sender, EventArgs e)
{
SaveDlg();
}
private void newFileToolStripMenuItem_Click(object sender, EventArgs e)
{
DialogResult msg = MessageBox.Show("Are you sure?", "Deleting code", MessageBoxButtons.YesNo);
if (msg == DialogResult.Yes)
fastColoredTextBox1.Clear();
}
private void replaceToolStripMenuItem_Click(object sender, EventArgs e)
{
fastColoredTextBox1.ShowReplaceDialog();
}
private void cApplicationToolStripMenuItem_Click(object sender, EventArgs e)
{
string path = "";
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = "Executable File|*.exe|Library|*.dll";
if(sfd.ShowDialog()==DialogResult.OK)
{
path = sfd.FileName;
}
if(path!="")
{
CSharpCodeProvider codeProvider = new CSharpCodeProvider();
ICodeCompiler icc = codeProvider.CreateCompiler();
string Output = path.GetAfter(@"\");
CompilerParameters parameters = new CompilerParameters();
if(path.Contains(".exe"))
parameters.GenerateExecutable = true;
else
parameters.GenerateExecutable = false;
parameters.OutputAssembly = path;
CompilerResults results = icc.CompileAssemblyFromSource(parameters, fastColoredTextBox1.Text);
if (results.Errors.Count > 0)
{
ErrorsList el = new ErrorsList(results.Errors);
el.Show();
}
else
{
//Successful Compile
MessageBox.Show("Compiled");
//Process.Start(Output);
}
}
}
private void buildRunToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void buildToolStripMenuItem_Click(object sender, EventArgs e)
{
string buildFolder = Application.StartupPath + @"\build\builded";
foreach(string f in Directory.GetFiles(buildFolder))
{
File.Delete(f);
}
foreach(string f in Directory.GetFiles(Application.StartupPath+@"\config\build\temp"))
{
string name = f.GetAfter(@"\");
File.Copy(f,buildFolder+@"\"+name);
if(name=="config.vxc")
{
try
{
StreamWriter sw = new StreamWriter(buildFolder + @"\" + name);
sw.Write(fastColoredTextBox1.Text);
//sw.Write(Translate.Encrypt(fastColoredTextBox1.Text, "vx"));
sw.Close();
}
catch { MessageBox.Show("Builded app has errors"); }
}
}
Process.Start(buildFolder);
}
private void testRunToolStripMenuItem_Click(object sender, EventArgs e)
{
string buildFolder = Application.StartupPath + @"\build\builded";
foreach (string f in Directory.GetFiles(buildFolder))
{
try
{
File.Delete(f);
}
catch { MessageBox.Show("failed"); }
}
foreach (string f in Directory.GetFiles(Application.StartupPath + @"\config\build\temp"))
{
string name = f.GetAfter(@"\");
File.Copy(f, buildFolder + @"\" + name);
if (name == "config.vxc")
{
try
{
StreamWriter sw = new StreamWriter(buildFolder + @"\" + name);
sw.Write(fastColoredTextBox1.Text);
//sw.Write(Translate.Encrypt(fastColoredTextBox1.Text, "vx"));
sw.Close();
}
catch { MessageBox.Show("Builded app has errors"); }
}
}
try
{
Process.Start(buildFolder + @"\App.exe");
}
catch { MessageBox.Show("Failed running app"); }
}
private void codeMarketToolStripMenuItem_Click(object sender, EventArgs e)
{
CodeMarket cm = new CodeMarket();
cm.Show();
}
}
}