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

Introduce serialization for actions #9926

Merged
12 commits merged into from
May 20, 2021
Merged

Introduce serialization for actions #9926

12 commits merged into from
May 20, 2021

Conversation

carlos-zamora
Copy link
Member

@carlos-zamora carlos-zamora commented Apr 22, 2021

Summary of the Pull Request

This PR builds on the ActionMap PR (#6900) by leveraging ActionMap to serialize actions. From the top down, the process is now as follows:

  • CascadiaSettings: remove the hack of copying whatever we had for actions before.
  • GlobalAppSettings: serialize the ActionMap to "actions": []
  • ActionMap: iterate over the internal _ActionMap (list of actions) and serialize each Command
  • Command: THIS IS WHERE THE MAGIC HAPPENS! For each key mapping, serialize an action. Only the first one needs to include the name and icon.
  • ActionAndArgs: Find the relevant IActionArgs parser and serialize the ActionAndArgs.
  • ActionArgs: ANNOYING CHANGE Serialize any args that are set. We need each setting to be saved as a std::optional. As with inheritance, this allows us to distinguish an explicit setting to the default value (sometimes null) vs an implicit "give me the default value". This allows us to serialize only the relevant details of each action, rather than writing all of the args.

References

Validation Steps Performed

Tests added!

@github-actions

This comment has been minimized.

@carlos-zamora carlos-zamora marked this pull request as ready for review April 22, 2021 23:58
@github-actions

This comment has been minimized.

@carlos-zamora carlos-zamora force-pushed the dev/cazamor/tsm/am/serialization branch 2 times, most recently from 5d0a656 to 3b99fde Compare April 23, 2021 21:32
@carlos-zamora carlos-zamora force-pushed the dev/cazamor/tsm/am/serialization branch 5 times, most recently from a6b5bde to 0068ae0 Compare May 5, 2021 04:21
Base automatically changed from dev/cazamor/tsm/action-map to main May 5, 2021 04:50
@carlos-zamora carlos-zamora force-pushed the dev/cazamor/tsm/am/serialization branch from 0068ae0 to 9cb377e Compare May 5, 2021 04:52
@DHowett

This comment has been minimized.

@carlos-zamora

This comment has been minimized.

Copy link
Member

@zadjii-msft zadjii-msft left a comment

Choose a reason for hiding this comment

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

I only really have the one main question that I want answered. Otherwise, the rest seems pretty straightforward.

We should make sure to add a test for #9926 (comment) as well, because it's a good edge case

@ghost ghost added the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label May 6, 2021
@zadjii-msft zadjii-msft added Area-Settings Issues related to settings and customizability, for console or terminal Issue-Task It's a feature request, but it doesn't really need a major design. Product-Terminal The new Windows Terminal. labels May 6, 2021
@ghost ghost removed the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label May 7, 2021
Copy link
Member

@zadjii-msft zadjii-msft left a comment

Choose a reason for hiding this comment

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

🙌 on the ACTION_TO_SERIALIZERS_PAIR thing, and thanks for adding the test!

@zadjii-msft zadjii-msft added the Needs-Second It's a PR that needs another sign-off label May 10, 2021
@carlos-zamora
Copy link
Member Author

Move focus doesn't display direction

This bug was caused by the list of ALL_SHORTCUT_ACTIONS_WITH_ARGS missing MoveFocus. I went ahead and sorted it, then double checked that I'm not missing anything.

#undef ON_ALL_ACTIONS
};

static const std::map<ShortcutAction, std::string_view, std::less<>> ActionToStringMap{
Copy link
Member

Choose a reason for hiding this comment

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

We have got to stop it with the globally initialized maps. Sorry. This looks like a case for til::static_map or til::presorted_static_map. I'd rather do that than have yet another static initializer 😄

Copy link
Member Author

Choose a reason for hiding this comment

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

Should I do what we did with GeneratedActionNames in ActionAndArgs::GenerateName? Define these in the function they're used as static lambda functions. Or does that not make this any better?

Copy link
Member

Choose a reason for hiding this comment

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

@DHowett Can you explain the problem with static initializers for the uninitiated? 🙂

Copy link
Member

Choose a reason for hiding this comment

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

Sure!

Initializing a static non-constexpr value at file scope generates a block of code that must be executed when the library is loaded, every time it is loaded. For something like the settings model, that cost is paid once on startup, but it is still a cost that must be paid before any of the actual settings model code is run.

constexpr is a different story: those are evaluated at compile time and stored permanently in the binary.

For a really, really good example of the cost of a static initializer (or something very similar) and the payback you get from replacing it with a fully-constexpr data store, look at commit 16e1e29.

Copy link
Member

Choose a reason for hiding this comment

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

This seems fairly solid - it even offers perfect hash functions: https://github.com/serge-sans-paille/frozen

Copy link
Member Author

Choose a reason for hiding this comment

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

Leonard and I couldn't get this to work, unfortunately. We kept running into til::presorted_static_map saying that it couldn't find the static_map in the ctor or something like that. Sorry!

src/cascadia/TerminalSettingsModel/ActionAndArgs.cpp Outdated Show resolved Hide resolved
src/cascadia/TerminalSettingsModel/ActionAndArgs.cpp Outdated Show resolved Hide resolved
src/cascadia/TerminalSettingsModel/ActionArgs.h Outdated Show resolved Hide resolved
@ghost ghost added Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something and removed Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something labels May 17, 2021
@DHowett
Copy link
Member

DHowett commented May 17, 2021 via email

ghost pushed a commit that referenced this pull request May 18, 2021
## Summary of the Pull Request

This PR lays the foundation for a new Actions page in the Settings UI as designed in #6900. The Actions page now leverages the `ActionMap` to display all of the key bindings and allow the user to modify the associated key chord or delete the key binding entirely.

## References

#9621 - ActionMap
#9926 - ActionMap serialization
#9428 - ActionMap Spec
#6900 - Actions page
#9427 - Actions page design doc

## Detailed Description of the Pull Request / Additional comments

### Settings Model Changes

- `Command::Copy()` now copies the `ActionAndArgs`
- `ActionMap::RebindKeys()` handles changing the key chord of a key binding. If a conflict occurs, the conflicting key chord is overwritten.
- `ActionMap::DeleteKeyBinding()` "deletes" a key binding by binding "unbound" to the given key chord.
- `ActionMap::KeyBindings()` presents another view (similar to `NameMap`) of the `ActionMap`. It specifically presents a map of key chords to commands. It is generated similar to how `NameMap` is generated.

### Editor Changes

- `Actions.xaml` is mainly split into two parts:
   - `ListView` (as before) holds the list of key bindings. We _could_ explore the idea of an items repeater, but the `ListView` seems to provide some niceties with regards to navigating the list via the key board (though none are selectable).
   - `DataTemplate` is used to represent each key binding inside the `ListView`. This is tricky because it is bound to a `KeyBindingViewModel` which must provide _all_ context necessary to modify the UI and the settings model. We cannot use names to target UI elements inside this template, so we must make the view model smart and force updates to the UI via changes in the view model.
- `KeyBindingViewModel` is a view model object that controls the UI and the settings model. 

There are a number of TODOs in Actions.cpp will be long-term follow-ups and would be nice to have. This includes...
- a binary search by name on `Actions::KeyBindingList`
- presenting an error when the provided key chord is invalid.

## Demo
![Actions Page Demo](https://user-images.githubusercontent.com/11050425/116034988-131d1b80-a619-11eb-8df2-c7e57c6fad86.gif)
@carlos-zamora carlos-zamora added the AutoMerge Marked for automatic merge by the bot when requirements are met label May 18, 2021
@ghost
Copy link

ghost commented May 18, 2021

Hello @carlos-zamora!

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 ff8fdbd into main May 20, 2021
@ghost ghost deleted the dev/cazamor/tsm/am/serialization branch May 20, 2021 18:44
@ghost
Copy link

ghost commented May 25, 2021

🎉Windows Terminal Preview v1.9.1445.0 has been released which incorporates this pull request.:tada:

Handy links:

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 Issues related to settings and customizability, for console or terminal AutoMerge Marked for automatic merge by the bot when requirements are met Issue-Task It's a feature request, but it doesn't really need a major design. Needs-Second It's a PR that needs another sign-off Product-Terminal The new Windows Terminal.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants