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; }
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(new[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '%', '&', '@', '$', '*', '=', '£', '#', '_', '½', '^' })) { _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.Contains(_currentWord) || (_currentWord.StartsWith('\'') || _currentWord.EndsWith('\'')) && _namesEtcList.Contains(_currentWord.Trim('\''))) { _noOfNamesEtc++; } else if (_skipAllList.Contains(_currentWord.ToUpper()) || (_currentWord.StartsWith('\'') || _currentWord.EndsWith('\'')) && _skipAllList.Contains(_currentWord.Trim('\'').ToUpper())) { _noOfSkippedWords++; } else if (_userWordList.Contains(_currentWord.ToLower()) || (_currentWord.StartsWith('\'') || _currentWord.EndsWith('\'')) && _userWordList.Contains(_currentWord.Trim('\'').ToLower())) { _noOfCorrectWords++; } else if (_changeAllDictionary.ContainsKey(_currentWord)) { _noOfChangedWords++; _mainWindow.CorrectWord(_changeAllDictionary[_currentWord], _currentParagraph, _currentWord, ref _firstChange, -1); } else if (_changeAllDictionary.ContainsKey(_currentWord.Trim('\''))) { _noOfChangedWords++; _mainWindow.CorrectWord(_changeAllDictionary[_currentWord], _currentParagraph, _currentWord.Trim('\''), ref _firstChange, -1); } else if (_namesEtcListUppercase.Contains(_currentWord) || _namesEtcListWithApostrophe.Contains(_currentWord) || _namesList.IsInNamesEtcMultiWordList(_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 && "`'".Contains(_currentWord[_currentWord.Length - 1])) correct = DoSpell(_currentWord.TrimEnd('\'').TrimEnd('`')); if (!correct && _currentWord.EndsWith("'s", StringComparison.Ordinal) && _currentWord.Length > 4) correct = DoSpell(_currentWord.TrimEnd('s').TrimEnd('\'')); if (!correct && _currentWord.EndsWith('\'') && DoSpell(_currentWord.TrimEnd('\''))) { _currentWord = _currentWord.TrimEnd('\''); correct = true; } if (!correct) { string removeUnicode = _currentWord.Replace(Char.ConvertFromUtf32(0x200b), string.Empty); // zero width space removeUnicode = removeUnicode.Replace(Char.ConvertFromUtf32(0x2060), string.Empty); // word joiner removeUnicode = removeUnicode.Replace(Char.ConvertFromUtf32(0xfeff), string.Empty); // zero width no-break space correct = DoSpell(removeUnicode); } } else { correct = false; if (_currentWord == "'") correct = true; else if (_languageName.StartsWith("en_", StringComparison.Ordinal) && (_currentWord.Equals("a", StringComparison.OrdinalIgnoreCase) || _currentWord == "I")) correct = true; else if (_languageName.StartsWith("da_", StringComparison.Ordinal) && _currentWord.Equals("i", StringComparison.OrdinalIgnoreCase)) correct = true; } if (!correct && Configuration.Settings.Tools.SpellCheckEnglishAllowInQuoteAsIng && _languageName.StartsWith("en_", StringComparison.Ordinal) && _currentWord.EndsWith("in'", StringComparison.OrdinalIgnoreCase)) { correct = DoSpell(_currentWord.TrimEnd('\'') + "g"); } if (correct) { _noOfCorrectWords++; } else { _mainWindow.FocusParagraph(_currentIndex); var 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" && !_currentWord.ToUpper().StartsWith("HTTP", StringComparison.Ordinal)) // TODO: Get fixed nhunspell suggestions = DoSuggest(_currentWord); // TODO: 0.9.6 fails on "Lt'S" if (_languageName.StartsWith("fr_", StringComparison.Ordinal) && (_currentWord.StartsWith("I'", StringComparison.Ordinal) || _currentWord.StartsWith("I’", StringComparison.Ordinal))) { if (_currentWord.Length > 3 && Utilities.LowercaseLetters.Contains(_currentWord[2]) && _currentSpellCheckWord.Index > 3) { string ending = _currentParagraph.Text.Substring(0, _currentSpellCheckWord.Index - 1).Trim(); if (ending.Length > 1 && !".!?".Contains(ending[ending.Length - 1])) { for (int i = 0; i < suggestions.Count; i++) { if (suggestions[i].StartsWith("L'") || suggestions[i].StartsWith("L’")) suggestions[i] = @"l" + suggestions[i].Substring(1); } } } } } suggestions.Remove(_currentWord); if (_currentWord.Length == 1) { if ((_currentWord == "L") && _languageName.StartsWith("en_", StringComparison.Ordinal)) { suggestions.Remove("I"); suggestions.Insert(0, "I"); } } if (AutoFixNames && _currentWord.Length > 1 && suggestions.Contains(char.ToUpper(_currentWord[0]) + _currentWord.Substring(1))) { ChangeWord = char.ToUpper(_currentWord[0]) + _currentWord.Substring(1); DoAction(SpellCheckAction.ChangeAll); return; } if (AutoFixNames && _currentWord.Length > 3 && suggestions.Contains(_currentWord.ToUpper())) { // does not work well with two letter words like "da" and "de" which get auto-corrected to "DA" and "DE" ChangeWord = _currentWord.ToUpper(); DoAction(SpellCheckAction.ChangeAll); return; } if (AutoFixNames && _currentWord.Length > 1 && _namesEtcList.Contains(char.ToUpper(_currentWord[0]) + _currentWord.Substring(1))) { ChangeWord = char.ToUpper(_currentWord[0]) + _currentWord.Substring(1); DoAction(SpellCheckAction.ChangeAll); return; } if (_prefix != null && _prefix == "''" && _currentWord.EndsWith("''")) { _prefix = string.Empty; _currentSpellCheckWord.Index += 2; _currentWord = _currentWord.Trim('\''); } if (_prefix != null && _prefix == "'" && _currentWord.EndsWith('\'')) { _prefix = string.Empty; _currentSpellCheckWord.Index++; _currentWord = _currentWord.Trim('\''); } 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 (!Visible) ShowDialog(_mainWindow); return; // wait for user input } } } } }
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; } } }