internal static void ClearHighlightsResults(Form1 form) { XtraTabControl pagesTabControl = form.pagesTabControl; if (form.IsOpening) { return; } RichTextBox tempRichTextBox = new RichTextBox(); //Temporary RichTextBox to avoid too much undo/redo into buffer try { foreach (XtraTabPage tabPage in pagesTabControl.TabPages) { CustomRichTextBox textBox = ProgramUtil.GetPageTextBox(tabPage); textBox.SuspendPainting(); tempRichTextBox.Rtf = textBox.Rtf; tempRichTextBox.SelectAll(); tempRichTextBox.Font = new Font(textBox.Font, FontStyle.Regular); tempRichTextBox.SelectionBackColor = tempRichTextBox.BackColor; RichTextBoxUtil.ReplaceRTFContent(textBox, tempRichTextBox); textBox.ResumePainting(); } } finally { tempRichTextBox.Dispose(); } TextManager.RefreshUndoRedoExternal(form); }
internal static void ClearTextCorrectness(CustomRichTextBox pageTextBox) { RichTextBox tempRichTextBox = new RichTextBox(); //Temporary RichTextBox to avoid too much undo/redo into buffer pageTextBox.SuspendPainting(); tempRichTextBox.Rtf = pageTextBox.Rtf; tempRichTextBox.SelectAll(); tempRichTextBox.Font = new Font(pageTextBox.Font, FontStyle.Regular); tempRichTextBox.SelectionBackColor = tempRichTextBox.BackColor; RichTextBoxUtil.ReplaceRTFContent(pageTextBox, tempRichTextBox); pageTextBox.ResumePainting(); tempRichTextBox.Dispose(); }
internal static void CheckTextCorrectness(Form1 form, String languageSign) { if (!ExistsDictionary(languageSign)) { WindowManager.ShowInfoBox(form, LanguageUtil.GetCurrentLanguageString("NoDictionary", className) + ConstantUtil.dtPadURL + "wikipage?title=Dictionaries"); return; } CustomXtraTabControl pagesTabControl = form.pagesTabControl; CustomRichTextBox pageTextBox = ProgramUtil.GetPageTextBox(pagesTabControl.SelectedTabPage); if (RichTextBoxUtil.ContainsUnderlineText(pageTextBox)) { ClearTextCorrectness(pageTextBox); } bool textCorrectness = true; RichTextBox tempRichTextBox = new RichTextBox { BackColor = pageTextBox.BackColor }; //Temporary RichTextBox to avoid too much undo/redo into buffer pageTextBox.SuspendPainting(); tempRichTextBox.Rtf = pageTextBox.Rtf; //Method 1: char parse (more accurate, slower) using (Hunspell hunspell = new Hunspell(ConstantUtil.ApplicationExecutionPath() + "\\Languages\\" + languageSign + ".aff", ConstantUtil.ApplicationExecutionPath() + "\\Languages\\" + languageSign + ".dic")) { int wordStart = 0; StringBuilder word = new StringBuilder(String.Empty); StringBuilder text = new StringBuilder(pageTextBox.Text); for (int i = 0; i < text.Length; i++) { if (text[i] == '\'' || (!Char.IsWhiteSpace(text[i]) && !Char.IsPunctuation(text[i]) && !Char.IsSymbol(text[i]) && !Char.IsSeparator(text[i]))) { word.Append(text[i]); if (i < text.Length - 1) { continue; } } if (!hunspell.Spell(word.ToString()) && !String.IsNullOrEmpty(word.ToString().Trim())) { tempRichTextBox.Select(wordStart, word.Length); tempRichTextBox.SelectionFont = new Font(pageTextBox.Font, FontStyle.Underline); tempRichTextBox.SelectionColor = (pageTextBox.BackColor == Color.Red) ? Color.Yellow : Color.Red; textCorrectness = false; } word = new StringBuilder(String.Empty); wordStart = i + 1; } } //Method 2: word parse (less accurate, faster) //String[] wordsList = pageTextBox.Text.Split(new[] { ' ', Convert.ToChar(ConstantUtil.newLine), '\t', '/', '\\', '.', '?', ';', ',', ':', '(', ')', '[', ']', '{', '}', '\\', '|', '/', '!', '"', '\'', '=' }, StringSplitOptions.RemoveEmptyEntries); //List<String> wordsAlreadySeen = new List<String>(); //using (Hunspell hunspell = new Hunspell(ConstantUtil.ApplicationExecutionPath() + "\\Languages\\" + languageSign + ".aff", ConstantUtil.ApplicationExecutionPath() + "\\Languages\\" + languageSign + ".dic")) //{ // foreach (String word in wordsList) // { // if (wordsAlreadySeen.Contains(word)) // { // continue; // } // wordsAlreadySeen.Add(word); // if (hunspell.Spell(word)) // { // continue; // } // int i = 0; // while (i != -1 && (i = pageTextBox.Text.IndexOf(word, i)) != -1) // { // tempRichTextBox.Select(i, word.Length); // tempRichTextBox.SelectionFont = new Font(pageTextBox.Font, FontStyle.Underline); // tempRichTextBox.SelectionColor = (pageTextBox.BackColor == Color.Red) ? Color.Yellow : Color.Red; // i += word.Length; // } // } //} pageTextBox.IsUnderlining = true; RichTextBoxUtil.ReplaceRTFContent(pageTextBox, tempRichTextBox); pageTextBox.ResumePainting(); tempRichTextBox.Dispose(); TextManager.RefreshUndoRedoExternal(form); if (textCorrectness) { WindowManager.ShowInfoBox(form, LanguageUtil.GetCurrentLanguageString("TextCorrect", className)); } }