///////////////////////////////////////////////////////////////////////////////////////////////////// // 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()); }
///////////////////////////////////////////////////////////////////////////////////////////////////// // 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()); }
/// <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><!-- --></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); }
/// <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); }