Example #1
0
        private void HostSession(IIntellisenseSession session, IPopupIntellisensePresenter popupPresenter)
        {
            // If the Popup presenter doesn't have anything to draw, don't even bother.

            if (popupPresenter.SurfaceElement == null)
            {
                return;
            }

            ISpaceReservationManager manager = _textView.GetSpaceReservationManager(popupPresenter.SpaceReservationManagerName);

            if (manager != null)
            {
                // If this is the first time we've seen this manager, subscribe to its AgentChanged event.

                if (!_reservationManagerIndex.ContainsValue(manager))
                {
                    manager.AgentChanged += this.OnSpaceReservationManager_AgentChanged;
                }

                ISpaceReservationAgent agent = manager.CreatePopupAgent(popupPresenter.PresentationSpan,
                                                                        popupPresenter.PopupStyles,
                                                                        popupPresenter.SurfaceElement);

                // We'll need to hold-on to the manager and agent so that later, when we want to hide this popup, we can clear
                // the agent.

                _reservationManagerIndex[agent] = manager;
                _reservationAgentIndex[session] = agent;

                // When we add this agent to the manager's collection, the popup will become visible.

                manager.AddAgent(agent);
            }
        }
        void PopupIntellisensePresenter_PropertyChanged(IPopupIntellisensePresenter popupPresenter, string propertyName)
        {
            if (wpfTextView.IsClosed)
            {
                UnregisterPopupIntellisensePresenterEvents(popupPresenter);
                return;
            }
            var sessionState = TryGetSessionState(popupPresenter);

            Debug.Assert(sessionState != null);
            if (sessionState == null)
            {
                return;
            }
            if (propertyName == nameof(popupPresenter.PresentationSpan) || propertyName == nameof(popupPresenter.PopupStyles))
            {
                var presentationSpan = popupPresenter.PresentationSpan;
                if (presentationSpan == null || sessionState.SpaceReservationAgent == null)
                {
                    PresenterUpdated(popupPresenter.Session);
                }
                else
                {
                    sessionState.SpaceReservationManager.UpdatePopupAgent(sessionState.SpaceReservationAgent, presentationSpan, popupPresenter.PopupStyles);
                }
            }
            else if (propertyName == nameof(popupPresenter.SurfaceElement))
            {
                PresenterUpdated(popupPresenter.Session);
            }
        }
Example #3
0
 internal WordCompletionPresenter(IPopupIntellisensePresenter source)
 {
     _popupIntellisensePresenter = source;
     _intellisenseCommandTarget  = source as IIntellisenseCommandTarget;
     _mouseProcessor             = source as IMouseProcessor;
     _disposable         = source as IDisposable;
     _componentConnector = source as IComponentConnector;
 }
 internal WordCompletionPresenter(IPopupIntellisensePresenter source)
 {
     _popupIntellisensePresenter = source;
     _intellisenseCommandTarget = source as IIntellisenseCommandTarget;
     _mouseProcessor = source as IMouseProcessor;
     _disposable = source as IDisposable;
     _componentConnector = source as IComponentConnector;
 }
 void UnregisterPopupIntellisensePresenterEvents(IPopupIntellisensePresenter popupPresenter)
 {
     if (popupPresenter != null)
     {
         popupPresenter.PopupStylesChanged      -= PopupIntellisensePresenter_PopupStylesChanged;
         popupPresenter.PresentationSpanChanged -= PopupIntellisensePresenter_PresentationSpanChanged;
         popupPresenter.SurfaceElementChanged   -= PopupIntellisensePresenter_SurfaceElementChanged;
     }
 }
Example #6
0
 SessionState TryGetSessionState(IPopupIntellisensePresenter popupPresenter)
 {
     foreach (var sessionState in sessionStates)
     {
         if (sessionState.PopupIntellisensePresenter == popupPresenter)
         {
             return(sessionState);
         }
     }
     return(null);
 }
Example #7
0
        private void OnPresenterPopupStylesChanged(object sender, ValueChangedEventArgs <Text.Adornments.PopupStyles> e)
        {
            IPopupIntellisensePresenter presenter = sender as IPopupIntellisensePresenter;

            if (presenter == null)
            {
                throw new ArgumentException("Expected 'sender' to be of type IPopupIntellisensePresenter", "sender");
            }

            this.RehostPresenter(presenter);
        }
Example #8
0
        private void OnPresenterSurfaceElementChanged(object sender, EventArgs e)
        {
            IPopupIntellisensePresenter presenter = sender as IPopupIntellisensePresenter;

            if (presenter == null)
            {
                throw new ArgumentException("Expected 'sender' to be of type IPopupIntellisensePresenter", "sender");
            }

            this.RehostPresenter(presenter);
        }
Example #9
0
        private void RehostSession(IIntellisenseSession session)
        {
            IPopupIntellisensePresenter popupPresenter = session.Presenter as IPopupIntellisensePresenter;

            if (popupPresenter == null)
            {
                throw new ArgumentException("Expected to rehost a session with presenter of type IPopupIntellisensePresenter",
                                            "session");
            }

            // If the Popup presenter doesn't have anything to draw, don't even bother.

            if (popupPresenter.PresentationSpan == null || popupPresenter.SurfaceElement == null)
            {
                return;
            }

            // We need to re-draw this popup.  This involves tearing down the old agent and re-creating it.  First, we've
            // got to find it.  We'll also want to save-off a reference to it so that we know we're re-hosting this session.  The
            // process of tearing-down and re-adding a space reservation agent is loud and messy.  We don't want to accidentally
            // dismiss this session, thinking that it went out-of-focus.

            _sessionBeingRehosted = session;

            try
            {
                ISpaceReservationAgent oldAgent = null;
                if ((_reservationAgentIndex.TryGetValue(session, out oldAgent)) && (oldAgent != null))
                {
                    ISpaceReservationManager manager = null;
                    if ((_reservationManagerIndex.TryGetValue(oldAgent, out manager)) && (manager != null))
                    {
                        manager.UpdatePopupAgent(oldAgent, popupPresenter.PresentationSpan, popupPresenter.PopupStyles);
                    }
                }
                else
                {
                    // This presenter hasn't yet been hosted in a popup.  Host it for the first time.

                    this.HostSession(session, popupPresenter);
                }
            }
            finally
            {
                // Clear out our state.  We're no longer re-hosting this session.

                _sessionBeingRehosted = null;
            }
        }
Example #10
0
        private void OnSessionPresenterChanged(object sender, EventArgs e)
        {
            // It could have been any of our sessions that fired this event.  That means we've first got to determine which one it
            // was.

            IIntellisenseSession session = sender as IIntellisenseSession;

            if (session == null)
            {
                throw new ArgumentException("Expected 'sender' to be of type IIntellisenseSession", "sender");
            }

            // Since the presenter changed, we could have a new owner for the keyboard.  Figure it out.

            this.ReleaseKeyboard();

            // We should make sure to re-subscribe to events on this new presenter.

            IPopupIntellisensePresenter popupPresenter = session.Presenter as IPopupIntellisensePresenter;

            if (popupPresenter != null)
            {
                popupPresenter.PresentationSpanChanged += this.OnPresenterPresentationSpanChanged;
                popupPresenter.SurfaceElementChanged   += this.OnPresenterSurfaceElementChanged;
                popupPresenter.PopupStylesChanged      += this.OnPresenterPopupStylesChanged;

                this.RehostSession(session);
            }
            else
            {
                ICustomIntellisensePresenter customPresenter = session.Presenter as ICustomIntellisensePresenter;
                if (customPresenter != null)
                {
                    customPresenter.Render();
                }
            }

            if ((session.TextView != null) && (_tipManager != null))
            {
                var tip = session.Presenter as IObscuringTip;
                if (tip != null)
                {
                    _tipManager.PushTip(session.TextView, tip);
                }
            }

            this.DoleOutKeyboard();
        }
        public void PushSession(IIntellisenseSession session)
        {
            // make sure the session is not already dismissed
            if (session.IsDismissed)
            {
                throw new ArgumentException("We cannot push a dismissed session on to the stack.");
            }

            // Tell whatever session has the keyboard to release it.  After we push, we'll figure out who deserves it.

            this.ReleaseKeyboard();

            // Add the session to our list.

            _sessions.Push(session);

            // Subscribe to events on this new session

            session.Dismissed        += this.OnSessionDismissed;
            session.PresenterChanged += this.OnSessionPresenterChanged;

            IPopupIntellisensePresenter popupPresenter = session.Presenter as IPopupIntellisensePresenter;

            if (popupPresenter != null)
            {
                popupPresenter.SurfaceElementChanged   += this.OnPresenterSurfaceElementChanged;
                popupPresenter.PresentationSpanChanged += this.OnPresenterPresentationSpanChanged;
                popupPresenter.PopupStylesChanged      += this.OnPresenterPopupStylesChanged;

                // Since this is a popup presenter, we're responsible for drawing it.  Therefore, here we'll create a popup agent
                // that will take care of rendering this session's presenter.

                this.HostSession(session, popupPresenter);
            }
            else
            {
                ICustomIntellisensePresenter customPresenter = session.Presenter as ICustomIntellisensePresenter;
                if (customPresenter != null)
                {
                    customPresenter.Render();
                }
            }

            // Now, figure out once again who deserves to own the keyboard.

            this.DoleOutKeyboard();
        }
Example #12
0
        private void RehostPresenter(IPopupIntellisensePresenter presenter)
        {
            IIntellisenseSession session = presenter.Session;

            if (session != null)
            {
                // Technically, there's probably no reason to release the keyboard here, but maybe there's a presenter that
                // conditionally holds-on to the keyboard depending on its presentation.  In that case, we'll give them another
                // chance to own the keyboard here.

                this.ReleaseKeyboard();

                RehostSession(session);

                this.DoleOutKeyboard();
            }
        }
Example #13
0
        private void RemoveSession(IIntellisenseSession session)
        {
            // A session can be added to the stack in only one way.  It must be pushed onto the top of the stack.  A session can
            // come off the stack in many ways, however.  It can be popped, or the session can be dismissed, etc.  We'll assume that
            // the session passed-in has already been removed from the stack.  We're just interested in removing it from our indices
            // and getting ourselves unhooked from its delegates.

            // First, unsubscribe from events to which we previously subscribed

            session.Dismissed        -= this.OnSessionDismissed;
            session.PresenterChanged -= this.OnSessionPresenterChanged;

            IPopupIntellisensePresenter popupPresenter = session.Presenter as IPopupIntellisensePresenter;

            if (popupPresenter != null)
            {
                popupPresenter.SurfaceElementChanged   -= this.OnPresenterSurfaceElementChanged;
                popupPresenter.PresentationSpanChanged -= this.OnPresenterPresentationSpanChanged;
                popupPresenter.PopupStylesChanged      -= this.OnPresenterPopupStylesChanged;

                // Now, see if we have a popup agent for this presenter.  If so, let's get rid of it.  This is what will "hide" the
                // popup.

                ISpaceReservationAgent agent;
                if ((_reservationAgentIndex.TryGetValue(session, out agent)) && (agent != null))
                {
                    ISpaceReservationManager manager;
                    if ((_reservationManagerIndex.TryGetValue(agent, out manager)) && (manager != null))
                    {
                        manager.RemoveAgent(agent);
                        _reservationManagerIndex.Remove(agent);

                        // If this was the last reference to this particular manager, stop listening to its AgentChanged event.

                        if (!_reservationManagerIndex.ContainsValue(manager))
                        {
                            manager.AgentChanged -= this.OnSpaceReservationManager_AgentChanged;
                        }
                    }
                    _reservationAgentIndex.Remove(session);
                }
            }
        }
		void PopupIntellisensePresenter_PropertyChanged(IPopupIntellisensePresenter popupPresenter, string propertyName) {
			if (wpfTextView.IsClosed) {
				UnregisterPopupIntellisensePresenterEvents(popupPresenter);
				return;
			}
			var sessionState = TryGetSessionState(popupPresenter);
			Debug.Assert(sessionState != null);
			if (sessionState == null)
				return;
			if (propertyName == nameof(popupPresenter.PresentationSpan) || propertyName == nameof(popupPresenter.PopupStyles)) {
				var presentationSpan = popupPresenter.PresentationSpan;
				if (presentationSpan == null || sessionState.SpaceReservationAgent == null)
					PresenterUpdated(popupPresenter.Session);
				else
					sessionState.SpaceReservationManager.UpdatePopupAgent(sessionState.SpaceReservationAgent, presentationSpan, popupPresenter.PopupStyles);
			}
			else if (propertyName == nameof(popupPresenter.SurfaceElement))
				PresenterUpdated(popupPresenter.Session);
		}
		void UnregisterPopupIntellisensePresenterEvents(IPopupIntellisensePresenter popupPresenter) {
			if (popupPresenter != null) {
				popupPresenter.PopupStylesChanged -= PopupIntellisensePresenter_PopupStylesChanged;
				popupPresenter.PresentationSpanChanged -= PopupIntellisensePresenter_PresentationSpanChanged;
				popupPresenter.SurfaceElementChanged -= PopupIntellisensePresenter_SurfaceElementChanged;
			}
		}
		SessionState TryGetSessionState(IPopupIntellisensePresenter popupPresenter) {
			foreach (var sessionState in sessionStates) {
				if (sessionState.PopupIntellisensePresenter == popupPresenter)
					return sessionState;
			}
			return null;
		}