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

Allow setting the action on Actions page #10220

Merged
merged 8 commits into from
Jul 2, 2021

Conversation

carlos-zamora
Copy link
Member

@carlos-zamora carlos-zamora commented May 26, 2021

Summary of the Pull Request

This introduces the ability to set the action for a key binding. A combo box is used to let the user select a new action.

References

#6900 - Actions page Epic
#9427 - Actions page design doc
#9949 - Actions page PR

Detailed Description of the Pull Request / Additional comments

Settings Model Changes

  • ActionAndArgs
    • new ctor that just takes a ShortcutAction
  • ActionMap
    • AvailableActions provides a map of all the "acceptable" actions to choose from. This is a merged list of (1) all { "command": X } style actions and (2) any actions with args that are already defined in the ActionMap (or any parents).
    • RegisterKeyBinding introduces a new unnamed key binding to the action map.

Editor Changes

  • XAML
    • Pretty straightforward, when in edit mode, we replace the text block with a combo box. This combo box just presents the actions you can choose from.
  • RebindKeysEventArgs --> ModifyKeyBindingEventArgs
  • AvailableActionAndArgs
    • stores the list of actions to choose from in the combo box
    • Unfortunately, KeyBindingViewModel needs this so that we can populate the combo box
    • Actions stores and maintains this though. We populate this from the settings model on navigation.
  • ProposedAction vs CurrentAction
    • similar to ProposedKeys and Keys, we need a way to distinguish the value from the settings model and the value of the control (i.e. combo box).
    • CurrentAction --> settings model
    • ProposedAction --> combo box selected item

Validation Steps Performed

  • Cancel:
    • ✔️ change action --> cancel button --> begin editing action again --> original action is selected
  • Accept:
    • ✔️ don't change anything
    • ✔️ change action --> OK! --> Save!
      • NOTE: The original action is still left as a stub { "command": "closePane" }. This is intentional because we want to prevent all modifications to the command palette.
    • ✔️ change action & change key chord --> OK! --> Save!
    • ✔️ change action & change key chord (conflicting key chord) --> OK! --> click ok on flyout --> Save!
      • NOTE: original action is left as a stub; original key chord explicitly unbound; new command/keys combo added.

@carlos-zamora carlos-zamora self-assigned this Jun 7, 2021
@carlos-zamora carlos-zamora force-pushed the dev/cazamor/actions-page/change-action branch from afcc655 to 1453376 Compare June 7, 2021 22:23
@carlos-zamora carlos-zamora removed their assignment Jun 9, 2021
Copy link
Contributor

@leonMSFT leonMSFT left a comment

Choose a reason for hiding this comment

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

Other than trying out the ComboBox.Text property instead of SelectedItem, :shipit:


// Check for this special case:
// we're changing the key chord,
// but the new key chord is already in use
if (args.OldKeys().Modifiers() != args.NewKeys().Modifiers() || args.OldKeys().Vkey() != args.NewKeys().Vkey())
Copy link
Contributor

@PankajBhojwani PankajBhojwani Jun 28, 2021

Choose a reason for hiding this comment

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

Question: do we also want to display a warning for something like "this action already has a keybinding, are you sure you want to add another?"

I know having multiple keybindings for an action is totally fine and not really 'conflicting', but with the long list of actions we currently show it might be easy for a user to miss that they've already set a keybinding for an action but forgot about it

Copy link
Contributor

Choose a reason for hiding this comment

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

Totally okay with having this be a follow-up or a "wait until someone asks for it before we implement it" kinda thing, just wanted to know if it's been discussed already

Copy link
Contributor

@PankajBhojwani PankajBhojwani left a comment

Choose a reason for hiding this comment

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

Exciting!

src/cascadia/TerminalSettingsEditor/Actions.cpp Outdated Show resolved Hide resolved
Comment on lines +65 to +66
// ProposedAction: the entry selected by the combo box; may disagree with the settings model.
// CurrentAction: the combo box item that maps to the settings model value.
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand this description... Why can it disagree with the settings model? And why does the combo box item map to a settings model value? The way I understand the code, CurrentAction is the actual action identifier/name.

Copy link
Member Author

Choose a reason for hiding this comment

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

Really it's because we have the "cancel"/"ok" system (aka the "edit mode" system). CurrentAction serves as...

  1. a record of what to set ProposedAction to on a cancellation
  2. a form of translation between ProposedAction and the settings model

If we got rid of the "edit mode" system, we don't have to worry about (1) anymore. To get rid of (2), KeyBindingViewModel would need a reference to the ActionMap. But even then, I think it's better to keep the ActionMap reference at a higher layer so that we can identify conflicting key bindings and key chords before editing the settings model. I think that's a better separation of responsibilities imo.


// If the action was changed,
// update the settings model and view model appropriately
auto attemptSetAction = [=]() {
Copy link
Member

Choose a reason for hiding this comment

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

attemptSetAction is always called when attemptRebindKeys is.
You can just merge the two lambdas into one.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yup! I really only separated them out so that it's easier to read. I'm down to combine them, but I'm still worried about readability. Would something like this be clear maybe?

auto applyChangesToSettingsModel = [](){
   // code for 'attemptRebindKeys'
   // code for 'attemptSetAction'
};

src/cascadia/TerminalSettingsEditor/Actions.h Outdated Show resolved Hide resolved
src/cascadia/TerminalSettingsModel/ActionMap.cpp Outdated Show resolved Hide resolved
@ghost ghost added the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Jun 28, 2021
@carlos-zamora carlos-zamora self-assigned this Jun 28, 2021
@ghost ghost removed the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Jun 28, 2021
@carlos-zamora
Copy link
Member Author

carlos-zamora commented Jul 2, 2021

Other than trying out the ComboBox.Text property instead of SelectedItem, :shipit:

Dude, I have no idea where the ComboBox.Text property goes haha. I bound to it, and the combo box just starts off empty (as in, it isn't bound to anything). There's no text around it. Nothing! Maybe it's used when you enable IsEditable?

Edit: @leonMSFT

@carlos-zamora carlos-zamora removed their assignment Jul 2, 2021
@carlos-zamora
Copy link
Member Author

Since we're so close to this merging, I'm gonna add "add action" in a separate PR, not this one.

I'll leave that for tomorrow though. I hope it'll only take like half a day to implement tbh.

@lhecker lhecker self-requested a review July 2, 2021 01:47
Copy link
Member

@lhecker lhecker left a comment

Choose a reason for hiding this comment

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

  • I think the combined applyChangesToSettingsModel would be a good idea as it prevents you from forgetting to call both at once
  • You wrote an excellent description for ProposedAction/CurrentAction: This should IMO be part of the comment in the code

@carlos-zamora carlos-zamora merged commit d3b9a78 into main Jul 2, 2021
@carlos-zamora carlos-zamora deleted the dev/cazamor/actions-page/change-action branch July 2, 2021 22:35
ghost pushed a commit that referenced this pull request Jul 7, 2021
## Summary of the Pull Request
This adds the "add new" button to the actions page. It build on the work of #10220 by basically just adding a new list item to the top of the key binding list.

This also makes it so that if you click the "accept changes" button when you have an invalid key chord, we don't do anything.

## References
#6900 - Actions page Epic
#9427 - Actions page design doc
#10220 - Actions page PR - set action

## Detailed Description of the Pull Request / Additional comments
- `ModifyKeyBindingEventArgs` is used to introduce new key bindings. We just ignore `OldKeys` and `OldActionName` because both didn't exist before.
- `IsNewlyAdded` tracks if this is an action that was added, but has not been confirmed to add to the settings model.
- `CancelChanges()` is directly bound to the cancel button. This allows us to delete the key binding when it's clicked on a "newly added" action.

## Validation Steps Performed
- Cancel:
   - Deletes the action (because it doesn't truly exist until you confirm changes)
- Accept:
   - Adds the new action.
   - If you attempt to edit it, the delete button is back.
- Add Action:
   - Delete button should not be visible (redundant with 'Cancel')
   - Action should be initialized to a value
   - Key chord should be empty
   - Cannot add another action if a newly added action exists
- Keyboard interaction:
   - escape --> cancel
   - enter --> accept
- Accessibility:
   - "add new" button has a name
- Interaction with other key bindings:
   - editing another action --> delete the "newly added" action (it hasn't been added yet)
   - only one action can be edited at a time
@ghost
Copy link

ghost commented Jul 14, 2021

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

Handy links:

@ghost
Copy link

ghost commented Oct 20, 2021

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

Handy links:

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.

6 participants