private void ShowActiveWordWithColor(SpellCheckWord word) { richTextBoxParagraph.SelectAll(); richTextBoxParagraph.SelectionColor = Color.Black; richTextBoxParagraph.SelectionLength = 0; for (int i = 0; i < 10; i++) { int idx = word.Index - i; if (idx >= 0 && idx < richTextBoxParagraph.Text.Length && richTextBoxParagraph.Text.Substring(idx).StartsWith(word.Text)) { richTextBoxParagraph.SelectionStart = idx; richTextBoxParagraph.SelectionLength = word.Text.Length; richTextBoxParagraph.SelectionColor = Color.Red; break; } idx = word.Index + i; if (idx >= 0 && idx < richTextBoxParagraph.Text.Length && richTextBoxParagraph.Text.Substring(idx).StartsWith(word.Text)) { richTextBoxParagraph.SelectionStart = idx; richTextBoxParagraph.SelectionLength = word.Text.Length; richTextBoxParagraph.SelectionColor = Color.Red; break; } } }
private void PrepareNextWord() { while (true) { if (_wordsIndex + 1 < _words.Count) { _wordsIndex++; _currentWord = _words[_wordsIndex].Text; _currentSpellCheckWord = _words[_wordsIndex]; } else { if (_currentIndex + 1 < _subtitle.Paragraphs.Count) { _currentIndex++; _currentParagraph = _subtitle.Paragraphs[_currentIndex]; SetWords(_currentParagraph.Text); _wordsIndex = 0; if (_words.Count == 0) { _currentWord = string.Empty; } else { _currentWord = _words[_wordsIndex].Text; _currentSpellCheckWord = _words[_wordsIndex]; } } else { ShowEndStatusMessage(Configuration.Settings.Language.SpellCheck.SpellCheckCompleted); DialogResult = DialogResult.OK; return; } } int minLength = 2; if (Configuration.Settings.Tools.SpellCheckOneLetterWords) minLength = 1; if (_currentWord.Trim().Length >= minLength && !_currentWord.Contains("0") && !_currentWord.Contains("1") && !_currentWord.Contains("2") && !_currentWord.Contains("3") && !_currentWord.Contains("4") && !_currentWord.Contains("5") && !_currentWord.Contains("6") && !_currentWord.Contains("7") && !_currentWord.Contains("8") && !_currentWord.Contains("9") && !_currentWord.Contains("%") && !_currentWord.Contains("&") && !_currentWord.Contains("@") && !_currentWord.Contains("$") && !_currentWord.Contains("*") && !_currentWord.Contains("=") && !_currentWord.Contains("£") && !_currentWord.Contains("#") && !_currentWord.Contains("_") && !_currentWord.Contains("½") && !_currentWord.Contains("^") && !_currentWord.Contains("£") ) { _prefix = string.Empty; _postfix = string.Empty; if (_currentWord.Length > 1) { if (_currentWord.StartsWith("'")) { _prefix = "'"; _currentWord = _currentWord.Substring(1); } if (_currentWord.StartsWith("`")) { _prefix = "`"; _currentWord = _currentWord.Substring(1); } } if (_namesEtcList.IndexOf(_currentWord) >= 0) { _noOfNamesEtc++; } else if ((_currentWord.EndsWith("'") || _currentWord.StartsWith("'")) && _namesEtcList.IndexOf(_currentWord.Trim("'".ToCharArray())) >= 0) { _noOfNamesEtc++; } else if (_skipAllList.IndexOf(_currentWord.ToUpper()) >= 0) { _noOfSkippedWords++; } else if ((_currentWord.EndsWith("'") || _currentWord.StartsWith("'")) && _skipAllList.IndexOf(_currentWord.ToUpper().Trim("'".ToCharArray())) >= 0) { _noOfSkippedWords++; } else if (_userWordList.IndexOf(_currentWord.ToLower()) >= 0) { _noOfCorrectWords++; } else if ((_currentWord.EndsWith("'") || _currentWord.StartsWith("'")) && _userWordList.IndexOf(_currentWord.Trim("'".ToCharArray()).ToLower()) >= 0) { _noOfCorrectWords++; } else if (_changeAllDictionary.ContainsKey(_currentWord)) { _noOfChangedWords++; _mainWindow.CorrectWord(_changeAllDictionary[_currentWord], _currentParagraph, _currentWord, ref _firstChange); } else if (_changeAllDictionary.ContainsKey(_currentWord.Trim("'".ToCharArray()))) { _noOfChangedWords++; _mainWindow.CorrectWord(_changeAllDictionary[_currentWord], _currentParagraph, _currentWord.Trim("'".ToCharArray()), ref _firstChange); } else if (_namesEtcListUppercase.IndexOf(_currentWord) >= 0) { _noOfNamesEtc++; } else if (_namesEtcListWithApostrophe.IndexOf(_currentWord) >= 0) { _noOfNamesEtc++; } else if (Utilities.IsInNamesEtcMultiWordList(_namesEtcMultiWordList, _currentParagraph.Text, _currentWord)) //TODO: verify this! { _noOfNamesEtc++; } else if (IsWordInUserPhrases(_userPhraseList, _wordsIndex, _words)) { _noOfCorrectWords++; } else { bool correct; if (_prefix == "'" && _currentWord.Length >= 1 && (DoSpell(_prefix + _currentWord) || _userWordList.Contains(_prefix + _currentWord))) { correct = true; } else if (_currentWord.Length > 1) { correct = DoSpell(_currentWord); if (!correct && (_currentWord.EndsWith("'") || _currentWord.EndsWith("`"))) correct = DoSpell(_currentWord.TrimEnd('\'').TrimEnd('`')); if (!correct && _currentWord.EndsWith("'s") && _currentWord.Length > 4) correct = DoSpell(_currentWord.TrimEnd('s').TrimEnd('\'')); if (!correct && _currentWord.EndsWith("'") && DoSpell(_currentWord.TrimEnd("'".ToCharArray()))) { _currentWord = _currentWord.TrimEnd("'".ToCharArray()); correct = true; } } else { correct = false; if (_currentWord == "'") correct = true; else if (_languageName.StartsWith("en_") && (_currentWord.ToLower() == "a" || _currentWord == "I")) correct = true; else if (_languageName.StartsWith("da_") && _currentWord.ToLower() == "i") correct = true; } if (!correct && Configuration.Settings.Tools.SpellCheckEnglishAllowInQuoteAsIng && _languageName.StartsWith("en_") && _currentWord.ToLower().EndsWith("in'")) { correct = DoSpell(_currentWord.TrimEnd('\'') + "g"); } if (correct) { _noOfCorrectWords++; } else { _mainWindow.FocusParagraph(_currentIndex); List<string> suggestions = new List<string>(); if ((_currentWord == "Lt's" || _currentWord == "Lt'S") && _languageName.StartsWith("en_")) { suggestions.Add("It's"); } else { if (_currentWord.ToUpper() != "LT'S" && _currentWord.ToUpper() != "SOX'S") //TODO: get fixed nhunspell suggestions = DoSuggest(_currentWord); //TODO: 0.9.6 fails on "Lt'S" if (_languageName.StartsWith("fr_") && (_currentWord.StartsWith("I'") || _currentWord.StartsWith("I’"))) { if (_currentWord.Length > 3 && Utilities.LowercaseLetters.Contains(_currentWord[2].ToString())) { if (_currentSpellCheckWord.Index > 3) { string ending = _currentParagraph.Text.Substring(0, _currentSpellCheckWord.Index - 1).Trim(); if (!ending.EndsWith(".") && !ending.EndsWith("!") && !ending.EndsWith("?")) { for (int i = 0; i < suggestions.Count; i++) { if (suggestions[i].StartsWith("L'") || suggestions[i].StartsWith("L’")) suggestions[i] = suggestions[i].Remove(0, 1).Insert(0, "l"); } } } } } } suggestions.Remove(_currentWord); if (_currentWord.Length == 1) { if ((_currentWord == "L") && _languageName.StartsWith("en_")) { suggestions.Remove("I"); suggestions.Insert(0, "I"); } } if (AutoFixNames && _currentWord.Length > 1 && suggestions.Contains(_currentWord.Substring(0, 1).ToUpper() + _currentWord.Substring(1))) { ChangeWord = _currentWord.Substring(0, 1).ToUpper() + _currentWord.Substring(1); DoAction(SpellCheckAction.ChangeAll); return; } else if (AutoFixNames && _currentWord.Length > 1 && suggestions.Contains(_currentWord.ToUpper())) { ChangeWord = _currentWord.ToUpper(); DoAction(SpellCheckAction.ChangeAll); return; } else if (AutoFixNames && _currentWord.Length > 1 && _namesEtcList.Contains(_currentWord.Substring(0, 1).ToUpper() + _currentWord.Substring(1))) { ChangeWord = _currentWord.Substring(0, 1).ToUpper() + _currentWord.Substring(1); DoAction(SpellCheckAction.ChangeAll); return; } else { if (_prefix != null && _prefix == "''" && _currentWord.EndsWith("''")) { _prefix = string.Empty; _currentSpellCheckWord.Index += 2; _currentWord = _currentWord.Trim("'".ToCharArray()); } if (_prefix != null && _prefix == "'" && _currentWord.EndsWith("'")) { _prefix = string.Empty; _currentSpellCheckWord.Index++; _currentWord = _currentWord.Trim("'".ToCharArray()); } if (_postfix != null && _postfix == "'") { _currentSpellCheckWord.Text = _currentWord + _postfix; Initialize(_languageName, _currentSpellCheckWord, suggestions, _currentParagraph.Text, string.Format(Configuration.Settings.Language.Main.LineXOfY, (_currentIndex + 1), _subtitle.Paragraphs.Count)); } else { _currentSpellCheckWord.Text = _currentWord; Initialize(_languageName, _currentSpellCheckWord, suggestions, _currentParagraph.Text, string.Format(Configuration.Settings.Language.Main.LineXOfY, (_currentIndex + 1), _subtitle.Paragraphs.Count)); } if (!this.Visible) this.ShowDialog(_mainWindow); return; // wait for user input } } } } } }
public void Initialize(string languageName, SpellCheckWord word, List<string> suggestions, string paragraph, string progress) { _originalWord = word.Text; _suggestions = suggestions; groupBoxWordNotFound.Visible = true; groupBoxEditWholeText.Visible = false; buttonEditWholeText.Text = Configuration.Settings.Language.SpellCheck.EditWholeText; Text = Configuration.Settings.Language.SpellCheck.Title + " [" + languageName + "] - " + progress; textBoxWord.Text = word.Text; textBoxWholeText.Text = paragraph; listBoxSuggestions.Items.Clear(); foreach (string suggestion in suggestions) { listBoxSuggestions.Items.Add(suggestion); } if (listBoxSuggestions.Items.Count > 0) listBoxSuggestions.SelectedIndex = 0; richTextBoxParagraph.Text = paragraph; FillSpellCheckDictionaries(languageName); ShowActiveWordWithColor(word); _action = SpellCheckAction.Skip; DialogResult = DialogResult.None; }