Beispiel #1
0
        public static IDisposable Advise <TObject, TEventInterface>(this IConnectionPointContainer container, TObject @object)
            where TObject : class, TEventInterface
            where TEventInterface : class
        {
            if (container == null)
            {
                throw new ArgumentNullException("container");
            }
            if (@object == null)
            {
                throw new ArgumentNullException("object");
            }

            Guid             eventGuid = typeof(TEventInterface).GUID;
            IConnectionPoint connectionPoint;

            container.FindConnectionPoint(eventGuid, out connectionPoint);
            if (connectionPoint == null)
            {
                throw new ArgumentException();
            }

            uint cookie;

            connectionPoint.Advise(@object, out cookie);
            return(new ConnectionPointCookie(connectionPoint, cookie));
        }
        int IVsCodeWindowEvents.OnNewView(IVsTextView pView)
        {
            if (pView == null)
            {
                throw new ArgumentNullException("pView");
            }

            IConnectionPointContainer connectionPointContainer = pView as IConnectionPointContainer;

            if (connectionPointContainer != null)
            {
                Guid             textViewEventsGuid = typeof(IVsTextViewEvents).GUID;
                IConnectionPoint connectionPoint;
                connectionPointContainer.FindConnectionPoint(ref textViewEventsGuid, out connectionPoint);
                if (connectionPoint != null)
                {
                    uint cookie;
                    connectionPoint.Advise(this, out cookie);
                    if (cookie != 0)
                    {
                        _textViewEventsCookies.Add(pView, cookie);
                    }
                }
            }

            return(VSConstants.S_OK);
        }
        int IVsCodeWindowEvents.OnCloseView(IVsTextView pView)
        {
            if (pView == null)
            {
                throw new ArgumentNullException("pView");
            }

            uint cookie;

            if (_textViewEventsCookies.TryGetValue(pView, out cookie))
            {
                _textViewEventsCookies.Remove(pView);

                IConnectionPointContainer connectionPointContainer = pView as IConnectionPointContainer;
                if (connectionPointContainer != null)
                {
                    Guid             textViewEventsGuid = typeof(IVsTextViewEvents).GUID;
                    IConnectionPoint connectionPoint;
                    connectionPointContainer.FindConnectionPoint(ref textViewEventsGuid, out connectionPoint);
                    if (connectionPoint != null)
                    {
                        connectionPoint.Unadvise(cookie);
                    }
                }
            }

            return(VSConstants.S_OK);
        }
Beispiel #4
0
        protected static void ReleaseHook(object container, Type connectionType, uint cookie)
        {
            if (container == null)
            {
                throw new ArgumentNullException("container");
            }
            else if (connectionType == null)
            {
                throw new ArgumentNullException("connectionType");
            }

            if (cookie == 0)
            {
                return;
            }

            IOleConnectionPointContainer ct = container as IOleConnectionPointContainer;

            if (ct == null)
            {
                return;
            }

            Guid cpGuid = connectionType.GUID;
            IOleConnectionPoint point;

            ct.FindConnectionPoint(ref cpGuid, out point);

            if (point != null)
            {
                point.Unadvise(cookie);
            }
        }
Beispiel #5
0
        public static void Unadvise <TEventInterface>([NotNull] this IConnectionPointContainer container, uint cookie)
            where TEventInterface : class
        {
            Requires.NotNull(container, nameof(container));

            if (cookie == 0)
            {
                return;
            }

            Guid             eventGuid = typeof(TEventInterface).GUID;
            IConnectionPoint connectionPoint;

            container.FindConnectionPoint(eventGuid, out connectionPoint);
            if (connectionPoint == null)
            {
                throw new ArgumentException();
            }

            connectionPoint.Unadvise(cookie);
        }
Beispiel #6
0
        public static IDisposable Advise <TObject, TEventInterface>([NotNull] this IConnectionPointContainer container, [NotNull] TObject @object)
            where TObject : class, TEventInterface
            where TEventInterface : class
        {
            Requires.NotNull(container, nameof(container));
            Requires.NotNull(@object, nameof(@object));

            Guid             eventGuid = typeof(TEventInterface).GUID;
            IConnectionPoint connectionPoint;

            container.FindConnectionPoint(eventGuid, out connectionPoint);
            if (connectionPoint == null)
            {
                throw new ArgumentException();
            }

            uint cookie;

            connectionPoint.Advise(@object, out cookie);
            return(new ConnectionPointCookie(connectionPoint, cookie));
        }
        public static void Unadvise <TEventInterface>(this IConnectionPointContainer container, uint cookie)
            where TEventInterface : class
        {
            Contract.Requires <ArgumentNullException>(container != null, "container");

            if (cookie == 0)
            {
                return;
            }

            Guid             eventGuid = typeof(TEventInterface).GUID;
            IConnectionPoint connectionPoint;

            container.FindConnectionPoint(eventGuid, out connectionPoint);
            if (connectionPoint == null)
            {
                throw new ArgumentException();
            }

            connectionPoint.Unadvise(cookie);
        }
Beispiel #8
0
        protected static bool TryHookConnectionPoint <T>(object container, Type connectionType, T sink, out uint cookie)
            where T : class
        {
            if (container == null)
            {
                throw new ArgumentNullException("container");
            }
            else if (connectionType == null)
            {
                throw new ArgumentNullException("connectionType");
            }
            else if (sink == null)
            {
                throw new ArgumentNullException("sink");
            }

            ThreadHelper.ThrowIfNotOnUIThread();

            IOleConnectionPointContainer ct = container as IOleConnectionPointContainer;

            if (ct == null)
            {
                cookie = 0;
                return(false);
            }

            Guid cpGuid = connectionType.GUID;
            IOleConnectionPoint point;

            ct.FindConnectionPoint(ref cpGuid, out point);

            if (point == null)
            {
                cookie = 0;
                return(false);
            }

            point.Advise(sink, out cookie);
            return(true);
        }
        public static IDisposable Advise <TObject, TEventInterface>(this IConnectionPointContainer container, TObject @object)
            where TObject : class, TEventInterface
            where TEventInterface : class
        {
            Contract.Requires <ArgumentNullException>(container != null, "container");
            Contract.Requires <ArgumentNullException>(@object != null, "object");
            Contract.Ensures(Contract.Result <IDisposable>() != null);

            Guid             eventGuid = typeof(TEventInterface).GUID;
            IConnectionPoint connectionPoint;

            container.FindConnectionPoint(eventGuid, out connectionPoint);
            if (connectionPoint == null)
            {
                throw new ArgumentException();
            }

            uint cookie;

            connectionPoint.Advise(@object, out cookie);
            return(new ConnectionPointCookie(connectionPoint, cookie));
        }
        public EditorNavigationDropdownBar(IVsCodeWindow codeWindow, IVsEditorAdaptersFactoryService editorAdaptersFactory, IEnumerable <IEditorNavigationSource> sources, IBufferGraphFactoryService bufferGraphFactoryService, IEditorNavigationTypeRegistryService editorNavigationTypeRegistryService)
        {
            Contract.Requires <ArgumentNullException>(codeWindow != null, "codeWindow");
            Contract.Requires <ArgumentNullException>(editorAdaptersFactory != null, "editorAdaptersFactory");
            Contract.Requires <ArgumentNullException>(sources != null, "sources");
            Contract.Requires <ArgumentNullException>(bufferGraphFactoryService != null, "bufferGraphFactoryService");
            Contract.Requires <ArgumentNullException>(editorNavigationTypeRegistryService != null, "editorNavigationTypeRegistryService");

            this._codeWindow            = codeWindow;
            this._editorAdaptersFactory = editorAdaptersFactory;
            this._sources = sources;
            this._bufferGraphFactoryService           = bufferGraphFactoryService;
            this._editorNavigationTypeRegistryService = editorNavigationTypeRegistryService;
            this._currentTextView = editorAdaptersFactory.GetWpfTextView(codeWindow.GetLastActiveView());
            this._dispatcher      = this._currentTextView.VisualElement.Dispatcher;
            this._imageList       = new ImageList()
            {
                ColorDepth = System.Windows.Forms.ColorDepth.Depth32Bit
            };

            _navigationControls =
                this._sources
                .SelectMany(source => source.GetNavigationTypes())
                .Distinct()
                //.OrderBy(...)
                .Select(type => Tuple.Create(type, new List <IEditorNavigationTarget>()))
                .ToArray();

            _selectedItem = new IEditorNavigationTarget[_navigationControls.Length];

            if (this._navigationControls.Length == 0)
            {
                return;
            }

            IConnectionPointContainer connectionPointContainer = codeWindow as IConnectionPointContainer;

            if (connectionPointContainer != null)
            {
                Guid             textViewEventsGuid = typeof(IVsCodeWindowEvents).GUID;
                IConnectionPoint connectionPoint;
                connectionPointContainer.FindConnectionPoint(ref textViewEventsGuid, out connectionPoint);
                if (connectionPoint != null)
                {
                    connectionPoint.Advise(this, out _codeWindowEventsCookie);
                }
            }

            IVsTextView primaryView = codeWindow.GetPrimaryView();

            if (primaryView != null)
            {
                ((IVsCodeWindowEvents)this).OnNewView(primaryView);
            }

            IVsTextView secondaryView = codeWindow.GetSecondaryView();

            if (secondaryView != null)
            {
                ((IVsCodeWindowEvents)this).OnNewView(secondaryView);
            }

            foreach (var source in this._sources)
            {
                source.NavigationTargetsChanged += WeakEvents.AsWeak(OnNavigationTargetsChanged, eh => source.NavigationTargetsChanged -= eh);
                UpdateNavigationTargets(source);
            }

            _currentTextView.Caret.PositionChanged += OnCaretPositionChanged;
        }