/// <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);
        }
Пример #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;
        }
Пример #3
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);
        }
Пример #4
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;
        }
        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);
        }
Пример #6
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);
        }