Introduce a way to bind an Enum setting for the Settings UI#8086
Introduce a way to bind an Enum setting for the Settings UI#808617 commits merged intofeature/settings-uifrom
Conversation
src/cascadia/TerminalSettingsModel/Microsoft.Terminal.Settings.ModelLib.vcxproj.filters
Outdated
Show resolved
Hide resolved
zadjii-msft
left a comment
There was a problem hiding this comment.
I'm fairly worried about how much boilerplate we're going to have to have - but at this point I think we're all used to seeing SOME_MACRO_THING that expands to a bunch of cppwinrt boilerplate that we know works.
I'm blocking over the initialization thing in EnumMappings.cpp, but I also know that the settings UI is all gas no brakes so you can go ahead and dismiss it if it isn't relevant
| uint8_t GlobalAppearance::CurrentTheme() | ||
| { | ||
| return static_cast<uint8_t>(GlobalSettings().Theme()); | ||
| } | ||
|
|
||
| void GlobalAppearance::CurrentTheme(const uint8_t index) | ||
| { | ||
| GlobalSettings().Theme(static_cast<ElementTheme>(index)); |
There was a problem hiding this comment.
Unfortunately I can't just bind an enum to a XAML property that expects an int (like SelectedIndex) so had to do something like this
There was a problem hiding this comment.
This also just does not work if the enum isn't consecutive 👀 since I'm binding this property to SelectedIndex
There was a problem hiding this comment.
Hmmmmmm. Okay, how about this? Is it possible for us to bind selectedITEM, and then pull the index out of the EnumEntry? We can also search the map to return the EnumEntry for the active theme.
There was a problem hiding this comment.
oh yeah we could keep a map of enum -> enumentry, and from there we can do enumMap.Lookup(globalsettings.theme()) to grab the initial EnumEntry for the databound SelectedItem. Then the TwoWay binding will do all the work as long as we set the xaml->viewmodel binding up so that it updates GlobalSettings().Theme()
There was a problem hiding this comment.
ehh actually scratch that first part, keeping a map just so we can initialize the SelectedItem seems overkill
There was a problem hiding this comment.
ehh screw it i made the map, it avoids having to do if(value), and binding SelectedItem avoids the whole index route
DHowett
left a comment
There was a problem hiding this comment.
Love it. This is all macroable!
carlos-zamora
left a comment
There was a problem hiding this comment.
This is awesome! Great work!
| <Page.Resources> | ||
| <DataTemplate x:DataType="local:EnumEntry" x:Key="EnumRadioButtonTemplate"> | ||
| <RadioButton Content="{x:Bind EnumName, Mode=OneWay}"/> | ||
| </DataTemplate> | ||
| </Page.Resources> |
zadjii-msft
left a comment
There was a problem hiding this comment.
Now THIS is working with macros
I like this a lot more now
|
Hello @leonMSFT! Because this pull request has the p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (
|
This PR's goal was to expose the String to Enum mappings we have in JsonUtils and to bind a group of Radio buttons to that setting and its possible enum values. To allow the Radio button groups to be data bound to, I created an EnumEntry class in TSE that'll take a string to represent your enum value name and an IInspectable to associate that name with an enum value. There's also macros that will initialize the necessary properties for a setting whose type is an enum. With these macros, you'll be able to bind to a collection of enum values and to the enum setting itself.
References #1564