예제 #1
0
        public void ShowToolTip(ITrackingSpan span, object toolTipContent, PopupStyles style)
        {
            if (span == null)
            {
                throw new ArgumentNullException(nameof(span));
            }
            if (toolTipContent == null)
            {
                throw new ArgumentNullException(nameof(toolTipContent));
            }
            if ((style & (PopupStyles.DismissOnMouseLeaveText | PopupStyles.DismissOnMouseLeaveTextOrContent)) == (PopupStyles.DismissOnMouseLeaveText | PopupStyles.DismissOnMouseLeaveTextOrContent))
            {
                throw new ArgumentOutOfRangeException(nameof(style));
            }

            ClearToolTip();

            var uiElement = GetUIElement(toolTipContent);

            if (uiElement == null)
            {
                throw new ArgumentException();
            }

            spaceReservationManager.AgentChanged += SpaceReservationManager_AgentChanged;
            toolTipAgent = spaceReservationManager.CreatePopupAgent(span, style, uiElement);
            spaceReservationManager.AddAgent(toolTipAgent);
        }
예제 #2
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);
            }
        }
예제 #3
0
        public void UpdatePopupAgent(ISpaceReservationAgent agent, ITrackingSpan visualSpan, PopupStyles styles)
        {
            if (wpfTextView.IsClosed)
            {
                throw new InvalidOperationException();
            }
            if (agent == null)
            {
                throw new ArgumentNullException(nameof(agent));
            }
            if (visualSpan == null)
            {
                throw new ArgumentNullException(nameof(visualSpan));
            }
            if ((styles & (PopupStyles.DismissOnMouseLeaveText | PopupStyles.DismissOnMouseLeaveTextOrContent)) == (PopupStyles.DismissOnMouseLeaveText | PopupStyles.DismissOnMouseLeaveTextOrContent))
            {
                throw new ArgumentOutOfRangeException(nameof(styles));
            }
            if (!spaceReservationAgents.Contains(agent))
            {
                throw new ArgumentOutOfRangeException(nameof(agent));
            }
            var popupAgent = agent as PopupSpaceReservationAgent;

            if (popupAgent == null)
            {
                throw new ArgumentException();
            }
            popupAgent.Update(visualSpan, styles);
            UpdateAggregateFocus();
            wpfTextView.QueueSpaceReservationStackRefresh();
        }
예제 #4
0
        public void ShowToolTip(ITrackingSpan span, object toolTipContent, PopupStyles style)
        {
            if (span == null)
            {
                throw new ArgumentNullException("span");
            }
            if (span.TextBuffer != _textView.TextBuffer)
            {
                throw new ArgumentException("Invalid span");
            }
            if (toolTipContent == null)
            {
                throw new ArgumentNullException("toolTipContent");
            }

            var element = toolTipContent as Control;

            if (element == null)
            {
                string toolTipContentAsString = toolTipContent as string;
                if (toolTipContentAsString != null)
                {
                    element = BuildTooltipUIElement(toolTipContentAsString);
                }
                else
                {
                    throw new ArgumentException("Invalid contnet", nameof(toolTipContent));
                }
            }

            this.ClearToolTip();
            _agent = _spaceReservationManager.CreatePopupAgent(span, style, element);
            _spaceReservationManager.AddAgent(_agent);
        }
예제 #5
0
 void OnAgentChanged(object sender, SpaceReservationAgentChangedEventArgs e)
 {
     if (_agent == e.OldAgent)
     {
         _agent = null;
     }
 }
예제 #6
0
 void SpaceReservationManager_AgentChanged(object sender, SpaceReservationAgentChangedEventArgs e)
 {
     if (e.OldAgent == toolTipAgent)
     {
         spaceReservationManager.AgentChanged -= SpaceReservationManager_AgentChanged;
         toolTipAgent = null;
     }
 }
예제 #7
0
 SessionState TryGetSessionState(ISpaceReservationAgent agent)
 {
     foreach (var sessionState in sessionStates)
     {
         if (sessionState.SpaceReservationAgent == agent)
         {
             return(sessionState);
         }
     }
     return(null);
 }
예제 #8
0
        public void AddAgent(ISpaceReservationAgent agent)
        {
            if (agent == null)
            {
                throw new ArgumentNullException("agent");
            }

            _agents.Add(agent);
            this.ChangeAgents(null, agent);
            this.CheckFocusChange();
            _view.QueueSpaceReservationStackRefresh();
        }
예제 #9
0
		public bool RemoveAgent(ISpaceReservationAgent agent) {
			if (agent == null)
				throw new ArgumentNullException(nameof(agent));
			if (!spaceReservationAgents.Remove(agent))
				return false;
			agent.GotFocus -= SpaceReservationAgent_GotFocus;
			agent.LostFocus -= SpaceReservationAgent_LostFocus;
			agent.Hide();
			AgentChanged?.Invoke(this, new SpaceReservationAgentChangedEventArgs(agent, null));
			UpdateAggregateFocus();
			wpfTextView.QueueSpaceReservationStackRefresh();
			return true;
		}
예제 #10
0
		public void AddAgent(ISpaceReservationAgent agent) {
			if (wpfTextView.IsClosed)
				throw new InvalidOperationException();
			if (agent == null)
				throw new ArgumentNullException(nameof(agent));
			if (spaceReservationAgents.Contains(agent))
				throw new InvalidOperationException();
			spaceReservationAgents.Add(agent);
			agent.GotFocus += SpaceReservationAgent_GotFocus;
			agent.LostFocus += SpaceReservationAgent_LostFocus;
			AgentChanged?.Invoke(this, new SpaceReservationAgentChangedEventArgs(null, agent));
			UpdateAggregateFocus();
			wpfTextView.QueueSpaceReservationStackRefresh();
		}
예제 #11
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;
            }
        }
예제 #12
0
 public bool RemoveAgent(ISpaceReservationAgent agent)
 {
     if (agent == null)
     {
         throw new ArgumentNullException(nameof(agent));
     }
     if (!spaceReservationAgents.Remove(agent))
     {
         return(false);
     }
     agent.GotFocus  -= SpaceReservationAgent_GotFocus;
     agent.LostFocus -= SpaceReservationAgent_LostFocus;
     agent.Hide();
     AgentChanged?.Invoke(this, new SpaceReservationAgentChangedEventArgs(agent, null));
     UpdateAggregateFocus();
     wpfTextView.QueueSpaceReservationStackRefresh();
     return(true);
 }
예제 #13
0
        public bool RemoveAgent(ISpaceReservationAgent agent)
        {
            if (agent == null)
            {
                throw new ArgumentNullException("agent");
            }

            if (_agents.Remove(agent))
            {
                this.ChangeAgents(agent, null);
                this.CheckFocusChange();
                _view.QueueSpaceReservationStackRefresh();

                return(true);
            }

            return(false);
        }
예제 #14
0
		public void ShowToolTip(ITrackingSpan span, object toolTipContent, PopupStyles style) {
			if (span == null)
				throw new ArgumentNullException(nameof(span));
			if (toolTipContent == null)
				throw new ArgumentNullException(nameof(toolTipContent));
			if ((style & (PopupStyles.DismissOnMouseLeaveText | PopupStyles.DismissOnMouseLeaveTextOrContent)) == (PopupStyles.DismissOnMouseLeaveText | PopupStyles.DismissOnMouseLeaveTextOrContent))
				throw new ArgumentOutOfRangeException(nameof(style));

			ClearToolTip();

			var uiElement = GetUIElement(toolTipContent);
			if (uiElement == null)
				throw new ArgumentException();

			spaceReservationManager.AgentChanged += SpaceReservationManager_AgentChanged;
			toolTipAgent = spaceReservationManager.CreatePopupAgent(span, style, uiElement);
			spaceReservationManager.AddAgent(toolTipAgent);
		}
예제 #15
0
 public void AddAgent(ISpaceReservationAgent agent)
 {
     if (wpfTextView.IsClosed)
     {
         throw new InvalidOperationException();
     }
     if (agent == null)
     {
         throw new ArgumentNullException(nameof(agent));
     }
     if (spaceReservationAgents.Contains(agent))
     {
         throw new InvalidOperationException();
     }
     spaceReservationAgents.Add(agent);
     agent.GotFocus  += SpaceReservationAgent_GotFocus;
     agent.LostFocus += SpaceReservationAgent_LostFocus;
     AgentChanged?.Invoke(this, new SpaceReservationAgentChangedEventArgs(null, agent));
     UpdateAggregateFocus();
     wpfTextView.QueueSpaceReservationStackRefresh();
 }
예제 #16
0
        public void Open(ITrackingSpan triggerSpan, IList <CompletionItem> items, CompletionItem selectedItem, CompletionItem suggestionModeItem, bool suggestionMode, bool isSoftSelected)
        {
            Instance = this;
            textView.Properties ["RoslynCompletionPresenterSession.IsCompletionActive"] = true;
            textView.LostAggregateFocus += CloseOnTextviewLostFocus;
            box.ShowAll();
            var manager = textView.GetSpaceReservationManager("completion");

            agent = manager.CreatePopupAgent(triggerSpan, Microsoft.VisualStudio.Text.Adornments.PopupStyles.None, Xwt.Toolkit.CurrentEngine.WrapWidget(box, Xwt.NativeWidgetSizing.DefaultPreferredSize));
            //HACK...
            Theme = ((Microsoft.VisualStudio.Text.Editor.Implementation.PopupAgent.PopUpContainer)((Microsoft.VisualStudio.Text.Editor.Implementation.PopupAgent)agent)._popup)._popup.Theme;
            Theme.CornerRadius = 0;
            Theme.Padding      = 0;
            UpdateStyle();
            Ide.Gui.Styles.Changed += HandleThemeChanged;
            IdeApp.Preferences.ColorScheme.Changed += HandleThemeChanged;

            Update(triggerSpan, items, selectedItem, suggestionModeItem, suggestionMode, isSoftSelected);
            manager.AddAgent(agent);
            textView.QueueSpaceReservationStackRefresh();
        }
예제 #17
0
        internal void PositionAndDisplay(GeometryGroup reservedGeometry)
        {
            _view.GuardedOperations.CallExtensionPoint(this,
                                                       () =>
            {
                if (_agents.Count != 0)
                {
                    if (_view.IsVisible)
                    {
                        for (int i = _agents.Count - 1; (i >= 0); --i)
                        {
                            var agent = _agents[i];

                            var requestedGeometry = agent.PositionAndDisplay(reservedGeometry);
                            if (requestedGeometry == null)
                            {
                                _agents.RemoveAt(i);
                                this.ChangeAgents(agent, null);
                            }
                            else if (!requestedGeometry.IsEmpty())
                            {
                                reservedGeometry.Children.Add(requestedGeometry);
                            }
                        }
                    }
                    else
                    {
                        for (int i = _agents.Count - 1; (i >= 0); --i)
                        {
                            ISpaceReservationAgent agent = _agents[i];
                            _agents.RemoveAt(i);
                            this.ChangeAgents(agent, null);
                        }
                    }

                    this.CheckFocusChange();
                }
            });
        }
예제 #18
0
        public void UpdatePopupAgent(ISpaceReservationAgent agent, ITrackingSpan visualSpan, PopupStyles styles)
        {
            if (agent == null)
            {
                throw new ArgumentNullException("agent");
            }
            if (visualSpan == null)
            {
                throw new ArgumentNullException("visualSpan");
            }

            PopupAgent popupAgent = agent as PopupAgent;

            if (popupAgent == null)
            {
                throw new ArgumentException("The agent is not a PopupAgent", "agent");
            }

            popupAgent.SetVisualSpan(visualSpan);
            popupAgent._style = styles;
            this.CheckFocusChange();
            _view.QueueSpaceReservationStackRefresh();
        }
예제 #19
0
        internal void ChangeAgents(ISpaceReservationAgent oldAgent, ISpaceReservationAgent newAgent)
        {
            if (oldAgent != null)
            {
                oldAgent.LostFocus -= OnAgentLostFocus;
                oldAgent.GotFocus  -= OnAgentGotFocus;
                oldAgent.Hide();
            }

            EventHandler <SpaceReservationAgentChangedEventArgs> agentChanged = this.AgentChanged;

            if (agentChanged != null)
            {
                agentChanged(this, new SpaceReservationAgentChangedEventArgs(oldAgent, newAgent));
            }

            if (newAgent != null)
            {
                newAgent.LostFocus += OnAgentLostFocus;
                newAgent.GotFocus  += OnAgentGotFocus;
            }

            _view.QueueSpaceReservationStackRefresh();
        }
예제 #20
0
 /// <summary>
 /// Initializes a new instance of <see cref="SpaceReservationAgentChangedEventArgs"/>.
 /// </summary>
 /// <param name="oldAgent">The <see cref="ISpaceReservationAgent "/> associated with the previous value.</param>
 /// <param name="newAgent">The <see cref="ISpaceReservationAgent "/> associated with the new value.</param>
 public SpaceReservationAgentChangedEventArgs(ISpaceReservationAgent oldAgent, ISpaceReservationAgent newAgent)
 {
     _oldAgent = oldAgent;
     _newAgent = newAgent;
 }
예제 #21
0
		public void UpdatePopupAgent(ISpaceReservationAgent agent, ITrackingSpan visualSpan, PopupStyles styles) {
			if (wpfTextView.IsClosed)
				throw new InvalidOperationException();
			if (agent == null)
				throw new ArgumentNullException(nameof(agent));
			if (visualSpan == null)
				throw new ArgumentNullException(nameof(visualSpan));
			if ((styles & (PopupStyles.DismissOnMouseLeaveText | PopupStyles.DismissOnMouseLeaveTextOrContent)) == (PopupStyles.DismissOnMouseLeaveText | PopupStyles.DismissOnMouseLeaveTextOrContent))
				throw new ArgumentOutOfRangeException(nameof(styles));
			if (!spaceReservationAgents.Contains(agent))
				throw new ArgumentOutOfRangeException(nameof(agent));
			var popupAgent = agent as PopupSpaceReservationAgent;
			if (popupAgent == null)
				throw new ArgumentException();
			popupAgent.Update(visualSpan, styles);
			UpdateAggregateFocus();
			wpfTextView.QueueSpaceReservationStackRefresh();
		}
예제 #22
0
		SessionState TryGetSessionState(ISpaceReservationAgent agent) {
			foreach (var sessionState in sessionStates) {
				if (sessionState.SpaceReservationAgent == agent)
					return sessionState;
			}
			return null;
		}
예제 #23
0
		void SpaceReservationManager_AgentChanged(object sender, SpaceReservationAgentChangedEventArgs e) {
			if (e.OldAgent == toolTipAgent) {
				spaceReservationManager.AgentChanged -= SpaceReservationManager_AgentChanged;
				toolTipAgent = null;
			}
		}