コード例 #1
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);
        }
コード例 #2
0
 void OnAgentChanged(object sender, MDSpaceReservationAgentChangedEventArgs e)
 {
     if (_agent == e.OldAgent)
     {
         _agent = null;
     }
 }
コード例 #3
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;
            }

            IMDSpaceReservationManager 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;
                }

                IMDSpaceReservationAgent 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);
            }
        }
コード例 #4
0
        public void AddAgent(IMDSpaceReservationAgent agent)
        {
            if (agent == null)
            {
                throw new ArgumentNullException("agent");
            }

            _agents.Add(agent);
            this.ChangeAgents(null, agent);
            this.CheckFocusChange();
            _view.QueueSpaceReservationStackRefresh();
        }
コード例 #5
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
            {
                IMDSpaceReservationAgent oldAgent = null;
                if ((_reservationAgentIndex.TryGetValue(session, out oldAgent)) && (oldAgent != null))
                {
                    IMDSpaceReservationManager 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;
            }
        }
コード例 #6
0
        public bool RemoveAgent(IMDSpaceReservationAgent agent)
        {
            if (agent == null)
            {
                throw new ArgumentNullException("agent");
            }

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

                return(true);
            }

            return(false);
        }
コード例 #7
0
        public void PositionAndDisplay(GeometryGroup reservedGeometry)
        {
            _view.GuardedOperations.CallExtensionPoint(this,
                                                       () =>
            {
                if (_agents.Count != 0)
                {
                    if (_view.Visible)
                    {
                        for (int i = _agents.Count - 1; (i >= 0); --i)
                        {
                            IMDSpaceReservationAgent agent = _agents[i];

                            Geometry 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)
                        {
                            IMDSpaceReservationAgent agent = _agents[i];
                            _agents.RemoveAt(i);
                            this.ChangeAgents(agent, null);
                        }
                    }

                    this.CheckFocusChange();
                }
            });
        }
コード例 #8
0
        public void UpdatePopupAgent(IMDSpaceReservationAgent 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();
        }
コード例 #9
0
        internal void ChangeAgents(IMDSpaceReservationAgent oldAgent, IMDSpaceReservationAgent newAgent)
        {
            if (oldAgent != null)
            {
                oldAgent.LostFocus -= OnAgentLostFocus;
                oldAgent.GotFocus  -= OnAgentGotFocus;
                oldAgent.Hide();
            }

            EventHandler <MDSpaceReservationAgentChangedEventArgs> agentChanged = this.AgentChanged;

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

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

            _view.QueueSpaceReservationStackRefresh();
        }
コード例 #10
0
 /// <summary>
 /// Initializes a new instance of <see cref="MDSpaceReservationAgentChangedEventArgs"/>.
 /// </summary>
 /// <param name="oldAgent">The <see cref="IMDSpaceReservationAgent "/> associated with the previous value.</param>
 /// <param name="newAgent">The <see cref="IMDSpaceReservationAgent "/> associated with the new value.</param>
 public MDSpaceReservationAgentChangedEventArgs(IMDSpaceReservationAgent oldAgent, IMDSpaceReservationAgent newAgent)
 {
     _oldAgent = oldAgent;
     _newAgent = newAgent;
 }