Rev 10 | Go to most recent revision | 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; |
||
7 | freddie | 449 | textColourF.ForeColor = editorView.SelectionColor; |
2 | tom | 450 | // sizeF.Text = editorView.SelectionFont.Size.ToString(); |
1 | freddie | 451 | } |
452 | |||
453 | #region File stuff |
||
454 | |||
455 | void ToolStripButton1Click(object sender, EventArgs e) |
||
456 | { |
||
457 | newFile(); |
||
458 | } |
||
459 | |||
460 | void NewToolStripMenuItemClick(object sender, EventArgs e) |
||
461 | { |
||
462 | newFile(); |
||
463 | } |
||
464 | |||
465 | void ToolStripButton2Click(object sender, EventArgs e) |
||
466 | { |
||
467 | openFile(); |
||
468 | } |
||
469 | |||
470 | void OpenToolStripMenuItemClick(object sender, EventArgs e) |
||
471 | { |
||
472 | openFile(); |
||
473 | } |
||
474 | |||
475 | void ToolStripButton3Click(object sender, EventArgs e) |
||
476 | { |
||
11 | freddie | 477 | save(); |
1 | freddie | 478 | } |
479 | |||
480 | void SaveToolStripMenuItemClick(object sender, EventArgs e) |
||
481 | { |
||
11 | freddie | 482 | save(); |
1 | freddie | 483 | } |
484 | |||
485 | void ToolStripButton4Click(object sender, EventArgs e) |
||
486 | { |
||
487 | closeFile(); |
||
488 | } |
||
489 | |||
3 | freddie | 490 | void SaveAsToolStripMenuItemClick(object sender, EventArgs e) |
491 | { |
||
492 | DialogResult res = saveFileDialog1.ShowDialog(); |
||
493 | if (saveFileDialog1.FileName != "" && res != DialogResult.Cancel) |
||
494 | { |
||
495 | renameFile(curFileID, saveFileDialog1.FileName); |
||
496 | files[curFileID].loc = saveFileDialog1.FileName; |
||
497 | files[curFileID].save(); |
||
498 | } |
||
499 | } |
||
500 | |||
11 | freddie | 501 | void ToolStripButton10Click(object sender, EventArgs e) |
502 | { |
||
503 | editorView.Undo(); |
||
504 | } |
||
505 | |||
506 | void ToolStripButton11Click(object sender, EventArgs e) |
||
507 | { |
||
508 | editorView.Redo(); |
||
509 | } |
||
510 | |||
511 | void UndoToolStripMenuItemClick(object sender, EventArgs e) |
||
512 | { |
||
513 | editorView.Undo(); |
||
514 | } |
||
515 | |||
516 | void RedoToolStripMenuItemClick(object sender, EventArgs e) |
||
517 | { |
||
518 | editorView.Redo(); |
||
519 | } |
||
520 | |||
521 | void ToolStripButton12Click(object sender, EventArgs e) |
||
522 | { |
||
523 | zoomIn(); |
||
524 | } |
||
525 | |||
526 | void ToolStripButton13Click(object sender, EventArgs e) |
||
527 | { |
||
528 | zoomOut(); |
||
529 | } |
||
530 | |||
1 | freddie | 531 | #endregion |
532 | |||
533 | #region Format stuff |
||
534 | |||
535 | void BoldFClick(object sender, EventArgs e) |
||
536 | { |
||
537 | if (editorView.SelectionFont.Bold) |
||
538 | remStyle(FontStyle.Bold); |
||
539 | else |
||
540 | addStyle(FontStyle.Bold); |
||
541 | } |
||
542 | |||
543 | void ItalicFClick(object sender, EventArgs e) |
||
544 | { |
||
545 | if (editorView.SelectionFont.Italic) |
||
546 | remStyle(FontStyle.Italic); |
||
547 | else |
||
548 | addStyle(FontStyle.Italic); |
||
549 | } |
||
550 | |||
551 | void UnderlineFClick(object sender, EventArgs e) |
||
552 | { |
||
553 | if (editorView.SelectionFont.Underline) |
||
554 | remStyle(FontStyle.Underline); |
||
555 | else |
||
556 | addStyle(FontStyle.Underline); |
||
557 | } |
||
558 | |||
559 | void ToolStripButton5Click(object sender, EventArgs e) |
||
560 | { |
||
561 | editorView.SelectionAlignment = HorizontalAlignment.Left; |
||
562 | } |
||
563 | |||
564 | void ToolStripButton6Click(object sender, EventArgs e) |
||
565 | { |
||
566 | editorView.SelectionAlignment = HorizontalAlignment.Center; |
||
567 | } |
||
568 | |||
569 | void ToolStripButton7Click(object sender, EventArgs e) |
||
570 | { |
||
571 | editorView.SelectionAlignment = HorizontalAlignment.Right; |
||
572 | } |
||
573 | |||
574 | void SizeFTextChanged(object sender, EventArgs e) |
||
575 | { |
||
576 | setSelection(); |
||
577 | FontStyle fStyle = editorView.SelectionFont.Style; |
||
578 | float size = 0.0f; |
||
579 | if (float.TryParse(sizeF.Text, out size)) |
||
580 | { |
||
581 | if (size > 0) |
||
582 | editorView.SelectionFont = new Font(editorView.SelectionFont.FontFamily, size, fStyle); |
||
583 | } |
||
584 | } |
||
585 | |||
586 | #endregion |
||
587 | |||
588 | void WordWrapToolStripMenuItemClick(object sender, EventArgs e) |
||
589 | { |
||
590 | editorView.WordWrap = ! editorView.WordWrap; |
||
591 | wordWrapToolStripMenuItem.Checked = editorView.WordWrap; |
||
592 | } |
||
6 | freddie | 593 | |
594 | void ToolStripButton8Click(object sender, EventArgs e) |
||
595 | { |
||
7 | freddie | 596 | insertImageFromFile(); |
6 | freddie | 597 | } |
7 | freddie | 598 | |
599 | #region editorMenuStrip |
||
600 | |||
601 | void CloseFileToolStripMenuItemClick(object sender, EventArgs e) |
||
602 | { |
||
603 | closeFile(); |
||
604 | } |
||
605 | |||
606 | void SaveFileToolStripMenuItemClick(object sender, EventArgs e) |
||
607 | { |
||
11 | freddie | 608 | save(); |
7 | freddie | 609 | } |
610 | |||
611 | void InToolStripMenuItemClick(object sender, EventArgs e) |
||
612 | { |
||
613 | zoomIn(); |
||
614 | } |
||
615 | |||
616 | void OutToolStripMenuItemClick(object sender, EventArgs e) |
||
617 | { |
||
618 | zoomOut(); |
||
619 | } |
||
620 | |||
11 | freddie | 621 | void UndoToolStripMenuItem1Click(object sender, EventArgs e) |
622 | { |
||
623 | editorView.Undo(); |
||
624 | } |
||
625 | |||
626 | void RedoToolStripMenuItem1Click(object sender, EventArgs e) |
||
627 | { |
||
628 | editorView.Redo(); |
||
629 | } |
||
630 | |||
7 | freddie | 631 | #endregion |
632 | |||
8 | freddie | 633 | void TextColourFClick(object sender, EventArgs e) |
7 | freddie | 634 | { |
635 | DialogResult res = colorDialog1.ShowDialog(); |
||
636 | if (res != DialogResult.Cancel) |
||
637 | { |
||
638 | textColourF.ForeColor = colorDialog1.Color; |
||
639 | editorView.SelectionColor = colorDialog1.Color; |
||
640 | } |
||
641 | } |
||
8 | freddie | 642 | |
643 | void ToolStripButton9Click(object sender, EventArgs e) |
||
644 | { |
||
645 | saveAll(); |
||
646 | } |
||
9 | freddie | 647 | |
648 | void TabControlSelectedIndexChanged(object sender, EventArgs e) |
||
649 | { |
||
650 | if (tabControl.SelectedIndex == 1 && files.Count == 0) |
||
651 | { |
||
652 | newFile(); |
||
653 | } |
||
654 | } |
||
655 | |||
656 | void SyntaxHighlightingToolStripMenuItemSelectedIndexChanged(object sender, EventArgs e) |
||
657 | { |
||
658 | |||
659 | files[curFileID].syntax = -1; |
||
660 | |||
661 | if (syntaxHighlightingToolStripMenuItem.SelectedIndex == 1) |
||
662 | { |
||
663 | for (int i = 0; i < syntaxes.Count; i++) |
||
664 | { |
||
665 | if (files[curFileID].loc.EndsWith(syntaxes[i].id)) |
||
666 | { |
||
667 | files[curFileID].syntax = i; |
||
668 | break; |
||
669 | } |
||
670 | } |
||
671 | } |
||
672 | else |
||
673 | files[curFileID].syntax = syntaxHighlightingToolStripMenuItem.SelectedIndex - 2; |
||
674 | |||
675 | applySyntax(curFileID); |
||
676 | showFile(curFileID); |
||
677 | |||
678 | } |
||
679 | |||
11 | freddie | 680 | public void clearFormatting(int fileID) |
681 | { |
||
682 | files[fileID].rtfBox.ResetFont(); |
||
683 | files[fileID].rtfBox.ResetBackColor(); |
||
684 | files[fileID].rtfBox.ResetForeColor(); |
||
685 | } |
||
686 | |||
9 | freddie | 687 | public void applySyntax(int fileID) |
688 | { |
||
689 | if (files[fileID].isRtf) |
||
690 | return; |
||
691 | |||
11 | freddie | 692 | clearFormatting(fileID); |
693 | |||
694 | if (files[fileID].syntax != -1) |
||
9 | freddie | 695 | { |
696 | int pos; |
||
697 | string[] data = files[fileID].rtfBox.Text.Split(new char[] { ' ', '\n' }); |
||
698 | for (int i = 0; i < syntaxes[files[fileID].syntax].words.Count; i++) |
||
699 | { |
||
700 | pos = 0; |
||
701 | for (int j = 0; j < data.Length; j++) |
||
702 | { |
||
703 | if (syntaxes[files[fileID].syntax].words[i].words.Contains(data[j])) |
||
704 | { |
||
705 | files[fileID].rtfBox.Select(pos, data[j].Length); |
||
706 | files[fileID].rtfBox.SelectionColor = syntaxes[files[fileID].syntax].words[i].colour; |
||
707 | } |
||
708 | pos += data[j].Length + 1; |
||
709 | } |
||
710 | } |
||
711 | } |
||
11 | freddie | 712 | |
713 | // fix selection (reset by application of syntax, somewhere.....) |
||
714 | setSelection(); |
||
715 | |||
9 | freddie | 716 | } |
1 | freddie | 717 | } |
718 | } |