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

Add IDs to Commands #16904

Merged
merged 32 commits into from
Apr 18, 2024
Merged

Add IDs to Commands #16904

merged 32 commits into from
Apr 18, 2024

Conversation

PankajBhojwani
Copy link
Contributor

@PankajBhojwani PankajBhojwani commented Mar 19, 2024

As laid out in #16816, adds an ID field to Command.

This first PR only adds IDs for built-in commands in defaults, and generates IDs for user-created commands that don't define an ID. Also note that for now we will not be allowing IDs for iterable/nested commands.

The follow-up PR is where we will actually use the IDs by referring to commands with them.

Refs #16816

Validation Steps Performed

User-created commands in the settings file get rewritten with generated IDs

// - Example: The "SendInput 'abc'" action will have the generated ID "User.sendInput.<hash of 'abc'>"
// Return Value:
// - The ID, based on the ShortcutAction and the Args
winrt::hstring ActionAndArgs::GenerateID() const
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These IDs are very similar to our InternalActionID except instead of also hashing the ShortcutAction, we only hash the Args and we leave the ShortcutAction as a string. Since these will end up in the user file, I prefer this as it will be more readable

Copy link
Member

Choose a reason for hiding this comment

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

this is clever, thanks!

Comment on lines +507 to +509
// we need to generate an ID for a command in the user settings if it doesn't already have one
auto actionMap{ winrt::get_self<ActionMap>(userSettings.globals->ActionMap()) };
fixedUp = actionMap->GenerateIDsForActions() || fixedUp;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since we aren't actually using these IDs yet, this could definitely be moved into the follow up PR that is actually going to refactor our maps to use the new IDs. However then that leaves this PR as just "adding an ID field to Command and barely populating them anywhere". I'm okay with either if anyone feels strongly about it

Copy link
Member

Choose a reason for hiding this comment

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

nah this is great

@PankajBhojwani PankajBhojwani marked this pull request as ready for review March 28, 2024 01:07
@DHowett
Copy link
Member

DHowett commented Mar 28, 2024

Notes from chat: test everything! test the round-trip serialization of a command with and without an ID, etc!

Copy link
Member

@DHowett DHowett left a comment

Choose a reason for hiding this comment

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

block for tests!

@microsoft-github-policy-service microsoft-github-policy-service bot 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 Mar 28, 2024
@zadjii-msft
Copy link
Member

omg why is this so little code

This comment has been minimized.

// - Example: The "SendInput 'abc'" action will have the generated ID "User.sendInput.<hash of 'abc'>"
// Return Value:
// - The ID, based on the ShortcutAction and the Args
winrt::hstring ActionAndArgs::GenerateID() const
Copy link
Member

Choose a reason for hiding this comment

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

this is clever, thanks!

src/cascadia/TerminalSettingsModel/ActionAndArgs.cpp Outdated Show resolved Hide resolved
src/cascadia/TerminalSettingsModel/ActionAndArgs.cpp Outdated Show resolved Hide resolved
src/cascadia/TerminalSettingsModel/ActionMap.cpp Outdated Show resolved Hide resolved
Comment on lines +507 to +509
// we need to generate an ID for a command in the user settings if it doesn't already have one
auto actionMap{ winrt::get_self<ActionMap>(userSettings.globals->ActionMap()) };
fixedUp = actionMap->GenerateIDsForActions() || fixedUp;
Copy link
Member

Choose a reason for hiding this comment

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

nah this is great

src/cascadia/TerminalSettingsModel/Command.cpp Outdated Show resolved Hide resolved
@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Apr 5, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot removed the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Apr 11, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Apr 12, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot removed the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Apr 12, 2024
@DHowett
Copy link
Member

DHowett commented Apr 17, 2024

FWIW, your sendInputID macro would benefit from a comment explaining why it's needed

and perhaps a better name like SEND_INPUT_ARCH_SPECIFIC_ACTION_HASH

@DHowett DHowett enabled auto-merge April 17, 2024 23:59
@DHowett DHowett added this pull request to the merge queue Apr 18, 2024
Merged via the queue into main with commit 06ab6f3 Apr 18, 2024
20 checks passed
@DHowett DHowett deleted the dev/pabhoj/action_id branch April 18, 2024 01:03
github-merge-queue bot pushed a commit that referenced this pull request Jun 4, 2024
As outlined in #16816, refactor `ActionMap` to use the new action IDs
added in #16904

## Validation steps performed

- [x] Legacy style commands are parsed correctly (and rewritten to the
new format)
- [x] Actions are still layered correctly and their IDs can be used to
'overwrite' actions in earlier layers
- [x] Keybindings that refer to an ID defined in another layer work
correctly
- [x] User-defined actions without an ID have one generated for them
(and their settings file is edited with it)
- [x] Schema updated

Refs #16816 
Closes #17133
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.

4 participants