/// <inheritdoc /> /// <returns>A comma-separated list of recognized syntax filter IDs</returns> public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { if (value is string) { string filterIds = value.ToString(); var allFilters = BuildComponentManager.SyntaxFiltersFrom("All"); var definedFilters = BuildComponentManager.SyntaxFiltersFrom(filterIds); // Convert to None, All, AllButUsage, or Standard? If not, // then convert to the list of defined filters that we know // about. if (definedFilters.Count == 0) { filterIds = "None"; } else if (definedFilters.Count == allFilters.Count) { filterIds = "All"; } else if (definedFilters.Count == allFilters.Count( af => af.Id.IndexOf("usage", StringComparison.OrdinalIgnoreCase) == -1)) { filterIds = "AllButUsage"; } else if (definedFilters.Count == 3 && (definedFilters.All(df => df.Id == "CSharp" || df.Id == "VisualBasic" || df.Id == "CPlusPlus"))) { filterIds = "Standard"; } else { filterIds = String.Join(", ", definedFilters.Select(f => f.Id).ToArray()); } return(filterIds); } return(base.ConvertFrom(context, culture, value)); }
public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, IServiceProvider provider, object value) { Collection <SyntaxFilterInfo> allFilters, definedFilters; IWindowsFormsEditorService editorService; CheckedListBox ckbListBox; string filterIds; // Only use the editor if we have a valid context if (context == null || provider == null || context.Instance == null || value == null) { return(base.EditValue(context, provider, value)); } editorService = (IWindowsFormsEditorService)provider.GetService( typeof(IWindowsFormsEditorService)); if (editorService == null) { return(base.EditValue(context, provider, value)); } allFilters = BuildComponentManager.SyntaxFiltersFrom("All"); definedFilters = BuildComponentManager.SyntaxFiltersFrom(value.ToString()); using (ckbListBox = new CheckedListBox()) { ckbListBox.BorderStyle = BorderStyle.None; ckbListBox.CheckOnClick = true; // Tahoma 8pt prevents it from clipping the bottom of each item ckbListBox.Font = new Font("Tahoma", 8.0f); // Load the values into the checked list box foreach (SyntaxFilterInfo info in allFilters) { ckbListBox.Items.Add(info.Id, definedFilters.Contains(info)); } // Adjust the height of the list box to show all items or // at most twelve of them. if (ckbListBox.Items.Count < 12) { ckbListBox.Height = ckbListBox.Items.Count * ckbListBox.ItemHeight; } else { ckbListBox.Height = ckbListBox.Items.Count * 12; } // Display it and let the user edit the value editorService.DropDownControl(ckbListBox); // Get the selected syntax filter ID values and return them // as a comma-separated string. This also checks for common // short-hand values and uses them if appropriate. if (ckbListBox.CheckedItems.Count == 0) { value = "None"; } else { filterIds = String.Join(", ", ckbListBox.CheckedItems.Cast <string>().ToArray()); definedFilters = BuildComponentManager.SyntaxFiltersFrom(filterIds); // Convert to All, AllButUsage, or Standard? if (definedFilters.Count == allFilters.Count) { filterIds = "All"; } else if (definedFilters.Count == allFilters.Count( af => af.Id.IndexOf("usage", StringComparison.OrdinalIgnoreCase) == -1)) { filterIds = "AllButUsage"; } else if (definedFilters.Count == 3 && (definedFilters.All(f => f.Id == "CSharp" || f.Id == "VisualBasic" || f.Id == "CPlusPlus"))) { filterIds = "Standard"; } value = filterIds; } } return(value); }