/// <summary> /// Determines if the border is being moused over and shows the info accordingly /// </summary> private void Border_ToolTipOpening(object sender, ToolTipEventArgs e) { var border = (Border)sender; e.Handled = true; bool KeepOpen() { var mousePoint = Mouse.GetPosition(border); return(!( mousePoint.X > border.ActualWidth || mousePoint.X < 0 || mousePoint.Y > border.ActualHeight || mousePoint.Y < 0 )); } var toolTipPresenter = _toolTipService.CreatePresenter( _textView, new ToolTipParameters(trackMouse: true, ignoreBufferChange: false, KeepOpen) ); _ = StartToolTipServiceAsync(toolTipPresenter); }
/// <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 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 && IsCaretWithinSpanOrAtEnd(analyzedSession.TrackingSpan, analyzedSession.TextView.TextSnapshot, caretPoint.Value)) { // Create a tooltip presenter that stays alive, even when the user types, without tracking the mouse. _toolTipPresenter = _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; }; } }