예제 #1
0
        private IContentProvider GetHtmlContent()
        {
            var parameter = _parameterIndex < _signatureItem.Parameters.Length
                                ? _signatureItem.Parameters[_parameterIndex]
                                : null;

            var signatureText = _signatureItem.Content;

            if (parameter == null)
            {
                return(new DirectContentProvider(signatureText));
            }

            var start  = parameter.Span.Start;
            var length = parameter.Span.Length;
            var end    = parameter.Span.End;

            var beforeParameterText = signatureText.Substring(0, start);
            var parameterText       = signatureText.Substring(start, length);
            var postParameterText   = signatureText.Substring(end);

            var sb = new StringBuilder();

            sb.Append(beforeParameterText);
            sb.Append(@"<b>");
            sb.Append(HtmlContentProvider.Escape(parameterText));
            sb.Append(@"</b>");
            sb.Append(postParameterText);
            var htmlSnippet = sb.ToString();

            return(new HtmlContentProvider(htmlSnippet));
        }
        /////////////////////////////////////////////////////////////////////////////////////////////////////
        // NON-PUBLIC PROCEDURES
        /////////////////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Looks into an AST for function declaration symbols to add.
        /// </summary>
        /// <param name="symbols">The list to update.</param>
        /// <param name="snapshot">The <see cref="ITextSnapshot"/> to examine.</param>
        /// <param name="compilationUnit">The <see cref="IAstNode"/> to examine.</param>
        private void AddFunctionDeclarationSymbolsFromAst(IList <INavigableSymbol> symbols, ITextSnapshot snapshot, CompilationUnit compilationUnit)
        {
            if ((compilationUnit != null) && (compilationUnit.HasMembers))
            {
                // Loop through the AST nodes
                foreach (FunctionDeclaration functionAstNode in compilationUnit.Members)
                {
                    // If the function declaration has a name and body...
                    if ((!string.IsNullOrEmpty(functionAstNode.Name)) && (functionAstNode.Body != null) &&
                        (functionAstNode.StartOffset.HasValue) && (functionAstNode.EndOffset.HasValue))
                    {
                        // Build the content
                        var htmlSnippet = new StringBuilder("<img src=\"resource:MethodPublic\" align=\"absbottom\" /> ");
                        htmlSnippet.Append(HtmlContentProvider.Escape(functionAstNode.Name));

                        // Create the symbol
                        var symbol = new NavigableSymbol()
                        {
                            ContentProvider = new HtmlContentProvider(htmlSnippet.ToString()),
                            SnapshotRange   = new TextSnapshotRange(snapshot, functionAstNode.StartOffset.Value, functionAstNode.EndOffset.Value)
                        };

                        symbols.Add(symbol);
                    }
                }
            }
        }
예제 #3
0
        public void HtmlResetPasswordContentNotEmpty()
        {
            HtmlContentProvider htmlContentProvider = new HtmlContentProvider("*****@*****.**");

            var result = htmlContentProvider.GetContentWithCode(ContentType.ResetPassword, "1234");

            Assert.NotEmpty(result);
        }
예제 #4
0
        public void HtmlActivateContentNotEmpty()
        {
            HtmlContentProvider htmlContentProvider = new HtmlContentProvider("*****@*****.**");

            var result = htmlContentProvider.GetContentWithCode(ContentType.ActivateAccount, "1234");

            Assert.NotEmpty(result);
        }
예제 #5
0
        /////////////////////////////////////////////////////////////////////////////////////////////////////
        // PUBLIC PROCEDURES
        /////////////////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Returns the content to use in the quick info popup.
        /// </summary>
        /// <returns>The content to use in the quick info popup.</returns>
        public object GetContent()
        {
            string htmlSnippet = String.Format(
                "<span style=\"color: " + HtmlContentProvider.GetCommentForegroundColor(highlightingStyleRegistry).ToWebColor() + ";\">This description tip is for the Type:</span><br/><b>{0}</b><br/><i style=\"color: " +
                HtmlContentProvider.GetNeutralForegroundColor(highlightingStyleRegistry).ToWebColor() + ";\">Generated at {1}</i>",
                HtmlContentProvider.Escape(type.FullName), DateTime.Now);

            return(new HtmlContentProvider(htmlSnippet).GetContent());
        }
        /// <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);
        }
예제 #7
0
        /////////////////////////////////////////////////////////////////////////////////////////////////////
        // PUBLIC PROCEDURES
        /////////////////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Returns the content to use in various IntelliPrompt popups.
        /// </summary>
        /// <returns>The content to use in various IntelliPrompt popups.</returns>
        public object GetContent()
        {
            var htmlSnippet = new StringBuilder();

            if (includeImage)
            {
                // Append icon
                htmlSnippet.Append("<img src=\"resource:");
                htmlSnippet.Append(HtmlContentProvider.Escape(CommonImageKind.MethodPublic.ToString()));
                htmlSnippet.Append("\" align=\"absbottom\" /> ");
            }

            // Append function name
            htmlSnippet.Append("<span style=\"color: " + HtmlContentProvider.GetKeywordForegroundColor(highlightingStyleRegistry).ToWebColor() + ";\">function</span> ");
            htmlSnippet.Append(HtmlContentProvider.Escape(functionDecl.Name));

            // Append parameters
            htmlSnippet.Append("(");
            for (int index = 0; index < functionDecl.Parameters.Count; index++)
            {
                if (index > 0)
                {
                    htmlSnippet.Append(", ");
                }

                if (index == parameterIndex)
                {
                    htmlSnippet.Append("<b>");
                }
                htmlSnippet.Append(functionDecl.Parameters[index]);
                if (index == parameterIndex)
                {
                    htmlSnippet.Append("</b>");
                }
            }
            htmlSnippet.Append(")");

            // Append description
            htmlSnippet.AppendFormat("<br/><span style=\"color: " + HtmlContentProvider.GetCommentForegroundColor(highlightingStyleRegistry).ToWebColor() + ";\">This function has {0} parameter{1}.</span>",
                                     functionDecl.Parameters.Count, (functionDecl.Parameters.Count == 1 ? String.Empty : "s"));

            return(new HtmlContentProvider(htmlSnippet.ToString(), backgroundColorHint).GetContent());
        }
예제 #8
0
        private static void AppendText(this StringBuilder sb, string text, IClassificationType classificationType, IHighlightingStyleRegistry highlightingStyleRegistry)
        {
            var highlightingStyle = highlightingStyleRegistry[classificationType];
            var styleBuilder      = new StringBuilder();

            styleBuilder.AppendStyle(highlightingStyle);
            var hasStyle = styleBuilder.Length > 0;

            if (hasStyle)
            {
                sb.Append(@"<span style=""");
                sb.Append(styleBuilder);
                sb.Append(@""">");
            }

            sb.Append(HtmlContentProvider.Escape(text));

            if (hasStyle)
            {
                sb.Append(@"</span>");
            }
        }
예제 #9
0
        /// <summary>
        /// Requests that an <see cref="ICompletionSession"/> be opened for the specified <see cref="IEditorView"/>.
        /// </summary>
        /// <param name="view">The <see cref="IEditorView"/> that will host the session.</param>
        /// <param name="canCommitWithoutPopup">Whether the session can immediately commit if a single match is made when the session is opened, commonly known as "complete word" functionality.</param>
        /// <returns>
        /// <c>true</c> if a session was opened; otherwise, <c>false</c>.
        /// </returns>
        public override bool RequestSession(IEditorView view, bool canCommitWithoutPopup)
        {
            //
            // IMPORTANT NOTE:
            // The items for this completion list are hard coded in this sample and
            // are simply meant to illustrate the rich features of the SyntaxEditor completion list.
            // When implementing a real language, you should vary the items based
            // on the current context of the caret.
            //

            // Create a session
            CompletionSession session = new CompletionSession();

            session.CanCommitWithoutPopup = canCommitWithoutPopup;

            // Set options
            session.CanHighlightMatchedText = this.CanHighlightMatchedText;
            session.MatchOptions            = CompletionMatchOptions.None;
            if (IsCaseSensitive == false)
            {
                session.MatchOptions |= CompletionMatchOptions.IsCaseInsensitive;
            }
            if (RequiresExact == true)
            {
                session.MatchOptions |= CompletionMatchOptions.RequiresExact;
            }
            if (UseAcronyms == true)
            {
                session.MatchOptions |= CompletionMatchOptions.UseAcronyms;
            }
            if (UseShorthand == true)
            {
                session.MatchOptions |= CompletionMatchOptions.UseShorthand;
            }

            // Add some items
            var highlightingStyleRegistry = view.HighlightingStyleRegistry;

            session.Items.Add(new CompletionItem("aField", new CommonImageSourceProvider(CommonImageKind.FieldPrivate),
                                                 new HtmlContentProvider("<img src=\"resource:FieldPrivate\" align=\"absbottom\" /> <span style=\"color: " + HtmlContentProvider.GetKeywordForegroundColor(highlightingStyleRegistry).ToWebColor() + ";\">int</span> <b>Foo.aField</b>")));
            session.Items.Add(new CompletionItem("AMethod", new CommonImageSourceProvider(CommonImageKind.MethodPublic),
                                                 new HtmlContentProvider("<img src=\"resource:MethodPublic\" align=\"absbottom\" /> <span style=\"color: " + HtmlContentProvider.GetKeywordForegroundColor(highlightingStyleRegistry).ToWebColor() + ";\">void</span> <b>Foo.AMethod</b>()")));
            session.Items.Add(new CompletionItem("AnIntValue", new CommonImageSourceProvider(CommonImageKind.PropertyPublic),
                                                 new HtmlContentProvider("<img src=\"resource:PropertyPublic\" align=\"absbottom\" /> <span style=\"color: " + HtmlContentProvider.GetKeywordForegroundColor(highlightingStyleRegistry).ToWebColor() + ";\">int</span> <b>Foo.AnIntValue</b>")));
            session.Items.Add(new CompletionItem("AStringValue", new CommonImageSourceProvider(CommonImageKind.PropertyPublic),
                                                 new HtmlContentProvider("<img src=\"resource:PropertyPublic\" align=\"absbottom\" /> <span style=\"color: " + HtmlContentProvider.GetKeywordForegroundColor(highlightingStyleRegistry).ToWebColor() + ";\">string</span> <b>Foo.AStringValue</b>")));
            session.Items.Add(new CompletionItem("Equals", new CommonImageSourceProvider(CommonImageKind.MethodPublic),
                                                 new HtmlContentProvider("<img src=\"resource:MethodPublic\" align=\"absbottom\" /> <span style=\"color: " + HtmlContentProvider.GetKeywordForegroundColor(highlightingStyleRegistry).ToWebColor() +
                                                                         ";\">bool</span> <b>object.Equals</b>(<span style=\"color: " + HtmlContentProvider.GetKeywordForegroundColor(highlightingStyleRegistry).ToWebColor() + ";\">object</span> obj)<br/><span style=\"color: " +
                                                                         HtmlContentProvider.GetCommentForegroundColor(highlightingStyleRegistry).ToWebColor() + ";\">Determines whether the specified <b>System.Object</b> is equal to the current <b>System.Object</b>.</span>")));
            session.Items.Add(new CompletionItem("GetHashCode", new CommonImageSourceProvider(CommonImageKind.MethodPublic),
                                                 new HtmlContentProvider("<img src=\"resource:MethodPublic\" align=\"absbottom\" /> <span style=\"color: " + HtmlContentProvider.GetKeywordForegroundColor(highlightingStyleRegistry).ToWebColor() +
                                                                         ";\">int</span> <b>object.GetHashCode</b>()<br/><span style=\"color: " + HtmlContentProvider.GetCommentForegroundColor(highlightingStyleRegistry).ToWebColor() + ";\">Gets a hash code for this <b>System.Object</b>.</span>")));
            session.Items.Add(new CompletionItem("GetType", new CommonImageSourceProvider(CommonImageKind.MethodPublic),
                                                 new HtmlContentProvider("<img src=\"resource:MethodPublic\" align=\"absbottom\" /> <span style=\"color: " + HtmlContentProvider.GetTypeNameForegroundColor(highlightingStyleRegistry).ToWebColor() +
                                                                         ";\">Type</span> <b>object.GetType</b>()<br/><span style=\"color: " + HtmlContentProvider.GetCommentForegroundColor(highlightingStyleRegistry).ToWebColor() + ";\">Gets the <b>System.Type</b> of the current instance.</span>")));
            session.Items.Add(new CompletionItem("ToString", new CommonImageSourceProvider(CommonImageKind.MethodPublic),
                                                 new HtmlContentProvider("<img src=\"resource:MethodPublic\" align=\"absbottom\" /> <span style=\"color: " + HtmlContentProvider.GetKeywordForegroundColor(highlightingStyleRegistry).ToWebColor() +
                                                                         ";\">string</span> <b>object.ToString</b>()<br/><span style=\"color: " + HtmlContentProvider.GetCommentForegroundColor(highlightingStyleRegistry).ToWebColor() + ";\">Returns the string representation of the object.</span>")));

            if (session.Items.Count > 0)
            {
                // Ensure the caret is visible
                view.Scroller.ScrollToCaret();

                // Ensure the items are sorted and open the session
                session.SortItems();
                session.Open(view);
                return(true);
            }

            return(false);
        }
        /// <summary>
        /// Requests that an <see cref="ICompletionSession"/> be opened for the specified <see cref="IEditorView"/>.
        /// </summary>
        /// <param name="view">The <see cref="IEditorView"/> that will host the session.</param>
        /// <param name="canCommitWithoutPopup">Whether the session can immediately commit if a single match is made when the session is opened, commonly known as "complete word" functionality.</param>
        /// <param name="includeStartDelimiter">Whether to include the start delimiter.</param>
        /// <returns>
        /// <c>true</c> if a session was opened; otherwise, <c>false</c>.
        /// </returns>
        public bool RequestSession(IEditorView view, bool canCommitWithoutPopup, bool includeStartDelimiter)
        {
            //
            // IMPORTANT NOTE:
            // The items for this completion list are hard coded in this sample and
            // are simply meant to illustrate the rich features of the SyntaxEditor completion list.
            // When implementing a real language, you should vary the items based
            // on the current context of the caret.
            //

            // Create a session
            CompletionSession session = new CompletionSession();

            session.CanCommitWithoutPopup = canCommitWithoutPopup;
            session.MatchOptions          = CompletionMatchOptions.TargetsDisplayText;

            // HTML allows ! and - characters to be typed too... make sure they are inserted
            session.AllowedCharacters.Add('!');
            session.AllowedCharacters.Add('-');

            // Add some items
            var highlightingStyleRegistry = view.HighlightingStyleRegistry;

            session.Items.Add(new CompletionItem("!--", new CommonImageSourceProvider(CommonImageKind.XmlComment),
                                                 new HtmlContentProvider("<b>&lt;!-- --&gt;</b> Comment<br/><span style=\"color: " + HtmlContentProvider.GetCommentForegroundColor(highlightingStyleRegistry).ToWebColor() + ";\">A comment.</span>"),
                                                 String.Format("{0}!-- ", (includeStartDelimiter ? "<" : String.Empty)), " -->"));
            session.Items.Add(new CompletionItem("a", new CommonImageSourceProvider(CommonImageKind.XmlTag),
                                                 new HtmlContentProvider("<b>a</b> Element<br/><span style=\"color: " + HtmlContentProvider.GetCommentForegroundColor(highlightingStyleRegistry).ToWebColor() + ";\">A hyperlink to another URL.</span>"),
                                                 String.Format("{0}a href=\"", (includeStartDelimiter ? "<" : String.Empty)), "\""));
            session.Items.Add(new CompletionItem("br", new CommonImageSourceProvider(CommonImageKind.XmlTag),
                                                 new HtmlContentProvider("<b>br</b> Element<br/><span style=\"color: " + HtmlContentProvider.GetCommentForegroundColor(highlightingStyleRegistry).ToWebColor() + ";\">Creates a line break.</span>"),
                                                 String.Format("{0}br/>", (includeStartDelimiter ? "<" : String.Empty)), null));

            if (session.Items.Count > 0)
            {
                // Ensure the caret is visible
                view.Scroller.ScrollToCaret();

                // Ensure the items are sorted and open the session
                session.SortItems();
                session.Open(view);
                return(true);
            }

            return(false);
        }
        /// <summary>
        /// Requests that an <see cref="ICompletionSession"/> be opened for the specified <see cref="IEditorView"/>.
        /// </summary>
        /// <param name="view">The <see cref="IEditorView"/> that will host the session.</param>
        /// <param name="canCommitWithoutPopup">Whether the session can immediately commit if a single match is made when the session is opened, commonly known as "complete word" functionality.</param>
        /// <returns>
        /// <c>true</c> if a session was opened; otherwise, <c>false</c>.
        /// </returns>
        public override bool RequestSession(IEditorView view, bool canCommitWithoutPopup)
        {
            //
            // IMPORTANT NOTE:
            // The items and filters for this completion list are hard coded in this sample and
            // are simply meant to illustrate the rich features of the SyntaxEditor completion list.
            // When implementing a real language, you should vary the items and filters based
            // on the current context of the caret.
            //

            // Create a session
            CompletionSession session = new CompletionSession();

            session.CanCommitWithoutPopup   = canCommitWithoutPopup;
            session.CanFilterUnmatchedItems = this.FilterUnmatchedItems;
            session.MatchOptions            = CompletionMatchOptions.UseAcronyms | CompletionMatchOptions.UseShorthand;

            // Add some items
            var highlightingStyleRegistry = view.HighlightingStyleRegistry;

            session.Items.Add(new CompletionItem("_intValue", new CommonImageSourceProvider(CommonImageKind.FieldPrivate),
                                                 new HtmlContentProvider("<span style=\"color: " + HtmlContentProvider.GetKeywordForegroundColor(highlightingStyleRegistry).ToWebColor() + ";\">int</span> <b>Foo._intValue</b><br/><span style=\"color: " +
                                                                         HtmlContentProvider.GetCommentForegroundColor(highlightingStyleRegistry).ToWebColor() + ";\">An integer value.</span>")));
            session.Items.Add(new CompletionItem("Equals", new CommonImageSourceProvider(CommonImageKind.MethodPublic),
                                                 new HtmlContentProvider("<span style=\"color: " + HtmlContentProvider.GetKeywordForegroundColor(highlightingStyleRegistry).ToWebColor() + ";\">bool</span> <b>object.Equals</b>(<span style=\"color: " +
                                                                         HtmlContentProvider.GetKeywordForegroundColor(highlightingStyleRegistry).ToWebColor() + ";\">object</span> obj)<br/><span style=\"color: " +
                                                                         HtmlContentProvider.GetCommentForegroundColor(highlightingStyleRegistry).ToWebColor() + ";\">Determines whether the specified <b>System.Object</b> is equal to the current <b>System.Object</b>.</span>")));
            session.Items.Add(new CompletionItem("GetHashCode", new CommonImageSourceProvider(CommonImageKind.MethodPublic),
                                                 new HtmlContentProvider("<span style=\"color: " + HtmlContentProvider.GetKeywordForegroundColor(highlightingStyleRegistry).ToWebColor() + ";\">int</span> <b>object.GetHashCode</b>()<br/><span style=\"color: " +
                                                                         HtmlContentProvider.GetCommentForegroundColor(highlightingStyleRegistry).ToWebColor() + ";\">Gets a hash code for this <b>System.Object</b>.</span>")));
            session.Items.Add(new CompletionItem("GetType", new CommonImageSourceProvider(CommonImageKind.MethodPublic),
                                                 new HtmlContentProvider("<span style=\"color: " + HtmlContentProvider.GetTypeNameForegroundColor(highlightingStyleRegistry).ToWebColor() + ";\">Type</span> <b>object.GetType</b>()<br/><span style=\"color: " +
                                                                         HtmlContentProvider.GetCommentForegroundColor(highlightingStyleRegistry).ToWebColor() + ";\">Gets the <b>System.Type</b> of the current instance.</span>")));
            session.Items.Add(new CompletionItem("IntValue", new CommonImageSourceProvider(CommonImageKind.PropertyPublic),
                                                 new HtmlContentProvider("<span style=\"color: " + HtmlContentProvider.GetKeywordForegroundColor(highlightingStyleRegistry).ToWebColor() + ";\">int</span> <b>Foo.IntValue</b><br/><span style=\"color: " +
                                                                         HtmlContentProvider.GetCommentForegroundColor(highlightingStyleRegistry).ToWebColor() + ";\">An integer value.</span>")));
            session.Items.Add(new CompletionItem("IntValueChanged", new CommonImageSourceProvider(CommonImageKind.EventPublic),
                                                 new HtmlContentProvider("<span style=\"color: " + HtmlContentProvider.GetTypeNameForegroundColor(highlightingStyleRegistry).ToWebColor() + ";\">EventHandler</span> <b>Foo.IntValueChanged</b>")));
            session.Items.Add(new CompletionItem("OnIntValueChanged", new CommonImageSourceProvider(CommonImageKind.MethodProtected),
                                                 new HtmlContentProvider("<span style=\"color: " + HtmlContentProvider.GetKeywordForegroundColor(highlightingStyleRegistry).ToWebColor() + ";\">void</span> <b>Foo.OnIntValueChanged</b>(<span style=\"color: " +
                                                                         HtmlContentProvider.GetTypeNameForegroundColor(highlightingStyleRegistry).ToWebColor() + ";\">EventArgs</span> e)")));
            session.Items.Add(new CompletionItem("ToString", new CommonImageSourceProvider(CommonImageKind.MethodPublic),
                                                 new HtmlContentProvider("<span style=\"color: " + HtmlContentProvider.GetKeywordForegroundColor(highlightingStyleRegistry).ToWebColor() + ";\">string</span> <b>object.ToString</b>()<br/><span style=\"color: " +
                                                                         HtmlContentProvider.GetCommentForegroundColor(highlightingStyleRegistry).ToWebColor() + ";\">Returns the string representation of the object.</span>")));

            //
            // NOTE: In the filters below, the filtering conditions are just looking at the item text and image used.
            //   Normally you would store some contextual object in the Tag property and examine that instead.
            //

            if (this.MemberTypeFilterButtonsVisible == true)
            {
                // Add member type filters
                session.Filters.Add(new CompletionFilter("Events",
                                                         (mysession, item) => (((item.Text == null) || (((CommonImageSourceProvider)item.ImageSourceProvider).ImageKind.ToString().StartsWith("Event"))) ? CompletionFilterResult.Included : CompletionFilterResult.Excluded)
                                                         )
                {
                    DisplayMode = CompletionFilterDisplayMode.ToggleButton,
                    GroupName   = "MemberType",
                    ToolTip     = "Events",
                    Content     = new Image()
                    {
                        Width = 16, Height = 16, Source = new CommonImageSourceProvider(CommonImageKind.EventPublic).GetImageSource()
                    }
                });
                session.Filters.Add(new CompletionFilter("Fields",
                                                         (mysession, item) => (((item.Text == null) || (((CommonImageSourceProvider)item.ImageSourceProvider).ImageKind.ToString().StartsWith("Field"))) ? CompletionFilterResult.Included : CompletionFilterResult.Excluded)
                                                         )
                {
                    DisplayMode = CompletionFilterDisplayMode.ToggleButton,
                    GroupName   = "MemberType",
                    ToolTip     = "Fields",
                    Content     = new Image()
                    {
                        Width = 16, Height = 16, Source = new CommonImageSourceProvider(CommonImageKind.FieldPublic).GetImageSource()
                    }
                });
                session.Filters.Add(new CompletionFilter("Methods",
                                                         (mysession, item) => (((item.Text == null) || (((CommonImageSourceProvider)item.ImageSourceProvider).ImageKind.ToString().StartsWith("Method"))) ? CompletionFilterResult.Included : CompletionFilterResult.Excluded)
                                                         )
                {
                    DisplayMode = CompletionFilterDisplayMode.ToggleButton,
                    GroupName   = "MemberType",
                    ToolTip     = "Methods",
                    Content     = new Image()
                    {
                        Width = 16, Height = 16, Source = new CommonImageSourceProvider(CommonImageKind.MethodPublic).GetImageSource()
                    }
                });
                session.Filters.Add(new CompletionFilter("Properties",
                                                         (mysession, item) => (((item.Text == null) || (((CommonImageSourceProvider)item.ImageSourceProvider).ImageKind.ToString().StartsWith("Property"))) ? CompletionFilterResult.Included : CompletionFilterResult.Excluded)
                                                         )
                {
                    DisplayMode = CompletionFilterDisplayMode.ToggleButton,
                    GroupName   = "MemberType",
                    ToolTip     = "Properties",
                    Content     = new Image()
                    {
                        Width = 16, Height = 16, Source = new CommonImageSourceProvider(CommonImageKind.PropertyPublic).GetImageSource()
                    }
                });
            }

            if (this.InheritedFilterButtonVisible == true)
            {
                // Add inherited filter
                session.Filters.Add(new CompletionFilter("Inherited",
                                                         (CompletionFilterPredicate) delegate(ICompletionSession mysession, ICompletionItem item) { return(("Equals,GetHashCode,GetType,ToString".IndexOf(item.Text) != -1) ? CompletionFilterResult.Included : CompletionFilterResult.Excluded); })
                {
                    DisplayMode = CompletionFilterDisplayMode.ToggleButton,
                    GroupName   = "Inherited",
                    ToolTip     = "Inherited members",
                    Content     = "Inherited"
                });
            }

            if (this.FilterTabsVisible == true)
            {
                // Add access filters
                session.Filters.Add(new CompletionFilter("All",
                                                         (mysession, item) => (((item.Text == null) || (((CommonImageSourceProvider)item.ImageSourceProvider).ImageKind.ToString().EndsWith("Public"))) ? CompletionFilterResult.Included : CompletionFilterResult.Excluded)
                                                         )
                {
                    DisplayMode = CompletionFilterDisplayMode.AllTab,
                    Content     = "All members",
                });
                session.Filters.Add(new CompletionFilter("Public",
                                                         (mysession, item) => (((item.Text == null) || (((CommonImageSourceProvider)item.ImageSourceProvider).ImageKind.ToString().EndsWith("Public"))) ? CompletionFilterResult.Included : CompletionFilterResult.Excluded)
                                                         )
                {
                    DisplayMode = CompletionFilterDisplayMode.Tab,
                    Content     = "Public members"
                });
            }

            if (session.Items.Count > 0)
            {
                // Ensure the caret is visible
                view.Scroller.ScrollToCaret();

                // Ensure the items are sorted and open the session
                session.SortItems();
                session.Open(view);
                return(true);
            }

            return(false);
        }
예제 #12
0
        /// <summary>
        /// Requests that an <see cref="IParameterInfoSession"/> be opened for the specified <see cref="IEditorView"/>.
        /// </summary>
        /// <param name="view">The <see cref="IEditorView"/> that will host the session.</param>
        /// <returns>
        /// <c>true</c> if a session was opened; otherwise, <c>false</c>.
        /// </returns>
        public override bool RequestSession(IEditorView view)
        {
            if (view == null)
            {
                return(false);
            }

            // Get a context object, which will be filled in if we are in a valid offset for parameter info
            var context = this.CreateContext(view);

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

            // Create a session
            var session = new ParameterInfoSession();

            // Add items (hardcoded in this sample)... a real implementation like the one in the Getting Started series would
            //   dynamically build this sort of data, and track the current parameter for bolding as well
            var highlightingStyleRegistry = view.HighlightingStyleRegistry;

            session.Items.Add(new SignatureItem(new HtmlContentProvider("<span style=\"color: " + HtmlContentProvider.GetKeywordForegroundColor(highlightingStyleRegistry).ToWebColor() +
                                                                        ";\">function</span> Foo()<br/><span style=\"color: " + HtmlContentProvider.GetCommentForegroundColor(highlightingStyleRegistry).ToWebColor() + ";\">Returns 0.</span>", view.DefaultBackgroundColor)));
            session.Items.Add(new SignatureItem(new HtmlContentProvider("<span style=\"color: " + HtmlContentProvider.GetKeywordForegroundColor(highlightingStyleRegistry).ToWebColor() +
                                                                        ";\">function</span> Foo(x)<br/><span style=\"color: " + HtmlContentProvider.GetCommentForegroundColor(highlightingStyleRegistry).ToWebColor() + ";\">Returns the value passed in.</span>", view.DefaultBackgroundColor)));
            session.Items.Add(new SignatureItem(new HtmlContentProvider("<span style=\"color: " + HtmlContentProvider.GetKeywordForegroundColor(highlightingStyleRegistry).ToWebColor() +
                                                                        ";\">function</span> Foo(x, y)<br/><span style=\"color: " + HtmlContentProvider.GetCommentForegroundColor(highlightingStyleRegistry).ToWebColor() + ";\">Returns the multiplicative result of the two arguments.</span>", view.DefaultBackgroundColor)));

            // Try to pick the best overload to show by default... normally this would be much more robust code where
            //   your context would include the number of arguments that have been specified and you'd base the selection on that...
            //   For this sample, we're just going to use the argument index
            switch (context.ArgumentIndex)
            {
            case 1:
                session.Selection = session.Items[2];
                break;

            case 0:
                session.Selection = session.Items[1];
                break;
            }

            // Open the session
            session.Open(view, new TextRange(context.ArgumentListOffset));

            return(true);
        }