/// <summary>
        /// Called when view gets aggregate focus. Typically implemented if derived class
        /// needs to access native VS adapters, like IVsTextView.
        /// </summary>
        protected virtual void OnTextViewGotAggregateFocus(ITextView textView, ITextBuffer textBuffer)
        {
            var listeners = ComponentLocatorForContentType <ITextViewCreationListener, IComponentContentTypes> .ImportMany(Shell.CompositionService, textBuffer.ContentType);

            foreach (var listener in listeners)
            {
                listener.Value.OnTextViewCreated(textView, textBuffer);
            }
        }
        public static ISuggestedActionsSource Create(ITextView textView, ITextBuffer textBuffer, IServiceContainer services)
        {
            // Check for detached documents in the interactive window projected buffers
            var cs   = services.GetService <ICompositionService>();
            var ctrs = services.GetService <IContentTypeRegistryService>();
            var suggestedActionProviders =
                ComponentLocatorForContentType <ISuggestedActionProvider, IComponentContentTypes>
                .ImportMany(cs, ctrs.GetContentType(MdContentTypeDefinition.ContentType)).Select(p => p.Value);

            return(new RmdSuggestedActionsSource(textView, textBuffer, suggestedActionProviders, services));
        }
        public void VsTextViewCreated(IVsTextView textViewAdapter)
        {
            var textView = EditorAdaptersFactoryService.GetWpfTextView(textViewAdapter);

            var formatter = ComponentLocatorForContentType <IEditorFormatterProvider, IComponentContentTypes> .ImportOne(HtmlContentTypeDefinition.HtmlContentType).Value;

            textView.Properties.GetOrCreateSingletonProperty <SurroundWith>(() => new SurroundWith(textViewAdapter, textView, CompletionBroker));
            textView.Properties.GetOrCreateSingletonProperty <ExpandSelection>(() => new ExpandSelection(textViewAdapter, textView));
            textView.Properties.GetOrCreateSingletonProperty <ContractSelection>(() => new ContractSelection(textViewAdapter, textView));
            textView.Properties.GetOrCreateSingletonProperty <EnterFormat>(() => new EnterFormat(textViewAdapter, textView, formatter));
            textView.Properties.GetOrCreateSingletonProperty <MinifySelection>(() => new MinifySelection(textViewAdapter, textView));
            textView.Properties.GetOrCreateSingletonProperty <HtmlGoToDefinition>(() => new HtmlGoToDefinition(textViewAdapter, textView));
        }
Exemple #4
0
        public void VsTextViewCreated(IVsTextView textViewAdapter)
        {
            var textView = EditorAdaptersFactoryService.GetWpfTextView(textViewAdapter);

            var formatter = ComponentLocatorForContentType <IEditorFormatterProvider, IComponentContentTypes> .ImportOne(HtmlContentTypeDefinition.HtmlContentType).Value;

            textView.Properties.GetOrCreateSingletonProperty(() => new ExpandSelection(textViewAdapter, textView));
            textView.Properties.GetOrCreateSingletonProperty(() => new ContractSelection(textViewAdapter, textView));
            textView.Properties.GetOrCreateSingletonProperty(() => new EnterFormat(textViewAdapter, textView, formatter, CompletionBroker));
            textView.Properties.GetOrCreateSingletonProperty(() => new MinifySelection(textViewAdapter, textView));
            textView.Properties.GetOrCreateSingletonProperty(() => new HtmlGoToDefinition(textViewAdapter, textView));
            textView.Properties.GetOrCreateSingletonProperty(() => new HtmlFindAllReferences(textViewAdapter, textView));
            textView.Properties.GetOrCreateSingletonProperty(() => new RetriggerTarget(textViewAdapter, textView, CompletionBroker));
        }
Exemple #5
0
        private void AddClassificationFromCompositeToken(List <ClassificationSpan> classifications, ITextSnapshot textSnapshot, ICompositeToken composite)
        {
            string contentTypeName = composite.ContentType;
            IClassificationNameProvider compositeNameProvider;

            if (!_compositeClassificationNameProviders.TryGetValue(contentTypeName, out compositeNameProvider))
            {
                IContentType contentType = ContentTypeRegistryService.GetContentType(contentTypeName);
                var          providers   = ComponentLocatorForContentType <IClassificationNameProvider, IComponentContentTypes> .
                                           FilterByContentTypeExact(contentType, ClassificationNameProviders);

                var lazyProvider = providers.FirstOrDefault();
                Debug.Assert(lazyProvider != null);

                if (lazyProvider != null)
                {
                    compositeNameProvider = lazyProvider.Value;
                    _compositeClassificationNameProviders[contentTypeName] = compositeNameProvider;
                }
            }

            foreach (object token in composite.TokenList)
            {
                // We don't necessarily map each token to a classification
                ITextRange range;
                string     classificationName = compositeNameProvider.GetClassificationName(token, out range);

                if (!string.IsNullOrEmpty(classificationName))
                {
                    IClassificationType ct = ClassificationRegistryService.GetClassificationType(classificationName);

                    if (ct != null)
                    {
                        Span tokenSpan        = new Span(range.Start, range.Length);
                        ClassificationSpan cs = new ClassificationSpan(new SnapshotSpan(textSnapshot, tokenSpan), ct);
                        classifications.Add(cs);
                    }
                }
            }
        }
Exemple #6
0
        public static ISettingsStorage GetSettings(ICompositionCatalog compositionCatalog, string contentTypeName)
        {
            ISettingsStorage settingsStorage = null;

            lock (_settingsLock) {
                if (_settingStorageMap.TryGetValue(contentTypeName, out settingsStorage))
                {
                    return(settingsStorage);
                }

                // Need to find the settings using MEF (don't use MEF inside of other locks, that can lead to deadlock)

                var contentTypeRegistry = compositionCatalog.ExportProvider.GetExportedValue <IContentTypeRegistryService>();

                var contentType = contentTypeRegistry.GetContentType(contentTypeName);
                Debug.Assert(contentType != null, "Cannot find content type object for " + contentTypeName);

                settingsStorage = ComponentLocatorForOrderedContentType <IWritableSettingsStorage> .FindFirstOrderedComponent(compositionCatalog.CompositionService, contentType);

                if (settingsStorage == null)
                {
                    settingsStorage = ComponentLocatorForOrderedContentType <ISettingsStorage> .FindFirstOrderedComponent(compositionCatalog.CompositionService, contentType);
                }

                if (settingsStorage == null)
                {
                    var storages = ComponentLocatorForContentType <IWritableSettingsStorage, IComponentContentTypes> .ImportMany(compositionCatalog.CompositionService, contentType);

                    if (storages.Any())
                    {
                        settingsStorage = storages.First().Value;
                    }
                }

                if (settingsStorage == null)
                {
                    var readonlyStorages = ComponentLocatorForContentType <ISettingsStorage, IComponentContentTypes> .ImportMany(compositionCatalog.CompositionService, contentType);

                    if (readonlyStorages.Any())
                    {
                        settingsStorage = readonlyStorages.First().Value;
                    }
                }

                Debug.Assert(settingsStorage != null, String.Format(CultureInfo.CurrentCulture,
                                                                    "Cannot find settings storage export for content type '{0}'", contentTypeName));

                if (_settingStorageMap.ContainsKey(contentTypeName))
                {
                    // some other thread came along and loaded settings already
                    settingsStorage = _settingStorageMap[contentTypeName];
                }
                else
                {
                    _settingStorageMap[contentTypeName] = settingsStorage;
                    settingsStorage.LoadFromStorage();
                }
            }

            return(settingsStorage);
        }
Exemple #7
0
        /// <summary>
        /// Called when view gets aggregate focus. Typically implemented if derived class
        /// needs to access native VS adapters, like IVsTextView.
        /// </summary>
        protected virtual void OnTextViewGotAggregateFocus(ITextView textView, ITextBuffer textBuffer)
        {
            IEnumerable <Lazy <ITextViewCreationListener, IComponentContentTypes> > listeners = ComponentLocatorForContentType <ITextViewCreationListener, IComponentContentTypes> .ImportMany(textBuffer.ContentType);

            foreach (var listener in listeners)
            {
                listener.Value.OnTextViewCreated(textView, textBuffer);
            }
        }