Menu

[r1]: / Basic-Debugger / MainForm.cs  Maximize  Restore  History

Download this file

277 lines (235 with data), 9.4 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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using Microsoft.Win32;
using System.Xml;
using System.IO;
namespace Basic_Debugger
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
RegistryKey r = Registry.CurrentUser.OpenSubKey("Software", true).CreateSubKey("QBasic.Net");
string[] s = r.GetValueNames();
for (int I = 0; I < s.Length; I++)
{
int l = 0;
if (int.TryParse(s[I].Replace("RecentProject", ""), out l))
_recentProjects.Items.Add(r.GetValue(s[I]));
if (s[I] == "DefaultDirectory")
defaultFolder = (string)r.GetValue(s[I]);
}
_start_Resize(null, null);
_project = new BasicProject();
}
public string defaultFolder = "";
public BasicProject _project;
private void _menuNewProject_Click(object sender, EventArgs e)
{
Initialise();
}
private void _menuSave_Click(object sender, EventArgs e)
{
if (_project.Name == null && _project.Location == null)
{
ProjectDialog p = new ProjectDialog(this);
p.ShowDialog(this);
if (!p.Finished)
return;
p.Dispose();
}
StreamWriter w = new StreamWriter(_project.Location + "\\" + _project.Name + ".bat", false);
w.Write(_main.Text);
w.Flush();
w.Close();
}
private void _menuDebug_Click(object sender, EventArgs e)
{
_main.SelectAll();
_main.SelectionColor = Color.Black;
_main.Select(0, 0);
_project.Code.MainCode = _main.Text;
int[] errors;
if (!_project.Debugger.Check(out errors))
{
string[] lines = _main.Text.Split("\n".ToCharArray());
for (int I = 0; I < lines.Length; I++)
{
for (int A = 0; A < errors.Length; A++)
{
if (I == errors[A])
{
int start = 0;
for (int C = 0; C < I; C++)
start += lines[C].Length + 1;
_main.Select(start, lines[I].Length);
_main.SelectionColor = Color.Red;
A = errors.Length;
}
}
}
MessageBox.Show("There were some errors in code");
}
else
{
int line = 0;
if (!_project.Debugger.Debug(out line))
{
string[] lines = _main.Text.Split("\n".ToCharArray());
int start = 0;
for (int C = 0; C < line; C++)
start += lines[C].Length + 1;
_main.Select(start, lines[line].Length);
_main.SelectionColor = Color.Red;
MessageBox.Show("Runtime Error");
}
}
}
void _start_Resize(object sender, System.EventArgs e)
{
//_recentProjectsGroup.Location = new Point((_start.Size.Width - _recentProjectsGroup.Width) / 2, _recentProjectsGroup.Location.Y);
_OpenProject.Location = new Point((_start.Size.Width - _OpenProject.Width) / 2, _OpenProject.Location.Y);
_newSave.Location = new Point((_start.Size.Width - _newSave.Width - 8 - _new.Width) / 2, _newSave.Location.Y);
_new.Location = new Point((_start.Size.Width - _newSave.Width - 8 - _new.Width) / 2 + _newSave.Width + 8, _new.Location.Y);
}
#region Basic commands
private void _menuUndo_Click(object sender, EventArgs e)
{
_main.Undo();
}
private void _menuRedo_Click(object sender, EventArgs e)
{
_main.Redo();
}
private void _menuCut_Click(object sender, EventArgs e)
{
_main.Cut();
}
private void _menuCopy_Click(object sender, EventArgs e)
{
_main.Copy();
}
private void _menuPaste_Click(object sender, EventArgs e)
{
_main.Paste();
}
private void _menuSelectAll_Click(object sender, EventArgs e)
{
_main.SelectAll();
}
#endregion
private void _new_Click(object sender, EventArgs e)
{
Initialise();
}
private void _newSave_Click(object sender, EventArgs e)
{
ProjectDialog p = new ProjectDialog(this);
p.ShowDialog(this);
if (p.Finished)
OpenProject(_project.Location + "\\" + _project.Name + ".qproj");
p.Dispose();
}
private void Initialise()
{
_start.Visible = false;
_main.Visible = true;
_main.Enabled = true;
_listSubs.Items.Clear();
if (_project.Name != null)
{
_listSubs.Items.Add(_project.Name);
RegistryKey r = Registry.CurrentUser.OpenSubKey("Software", true).CreateSubKey("QBasic.Net");
int l = 1, temp;
string[] s = r.GetValueNames();
for (int I = 0; I < s.Length; I++)
{
if (int.TryParse(s[I].Replace("RecentProject", ""), out temp))
{
if ((string)r.GetValue(s[I]) != (_project.Location + "\\" + _project.Name + ".qproj"))
l++;
else
{
I = s.Length;
l = -1;
}
}
}
if (l > 0)
r.SetValue("RecentProject" + l, _project.Location + "\\" + _project.Name + ".qproj");
}
else
_listSubs.Items.Add("Main");
}
#region Open Project part
void _recentProjects_DoubleClick(object sender, System.EventArgs e)
{
if (!string.IsNullOrEmpty((string)_recentProjects.SelectedItem))
OpenProject((string)_recentProjects.SelectedItem);
}
private void _OpenProject_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty((string)_recentProjects.SelectedItem))
OpenProject((string)_recentProjects.SelectedItem);
else
_menuOpenProject_Click(null, null);
}
private void _menuOpenProject_Click(object sender, EventArgs e)
{
if (defaultFolder == "")
_openDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
else
_openDialog.InitialDirectory = defaultFolder;
_openDialog.Multiselect = false;
_openDialog.FileName = "";
if (_openDialog.ShowDialog() != DialogResult.Cancel)
OpenProject(_openDialog.FileName);
}
private void OpenProject(string ProjectFile)
{
_project.Location = new FileInfo(ProjectFile).DirectoryName;
_project.Code = new Code();
XmlDocument x = new XmlDocument();
x.PreserveWhitespace = true;
x.Load(ProjectFile);
XmlNodeReader r = new XmlNodeReader(x);
StreamReader read;
while (r.Read())
{
if (r.NodeType == XmlNodeType.Element)
{
switch (r.Name)
{
case "Name":
_project.Name = r.ReadElementContentAsString();
break;
case "Sub":
_project.Code.Subs.Add(new Sub(r.ReadElementContentAsString()));
read = new StreamReader(_project.Location + "\\" + r.ReadElementContentAsString() + ".bat");
_project.Code.Subs[r.ReadElementContentAsString()].Content = read.ReadToEnd();
read.Close();
break;
}
}
}
r.Close();
read = new StreamReader(_project.Location + "\\" + _project.Name + ".bat");
_project.Code.MainCode = read.ReadToEnd();
read.Close();
_main.Text = _project.Code.MainCode;
Initialise();
}
#endregion
private void _menuExit_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
MongoDB Logo MongoDB