/// <summary> /// Initializes TextHighlighter fill the keywords lists. /// </summary> public static void InitHighlighter() { langs = new List <HighlightLanguage>(); if (Settings.HighlightHTML) { langs.Add(xmlUtil.ParserLanguageLexical(LANGFILE, "html")); } if (Settings.HighlightPHP) { langs.Add(xmlUtil.ParserLanguageLexical(LANGFILE, "php")); } if (Settings.HighlightSQL) { langs.Add(xmlUtil.ParserLanguageLexical(LANGFILE, "sql")); } rtfdirectedit = new RTFDirectEdit(); keywordsinit = true; }
/// <summary> /// Clear the keywords list. /// </summary> public static void DeinitHighlighter() { keywordsinit = false; rtfdirectedit = null; GC.Collect(); }
/// <summary> /// Import a Tomboy note file as note content for a new note. /// And set the new note title. /// </summary> /// <param name="reader">The streamreader to read the Tomboy note with.</param> /// <param name="tomboynotefile">The Tomboy note file full filepath and filename.</param> /// <param name="tbTitle">The textbox to set the title in.</param> /// <param name="rtbNewNote">The richedittextbox to set the content in.</param> public void ReadTomboyfile(StreamReader reader, string tomboynotefile, TextBox tbTitle, RichTextBox rtbNewNote) { tbTitle.Text = xmlUtil.GetContentString(tomboynotefile, "title"); rtbNewNote.Clear(); System.Xml.XmlTextReader xmlreader = new System.Xml.XmlTextReader(reader); xmlreader.ProhibitDtd = true; while (xmlreader.Read()) { if (xmlreader.Name == "note-content") { string tomboynotecontent = xmlreader.ReadInnerXml(); bool innode = false; bool begintag = false; int startnodepos = 0; int textpos = 0; List <string> formattype = new List <string>(); List <bool> formatisbegintag = new List <bool>(); List <int> formatstartpos = new List <int>(); for (int i = 0; i < tomboynotecontent.Length; i++) { if (tomboynotecontent[i] == '<' && !innode) { startnodepos = i; innode = true; begintag = true; if (i + 1 <= tomboynotecontent.Length) { if (tomboynotecontent[i + 1] == '/') { begintag = false; } } } else if (tomboynotecontent[i] == '>' && innode) { formatisbegintag.Add(begintag); if (begintag) { string tag = tomboynotecontent.Substring(startnodepos + 1, i - startnodepos - 1); for (int c = 0; c < tag.Length; c++) { if (tag[c] == ' ') { formattype.Add(tag.Substring(0, c)); break; } } formatstartpos.Add(textpos); } else { formattype.Add(tomboynotecontent.Substring(startnodepos + 2, i - startnodepos - 2)); formatstartpos.Add(textpos); } innode = false; } else if (!innode) { rtbNewNote.Text += tomboynotecontent[i]; textpos++; } } RTFDirectEdit rtfdirectedit = new RTFDirectEdit(); int poslastbold = int.MaxValue; int poslastitalic = int.MaxValue; int poslaststrikethrought = int.MaxValue; int poslastsizesmall = int.MaxValue; int poslastsizelarge = int.MaxValue; int poslastsizehuge = int.MaxValue; for (int i = 0; i < formattype.Count; i++) { switch (formattype[i]) { case "bold": if (formatisbegintag[i]) { poslastbold = formatstartpos[i]; } else if (poslastbold != int.MaxValue) { rtbNewNote.Rtf = rtfdirectedit.AddBoldTagInRTF(rtbNewNote.Rtf, poslastbold, formatstartpos[i] - poslastbold); } break; case "italic": if (formatisbegintag[i]) { poslastitalic = formatstartpos[i]; } else if (poslastitalic != int.MaxValue) { rtbNewNote.Rtf = rtfdirectedit.AddItalicTagInRTF(rtbNewNote.Rtf, poslastitalic, formatstartpos[i] - poslastitalic); } break; case "strikethrough": if (formatisbegintag[i]) { poslaststrikethrought = formatstartpos[i]; } else if (poslaststrikethrought != int.MaxValue) { rtbNewNote.Rtf = rtfdirectedit.AddStrikeTagInRTF(rtbNewNote.Rtf, poslaststrikethrought, formatstartpos[i] - poslaststrikethrought); } break; case "size:small": if (formatisbegintag[i]) { poslastsizesmall = formatstartpos[i]; } else if (poslastsizehuge != int.MaxValue) { int textlen = formatstartpos[i] - poslastsizesmall; rtbNewNote.Rtf = rtfdirectedit.SetSizeTagInRtf(rtbNewNote.Rtf, poslastsizesmall, textlen, 9); } break; case "size:large": if (formatisbegintag[i]) { poslastsizelarge = formatstartpos[i]; } else if (poslastsizelarge != int.MaxValue) { int textlen = formatstartpos[i] - poslastsizelarge; rtbNewNote.Rtf = rtfdirectedit.SetSizeTagInRtf(rtbNewNote.Rtf, poslastsizesmall, textlen, 14); } break; case "size:huge": if (formatisbegintag[i]) { poslastsizehuge = formatstartpos[i]; } else if (poslastsizehuge != int.MaxValue) { int textlen = formatstartpos[i] - poslastsizelarge; rtbNewNote.Rtf = rtfdirectedit.SetSizeTagInRtf(rtbNewNote.Rtf, poslastsizesmall, textlen, 16); } break; } } } } }