//=====================================================================

        /// <summary>
        /// Creates a tag provider for the specified view and buffer
        /// </summary>
        /// <typeparam name="T">The tag type</typeparam>
        /// <param name="textView">The text view</param>
        /// <param name="buffer">The text buffer</param>
        /// <returns>The tag provider for the specified view and buffer or null if the buffer does not match the
        /// one in the view or spell checking as you type is disabled.</returns>
        public ITagger <T> CreateTagger <T>(ITextView textView, ITextBuffer buffer) where T : ITag
        {
            SpellingTagger spellingTagger = null;

            // Make sure we are only tagging the top buffer
            if (textView == null || buffer == null || spellingService == null || textView.TextBuffer != buffer)
            {
                return(null);
            }

            if (!textView.Properties.TryGetProperty(typeof(SpellingTagger), out spellingTagger))
            {
                // Getting the configuration determines if spell checking is enabled for this file
                var config = spellingService.GetConfiguration(buffer);

                if (config != null)
                {
                    var dictionary = spellingService.GetDictionary(buffer);

                    if (dictionary != null)
                    {
                        var naturalTextAggregator = aggregatorFactory.CreateTagAggregator <INaturalTextTag>(textView,
                                                                                                            TagAggregatorOptions.MapByContentType);
                        var urlAggregator = aggregatorFactory.CreateTagAggregator <IUrlTag>(textView);

                        spellingTagger = new SpellingTagger(buffer, textView, naturalTextAggregator, urlAggregator,
                                                            config, dictionary);
                        textView.Properties[typeof(SpellingTagger)] = spellingTagger;
                    }
                }
            }

            return(spellingTagger as ITagger <T>);
        }
Пример #2
0
        //=====================================================================

        /// <summary>
        /// Creates a tag provider for the specified view and buffer
        /// </summary>
        /// <typeparam name="T">The tag type</typeparam>
        /// <param name="textView">The text view</param>
        /// <param name="buffer">The text buffer</param>
        /// <returns>The tag provider for the specified view and buffer or null if the buffer does not match the
        /// one in the view or spell checking as you type is disabled.</returns>
        public ITagger <T> CreateTagger <T>(ITextView textView, ITextBuffer buffer) where T : ITag
        {
            SpellingTagger spellingTagger;

            // Make sure we only tagging top buffer and only if wanted
            if (textView.TextBuffer != buffer || !SpellCheckerConfiguration.SpellCheckAsYouType ||
                SpellCheckerConfiguration.IsExcludedByExtension(buffer.GetFilenameExtension()))
            {
                return(null);
            }

            if (textView.Properties.TryGetProperty(typeof(SpellingTagger), out spellingTagger))
            {
                return(spellingTagger as ITagger <T>);
            }

            var dictionary = spellingDictionaryFactory.GetDictionary(buffer);

            if (dictionary == null)
            {
                return(null);
            }

            var naturalTextAggregator = aggregatorFactory.CreateTagAggregator <INaturalTextTag>(textView,
                                                                                                TagAggregatorOptions.MapByContentType);
            var urlAggregator = aggregatorFactory.CreateTagAggregator <IUrlTag>(textView);

            spellingTagger = new SpellingTagger(buffer, textView, naturalTextAggregator, urlAggregator, dictionary);
            textView.Properties[typeof(SpellingTagger)] = spellingTagger;

            return(spellingTagger as ITagger <T>);
        }