Skip to content

Fixes #4851 - Add DropDownList<TEnum> for type-safe enum selection - #4852

Merged
tig merged 5 commits into
v2_developfrom
copilot/add-dropdownlist-generic-type
Mar 25, 2026
Merged

tig merged 5 commits into
v2_developfrom
copilot/add-dropdownlist-generic-type

Conversation

Copilot AI commented Mar 24, 2026 •

Copy link
Copy Markdown
Contributor

DropDownList was cumbersome to use with enum sources, requiring manual population and string-to-enum conversion at every call site. DropDownList<TEnum> closes the gap with OptionSelector<TEnum> — the two are now interchangeable for enum-backed selection, differing only in appearance and size.

Proposed Changes/Todos

  • Add Terminal.Gui/Views/DropDownListTEnum.cs — new sealed class DropDownList<TEnum> : DropDownList, IValue where TEnum : struct, Enum
    • Constructor auto-populates Source from Enum.GetValues<TEnum>()
    • Typed TEnum? Value property (get parses Text via Enum.TryParse; set writes value.ToString())
    • Typed event EventHandler<EventArgs<TEnum?>>? ValueChanged — mirrors OptionSelector<TEnum> exactly
    • Implements IValue.GetValue() for data binding
  • Update DropDownListExample.cs — added DropDownList<DayOfWeekShort> demo in the UICatalog scenario
  • Update DropDownListTests.cs — added DropDownListGenericTests (11 tests: source population, value round-trip, event firing, interchangeability assertion)
  • Fix CI build error CS0266: IListDataSource.ToList() returns non-generic System.Collections.IList; added explicit .Cast<object?>() in test assertion

Before / After

// Before — manual wiring, string conversion at every call site
var dd = new DropDownList {
    Source = new ListWrapper<string>(new ObservableCollection<string>(Enum.GetNames<DayOfWeek>()))
};
dd.ValueChanged += (_, e) => Process(Enum.Parse<DayOfWeek>(e.NewValue!));

// After — one line, fully type-safe
var dd = new DropDownList<DayOfWeek> { Value = DayOfWeek.Monday };
dd.ValueChanged += (_, e) => Process(e.Value);  // e.Value is DayOfWeek?

Pull Request checklist:

  • I've named my PR in the form of "Fixes #issue. Terse description."
  • My code follows the style guidelines of Terminal.Gui - if you use Visual Studio, hit CTRL-K-D to automatically reformat your files before committing.
  • My code follows the Terminal.Gui library design guidelines
  • I ran dotnet test before commit
  • I have made corresponding changes to the API documentation (using /// style comments)
  • My changes generate no new warnings
  • I have checked my code and corrected any poor grammar or misspellings
  • I conducted basic QA to assure all features are working
Original prompt

This section details on the original issue you should resolve

<issue_title>Add DropdownList</issue_title>
<issue_description>DropdownList is working great.

But for many scenarios where the list source is from an enum, it's harder to use than it could be.

We should add a DropDownList that works exactly like OptionSelector.

They should be interchangeable except for how they look and their size.</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Add DropdownList<T> for enum support Fixes #issue. Add DropDownList<TEnum> for type-safe enum selection Mar 24, 2026
Copilot AI requested a review from tig March 24, 2026 21:16
Copilot finished work on behalf of tig March 24, 2026 21:16
@tig

tig commented Mar 24, 2026

Copy link
Copy Markdown
Member

@copilot ci/cs
Tests are failing

Copilot AI commented Mar 24, 2026

Copy link
Copy Markdown
Contributor Author

@copilot ci/cs
Tests are failing

Fixed in 2138108. The build error was CS0266: IListDataSource.ToList() returns System.Collections.IList (non-generic), which can't be implicitly assigned to IList<object?>. Added explicit .Cast<object?>() to the assertion. All 15,129 tests pass.

Copilot AI changed the title Fixes #issue. Add DropDownList<TEnum> for type-safe enum selection Add DropDownList<TEnum> for type-safe enum selection Mar 24, 2026
Copilot finished work on behalf of tig March 24, 2026 22:22
@tig
tig marked this pull request as ready for review March 25, 2026 01:14
@tig
tig requested a review from BDisp March 25, 2026 01:14
@tig tig changed the title Add DropDownList<TEnum> for type-safe enum selection Fixes #4851 - Add DropDownList<TEnum> for type-safe enum selection Mar 25, 2026
tig added 2 commits March 25, 2026 16:46
Update ApplicationMouse to track active popover at mouse press and suppress Clicked events if the popover closes during the press → release → click cycle, preventing event leakage to underlying views. Add trace logging for this suppression. Refactor DropDownListExample to use Value instead of Text for read-only dropdown initialization and condense enum dropdown setup.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add DropdownList<T>

3 participants