/// <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); }
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; }; } }
private void DisplayTooltip(SnapshotSpan span) { _toolTipProvider.Dismiss(); _isTooltipShown = true; // Note, keep a local copy of ActiveTagData.Current. // In case ActiveTagData.Current changes by other thread or by async re-entrancy. ActiveTagData activeData = ActiveTagData.Current; if (activeData == null) { Debug.WriteLine($"{nameof(ActiveTagData.Current)} is empty, this is probably a code bug."); return; } List <object> uiList = new List <object>(); uiList.Add(activeData.TextView); activeData.TooltipControl.Width = _view.ViewportWidth; _toolTipProvider.StartOrUpdate( span.Snapshot.CreateTrackingSpan(span, SpanTrackingMode.EdgeExclusive), uiList); }