Example #1
0
        public void SubjectBuffersConnected(
            ITextView textView,
            ConnectionReason reason,
            IReadOnlyCollection <ITextBuffer> subjectBuffers)
        {
            IntellisenseManager manager = textView.Properties.GetOrCreateSingletonProperty(
                delegate { return(new IntellisenseManager(this, textView)); });

            // Create the appropriate Intellisense controllers for the content types in the buffer graph. It's important that we do
            // this after creating the brokers, as the controllers will most likely start using the brokers immediately.

            for (int f = 0; f < this.IntellisenseControllerFactories.Count; ++f)
            {
                var factory = this.IntellisenseControllerFactories[f];

                // filter subject buffers to get the ones that match the factory content types
                FrugalList <ITextBuffer> matchingSubjectBuffers = new FrugalList <ITextBuffer>();
                foreach (string factoryContentType in factory.Metadata.ContentTypes)
                {
                    foreach (ITextBuffer subjectBuffer in subjectBuffers)
                    {
                        if (subjectBuffer.ContentType.IsOfType(factoryContentType) &&
                            !matchingSubjectBuffers.Contains(subjectBuffer))
                        {
                            matchingSubjectBuffers.Add(subjectBuffer);
                        }
                    }
                }

                if (matchingSubjectBuffers.Count > 0)
                {
                    // This controller factory is registered for the content type we understand.  Go ahead and create
                    // one.  Note that this won't give us a handle to a controller object.  We wouldn't be able to do anything
                    // with such a reference anyway.

                    if (manager.Controllers[f] == null)
                    {
                        manager.Controllers[f] = this.GuardedOperations.InstantiateExtension
                                                     (factory, factory,
                                                     provider => provider.TryCreateIntellisenseController(textView, matchingSubjectBuffers));
                    }
                    else
                    {
                        foreach (ITextBuffer matchingSubjectBuffer in matchingSubjectBuffers)
                        {
                            manager.Controllers[f].ConnectSubjectBuffer(matchingSubjectBuffer);
                        }
                    }
                }
            }
        }
Example #2
0
        public void SubjectBuffersDisconnected(
            ITextView textView,
            ConnectionReason reason,
            IReadOnlyCollection <ITextBuffer> subjectBuffers)
        {
            // Notify controllers that subject buffer is no longer interesting. We let the controller figure out if the
            // buffer was interesting in the first place.
            IntellisenseManager manager = textView.Properties.GetProperty <IntellisenseManager>(typeof(IntellisenseManager));

            for (int f = 0; f < manager.Controllers.Length; ++f)
            {
                if (manager.Controllers[f] != null)
                {
                    foreach (ITextBuffer subjectBuffer in subjectBuffers)
                    {
                        manager.Controllers[f].DisconnectSubjectBuffer(subjectBuffer);
                    }
                }
            }
        }