/// <summary> /// Add the word to the dictionary /// </summary> /// <param name="sender">The sender of the event</param> /// <param name="e">The event arguments</param> /// <remarks>Since we're making the change through the dictionary, the <c>TagsChanged</c> event will /// be raised and will notify us of the remaining misspellings.</remarks> private void cmdAddToDictionary_Executed(object sender, ExecutedRoutedEventArgs e) { MisspellingTag currentIssue = ucSpellCheck.CurrentIssue as MisspellingTag; string word; if (currentIssue != null) { word = ucSpellCheck.MisspelledWord; if (word.Length != 0) { // If the parameter is a CultureInfo instance, the word will be added to the dictionary for // that culture. If null, it's added to the first available dictionary. currentTagger.Dictionary.AddWordToDictionary(word, e.Parameter as CultureInfo); // If adding a modified word, replace the word in the file too if (!word.Equals(currentIssue.Word, StringComparison.OrdinalIgnoreCase)) { cmdReplace_Executed(sender, e); } } else { MessageBox.Show("Cannot add an empty word to the dictionary", PackageResources.PackageTitle, MessageBoxButton.OK, MessageBoxImage.Exclamation); } } }
/// <summary> /// Replace the current misspelled word with the selected word /// </summary> /// <param name="sender">The sender of the event</param> /// <param name="e">The event arguments</param> /// <remarks>Since we're making the change through the text buffer, the <c>TagsChanged</c> event will /// be raised and will notify us of the remaining misspellings.</remarks> private void cmdReplace_Executed(object sender, ExecutedRoutedEventArgs e) { ITrackingSpan span; MisspellingTag currentIssue = ucSpellCheck.CurrentIssue as MisspellingTag; if (currentIssue != null && currentIssue.Word.Length != 0) { if (currentIssue.MisspellingType != MisspellingType.DoubledWord) { var suggestion = ucSpellCheck.SelectedSuggestion; if (suggestion != null) { string replaceWith = suggestion.Suggestion; if (currentIssue.EscapeApostrophes) { replaceWith = replaceWith.Replace("'", "''"); } span = currentIssue.Span; span.TextBuffer.Replace(span.GetSpan(span.TextBuffer.CurrentSnapshot), replaceWith); } } else { span = currentIssue.DeleteWordSpan; span.TextBuffer.Replace(span.GetSpan(span.TextBuffer.CurrentSnapshot), String.Empty); } } }
/// <summary> /// Ignore all occurrences of the misspelled word /// </summary> /// <param name="sender">The sender of the event</param> /// <param name="e">The event arguments</param> /// <remarks>Since we're making the change through the dictionary, the <c>TagsChanged</c> event will /// be raised and will notify us of the remaining misspellings.</remarks> private void cmdIgnoreAll_Executed(object sender, ExecutedRoutedEventArgs e) { MisspellingTag currentIssue = ucSpellCheck.CurrentIssue as MisspellingTag; if (currentIssue != null && currentIssue.Word.Length != 0) { currentTagger.Dictionary.IgnoreWord(currentIssue.Word); } }
/// <summary> /// Replace all occurrences of the misspelled word with the selected word /// </summary> /// <param name="sender">The sender of the event</param> /// <param name="e">The event arguments</param> /// <remarks>Since we're making the change through the dictionary, the <c>TagsChanged</c> event will /// be raised and will notify us of the remaining misspellings.</remarks> private void cmdReplaceAll_Executed(object sender, ExecutedRoutedEventArgs e) { MisspellingTag currentIssue = ucSpellCheck.CurrentIssue as MisspellingTag; if (currentIssue != null && currentIssue.Word.Length != 0) { var suggestion = ucSpellCheck.SelectedSuggestion; if (suggestion != null) { currentTagger.Dictionary.ReplaceAllOccurrences(currentIssue.Word, suggestion); } } }
/// <summary> /// Replace all occurrences of the misspelled word with the selected word /// </summary> /// <param name="sender">The sender of the event</param> /// <param name="e">The event arguments</param> /// <remarks>Since we're making the change through the dictionary, the <c>TagsChanged</c> event will /// be raised and will notify us of the remaining misspellings.</remarks> private void cmdReplaceAll_Executed(object sender, ExecutedRoutedEventArgs e) { MisspellingTag currentIssue = ucSpellCheck.CurrentIssue as MisspellingTag; if (currentIssue != null && currentIssue.Word.Length != 0) { var suggestion = ucSpellCheck.SelectedSuggestion; if (suggestion != null) { var replacement = suggestion; if (currentIssue.EscapeApostrophes) { replacement = new SpellingSuggestion(replacement.Culture, replacement.Suggestion.Replace("'", "''")); } currentTagger.Dictionary.ReplaceAllOccurrences(currentIssue.Word, replacement); } } }
//===================================================================== /// <summary> /// Get the suggested actions for misspelled words /// </summary> /// <param name="errorSpan">The error span for the misspelled word</param> /// <param name="misspellingType">The misspelling type</param> /// <param name="suggestions">The suggestions to use as the replacement</param> /// <returns>A enumerable list of suggested action sets</returns> private IEnumerable <SuggestedActionSet> GetMisspellingSuggestedActions(SnapshotSpan errorSpan, MisspellingTag misspelling) { List <SuggestedActionSet> actionSets = new List <SuggestedActionSet>(); List <ISuggestedAction> actions = new List <ISuggestedAction>(); ITrackingSpan trackingSpan = errorSpan.Snapshot.CreateTrackingSpan(errorSpan, SpanTrackingMode.EdgeExclusive); if (dictionary.DictionaryCount > 1) { // Merge the same words from different dictionaries var words = misspelling.Suggestions.GroupBy(w => w.Suggestion).Select(g => new MultiLanguageSpellSuggestedAction(trackingSpan, g.First(), misspelling.EscapeApostrophes, g.Select(w => w.Culture), dictionary)); actions.AddRange(words); } else { actions.AddRange(misspelling.Suggestions.Select(word => new SpellSuggestedAction(trackingSpan, word, misspelling.EscapeApostrophes, dictionary))); } if (actions.Count != 0) { actionSets.Add(new SuggestedActionSet(null, actions, null, SuggestedActionSetPriority.Low)); } // Add Dictionary operations actions = new List <ISuggestedAction> { new SpellDictionarySuggestedAction(trackingSpan, dictionary, "Ignore Once", DictionaryAction.IgnoreOnce, null), new SpellDictionarySuggestedAction(trackingSpan, dictionary, "Ignore All", DictionaryAction.IgnoreAll, null) }; actionSets.Add(new SuggestedActionSet(null, actions, null, SuggestedActionSetPriority.Low)); if (misspelling.MisspellingType == MisspellingType.MisspelledWord) { actions = new List <ISuggestedAction>(); if (dictionary.Dictionaries.Count() == 1) { actions.Add(new SpellDictionarySuggestedAction(trackingSpan, dictionary, "Add to Dictionary", DictionaryAction.AddWord, dictionary.Dictionaries.First().Culture)); actionSets.Add(new SuggestedActionSet(null, actions, null, SuggestedActionSetPriority.Low)); } else { // If there are multiple dictionaries, put them in a submenu foreach (var d in dictionary.Dictionaries) { actions.Add(new SpellDictionarySuggestedAction(trackingSpan, dictionary, String.Empty, DictionaryAction.AddWord, d.Culture)); } actionSets.Add(new SuggestedActionSet(null, new[] { new SuggestedActionSubmenu("Add to Dictionary", new[] { new SuggestedActionSet(null, actions) }) }, null, SuggestedActionSetPriority.Low)); } } return(actionSets); }