protected override bool RequestSession(IEditorView view, object context)
        {
            var linkTagContext = context as LinkTagContext;
            if (linkTagContext == null)
                return false;

            var linkTag = linkTagContext.TagRange.Tag;
            var session = new QuickInfoSession()
            {
                Context = context,
            };

            if (linkTag.NavigationType == LinkTagNavigationType.ExternalUrl)
            {
                var htmlSnippet = string.Format("{0}<br/>Shift + Click to follow link", linkTag.Url);
                session.Content = new HtmlContentProvider(htmlSnippet).GetContent();
            }
            else
            {
                session.Content = new QuickDocumentView() {DocumentId = linkTag.Url};
            }

            session.Open(view, linkTagContext.TagRange.SnapshotRange);

            return true;
        }
Exemple #2
0
        protected override bool RequestSession(IEditorView view, object context)
        {
            var linkTagContext = context as LinkTagContext;

            if (linkTagContext == null)
            {
                return(false);
            }

            var linkTag = linkTagContext.TagRange.Tag;
            var session = new QuickInfoSession()
            {
                Context = context,
            };

            if (linkTag.NavigationType == LinkTagNavigationType.ExternalUrl)
            {
                var htmlSnippet = string.Format("{0}<br/>Shift + Click to follow link", linkTag.Url);
                session.Content = new HtmlContentProvider(htmlSnippet).GetContent();
            }
            else
            {
                session.Content = new QuickDocumentView()
                {
                    DocumentId = linkTag.Url
                };
            }

            session.Open(view, linkTagContext.TagRange.SnapshotRange);

            return(true);
        }
        /// <summary>
        /// Requests that an <see cref="IQuickInfoSession"/> be opened for the specified <see cref="IEditorView"/>.
        /// </summary>
        /// <param name="view">The <see cref="IEditorView"/> that will host the session.</param>
        /// <param name="context">A context object returned by <see cref="GetContext"/>.</param>
        /// <returns>
        /// <c>true</c> if a session was opened; otherwise, <c>false</c>.
        /// </returns>
        protected override bool RequestSession(IEditorView view, object context)
        {
            // Create a session and assign a context that can be used to identify it
            QuickInfoSession session = new QuickInfoSession();

            session.Context = context;

            TextRangeContext textRangeContext = context as TextRangeContext;

            if (textRangeContext != null)
            {
                // Get a reader initialized to the offset
                ITextSnapshotReader reader = view.CurrentSnapshot.GetReader(textRangeContext.Range.StartOffset);
                IToken token = reader.Token;
                if (token != null)
                {
                    // Create some marked-up content indicating the token at the offset and the line it's on
                    session.Content = new HtmlContentProvider(
                        String.Format("Target word: <b>{0}</b><br/>Token: <b>{1}</b><br/><span style=\"color: Green;\">Found on line {2}.</span>",
                                      HtmlContentProvider.Escape(view.CurrentSnapshot.GetSubstring(textRangeContext.Range)),
                                      token.Key,
                                      view.OffsetToPosition(textRangeContext.Range.StartOffset).Line + 1), view.DefaultBackgroundColor).GetContent();

                    // Open the session
                    session.Open(view, textRangeContext.Range);
                    return(true);
                }
            }
            else
            {
                LineNumberMarginContext marginContext = context as LineNumberMarginContext;
                if (marginContext != null)
                {
                    // Create some marked-up content indicating the line number
                    session.Content = new HtmlContentProvider(String.Format("Line number: <b>{0}</b>", marginContext.LineIndex + 1), view.DefaultBackgroundColor).GetContent();

                    // Get the margin
                    IEditorViewMargin margin = view.Margins[EditorViewMarginKeys.LineNumber];

                    // Get the view line that contains the line
                    ITextViewLine viewLine = view.GetViewLine(new TextPosition(marginContext.LineIndex, 0));
                    if ((margin != null) && (viewLine != null))
                    {
                        // Get line bounds relative to the margin
                        Rect bounds = view.TransformFromTextArea(viewLine.Bounds);
                        bounds.X     = 0;
                        bounds.Width = margin.VisualElement.RenderSize.Width;

                        // Open the session
                        session.Open(view, PlacementMode.Bottom, view.VisualElement, bounds);
                        return(true);
                    }
                }
            }
            return(false);
        }
Exemple #4
0
        internal void CancelAndDismissExistingSessions()
        {
            AssertIsForeground();

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

            if (QuickInfoSession != null)
            {
                QuickInfoSession.Dismiss();
                QuickInfoSession = null;
                TEST_MostRecentQuickInfoContent = null;
            }
        }
        protected override bool RequestSession(IEditorView view, object context)
        {
            var linkTagContext = context as LinkTagContext;
            if (linkTagContext == null)
                return false;

            var linkTag = linkTagContext.TagRange.Tag;
            var htmlSnippet = linkTag.NavigationType == LinkTagNavigationType.ExternalUrl ? "Shift-Click to navigate to Url " + linkTag.Url
                : "Shift-Click to navigate to document " + linkTag.Url;

            var session = new QuickInfoSession()
            {
                Context = context,
                Content = new HtmlContentProvider(htmlSnippet).GetContent()
            };

            session.Open(view, linkTagContext.TagRange.SnapshotRange);

            return true;
        }
Exemple #6
0
        internal void EventHookupFoundInSession(EventHookupSession analyzedSession)
        {
            AssertIsForeground();

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

            // Ensure the analyzed session matches the current session and that the caret is still
            // in the session's tracking span.
            if (CurrentSession == analyzedSession &&
                QuickInfoSession == null &&
                caretPoint.HasValue &&
                analyzedSession.TrackingSpan.GetSpan(CurrentSession.TextView.TextSnapshot).Contains(caretPoint.Value))
            {
                QuickInfoSession = _quickInfoBroker.CreateQuickInfoSession(analyzedSession.TextView,
                                                                           analyzedSession.TrackingPoint,
                                                                           trackMouse: false);

                // Special indicator that this quick info session was created by event hookup,
                // which is used when deciding whether and how to display the session
                QuickInfoSession.Properties.AddProperty(typeof(EventHookupSessionManager), this);
                QuickInfoSession.Properties.AddProperty(QuickInfoUtilities.EventHookupKey, "EventHookup");

                // Watch all text buffer changes & caret moves while this quick info 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; };

                QuickInfoSession.Start();

                // HACK! Workaround for VS dismissing quick info sessions on buffer changed events.
                // This must happen after the QuickInfoSession is started.
                if (_prematureDismissalPreventer != null)
                {
                    _prematureDismissalPreventer.HACK_EnsureQuickInfoSessionNotDismissedPrematurely(analyzedSession.TextView);
                    QuickInfoSession.Dismissed += (s, e) => { _prematureDismissalPreventer.HACK_OnQuickInfoSessionDismissed(analyzedSession.TextView); };
                }
            }
        }
        protected override bool RequestSession(IEditorView view, object context)
        {
            var model = context as QuickInfoModel;

            if (model == null)
            {
                return(false);
            }

            var text = model.SemanticModel.SyntaxTree.Text;
            var textSnapshotRange = text.ToSnapshotRange(model.Span);
            var textRange         = textSnapshotRange.TextRange;
            var content           = SymbolContentProvider.GetContentProvider(model.Glyph, model.Markup).GetContent();

            var quickInfoSession = new QuickInfoSession();

            quickInfoSession.Context = context;
            quickInfoSession.Content = content;
            quickInfoSession.Open(view, textRange);
            return(true);
        }
Exemple #8
0
        protected override bool RequestSession(IEditorView view, object context)
        {
            var linkTagContext = context as LinkTagContext;

            if (linkTagContext == null)
            {
                return(false);
            }

            var linkTag     = linkTagContext.TagRange.Tag;
            var htmlSnippet = linkTag.NavigationType == LinkTagNavigationType.ExternalUrl ? "Shift-Click to navigate to Url " + linkTag.Url
                : "Shift-Click to navigate to document " + linkTag.Url;

            var session = new QuickInfoSession()
            {
                Context = context,
                Content = new HtmlContentProvider(htmlSnippet).GetContent()
            };

            session.Open(view, linkTagContext.TagRange.SnapshotRange);

            return(true);
        }
        /// <summary>
        /// Requests that an <see cref="IQuickInfoSession"/> be opened for the specified <see cref="IEditorView"/>.
        /// </summary>
        /// <param name="view">The <see cref="IEditorView"/> that will host the session.</param>
        /// <param name="context">A context object returned by <see cref="GetContext"/>.</param>
        /// <returns>
        /// <c>true</c> if a session was opened; otherwise, <c>false</c>.
        /// </returns>
        protected override bool RequestSession(IEditorView view, object context)
        {
            SimpleContext languageContext = context as SimpleContext;

            if ((languageContext != null) && (languageContext.InitializationSnapshotRange.HasValue))
            {
                // Create a session and assign a context that can be used to identify it
                QuickInfoSession session = new QuickInfoSession();
                session.Context = context;

                switch (languageContext.Type)
                {
                case SimpleContextType.FunctionReference:
                    // When hovering over a function reference...
                    if (languageContext.TargetFunction != null)
                    {
                        session.Content = new FunctionContentProvider(view.HighlightingStyleRegistry, languageContext.TargetFunction, true, view.DefaultBackgroundColor).GetContent();
                    }
                    break;
                }

                // If content was created...
                if (session.Content != null)
                {
                    // Ensure the caret is visible (only if not tracking pointer input)
                    if (!this.CanTrackPointerInput)
                    {
                        view.Scroller.ScrollToCaret();
                    }

                    // Open the session
                    session.Open(view, languageContext.InitializationSnapshotRange.Value);
                    return(true);
                }
            }
            return(false);
        }