//=====================================================================
        /// <summary>
        /// This constructor is used for misspelled words with a specific type
        /// </summary>
        /// <param name="misspellingType">The misspelling type</param>
        /// <param name="span">The span containing the misspelled word</param>
        /// <param name="suggestions">The suggestions that can be used to replace the misspelled word</param>
        /// <overloads>There are three overloads for the constructor</overloads>
        public MisspellingTag(MisspellingType misspellingType, SnapshotSpan span, IEnumerable<SpellingSuggestion> suggestions)
        {
            if(misspellingType == MisspellingType.DoubledWord)
                throw new ArgumentException("Misspelling type cannot be doubled word");

            this.MisspellingType = misspellingType;
            this.Span = this.DeleteWordSpan = span.Snapshot.CreateTrackingSpan(span, SpanTrackingMode.EdgeExclusive);
            this.Suggestions = suggestions ?? new SpellingSuggestion[0];
        }
Example #2
0
        //=====================================================================

        /// <summary>
        /// This constructor is used for misspelled words with a specific type
        /// </summary>
        /// <param name="misspellingType">The misspelling type</param>
        /// <param name="span">The span containing the misspelled word</param>
        /// <param name="suggestions">The suggestions that can be used to replace the misspelled word</param>
        /// <overloads>There are two overloads for the constructor</overloads>
        public MisspellingTag(MisspellingType misspellingType, SnapshotSpan span, IEnumerable <string> suggestions)
        {
            if (misspellingType == MisspellingType.DoubledWord)
            {
                throw new ArgumentException("Misspelling type cannot be doubled word");
            }

            this.MisspellingType = misspellingType;
            this.Span            = this.DeleteWordSpan = span.Snapshot.CreateTrackingSpan(span, SpanTrackingMode.EdgeExclusive);
            this.Suggestions     = suggestions;
        }
        //=====================================================================
        /// <summary>
        /// This constructor is used for misspelled words with a specific type
        /// </summary>
        /// <param name="misspellingType">The misspelling type</param>
        /// <param name="span">The span containing the misspelled word</param>
        /// <param name="word">The misspelled word</param>
        /// <param name="suggestions">The suggestions that can be used to replace the misspelled word</param>
        /// <overloads>There are three overloads for the constructor</overloads>
        public FileMisspelling(MisspellingType misspellingType, Span span, string word,
            IEnumerable<SpellingSuggestion> suggestions)
        {
            if(misspellingType == MisspellingType.DoubledWord)
                throw new ArgumentException("Misspelling type cannot be doubled word");

            this.MisspellingType = misspellingType;
            this.Span = this.DeleteWordSpan = span;
            this.Word = word;
            this.Suggestions = suggestions ?? new SpellingSuggestion[0];
            this.SuggestionsDetermined = (suggestions != null);
        }
        //=====================================================================

        /// <summary>
        /// This constructor is used for misspelled words with a specific type
        /// </summary>
        /// <param name="misspellingType">The misspelling type</param>
        /// <param name="span">The span containing the misspelled word</param>
        /// <param name="word">The misspelled word</param>
        /// <param name="suggestions">The suggestions that can be used to replace the misspelled word</param>
        /// <overloads>There are three overloads for the constructor</overloads>
        public FileMisspelling(MisspellingType misspellingType, Span span, string word,
                               IEnumerable <SpellingSuggestion> suggestions)
        {
            if (misspellingType == MisspellingType.DoubledWord)
            {
                throw new ArgumentException("Misspelling type cannot be doubled word");
            }

            this.MisspellingType       = misspellingType;
            this.Span                  = this.DeleteWordSpan = span;
            this.Word                  = word;
            this.Suggestions           = suggestions ?? new SpellingSuggestion[0];
            this.SuggestionsDetermined = (suggestions != null);
            this.ActualBounds          = Rect.Empty;
        }
        //=====================================================================

        /// <summary>
        /// Get the smart tag 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 read-only collection of smart tag action sets</returns>
        private ReadOnlyCollection <SmartTagActionSet> GetMisspellingSmartTagActions(SnapshotSpan errorSpan,
                                                                                     MisspellingType misspellingType, IEnumerable <string> suggestions)
        {
            List <SmartTagActionSet> smartTagSets = new List <SmartTagActionSet>();

            ITrackingSpan trackingSpan = errorSpan.Snapshot.CreateTrackingSpan(errorSpan,
                                                                               SpanTrackingMode.EdgeExclusive);

            // Add spelling suggestions (if there are any)
            List <ISmartTagAction> actions = new List <ISmartTagAction>();

            foreach (var suggestion in suggestions)
            {
                actions.Add(new SpellSmartTagAction(trackingSpan, suggestion, dictionary));
            }

            if (actions.Count > 0)
            {
                // This acts as a place holder to tell the user to hold the Ctrl key down to replace all
                // occurrences of the selected word.
                actions.Insert(0, new SpellSmartTagAction(null, "Hold Ctrl to replace all", null));

                smartTagSets.Add(new SmartTagActionSet(actions.AsReadOnly()));
            }

            // Add Dictionary operations (ignore all)
            List <ISmartTagAction> dictionaryActions = new List <ISmartTagAction>();

            dictionaryActions.Add(new SpellDictionarySmartTagAction(trackingSpan, dictionary, "Ignore Once",
                                                                    DictionaryAction.IgnoreOnce));
            dictionaryActions.Add(new SpellDictionarySmartTagAction(trackingSpan, dictionary, "Ignore All",
                                                                    DictionaryAction.IgnoreAll));

            if (misspellingType == MisspellingType.MisspelledWord)
            {
                dictionaryActions.Add(new SpellDictionarySmartTagAction(trackingSpan, dictionary, "Add to Dictionary",
                                                                        DictionaryAction.AddWord));
            }

            smartTagSets.Add(new SmartTagActionSet(dictionaryActions.AsReadOnly()));

            return(smartTagSets.AsReadOnly());
        }
Example #6
0
        //=====================================================================

        /// <summary>
        /// Get the smart tag 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 read-only collection of smart tag action sets</returns>
        private ReadOnlyCollection <SmartTagActionSet> GetMisspellingSmartTagActions(SnapshotSpan errorSpan,
                                                                                     MisspellingType misspellingType, IEnumerable <SpellingSuggestion> suggestions)
        {
            List <SmartTagActionSet> smartTagSets = new List <SmartTagActionSet>();
            List <ISmartTagAction>   actions      = new List <ISmartTagAction>();
            ITrackingSpan            trackingSpan = errorSpan.Snapshot.CreateTrackingSpan(errorSpan,
                                                                                          SpanTrackingMode.EdgeExclusive);

            // Add spelling suggestions grouped by language when appropriate
            foreach (var word in suggestions)
            {
                if (!word.IsGroupHeader)
                {
                    actions.Add(new SpellSmartTagAction(trackingSpan, word, dictionary));
                }
                else
                {
                    if (actions.Count != 0)
                    {
                        smartTagSets.Add(new SmartTagActionSet(actions.AsReadOnly()));
                        actions = new List <ISmartTagAction>();
                    }

                    actions.Add(new LabelSmartTagAction(String.Format(CultureInfo.InvariantCulture, "{0} ({1})",
                                                                      word.Culture.EnglishName, word.Culture.Name)));
                }
            }

            if (actions.Count != 0)
            {
                smartTagSets.Add(new SmartTagActionSet(actions.AsReadOnly()));
            }

            if (smartTagSets.Count != 0)
            {
                // This acts as a place holder to tell the user to hold the Ctrl key down to replace all
                // occurrences of the selected word.
                actions = new List <ISmartTagAction>();
                actions.Add(new LabelSmartTagAction("Hold Ctrl to replace all"));

                smartTagSets.Insert(0, new SmartTagActionSet(actions.AsReadOnly()));
            }

            // Add Dictionary operations
            actions = new List <ISmartTagAction>();

            actions.Add(new SpellDictionarySmartTagAction(trackingSpan, dictionary, "Ignore Once",
                                                          DictionaryAction.IgnoreOnce, null));
            actions.Add(new SpellDictionarySmartTagAction(trackingSpan, dictionary, "Ignore All",
                                                          DictionaryAction.IgnoreAll, null));

            smartTagSets.Add(new SmartTagActionSet(actions.AsReadOnly()));

            if (misspellingType == MisspellingType.MisspelledWord)
            {
                actions = new List <ISmartTagAction>();

                foreach (var d in dictionary.Dictionaries)
                {
                    actions.Add(new SpellDictionarySmartTagAction(trackingSpan, dictionary,
                                                                  "Add to Dictionary", DictionaryAction.AddWord, d.Culture));
                }

                smartTagSets.Add(new SmartTagActionSet(actions.AsReadOnly()));
            }

            return(smartTagSets.AsReadOnly());
        }
        //=====================================================================

        /// <summary>
        /// Get the smart tag 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 read-only collection of smart tag action sets</returns>
        private ReadOnlyCollection <SmartTagActionSet> GetMisspellingSmartTagActions(SnapshotSpan errorSpan,
                                                                                     MisspellingType misspellingType, IEnumerable <ISpellingSuggestion> suggestions)
        {
            List <SmartTagActionSet> smartTagSets = new List <SmartTagActionSet>();
            List <ISmartTagAction>   actions      = new List <ISmartTagAction>();
            ITrackingSpan            trackingSpan = errorSpan.Snapshot.CreateTrackingSpan(errorSpan,
                                                                                          SpanTrackingMode.EdgeExclusive);

            if (dictionary.DictionaryCount > 1)
            {
                // Merge the same words from different dictionaries
                var words = suggestions.GroupBy(w => w.Suggestion).Select(g =>
                                                                          new MultiLanguageSpellSmartTagAction(trackingSpan, g.First(),
                                                                                                               g.Select(w => w.Culture), dictionary));

                actions.AddRange(words);
            }
            else
            {
                actions.AddRange(suggestions.Select(word => new SpellSmartTagAction(trackingSpan, word, dictionary)));
            }

            if (actions.Count != 0)
            {
                smartTagSets.Add(new SmartTagActionSet(actions.AsReadOnly()));
            }

            if (smartTagSets.Count != 0)
            {
                // This acts as a place holder to tell the user to hold the Ctrl key down to replace all
                // occurrences of the selected word.
                actions = new List <ISmartTagAction>();
                actions.Add(new LabelSmartTagAction("Hold Ctrl to replace all"));

                smartTagSets.Insert(0, new SmartTagActionSet(actions.AsReadOnly()));
            }

            // Add Dictionary operations
            actions = new List <ISmartTagAction>();

            actions.Add(new SpellDictionarySmartTagAction(trackingSpan, dictionary, "Ignore Once",
                                                          DictionaryAction.IgnoreOnce, null));
            actions.Add(new SpellDictionarySmartTagAction(trackingSpan, dictionary, "Ignore All",
                                                          DictionaryAction.IgnoreAll, null));

            smartTagSets.Add(new SmartTagActionSet(actions.AsReadOnly()));

            if (misspellingType == MisspellingType.MisspelledWord)
            {
                actions = new List <ISmartTagAction>();

                foreach (var d in dictionary.Dictionaries)
                {
                    actions.Add(new SpellDictionarySmartTagAction(trackingSpan, dictionary,
                                                                  "Add to Dictionary", DictionaryAction.AddWord, d.Culture));
                }

                smartTagSets.Add(new SmartTagActionSet(actions.AsReadOnly()));
            }

            return(smartTagSets.AsReadOnly());
        }
Example #8
0
        //=====================================================================

        /// <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,
                                                                                MisspellingType misspellingType, IEnumerable <ISpellingSuggestion> suggestions)
        {
            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 = suggestions.GroupBy(w => w.Suggestion).Select(g =>
                                                                          new MultiLanguageSpellSuggestedAction(trackingSpan, g.First(),
                                                                                                                g.Select(w => w.Culture), dictionary));

                actions.AddRange(words);
            }
            else
            {
                actions.AddRange(suggestions.Select(word => new SpellSuggestedAction(trackingSpan, word, dictionary)));
            }

            if (actions.Count != 0)
            {
                actionSets.Add(new SuggestedActionSet(actions, SuggestedActionSetPriority.Low));
            }

            // Add Dictionary operations
            actions = new List <ISuggestedAction>();

            actions.Add(new SpellDictionarySuggestedAction(trackingSpan, dictionary, "Ignore Once",
                                                           DictionaryAction.IgnoreOnce, null));
            actions.Add(new SpellDictionarySuggestedAction(trackingSpan, dictionary, "Ignore All",
                                                           DictionaryAction.IgnoreAll, null));

            actionSets.Add(new SuggestedActionSet(actions, SuggestedActionSetPriority.Low));

            if (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(actions, 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(new[] { new SuggestedActionSubmenu("Add to Dictionary",
                                                                                             new[] { new SuggestedActionSet(actions) }) }, SuggestedActionSetPriority.Low));
                }
            }

            return(actionSets);
        }