public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { var editorService = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService)); var listBox = new DoubleListBox(); Tag[] categories = FetchAllCategories(); listBox.AssignFlattenedSecondaryList(CatalogTagRegistry.AllTags().ToObjectArray()); Tag currentlySelectedTag = ExtractTag(value); Tag currentCategory = GetCurrentCategory(currentlySelectedTag); listBox.AssignPrimaryList(categories.ToObjectArray()); AssignSelectedIndex(categories.ToObjectArray(), currentCategory, index => listBox.PrimarySelectedIndex = index); object[] availableTags = UpdateTagListBox(currentCategory, listBox); AssignSelectedIndex(availableTags, currentlySelectedTag, index => listBox.SecondarySelectedIndex = index); listBox.PrimaryItemSelected += (sender, args) => { int selectedIndex = listBox.PrimarySelectedIndex; Tag selectedCategory = categories[selectedIndex]; UpdateTagListBox(selectedCategory, listBox); }; listBox.SecondaryItemSelected += (sender, args) => editorService.CloseDropDown(); editorService.DropDownControl(listBox); return(listBox.SecondarySelectedItem ?? value); }
private static IEnumerable <Tag> FetchTagsForCategory(Tag category) { return(CatalogTagRegistry.FetchTagsForCategory(category.Value).Order().ToArray()); }
private static Tag GetCurrentCategory(Tag currentlySelectedTag) { return(CatalogTagRegistry.GetCategoryFor(currentlySelectedTag)); }
private static Tag[] FetchAllCategories() { return (CatalogTagRegistry.AllCategoriesWithDummiesForUnpairedTags().Order().ToArray()); }