Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Order enum settings according to enum values #8784

Merged
1 commit merged into from
Jan 14, 2021
Merged

Conversation

carlos-zamora
Copy link
Member

@carlos-zamora carlos-zamora commented Jan 13, 2021

Sorts the list of EnumEntrys that is used to create combo boxes and
radio buttons in the Settings UI. INITIALIZE_BINDABLE_ENUM_SETTING
sorts the list in increasing order of the enum values, whereas
INITIALIZE_BINDABLE_ENUM_SETTING_REVERSE_ORDER does so in decreasing
order.

References

#6800 - Settings UI Epic

I attempted sorting the IObservableVector<EnumEntry> using
std::sort, but I would get an error in
winrt::Windows::Foundation::swap (C2665). So instead, I did the
following approach:

  • (unchanged) we're converting the IMap from EnumMappings into (1) a
    map of localized strings and (2) the list for XAML controls
  • instead of storing EnumEntrys to the IObservableVector directly,
    store it to a std::vector
  • sort the vector using std::sort
  • now initialize the IObservableVector using the sorted
    std::vector

This uses the value of the associated enum to determine a sorting order.
Since we want the "negative" value (i.e. "none" or "hidden") to be last,
I use EnumEntryComparator and EnumEntryReverseComparator to
determine whether we want increasing or decreasing order respectively.
INITIALIZE_BINDABLE_ENUM_SETTING_REVERSE_ORDER is a copy of
INITIALIZE_BINDABLE_ENUM_SETTING, except it uses
EnumEntryReverseComparator to sort in decreasing order.

Closes #8758

@ghost ghost added Area-Settings UI Anything specific to the SUI Issue-Bug It either shouldn't be doing this or needs an investigation. Priority-2 A description (P2) Product-Terminal The new Windows Terminal. labels Jan 13, 2021
@carlos-zamora
Copy link
Member Author

carlos-zamora commented Jan 13, 2021

Launch Mode
Theme
Tab Width Mode
Font Weight
Cursor shape
Background Image Stretch Mode
Scrollbar visibility
Antialiasing text
Close on exit
Bell style

@cinnamon-msft Are all of these in the order you want? Or should I reorder any of them? I could introduce custom ordering, if you want.

@zadjii-msft
Copy link
Member

@msftbot make sure @DHowett signs off on this

@ghost ghost added the AutoMerge Marked for automatic merge by the bot when requirements are met label Jan 13, 2021
@ghost
Copy link

ghost commented Jan 13, 2021

Hello @zadjii-msft!

Because you've given me some instructions on how to help merge this pull request, I'll be modifying my merge approach. Here's how I understand your requirements for merging this pull request:

  • I'll only merge this pull request if it's approved by @DHowett

If this doesn't seem right to you, you can tell me to cancel these instructions and use the auto-merge policy that has been configured for this repository. Try telling me "forget everything I just told you".

@zadjii-msft
Copy link
Member

I'm tagging Dustin here, for the issue we discussed about sorting IObservableVectors. We really shouldn't need to stash a copy of the vector...

@DHowett DHowett removed the AutoMerge Marked for automatic merge by the bot when requirements are met label Jan 13, 2021
@DHowett
Copy link
Member

DHowett commented Jan 13, 2021

I don't mind this that much. Fortunately we're not stashing a copy. The vector is created, sorted, and then moved into the new instance of IObservable.... It's just the same as what we were doing, but with a sort in the middle. 😄

std::sort(begin(name##List), end(name##List), EnumEntryComparator<enumType>()); \
_##name##List = winrt::single_threaded_observable_vector<winrt::Microsoft::Terminal::Settings::Editor::EnumEntry>(std::move(name##List));

#define INITIALIZE_BINDABLE_ENUM_SETTING_REVERSE_ORDER(name, enumMappingsName, enumType, resourceSectionAndType, resourceProperty) \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sure that we could refactor these macros so there was one base macro that could sort either direction, and then INITIALIZE_BINDABLE_ENUM_SETTING and INITIALIZE_BINDABLE_ENUM_SETTING_REVERSE_ORDER would just pass the correct arg to the base macro, but ¯\_(ツ)_/¯

@zadjii-msft zadjii-msft added the AutoMerge Marked for automatic merge by the bot when requirements are met label Jan 14, 2021
@ghost
Copy link

ghost commented Jan 14, 2021

Hello @zadjii-msft!

Because this pull request has the AutoMerge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

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 (@msftbot) and give me an instruction to get started! Learn more here.

@ghost ghost merged commit 9b1bb13 into main Jan 14, 2021
@ghost ghost deleted the dev/cazamor/sui/enum-ordering branch January 14, 2021 11:47
@carlos-zamora carlos-zamora mentioned this pull request Jan 21, 2021
25 tasks
mpela81 pushed a commit to mpela81/terminal that referenced this pull request Jan 28, 2021
Sorts the list of `EnumEntry`s that is used to create combo boxes and
radio buttons in the Settings UI. `INITIALIZE_BINDABLE_ENUM_SETTING`
sorts the list in increasing order of the enum values, whereas
`INITIALIZE_BINDABLE_ENUM_SETTING_REVERSE_ORDER` does so in decreasing
order.

## References
microsoft#6800 - Settings UI Epic

I attempted sorting the `IObservableVector<EnumEntry>` using
`std::sort`, but I would get an error in
`winrt::Windows::Foundation::swap` (`C2665`). So instead, I did the
following approach:
- (unchanged) we're converting the `IMap` from EnumMappings into (1) a
  map of localized strings and (2) the list for XAML controls
- instead of storing `EnumEntry`s to the `IObservableVector` directly,
  store it to a `std::vector`
- sort the vector using `std::sort`
- _now_ initialize the `IObservableVector` using the sorted
  `std::vector`

This uses the value of the associated enum to determine a sorting order.
Since we want the "negative" value (i.e. "none" or "hidden") to be last,
I use `EnumEntryComparator` and `EnumEntryReverseComparator` to
determine whether we want increasing or decreasing order respectively.
`INITIALIZE_BINDABLE_ENUM_SETTING_REVERSE_ORDER` is a copy of
`INITIALIZE_BINDABLE_ENUM_SETTING`, except it uses
`EnumEntryReverseComparator` to sort in decreasing order.

Closes microsoft#8758
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Settings UI Anything specific to the SUI AutoMerge Marked for automatic merge by the bot when requirements are met Issue-Bug It either shouldn't be doing this or needs an investigation. Priority-2 A description (P2) Product-Terminal The new Windows Terminal.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enum settings should be ordered better
3 participants