Rev 8 | 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 |
||
| 79 | { |
||
| 80 | string str = rtfBox.Rtf; |
||
| 81 | rtfBox.Rtf = rtfBox.Text; |
||
| 82 | rtfBox.SaveFile(loc); |
||
| 83 | rtfBox.Rtf = str; |
||
| 84 | } |
||
| 1 | freddie | 85 | saved = true; |
| 86 | } |
||
| 87 | |||
| 4 | freddie | 88 | public bool open() |
| 1 | freddie | 89 | { |
| 90 | try |
||
| 91 | { |
||
| 92 | rtfBox.LoadFile(loc); |
||
| 93 | saved = true; |
||
| 9 | freddie | 94 | if (loc.EndsWith(".rtf")) |
| 95 | isRtf = true; |
||
| 96 | else |
||
| 97 | isRtf = false; |
||
| 1 | freddie | 98 | } |
| 99 | catch (Exception ex) |
||
| 100 | { |
||
| 9 | freddie | 101 | try |
| 102 | { |
||
| 103 | System.IO.StreamReader reader = new System.IO.StreamReader(loc); |
||
| 104 | rtfBox.Text = reader.ReadToEnd(); |
||
| 105 | // MessageBox.Show("File not loaded as RTF: " + ex.Message, "Load Notice", MessageBoxButtons.OK, MessageBoxIcon.Warning); |
||
| 106 | isRtf = false; |
||
| 107 | } |
||
| 108 | catch (Exception ex2) |
||
| 109 | { |
||
| 110 | MessageBox.Show(ex2.Message, "Load Error", MessageBoxButtons.OK, MessageBoxIcon.Error); |
||
| 111 | return false; |
||
| 112 | } |
||
| 1 | freddie | 113 | } |
| 4 | freddie | 114 | return true; |
| 1 | freddie | 115 | } |
| 116 | } |
||
| 117 | |||
| 9 | freddie | 118 | public class syntax |
| 119 | { |
||
| 120 | |||
| 121 | public string id; |
||
| 122 | public List<word> words; |
||
| 123 | public List<comment> comments; |
||
| 124 | |||
| 125 | public syntax(string idN) |
||
| 126 | { |
||
| 127 | id = idN; |
||
| 128 | words = new List<MainForm.word>(); |
||
| 129 | comments = new List<MainForm.comment>(); |
||
| 130 | } |
||
| 131 | |||
| 132 | } |
||
| 133 | |||
| 1 | freddie | 134 | public List<rtfFile> files = new List<rtfFile>(); |
| 135 | public int curFileID; |
||
| 136 | |||
| 9 | freddie | 137 | public List<syntax> syntaxes = new List<syntax>(); |
| 138 | |||
| 1 | freddie | 139 | public int selectionStart; |
| 140 | public int selectionLength; |
||
| 141 | |||
| 142 | public MainForm() |
||
| 143 | { |
||
| 144 | |||
| 145 | InitializeComponent(); |
||
| 146 | |||
| 147 | } |
||
| 148 | |||
| 149 | void MainFormLoad(object sender, EventArgs e) |
||
| 150 | { |
||
| 151 | welcomeView.Url = new Uri("http://tim32.org/~freddie/LassyPad/Welcome.htm"); |
||
| 152 | initAll(); |
||
| 7 | freddie | 153 | |
| 154 | bool openRes; |
||
| 155 | string[] envArgs = System.Environment.GetCommandLineArgs(); |
||
| 156 | for (int i = 0; i < envArgs.Length; i++) |
||
| 157 | { |
||
| 158 | if (envArgs[i].EndsWith(".rtf") || envArgs[i].EndsWith(".txt")) |
||
| 159 | { |
||
| 160 | files.Add(new rtfFile(envArgs[i])); |
||
| 161 | openRes = files[files.Count - 1].open(); |
||
| 162 | if (openRes) |
||
| 163 | { |
||
| 164 | treeView.Nodes["Files"].Nodes.Add(envArgs[i], envArgs[i]); |
||
| 165 | showFile(files.Count - 1); |
||
| 166 | } |
||
| 167 | else |
||
| 168 | files.RemoveAt(files.Count - 1); |
||
| 169 | } |
||
| 170 | } |
||
| 1 | freddie | 171 | } |
| 172 | |||
| 173 | public void initAll() |
||
| 174 | { |
||
| 175 | initTreeView(); |
||
| 9 | freddie | 176 | loadSyntaxes(); |
| 1 | freddie | 177 | } |
| 178 | |||
| 179 | public void initTreeView() |
||
| 180 | { |
||
| 181 | // welcome |
||
| 182 | treeView.Nodes.Add("Welcome", "Welcome"); |
||
| 183 | treeView.Nodes["Welcome"].Nodes.Add("Introduction", "Introduction"); |
||
| 184 | treeView.Nodes["Welcome"].Nodes.Add("Help", "Help"); |
||
| 185 | |||
| 186 | // |
||
| 187 | treeView.Nodes.Add("Files", "Files"); |
||
| 188 | } |
||
| 189 | |||
| 9 | freddie | 190 | public void loadSyntaxes() |
| 191 | { |
||
| 192 | System.IO.StreamReader reader = new System.IO.StreamReader("data/syntaxes.dat"); |
||
| 193 | string r = reader.ReadToEnd(); |
||
| 194 | string[] data = r.Split('\n'); |
||
| 195 | string[] d, d2; |
||
| 196 | |||
| 197 | for (int i = 0; i < data.Length; i++) |
||
| 198 | { |
||
| 199 | data[i] = data[i].Replace("\r", ""); |
||
| 200 | if (data[i].EndsWith(":")) |
||
| 201 | { |
||
| 202 | syntaxes.Add(new syntax(data[i].Substring(0, data[i].Length - 1))); |
||
| 203 | syntaxHighlightingToolStripMenuItem.Items.Add(data[i].Substring(0, data[i].Length - 1)); |
||
| 204 | } |
||
| 205 | else |
||
| 206 | { |
||
| 207 | d = data[i].Split(' '); |
||
| 208 | switch (d[0]) |
||
| 209 | { |
||
| 210 | case ("word"): |
||
| 211 | { |
||
| 212 | if (d.Length == 3) |
||
| 213 | syntaxes[syntaxes.Count - 1].words.Add(new word(Color.FromName(d[1]), d[2])); |
||
| 214 | else if (d.Length == 5) |
||
| 215 | { |
||
| 216 | d2 = d[1].Split(','); |
||
| 217 | syntaxes[syntaxes.Count - 1].words.Add(new word(Color.FromArgb(int.Parse(d2[0]), int.Parse(d2[1]), int.Parse(d2[2])), d[2])); |
||
| 218 | } |
||
| 219 | break; |
||
| 220 | } |
||
| 221 | } |
||
| 222 | } |
||
| 223 | } |
||
| 224 | } |
||
| 225 | |||
| 1 | freddie | 226 | void TreeViewNodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) |
| 227 | { |
||
| 228 | if (e.Node.Level == 0) |
||
| 229 | { |
||
| 230 | switch (e.Node.Name) |
||
| 231 | { |
||
| 232 | case ("Welcome"): |
||
| 233 | { |
||
| 234 | welcomeView.Url = new Uri("http://tim32.org/~freddie/LassyPad/Welcome.htm"); |
||
| 235 | break; |
||
| 236 | } |
||
| 237 | } |
||
| 238 | } |
||
| 239 | else |
||
| 240 | { |
||
| 241 | switch (e.Node.Parent.Name) |
||
| 242 | { |
||
| 243 | case ("Welcome"): |
||
| 244 | { |
||
| 245 | if (e.Node.Name == "Introduction") |
||
| 246 | welcomeView.Url = new Uri("http://tim32.org/~freddie/LassyPad/Introduction.htm"); |
||
| 247 | else if (e.Node.Name == "Help") |
||
| 248 | welcomeView.Url = new Uri("http://tim32.org/~freddie/LassyPad/Help.htm"); |
||
| 249 | |||
| 250 | break; |
||
| 251 | } |
||
| 252 | case ("Files"): |
||
| 253 | { |
||
| 254 | showFile(e.Node.Name); |
||
| 255 | break; |
||
| 256 | } |
||
| 257 | } |
||
| 258 | } |
||
| 259 | } |
||
| 260 | |||
| 261 | // other functions |
||
| 262 | |||
| 7 | freddie | 263 | public void insertImageFromFile() |
| 264 | { |
||
| 265 | DialogResult res = openFileDialog1.ShowDialog(); |
||
| 266 | if (openFileDialog1.FileName != "" && res != DialogResult.Cancel) |
||
| 267 | { |
||
| 268 | // HELL - Get help from somewhere.... |
||
| 269 | } |
||
| 270 | } |
||
| 271 | |||
| 272 | public void zoomIn() |
||
| 273 | { |
||
| 274 | editorView.ZoomFactor *= 1.2f; |
||
| 275 | } |
||
| 276 | |||
| 277 | public void zoomOut() |
||
| 278 | { |
||
| 279 | editorView.ZoomFactor /= 1.2f; |
||
| 280 | } |
||
| 281 | |||
| 1 | freddie | 282 | public void setSelection() |
| 283 | { |
||
| 284 | editorView.Select(selectionStart, selectionLength); |
||
| 285 | } |
||
| 286 | |||
| 287 | public void showFile(int fileID) |
||
| 288 | { |
||
| 289 | tabControl.SelectedIndex = 1; |
||
| 290 | editorView.Rtf = files[fileID].rtfBox.Rtf; |
||
| 291 | curFileID = fileID; |
||
| 9 | freddie | 292 | if (files[curFileID].isRtf) |
| 293 | syntaxHighlightingToolStripMenuItem.Enabled = false; |
||
| 294 | else |
||
| 295 | syntaxHighlightingToolStripMenuItem.Enabled = true; |
||
| 1 | freddie | 296 | } |
| 297 | |||
| 298 | public void showFile(string filename) |
||
| 299 | { |
||
| 300 | tabControl.SelectedIndex = 1; |
||
| 301 | for (int i = 0; i < files.Count; i++) |
||
| 302 | { |
||
| 3 | freddie | 303 | if (files[i].loc == filename) |
| 304 | { |
||
| 305 | editorView.Rtf = files[i].rtfBox.Rtf; |
||
| 306 | curFileID = i; |
||
| 9 | freddie | 307 | if (files[curFileID].isRtf) |
| 308 | syntaxHighlightingToolStripMenuItem.Enabled = false; |
||
| 309 | else |
||
| 310 | syntaxHighlightingToolStripMenuItem.Enabled = true; |
||
| 3 | freddie | 311 | return; |
| 312 | } |
||
| 1 | freddie | 313 | } |
| 314 | } |
||
| 315 | |||
| 316 | // file functions |
||
| 317 | |||
| 318 | public void newFile() |
||
| 319 | { |
||
| 320 | int i = 0; |
||
| 3 | freddie | 321 | bool exists; |
| 1 | freddie | 322 | while (true) |
| 323 | { |
||
| 3 | freddie | 324 | exists = false; |
| 1 | freddie | 325 | for (int j = 0; j < files.Count; j++) |
| 326 | { |
||
| 3 | freddie | 327 | if ((files[j].loc == "NewFile" + i.ToString() + ".rtf")) |
| 328 | exists = true; |
||
| 1 | freddie | 329 | } |
| 3 | freddie | 330 | if (!exists) |
| 331 | { |
||
| 332 | files.Add(new rtfFile("NewFile" + i.ToString() + ".rtf")); |
||
| 333 | treeView.Nodes["Files"].Nodes.Add("NewFile" + i.ToString() + ".rtf", "NewFile" + i.ToString() + ".rtf"); |
||
| 9 | freddie | 334 | files[files.Count - 1].isRtf = true; |
| 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); |
||
| 372 | showFile(files.Count - 1); |
||
| 373 | } |
||
| 374 | else |
||
| 375 | files.RemoveAt(files.Count - 1); |
||
| 1 | freddie | 376 | } |
| 377 | } |
||
| 378 | |||
| 379 | public void closeFile() |
||
| 380 | { |
||
| 381 | if (curFileID < files.Count && curFileID > -1) |
||
| 382 | { |
||
| 383 | treeView.Nodes["Files"].Nodes.RemoveByKey(files[curFileID].loc); |
||
| 384 | files.RemoveAt(curFileID); |
||
| 385 | if (curFileID >= files.Count) |
||
| 386 | curFileID--; |
||
| 387 | if (files.Count > 0) |
||
| 388 | showFile(curFileID); |
||
| 389 | else |
||
| 390 | tabControl.SelectedIndex = 0; |
||
| 391 | } |
||
| 392 | } |
||
| 393 | |||
| 8 | freddie | 394 | public void saveAll() |
| 395 | { |
||
| 396 | for (int i = 0; i < files.Count; i++) |
||
| 397 | files[i].save(); |
||
| 398 | } |
||
| 399 | |||
| 1 | freddie | 400 | // format functions |
| 401 | |||
| 402 | public void addStyle(FontStyle newStyles) |
||
| 403 | { |
||
| 404 | FontStyle fStyle = editorView.SelectionFont.Style; |
||
| 405 | editorView.SelectionFont = new Font(editorView.SelectionFont, fStyle | newStyles); |
||
| 406 | } |
||
| 407 | |||
| 408 | public void remStyle(FontStyle remStyles) |
||
| 409 | { |
||
| 410 | FontStyle fStyle = editorView.SelectionFont.Style; |
||
| 411 | fStyle -= remStyles; |
||
| 412 | editorView.SelectionFont = new Font(editorView.SelectionFont, fStyle); |
||
| 413 | } |
||
| 414 | |||
| 415 | // form events |
||
| 416 | |||
| 417 | void EditorViewTextChanged(object sender, EventArgs e) |
||
| 418 | { |
||
| 419 | if (curFileID < files.Count && curFileID > -1) |
||
| 420 | { |
||
| 421 | files[curFileID].rtfBox.Rtf = editorView.Rtf; |
||
| 422 | files[curFileID].saved = false; |
||
| 423 | } |
||
| 424 | } |
||
| 425 | |||
| 426 | void EditorViewSelectionChanged(object sender, EventArgs e) |
||
| 427 | { |
||
| 428 | selectionStart = editorView.SelectionStart; |
||
| 429 | selectionLength = editorView.SelectionLength; |
||
| 7 | freddie | 430 | textColourF.ForeColor = editorView.SelectionColor; |
| 2 | tom | 431 | // sizeF.Text = editorView.SelectionFont.Size.ToString(); |
| 1 | freddie | 432 | } |
| 433 | |||
| 434 | #region File stuff |
||
| 435 | |||
| 436 | void ToolStripButton1Click(object sender, EventArgs e) |
||
| 437 | { |
||
| 438 | newFile(); |
||
| 439 | } |
||
| 440 | |||
| 441 | void NewToolStripMenuItemClick(object sender, EventArgs e) |
||
| 442 | { |
||
| 443 | newFile(); |
||
| 444 | } |
||
| 445 | |||
| 446 | void ToolStripButton2Click(object sender, EventArgs e) |
||
| 447 | { |
||
| 448 | openFile(); |
||
| 449 | } |
||
| 450 | |||
| 451 | void OpenToolStripMenuItemClick(object sender, EventArgs e) |
||
| 452 | { |
||
| 453 | openFile(); |
||
| 454 | } |
||
| 455 | |||
| 456 | void ToolStripButton3Click(object sender, EventArgs e) |
||
| 457 | { |
||
| 458 | files[curFileID].save(); |
||
| 459 | } |
||
| 460 | |||
| 461 | void SaveToolStripMenuItemClick(object sender, EventArgs e) |
||
| 462 | { |
||
| 463 | files[curFileID].save(); |
||
| 464 | } |
||
| 465 | |||
| 466 | void ToolStripButton4Click(object sender, EventArgs e) |
||
| 467 | { |
||
| 468 | closeFile(); |
||
| 469 | } |
||
| 470 | |||
| 3 | freddie | 471 | void SaveAsToolStripMenuItemClick(object sender, EventArgs e) |
| 472 | { |
||
| 473 | DialogResult res = saveFileDialog1.ShowDialog(); |
||
| 474 | if (saveFileDialog1.FileName != "" && res != DialogResult.Cancel) |
||
| 475 | { |
||
| 476 | renameFile(curFileID, saveFileDialog1.FileName); |
||
| 477 | files[curFileID].loc = saveFileDialog1.FileName; |
||
| 478 | files[curFileID].save(); |
||
| 479 | } |
||
| 480 | } |
||
| 481 | |||
| 1 | freddie | 482 | #endregion |
| 483 | |||
| 484 | #region Format stuff |
||
| 485 | |||
| 486 | void BoldFClick(object sender, EventArgs e) |
||
| 487 | { |
||
| 488 | if (editorView.SelectionFont.Bold) |
||
| 489 | remStyle(FontStyle.Bold); |
||
| 490 | else |
||
| 491 | addStyle(FontStyle.Bold); |
||
| 492 | } |
||
| 493 | |||
| 494 | void ItalicFClick(object sender, EventArgs e) |
||
| 495 | { |
||
| 496 | if (editorView.SelectionFont.Italic) |
||
| 497 | remStyle(FontStyle.Italic); |
||
| 498 | else |
||
| 499 | addStyle(FontStyle.Italic); |
||
| 500 | } |
||
| 501 | |||
| 502 | void UnderlineFClick(object sender, EventArgs e) |
||
| 503 | { |
||
| 504 | if (editorView.SelectionFont.Underline) |
||
| 505 | remStyle(FontStyle.Underline); |
||
| 506 | else |
||
| 507 | addStyle(FontStyle.Underline); |
||
| 508 | } |
||
| 509 | |||
| 510 | void ToolStripButton5Click(object sender, EventArgs e) |
||
| 511 | { |
||
| 512 | editorView.SelectionAlignment = HorizontalAlignment.Left; |
||
| 513 | } |
||
| 514 | |||
| 515 | void ToolStripButton6Click(object sender, EventArgs e) |
||
| 516 | { |
||
| 517 | editorView.SelectionAlignment = HorizontalAlignment.Center; |
||
| 518 | } |
||
| 519 | |||
| 520 | void ToolStripButton7Click(object sender, EventArgs e) |
||
| 521 | { |
||
| 522 | editorView.SelectionAlignment = HorizontalAlignment.Right; |
||
| 523 | } |
||
| 524 | |||
| 525 | void SizeFTextChanged(object sender, EventArgs e) |
||
| 526 | { |
||
| 527 | setSelection(); |
||
| 528 | FontStyle fStyle = editorView.SelectionFont.Style; |
||
| 529 | float size = 0.0f; |
||
| 530 | if (float.TryParse(sizeF.Text, out size)) |
||
| 531 | { |
||
| 532 | if (size > 0) |
||
| 533 | editorView.SelectionFont = new Font(editorView.SelectionFont.FontFamily, size, fStyle); |
||
| 534 | } |
||
| 535 | } |
||
| 536 | |||
| 537 | #endregion |
||
| 538 | |||
| 539 | void WordWrapToolStripMenuItemClick(object sender, EventArgs e) |
||
| 540 | { |
||
| 541 | editorView.WordWrap = ! editorView.WordWrap; |
||
| 542 | wordWrapToolStripMenuItem.Checked = editorView.WordWrap; |
||
| 543 | } |
||
| 6 | freddie | 544 | |
| 545 | void ToolStripButton8Click(object sender, EventArgs e) |
||
| 546 | { |
||
| 7 | freddie | 547 | insertImageFromFile(); |
| 6 | freddie | 548 | } |
| 7 | freddie | 549 | |
| 550 | #region editorMenuStrip |
||
| 551 | |||
| 552 | void CloseFileToolStripMenuItemClick(object sender, EventArgs e) |
||
| 553 | { |
||
| 554 | closeFile(); |
||
| 555 | } |
||
| 556 | |||
| 557 | void SaveFileToolStripMenuItemClick(object sender, EventArgs e) |
||
| 558 | { |
||
| 559 | files[curFileID].save(); |
||
| 560 | } |
||
| 561 | |||
| 562 | void InToolStripMenuItemClick(object sender, EventArgs e) |
||
| 563 | { |
||
| 564 | zoomIn(); |
||
| 565 | } |
||
| 566 | |||
| 567 | void OutToolStripMenuItemClick(object sender, EventArgs e) |
||
| 568 | { |
||
| 569 | zoomOut(); |
||
| 570 | } |
||
| 571 | |||
| 572 | #endregion |
||
| 573 | |||
| 8 | freddie | 574 | void TextColourFClick(object sender, EventArgs e) |
| 7 | freddie | 575 | { |
| 576 | DialogResult res = colorDialog1.ShowDialog(); |
||
| 577 | if (res != DialogResult.Cancel) |
||
| 578 | { |
||
| 579 | textColourF.ForeColor = colorDialog1.Color; |
||
| 580 | editorView.SelectionColor = colorDialog1.Color; |
||
| 581 | } |
||
| 582 | } |
||
| 8 | freddie | 583 | |
| 584 | void ToolStripButton9Click(object sender, EventArgs e) |
||
| 585 | { |
||
| 586 | saveAll(); |
||
| 587 | } |
||
| 9 | freddie | 588 | |
| 589 | void TabControlSelectedIndexChanged(object sender, EventArgs e) |
||
| 590 | { |
||
| 591 | if (tabControl.SelectedIndex == 1 && files.Count == 0) |
||
| 592 | { |
||
| 593 | newFile(); |
||
| 594 | } |
||
| 595 | } |
||
| 596 | |||
| 597 | void SyntaxHighlightingToolStripMenuItemSelectedIndexChanged(object sender, EventArgs e) |
||
| 598 | { |
||
| 599 | |||
| 600 | // clear own highlighting |
||
| 601 | files[curFileID].rtfBox.Rtf = editorView.Text; |
||
| 602 | files[curFileID].syntax = -1; |
||
| 603 | |||
| 604 | // sort out new stuff |
||
| 605 | if (syntaxHighlightingToolStripMenuItem.SelectedIndex == 1) |
||
| 606 | { |
||
| 607 | for (int i = 0; i < syntaxes.Count; i++) |
||
| 608 | { |
||
| 609 | if (files[curFileID].loc.EndsWith(syntaxes[i].id)) |
||
| 610 | { |
||
| 611 | files[curFileID].syntax = i; |
||
| 612 | break; |
||
| 613 | } |
||
| 614 | } |
||
| 615 | } |
||
| 616 | else |
||
| 617 | files[curFileID].syntax = syntaxHighlightingToolStripMenuItem.SelectedIndex - 2; |
||
| 618 | |||
| 619 | applySyntax(curFileID); |
||
| 620 | showFile(curFileID); |
||
| 621 | |||
| 622 | } |
||
| 623 | |||
| 624 | public void applySyntax(int fileID) |
||
| 625 | { |
||
| 626 | if (files[fileID].isRtf) |
||
| 627 | return; |
||
| 628 | |||
| 629 | if (files[fileID].syntax == -1) |
||
| 630 | files[fileID].rtfBox.Rtf = files[fileID].rtfBox.Text; |
||
| 631 | else |
||
| 632 | { |
||
| 633 | int pos; |
||
| 634 | string[] data = files[fileID].rtfBox.Text.Split(new char[] { ' ', '\n' }); |
||
| 635 | for (int i = 0; i < syntaxes[files[fileID].syntax].words.Count; i++) |
||
| 636 | { |
||
| 637 | pos = 0; |
||
| 638 | for (int j = 0; j < data.Length; j++) |
||
| 639 | { |
||
| 640 | if (syntaxes[files[fileID].syntax].words[i].words.Contains(data[j])) |
||
| 641 | { |
||
| 642 | files[fileID].rtfBox.Select(pos, data[j].Length); |
||
| 643 | files[fileID].rtfBox.SelectionColor = syntaxes[files[fileID].syntax].words[i].colour; |
||
| 644 | } |
||
| 645 | pos += data[j].Length + 1; |
||
| 646 | } |
||
| 647 | } |
||
| 648 | } |
||
| 649 | |||
| 650 | } |
||
| 1 | freddie | 651 | } |
| 652 | } |