Ejemplo n.º 1
0
        public async Task DismissAsync()
        {
            // Ensure that we have the UI thread. To avoid races, the rest of this method must be sync.
            await this.joinableTaskContext.Factory.SwitchToMainThreadAsync();

            var currentState = this.State;

            if (currentState != QuickInfoSessionState.Dismissed)
            {
                // Cancel any running computations.
                this.uiThreadOnlyLinkedCancellationTokenSource?.Cancel();
                this.uiThreadOnlyLinkedCancellationTokenSource = null;

                // Dismiss presenter.
                var presenter = this.uiThreadOnlyPresenter;
                if (presenter != null)
                {
                    presenter.Dismissed -= this.OnDismissed;
                    this.uiThreadOnlyPresenter.Dismiss();

                    this.uiThreadOnlyPresenter = null;
                }

                // Update object state.
                Volatile.Write(ref this.content, ImmutableList <object> .Empty);
                Volatile.Write(ref this.applicableToSpan, null);

                // Alert subscribers on the UI thread.
                this.TransitionTo(QuickInfoSessionState.Dismissed);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Waits for the description to be created and updates the tooltip with the associated information
        /// </summary>
        private async Task StartToolTipServiceAsync(IToolTipPresenter toolTipPresenter)
        {
            var uiList = await Task.Run(() => CreateDescriptionAsync(_threadingContext.DisposalToken)).ConfigureAwait(false);

            await _threadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(_threadingContext.DisposalToken);

            toolTipPresenter.StartOrUpdate(_textView.TextSnapshot.CreateTrackingSpan(_span.Start, _span.Length, SpanTrackingMode.EdgeInclusive), uiList);
        }
Ejemplo n.º 3
0
        public GuardedToolTipPresenter(
            IGuardedOperations guardedOperations,
            IToolTipPresenter presenter)
        {
            this.guardedOperations = guardedOperations ?? throw new ArgumentNullException(nameof(guardedOperations));
            this.Presenter         = presenter ?? throw new ArgumentNullException(nameof(presenter));

            presenter.Dismissed += this.OnDismissed;
        }
 /// <summary>
 /// Create a new instance of <seealso cref="StackdriverTagger"/> class.
 /// </summary>
 /// <param name="view">The text view on which the tag shows.</param>
 /// <param name="sourceBuffer">The source buffer with the text view.</param>
 /// <param name="toolTipProviderFactory">The tool tip provider. <seealso cref="IToolTipProviderFactory"/>. </param>
 public StackdriverTagger(ITextView view, ITextBuffer sourceBuffer, IToolTipService toolTipService)
 {
     _sourceBuffer             = sourceBuffer;
     _view                     = view;
     _view.LayoutChanged      += OnViewLayoutChanged;
     _view.LostAggregateFocus += OnLostAggregateFocus;
     _toolTipProvider          = toolTipService.CreatePresenter(_view);
     if (_view == ActiveTagData.Current?.TextView)
     {
         ShowOrUpdateToolTip();
     }
 }
        internal void CancelAndDismissExistingSessions()
        {
            AssertIsForeground();

            if (CurrentSession != null)
            {
                CurrentSession.Cancel();
                CurrentSession = null;
            }

            if (_toolTipPresenter != null)
            {
                _toolTipPresenter.Dismiss();
                _toolTipPresenter = null;
            }

            // For test purposes only!
            TEST_MostRecentToolTipContent = null;
        }
        internal void CancelAndDismissExistingSessions()
        {
            ThreadingContext.ThrowIfNotOnUIThread();

            if (CurrentSession != null)
            {
                CurrentSession.Cancel();
                CurrentSession = null;
            }

            if (_toolTipPresenter != null)
            {
                _toolTipPresenter.Dismiss();
                _toolTipPresenter = null;
            }

            // For test purposes only!
            TEST_MostRecentToolTipContent = null;
        }
        internal void EventHookupFoundInSession(EventHookupSession analyzedSession)
        {
            AssertIsForeground();

            var caretPoint = analyzedSession.TextView.GetCaretPoint(analyzedSession.SubjectBuffer);

            // only generate tooltip if it is not already shown (_toolTipPresenter == null)
            // Ensure the analyzed session matches the current session and that the caret is still
            // in the session's tracking span.
            if (_toolTipPresenter == null &&
                CurrentSession == analyzedSession &&
                caretPoint.HasValue &&
                analyzedSession.TrackingSpan.GetSpan(CurrentSession.TextView.TextSnapshot).Contains(caretPoint.Value))
            {
                // Create a tooltip presenter that stays alive, even when the user types, without tracking the mouse.
                _toolTipPresenter = this._toolTipService.CreatePresenter(analyzedSession.TextView,
                                                                         new ToolTipParameters(trackMouse: false, ignoreBufferChange: true));

                // tooltips text is: Program_MyEvents;      (Press TAB to insert)
                // GetEventNameTask() gets back the event name, only needs to add a semicolon after it.
                var textRuns = new[]
                {
                    new ClassifiedTextRun(ClassificationTypeNames.MethodName, analyzedSession.GetEventNameTask.Result, ClassifiedTextRunStyle.UseClassificationFont),
                    new ClassifiedTextRun(ClassificationTypeNames.Punctuation, ";", ClassifiedTextRunStyle.UseClassificationFont),
                    new ClassifiedTextRun(ClassificationTypeNames.Text, CSharpEditorResources.Press_TAB_to_insert),
                };
                var content = new[] { new ClassifiedTextElement(textRuns) };

                _toolTipPresenter.StartOrUpdate(analyzedSession.TrackingSpan, content);

                // For test purposes only!
                TEST_MostRecentToolTipContent = content;

                // Watch all text buffer changes & caret moves while this event hookup session is active
                analyzedSession.TextView.TextSnapshot.TextBuffer.Changed += TextBuffer_Changed;
                CurrentSession.Dismissed += () => { analyzedSession.TextView.TextSnapshot.TextBuffer.Changed -= TextBuffer_Changed; };

                analyzedSession.TextView.Caret.PositionChanged += Caret_PositionChanged;
                CurrentSession.Dismissed += () => { analyzedSession.TextView.Caret.PositionChanged -= Caret_PositionChanged; };
            }
        }
Ejemplo n.º 8
0
        private void CreateAndStartPresenter()
        {
            IntellisenseUtilities.ThrowIfNotOnMainThread(this.joinableTaskContext);
            Debug.Assert(this.uiThreadOnlyPresenter == null);

            // Configure presenter behavior.
            var parameters = new ToolTipParameters(
                this.Options.HasFlag(QuickInfoSessionOptions.TrackMouse),
                keepOpenFunc: this.ContentRequestsKeepOpen);

            // Create and show presenter.
            this.uiThreadOnlyPresenter            = this.toolTipService.CreatePresenter(this.TextView, parameters);
            this.uiThreadOnlyPresenter.Dismissed += this.OnDismissed;
            this.uiThreadOnlyPresenter.StartOrUpdate(this.ApplicableToSpan, this.Content);

            // Ensure that the presenter didn't dismiss the session.
            if (this.State != QuickInfoSessionState.Dismissed)
            {
                // Update state and alert subscribers on the UI thread.
                this.TransitionTo(QuickInfoSessionState.Visible);
            }
        }