Rev 11 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | freddie | 1 | /* |
2 | * Created by SharpDevelop. |
||
3 | * User: 06pfjn |
||
4 | * Date: 30/06/2010 |
||
5 | * Time: 12:15 |
||
6 | * |
||
7 | * To change this template use Tools | Options | Coding | Edit Standard Headers. |
||
8 | */ |
||
9 | using System; |
||
10 | using System.Collections.Generic; |
||
11 | using System.Drawing; |
||
12 | using System.Windows.Forms; |
||
13 | |||
14 | namespace LassyPad |
||
15 | { |
||
16 | /// <summary> |
||
17 | /// Description of MainForm. |
||
18 | /// </summary> |
||
19 | public partial class MainForm : Form |
||
20 | { |
||
9 | freddie | 21 | |
22 | public class word |
||
23 | { |
||
24 | public Color colour; |
||
25 | public List<string> words; |
||
1 | freddie | 26 | |
9 | freddie | 27 | public word(Color colourN, string wordsN) |
28 | { |
||
29 | colour = colourN; |
||
30 | words = new List<string>(); |
||
31 | string[] tempWords = wordsN.Split(','); |
||
32 | for (int i = 0; i < tempWords.Length; i++) |
||
33 | words.Add(tempWords[i]); |
||
34 | } |
||
35 | |||
36 | } |
||
37 | |||
38 | public class comment |
||
39 | { |
||
40 | public Color colour; |
||
41 | public string start; |
||
42 | public string end; |
||
43 | |||
44 | public comment(Color colourN, string startN, string endN) |
||
45 | { |
||
46 | colour = colourN; |
||
47 | start = startN; |
||
48 | end = endN; |
||
49 | } |
||
50 | |||
51 | public comment(Color colourN, string startN) |
||
52 | { |
||
53 | colour = colourN; |
||
54 | start = startN; |
||
55 | end = "\n"; |
||
56 | } |
||
57 | } |
||
58 | |||
1 | freddie | 59 | public class rtfFile |
60 | { |
||
61 | public string loc; |
||
62 | public RichTextBox rtfBox; |
||
63 | public bool saved; |
||
9 | freddie | 64 | public bool isRtf; |
65 | public int syntax; |
||
66 | |||
1 | freddie | 67 | public rtfFile(string locN) |
68 | { |
||
69 | loc = locN; |
||
70 | saved = true; |
||
71 | rtfBox = new RichTextBox(); |
||
72 | } |
||
73 | |||
74 | public void save() |
||
75 | { |
||
9 | freddie | 76 | if (loc.EndsWith(".rtf")) |
77 | rtfBox.SaveFile(loc); |
||
78 | else |
||
11 | freddie | 79 | rtfBox.SaveFile(loc, RichTextBoxStreamType.PlainText); |
1 | freddie | 80 | saved = true; |
81 | } |
||
82 | |||
4 | freddie | 83 | public bool open() |
1 | freddie | 84 | { |
85 | try |
||
86 | { |
||
87 | saved = true; |
||
9 | freddie | 88 | if (loc.EndsWith(".rtf")) |
10 | freddie | 89 | { |
11 | freddie | 90 | rtfBox.LoadFile(loc); |
9 | freddie | 91 | isRtf = true; |
10 | freddie | 92 | } |
9 | freddie | 93 | else |
10 | freddie | 94 | { |
95 | rtfBox.LoadFile(loc, RichTextBoxStreamType.PlainText); |
||
9 | freddie | 96 | isRtf = false; |
10 | freddie | 97 | } |
1 | freddie | 98 | } |
99 | catch (Exception ex) |
||
100 | { |
||
10 | freddie | 101 | MessageBox.Show(ex.Message, "Load Error", MessageBoxButtons.OK, MessageBoxIcon.Error); |
102 | return false; |
||
1 | freddie | 103 | } |
4 | freddie | 104 | return true; |
1 | freddie | 105 | } |
106 | } |
||
107 | |||
9 | freddie | 108 | public class syntax |
109 | { |
||
110 | |||
111 | public string id; |
||
112 | public List<word> words; |
||
113 | public List<comment> comments; |
||
114 | |||
115 | public syntax(string idN) |
||
116 | { |
||
117 | id = idN; |
||
118 | words = new List<MainForm.word>(); |
||
119 | comments = new List<MainForm.comment>(); |
||
120 | } |
||
121 | |||
122 | } |
||
123 | |||
1 | freddie | 124 | public List<rtfFile> files = new List<rtfFile>(); |
125 | public int curFileID; |
||
126 | |||
9 | freddie | 127 | public List<syntax> syntaxes = new List<syntax>(); |
128 | |||
1 | freddie | 129 | public int selectionStart; |
130 | public int selectionLength; |
||
131 | |||
132 | public MainForm() |
||
133 | { |
||
134 | |||
135 | InitializeComponent(); |
||
136 | |||
137 | } |
||
138 | |||
139 | void MainFormLoad(object sender, EventArgs e) |
||
140 | { |
||
141 | welcomeView.Url = new Uri("http://tim32.org/~freddie/LassyPad/Welcome.htm"); |
||
142 | initAll(); |
||
7 | freddie | 143 | |
144 | bool openRes; |
||
145 | string[] envArgs = System.Environment.GetCommandLineArgs(); |
||
146 | for (int i = 0; i < envArgs.Length; i++) |
||
147 | { |
||
148 | if (envArgs[i].EndsWith(".rtf") || envArgs[i].EndsWith(".txt")) |
||
149 | { |
||
150 | files.Add(new rtfFile(envArgs[i])); |
||
151 | openRes = files[files.Count - 1].open(); |
||
152 | if (openRes) |
||
153 | { |
||
154 | treeView.Nodes["Files"].Nodes.Add(envArgs[i], envArgs[i]); |
||
155 | showFile(files.Count - 1); |
||
156 | } |
||
157 | else |
||
158 | files.RemoveAt(files.Count - 1); |
||
159 | } |
||
160 | } |
||
1 | freddie | 161 | } |
162 | |||
163 | public void initAll() |
||
164 | { |
||
165 | initTreeView(); |
||
9 | freddie | 166 | loadSyntaxes(); |
1 | freddie | 167 | } |
168 | |||
169 | public void initTreeView() |
||
170 | { |
||
171 | // welcome |
||
11 | freddie | 172 | treeView.SelectedImageIndex = 4; |
173 | |||
1 | freddie | 174 | treeView.Nodes.Add("Welcome", "Welcome"); |
11 | freddie | 175 | treeView.Nodes["Welcome"].ImageIndex = 3; |
176 | |||
1 | freddie | 177 | treeView.Nodes["Welcome"].Nodes.Add("Introduction", "Introduction"); |
11 | freddie | 178 | treeView.Nodes["Welcome"].Nodes["Introduction"].ImageIndex = 3; |
179 | |||
1 | freddie | 180 | treeView.Nodes["Welcome"].Nodes.Add("Help", "Help"); |
11 | freddie | 181 | treeView.Nodes["Welcome"].Nodes["Help"].ImageIndex = 3; |
1 | freddie | 182 | |
183 | // |
||
184 | treeView.Nodes.Add("Files", "Files"); |
||
11 | freddie | 185 | treeView.Nodes["Files"].ImageIndex = 2; |
1 | freddie | 186 | } |
187 | |||
9 | freddie | 188 | public void loadSyntaxes() |
189 | { |
||
190 | System.IO.StreamReader reader = new System.IO.StreamReader("data/syntaxes.dat"); |
||
191 | string r = reader.ReadToEnd(); |
||
192 | string[] data = r.Split('\n'); |
||
193 | string[] d, d2; |
||
194 | |||
195 | for (int i = 0; i < data.Length; i++) |
||
196 | { |
||
197 | data[i] = data[i].Replace("\r", ""); |
||
198 | if (data[i].EndsWith(":")) |
||
199 | { |
||
200 | syntaxes.Add(new syntax(data[i].Substring(0, data[i].Length - 1))); |
||
201 | syntaxHighlightingToolStripMenuItem.Items.Add(data[i].Substring(0, data[i].Length - 1)); |
||
202 | } |
||
203 | else |
||
204 | { |
||
205 | d = data[i].Split(' '); |
||
206 | switch (d[0]) |
||
207 | { |
||
208 | case ("word"): |
||
209 | { |
||
210 | if (d.Length == 3) |
||
211 | syntaxes[syntaxes.Count - 1].words.Add(new word(Color.FromName(d[1]), d[2])); |
||
212 | else if (d.Length == 5) |
||
213 | { |
||
214 | d2 = d[1].Split(','); |
||
215 | syntaxes[syntaxes.Count - 1].words.Add(new word(Color.FromArgb(int.Parse(d2[0]), int.Parse(d2[1]), int.Parse(d2[2])), d[2])); |
||
216 | } |
||
217 | break; |
||
218 | } |
||
219 | } |
||
220 | } |
||
221 | } |
||
222 | } |
||
223 | |||
1 | freddie | 224 | void TreeViewNodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) |
225 | { |
||
226 | if (e.Node.Level == 0) |
||
227 | { |
||
228 | switch (e.Node.Name) |
||
229 | { |
||
230 | case ("Welcome"): |
||
231 | { |
||
232 | welcomeView.Url = new Uri("http://tim32.org/~freddie/LassyPad/Welcome.htm"); |
||
233 | break; |
||
234 | } |
||
235 | } |
||
236 | } |
||
237 | else |
||
238 | { |
||
239 | switch (e.Node.Parent.Name) |
||
240 | { |
||
241 | case ("Welcome"): |
||
242 | { |
||
243 | if (e.Node.Name == "Introduction") |
||
244 | welcomeView.Url = new Uri("http://tim32.org/~freddie/LassyPad/Introduction.htm"); |
||
245 | else if (e.Node.Name == "Help") |
||
246 | welcomeView.Url = new Uri("http://tim32.org/~freddie/LassyPad/Help.htm"); |
||
247 | |||
248 | break; |
||
249 | } |
||
250 | case ("Files"): |
||
251 | { |
||
252 | showFile(e.Node.Name); |
||
253 | break; |
||
254 | } |
||
255 | } |
||
256 | } |
||
257 | } |
||
258 | |||
259 | // other functions |
||
260 | |||
7 | freddie | 261 | public void insertImageFromFile() |
262 | { |
||
263 | DialogResult res = openFileDialog1.ShowDialog(); |
||
264 | if (openFileDialog1.FileName != "" && res != DialogResult.Cancel) |
||
265 | { |
||
266 | // HELL - Get help from somewhere.... |
||
267 | } |
||
268 | } |
||
269 | |||
270 | public void zoomIn() |
||
271 | { |
||
272 | editorView.ZoomFactor *= 1.2f; |
||
273 | } |
||
274 | |||
275 | public void zoomOut() |
||
276 | { |
||
277 | editorView.ZoomFactor /= 1.2f; |
||
278 | } |
||
279 | |||
1 | freddie | 280 | public void setSelection() |
281 | { |
||
282 | editorView.Select(selectionStart, selectionLength); |
||
283 | } |
||
284 | |||
285 | public void showFile(int fileID) |
||
286 | { |
||
287 | tabControl.SelectedIndex = 1; |
||
288 | editorView.Rtf = files[fileID].rtfBox.Rtf; |
||
289 | curFileID = fileID; |
||
9 | freddie | 290 | if (files[curFileID].isRtf) |
291 | syntaxHighlightingToolStripMenuItem.Enabled = false; |
||
292 | else |
||
293 | syntaxHighlightingToolStripMenuItem.Enabled = true; |
||
1 | freddie | 294 | } |
295 | |||
296 | public void showFile(string filename) |
||
297 | { |
||
298 | tabControl.SelectedIndex = 1; |
||
299 | for (int i = 0; i < files.Count; i++) |
||
300 | { |
||
3 | freddie | 301 | if (files[i].loc == filename) |
302 | { |
||
303 | editorView.Rtf = files[i].rtfBox.Rtf; |
||
304 | curFileID = i; |
||
9 | freddie | 305 | if (files[curFileID].isRtf) |
306 | syntaxHighlightingToolStripMenuItem.Enabled = false; |
||
307 | else |
||
308 | syntaxHighlightingToolStripMenuItem.Enabled = true; |
||
3 | freddie | 309 | return; |
310 | } |
||
1 | freddie | 311 | } |
312 | } |
||
313 | |||
314 | // file functions |
||
315 | |||
316 | public void newFile() |
||
317 | { |
||
318 | int i = 0; |
||
3 | freddie | 319 | bool exists; |
1 | freddie | 320 | while (true) |
321 | { |
||
3 | freddie | 322 | exists = false; |
1 | freddie | 323 | for (int j = 0; j < files.Count; j++) |
324 | { |
||
3 | freddie | 325 | if ((files[j].loc == "NewFile" + i.ToString() + ".rtf")) |
326 | exists = true; |
||
1 | freddie | 327 | } |
3 | freddie | 328 | if (!exists) |
329 | { |
||
330 | files.Add(new rtfFile("NewFile" + i.ToString() + ".rtf")); |
||
331 | treeView.Nodes["Files"].Nodes.Add("NewFile" + i.ToString() + ".rtf", "NewFile" + i.ToString() + ".rtf"); |
||
11 | freddie | 332 | treeView.Nodes["Files"].Nodes["NewFile" + i.ToString() + ".rtf"].ImageIndex = 0; |
9 | freddie | 333 | files[files.Count - 1].isRtf = true; |
11 | freddie | 334 | // TODO: Eat cake |
3 | freddie | 335 | showFile(files.Count - 1); |
336 | return; |
||
337 | } |
||
1 | freddie | 338 | i++; |
339 | } |
||
340 | |||
341 | } |
||
342 | |||
343 | public void renameFile(string filename, string newFilename) |
||
344 | { |
||
3 | freddie | 345 | treeView.Nodes["Files"].Nodes[filename].Text = newFilename; |
346 | treeView.Nodes["Files"].Nodes[filename].Name = newFilename; |
||
1 | freddie | 347 | for (int i = 0; i < files.Count; i++) |
348 | { |
||
349 | if (files[i].loc == filename) |
||
350 | files[i].loc = newFilename; |
||
351 | } |
||
352 | } |
||
353 | |||
3 | freddie | 354 | public void renameFile(int fileID, string newFilename) |
355 | { |
||
356 | treeView.Nodes["Files"].Nodes[files[fileID].loc].Text = newFilename; |
||
357 | treeView.Nodes["Files"].Nodes[files[fileID].loc].Name = newFilename; |
||
358 | files[fileID].loc = newFilename; |
||
359 | } |
||
360 | |||
1 | freddie | 361 | public void openFile() |
362 | { |
||
4 | freddie | 363 | bool openRes; |
1 | freddie | 364 | DialogResult res = openFileDialog1.ShowDialog(); |
365 | if (openFileDialog1.FileName != "" && res != DialogResult.Cancel) |
||
366 | { |
||
367 | files.Add(new rtfFile(openFileDialog1.FileName)); |
||
4 | freddie | 368 | openRes = files[files.Count - 1].open(); |
369 | if (openRes) |
||
370 | { |
||
371 | treeView.Nodes["Files"].Nodes.Add(openFileDialog1.FileName, openFileDialog1.FileName); |
||
11 | freddie | 372 | if (files[files.Count - 1].isRtf) |
373 | treeView.Nodes["Files"].Nodes[openFileDialog1.FileName].ImageIndex = 0; |
||
374 | else |
||
375 | treeView.Nodes["Files"].Nodes[openFileDialog1.FileName].ImageIndex = 1; |
||
4 | freddie | 376 | showFile(files.Count - 1); |
377 | } |
||
378 | else |
||
379 | files.RemoveAt(files.Count - 1); |
||
1 | freddie | 380 | } |
381 | } |
||
382 | |||
383 | public void closeFile() |
||
384 | { |
||
385 | if (curFileID < files.Count && curFileID > -1) |
||
386 | { |
||
387 | treeView.Nodes["Files"].Nodes.RemoveByKey(files[curFileID].loc); |
||
388 | files.RemoveAt(curFileID); |
||
389 | if (curFileID >= files.Count) |
||
390 | curFileID--; |
||
391 | if (files.Count > 0) |
||
392 | showFile(curFileID); |
||
393 | else |
||
394 | tabControl.SelectedIndex = 0; |
||
395 | } |
||
396 | } |
||
397 | |||
11 | freddie | 398 | public void save() |
399 | { |
||
400 | if (curFileID < files.Count - 1 && curFileID > -1) |
||
401 | files[curFileID].save(); |
||
402 | } |
||
403 | |||
8 | freddie | 404 | public void saveAll() |
405 | { |
||
406 | for (int i = 0; i < files.Count; i++) |
||
407 | files[i].save(); |
||
408 | } |
||
409 | |||
1 | freddie | 410 | // format functions |
411 | |||
412 | public void addStyle(FontStyle newStyles) |
||
413 | { |
||
414 | FontStyle fStyle = editorView.SelectionFont.Style; |
||
415 | editorView.SelectionFont = new Font(editorView.SelectionFont, fStyle | newStyles); |
||
416 | } |
||
417 | |||
418 | public void remStyle(FontStyle remStyles) |
||
419 | { |
||
420 | FontStyle fStyle = editorView.SelectionFont.Style; |
||
421 | fStyle -= remStyles; |
||
422 | editorView.SelectionFont = new Font(editorView.SelectionFont, fStyle); |
||
423 | } |
||
424 | |||
425 | // form events |
||
426 | |||
427 | void EditorViewTextChanged(object sender, EventArgs e) |
||
428 | { |
||
11 | freddie | 429 | selectionStart = editorView.SelectionStart; |
430 | selectionLength = editorView.SelectionLength; |
||
431 | |||
1 | freddie | 432 | if (curFileID < files.Count && curFileID > -1) |
433 | { |
||
434 | files[curFileID].rtfBox.Rtf = editorView.Rtf; |
||
435 | files[curFileID].saved = false; |
||
11 | freddie | 436 | |
437 | // handle syntax highlighting |
||
438 | // HACK: This is REALLY poor!! |
||
439 | applySyntax(curFileID); |
||
440 | showFile(curFileID); |
||
441 | // TODO: Write cool code to fix it!! |
||
1 | freddie | 442 | } |
443 | } |
||
444 | |||
445 | void EditorViewSelectionChanged(object sender, EventArgs e) |
||
446 | { |
||
447 | selectionStart = editorView.SelectionStart; |
||
448 | selectionLength = editorView.SelectionLength; |
||
12 | freddie | 449 | // TODO: Find a way to get first char formatting |
450 | // textColourF.ForeColor = editorView.SelectionColor; |
||
2 | tom | 451 | // sizeF.Text = editorView.SelectionFont.Size.ToString(); |
12 | freddie | 452 | // fontTypeF.Text = editorView.SelectionFont.FontFamily(); |
1 | freddie | 453 | } |
454 | |||
455 | #region File stuff |
||
456 | |||
457 | void ToolStripButton1Click(object sender, EventArgs e) |
||
458 | { |
||
459 | newFile(); |
||
460 | } |
||
461 | |||
462 | void NewToolStripMenuItemClick(object sender, EventArgs e) |
||
463 | { |
||
464 | newFile(); |
||
465 | } |
||
466 | |||
467 | void ToolStripButton2Click(object sender, EventArgs e) |
||
468 | { |
||
469 | openFile(); |
||
470 | } |
||
471 | |||
472 | void OpenToolStripMenuItemClick(object sender, EventArgs e) |
||
473 | { |
||
474 | openFile(); |
||
475 | } |
||
476 | |||
477 | void ToolStripButton3Click(object sender, EventArgs e) |
||
478 | { |
||
11 | freddie | 479 | save(); |
1 | freddie | 480 | } |
481 | |||
482 | void SaveToolStripMenuItemClick(object sender, EventArgs e) |
||
483 | { |
||
11 | freddie | 484 | save(); |
1 | freddie | 485 | } |
486 | |||
487 | void ToolStripButton4Click(object sender, EventArgs e) |
||
488 | { |
||
489 | closeFile(); |
||
490 | } |
||
491 | |||
3 | freddie | 492 | void SaveAsToolStripMenuItemClick(object sender, EventArgs e) |
493 | { |
||
494 | DialogResult res = saveFileDialog1.ShowDialog(); |
||
495 | if (saveFileDialog1.FileName != "" && res != DialogResult.Cancel) |
||
496 | { |
||
497 | renameFile(curFileID, saveFileDialog1.FileName); |
||
498 | files[curFileID].loc = saveFileDialog1.FileName; |
||
499 | files[curFileID].save(); |
||
500 | } |
||
501 | } |
||
502 | |||
11 | freddie | 503 | void ToolStripButton10Click(object sender, EventArgs e) |
504 | { |
||
505 | editorView.Undo(); |
||
506 | } |
||
507 | |||
508 | void ToolStripButton11Click(object sender, EventArgs e) |
||
509 | { |
||
510 | editorView.Redo(); |
||
511 | } |
||
512 | |||
513 | void UndoToolStripMenuItemClick(object sender, EventArgs e) |
||
514 | { |
||
515 | editorView.Undo(); |
||
516 | } |
||
517 | |||
518 | void RedoToolStripMenuItemClick(object sender, EventArgs e) |
||
519 | { |
||
520 | editorView.Redo(); |
||
521 | } |
||
522 | |||
523 | void ToolStripButton12Click(object sender, EventArgs e) |
||
524 | { |
||
525 | zoomIn(); |
||
526 | } |
||
527 | |||
528 | void ToolStripButton13Click(object sender, EventArgs e) |
||
529 | { |
||
530 | zoomOut(); |
||
531 | } |
||
532 | |||
1 | freddie | 533 | #endregion |
534 | |||
535 | #region Format stuff |
||
536 | |||
537 | void BoldFClick(object sender, EventArgs e) |
||
538 | { |
||
539 | if (editorView.SelectionFont.Bold) |
||
540 | remStyle(FontStyle.Bold); |
||
541 | else |
||
542 | addStyle(FontStyle.Bold); |
||
543 | } |
||
544 | |||
545 | void ItalicFClick(object sender, EventArgs e) |
||
546 | { |
||
547 | if (editorView.SelectionFont.Italic) |
||
548 | remStyle(FontStyle.Italic); |
||
549 | else |
||
550 | addStyle(FontStyle.Italic); |
||
551 | } |
||
552 | |||
553 | void UnderlineFClick(object sender, EventArgs e) |
||
554 | { |
||
555 | if (editorView.SelectionFont.Underline) |
||
556 | remStyle(FontStyle.Underline); |
||
557 | else |
||
558 | addStyle(FontStyle.Underline); |
||
559 | } |
||
560 | |||
561 | void ToolStripButton5Click(object sender, EventArgs e) |
||
562 | { |
||
563 | editorView.SelectionAlignment = HorizontalAlignment.Left; |
||
564 | } |
||
565 | |||
566 | void ToolStripButton6Click(object sender, EventArgs e) |
||
567 | { |
||
568 | editorView.SelectionAlignment = HorizontalAlignment.Center; |
||
569 | } |
||
570 | |||
571 | void ToolStripButton7Click(object sender, EventArgs e) |
||
572 | { |
||
573 | editorView.SelectionAlignment = HorizontalAlignment.Right; |
||
574 | } |
||
575 | |||
576 | void SizeFTextChanged(object sender, EventArgs e) |
||
577 | { |
||
578 | setSelection(); |
||
579 | FontStyle fStyle = editorView.SelectionFont.Style; |
||
580 | float size = 0.0f; |
||
581 | if (float.TryParse(sizeF.Text, out size)) |
||
582 | { |
||
583 | if (size > 0) |
||
584 | editorView.SelectionFont = new Font(editorView.SelectionFont.FontFamily, size, fStyle); |
||
585 | } |
||
586 | } |
||
587 | |||
12 | freddie | 588 | void fontTypeFTextChanged(object sender, EventArgs e) |
589 | { |
||
590 | editorView.SelectionFont = new Font(fontTypeF.Text, editorView.SelectionFont.Size, editorView.SelectionFont.Style); |
||
591 | } |
||
592 | |||
1 | freddie | 593 | #endregion |
594 | |||
595 | void WordWrapToolStripMenuItemClick(object sender, EventArgs e) |
||
596 | { |
||
597 | editorView.WordWrap = ! editorView.WordWrap; |
||
598 | wordWrapToolStripMenuItem.Checked = editorView.WordWrap; |
||
599 | } |
||
6 | freddie | 600 | |
601 | void ToolStripButton8Click(object sender, EventArgs e) |
||
602 | { |
||
7 | freddie | 603 | insertImageFromFile(); |
6 | freddie | 604 | } |
7 | freddie | 605 | |
606 | #region editorMenuStrip |
||
607 | |||
608 | void CloseFileToolStripMenuItemClick(object sender, EventArgs e) |
||
609 | { |
||
610 | closeFile(); |
||
611 | } |
||
612 | |||
613 | void SaveFileToolStripMenuItemClick(object sender, EventArgs e) |
||
614 | { |
||
11 | freddie | 615 | save(); |
7 | freddie | 616 | } |
617 | |||
618 | void InToolStripMenuItemClick(object sender, EventArgs e) |
||
619 | { |
||
620 | zoomIn(); |
||
621 | } |
||
622 | |||
623 | void OutToolStripMenuItemClick(object sender, EventArgs e) |
||
624 | { |
||
625 | zoomOut(); |
||
626 | } |
||
627 | |||
11 | freddie | 628 | void UndoToolStripMenuItem1Click(object sender, EventArgs e) |
629 | { |
||
630 | editorView.Undo(); |
||
631 | } |
||
632 | |||
633 | void RedoToolStripMenuItem1Click(object sender, EventArgs e) |
||
634 | { |
||
635 | editorView.Redo(); |
||
636 | } |
||
637 | |||
7 | freddie | 638 | #endregion |
639 | |||
8 | freddie | 640 | void TextColourFClick(object sender, EventArgs e) |
7 | freddie | 641 | { |
642 | DialogResult res = colorDialog1.ShowDialog(); |
||
643 | if (res != DialogResult.Cancel) |
||
644 | { |
||
645 | textColourF.ForeColor = colorDialog1.Color; |
||
646 | editorView.SelectionColor = colorDialog1.Color; |
||
647 | } |
||
648 | } |
||
8 | freddie | 649 | |
650 | void ToolStripButton9Click(object sender, EventArgs e) |
||
651 | { |
||
652 | saveAll(); |
||
653 | } |
||
9 | freddie | 654 | |
655 | void TabControlSelectedIndexChanged(object sender, EventArgs e) |
||
656 | { |
||
657 | if (tabControl.SelectedIndex == 1 && files.Count == 0) |
||
658 | { |
||
659 | newFile(); |
||
660 | } |
||
661 | } |
||
662 | |||
663 | void SyntaxHighlightingToolStripMenuItemSelectedIndexChanged(object sender, EventArgs e) |
||
664 | { |
||
665 | |||
666 | files[curFileID].syntax = -1; |
||
667 | |||
668 | if (syntaxHighlightingToolStripMenuItem.SelectedIndex == 1) |
||
669 | { |
||
670 | for (int i = 0; i < syntaxes.Count; i++) |
||
671 | { |
||
672 | if (files[curFileID].loc.EndsWith(syntaxes[i].id)) |
||
673 | { |
||
674 | files[curFileID].syntax = i; |
||
675 | break; |
||
676 | } |
||
677 | } |
||
678 | } |
||
679 | else |
||
680 | files[curFileID].syntax = syntaxHighlightingToolStripMenuItem.SelectedIndex - 2; |
||
681 | |||
682 | applySyntax(curFileID); |
||
683 | showFile(curFileID); |
||
684 | |||
685 | } |
||
686 | |||
11 | freddie | 687 | public void clearFormatting(int fileID) |
688 | { |
||
689 | files[fileID].rtfBox.ResetFont(); |
||
690 | files[fileID].rtfBox.ResetBackColor(); |
||
691 | files[fileID].rtfBox.ResetForeColor(); |
||
692 | } |
||
693 | |||
9 | freddie | 694 | public void applySyntax(int fileID) |
695 | { |
||
696 | if (files[fileID].isRtf) |
||
697 | return; |
||
698 | |||
11 | freddie | 699 | clearFormatting(fileID); |
700 | |||
701 | if (files[fileID].syntax != -1) |
||
9 | freddie | 702 | { |
703 | int pos; |
||
704 | string[] data = files[fileID].rtfBox.Text.Split(new char[] { ' ', '\n' }); |
||
705 | for (int i = 0; i < syntaxes[files[fileID].syntax].words.Count; i++) |
||
706 | { |
||
707 | pos = 0; |
||
708 | for (int j = 0; j < data.Length; j++) |
||
709 | { |
||
710 | if (syntaxes[files[fileID].syntax].words[i].words.Contains(data[j])) |
||
711 | { |
||
712 | files[fileID].rtfBox.Select(pos, data[j].Length); |
||
713 | files[fileID].rtfBox.SelectionColor = syntaxes[files[fileID].syntax].words[i].colour; |
||
714 | } |
||
715 | pos += data[j].Length + 1; |
||
716 | } |
||
717 | } |
||
718 | } |
||
11 | freddie | 719 | |
720 | // fix selection (reset by application of syntax, somewhere.....) |
||
721 | setSelection(); |
||
722 | |||
9 | freddie | 723 | } |
1 | freddie | 724 | } |
725 | } |