Пример #1
0
        //=====================================================================

        /// <summary>
        /// Get the configuration settings for the specified buffer
        /// </summary>
        /// <param name="buffer">The buffer for which to get the configuration settings</param>
        /// <returns>The spell checker configuration settings for the buffer or null if one is not provided or
        /// is disabled for the given buffer.</returns>
        public SpellCheckerConfiguration GetConfiguration(ITextBuffer buffer)
        {
            SpellCheckerConfiguration config = null;
            bool isDisabled = false;

            // If not given a buffer or already checked for and found to be disabled, don't go any further
            if (buffer != null && !buffer.Properties.TryGetProperty(SpellCheckerDisabledKey, out isDisabled) &&
                !buffer.Properties.TryGetProperty(typeof(SpellCheckerConfiguration), out config))
            {
                // Generate the configuration settings unique to the file
                config = this.GenerateConfiguration(buffer);

                if (!config.SpellCheckAsYouType || config.IsExcludedByExtension(buffer.GetFilenameExtension()))
                {
                    // Mark it as disabled so that we don't have to check again
                    buffer.Properties[SpellCheckerDisabledKey] = true;
                    config = null;
                }
                else
                {
                    buffer.Properties[typeof(SpellCheckerConfiguration)] = config;
                }
            }

            return(config);
        }
Пример #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>);
        }