Skip to content

Conversation

PankajBhojwani
Copy link
Contributor

@PankajBhojwani PankajBhojwani commented May 14, 2025

Implements reflection to the various ActionArg types in the settings model, which allows these structs to provide information about themselves (i.e. what args they contain and what types they are). This is necessary as a pre-requisite for the Settings Editor to display and modify these arg values.

Detailed Description of the Pull Request / Additional comments

  • The IActionArgs interface now has additional methods:
    • Get the number of args
    • Get/Set an arg at a specific index
    • Get a vector of arg descriptions; the arg description contains:
      • name of the arg
      • type of the arg
      • whether the arg is required
      • a tag, this is to cover special cases (for example the ColorScheme argument is technically of type "string", but only allows specific values)
  • All the macros in ActionArgsMagic have been updated to support the new interface
  • ActionMap has been updated to support adding/editing/deleting actions and keybindings from outside the SettingsModel
    • It also handles ID change requests for commands
  • EnumMappings have been added to various ActionArg enums that weren't there before

Validation Steps Performed

Bug bashed in conjunction with #18917

@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 May 15, 2025
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.

noted

@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 May 16, 2025
@@ -757,6 +838,12 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
AddAction(*cmd, keys);
}

void ActionMap::DeleteUserCommand(const winrt::hstring& cmdID)
{
_ActionMap.erase(cmdID);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
_ActionMap.erase(cmdID);
_ActionMap.erase(cmdID);
_changeLog.emplace(IDKey)

This one I'm iffy on, so I want to discuss here.

Currently, there isn't a place where we're tracking if a user added an ID. In the JSON, the user would be using "id" in two cases for Action Map:

  1. create a new action in the "actions" block (i.e. {"command": "terminalChat", "id": "User.terminalChat"})
    • That's fine? We care about action arg usage and that's already being handled.
  2. create a key binding in the "keybindings"block (i.e. {"id": "User.terminalChat", "keys": "ctrl+?})
    • That's fine too. We care about "keys" usage and that's already being handled.

(related: "id" is used in the new tab menu, but we're just tracking "action" there which is sufficient)

Long-term, however, we want _changeLog to be a way for us to know if the user changed anything. So maybe we do want to apply the code suggestion and update case 1 to add "id" too? Thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This one is tough because I imagine most users won't be actually adding their own IDs - it will just be autogenerated for them. So distinguishing between us generating an ID for them vs an ID they added or changed is... tricky

@PankajBhojwani PankajBhojwani marked this pull request as ready for review June 3, 2025 21:20
Copy link
Member

@carlos-zamora carlos-zamora left a comment

Choose a reason for hiding this comment

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

This looks great! Really just blocking over the missing SaveSnippet name in the map (the other two are a question and a suggestion). Nice work!

I'll come back and approve when that SaveSnippet comment gets resolved. I'll have to come back and approve it anyways haha.

@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 Jun 4, 2025
@microsoft-github-policy-service microsoft-github-policy-service bot added the No-Recent-Activity This issue/PR is going stale and may be auto-closed without further activity. label Jun 12, 2025
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.

16/18 files reviewed


// append this argument's description to the internal vector
#define APPEND_ARG_DESCRIPTION(type, name, jsonKey, required, typeHint, ...) \
temp.push_back({ RS_(LOCALIZED_NAME(name)), L## #type, std::wstring_view(L## #required) != L"false", typeHint });
Copy link
Member

Choose a reason for hiding this comment

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

can we not treat required as a true boolean? Is is because sometimes we have required be based on other properties?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

required is definitely a misleading word here, it's more like validation i.e. it takes the form of something like this: args->Commandline().empty() (in the case of EXECUTE_COMMANDLINE_ARGS for example). So what we're doing here is something like "this arg has a validation, therefore it is required" which isn't technically correct but works since the validation is all "this cannot be none/empty"


// append this argument's description to the internal vector
#define APPEND_ARG_DESCRIPTION(type, name, jsonKey, required, typeHint, ...) \
temp.push_back({ RS_(LOCALIZED_NAME(name)), L## #type, std::wstring_view(L## #required) != L"false", typeHint });
Copy link
Member

Choose a reason for hiding this comment

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

(note that using RS_ means it expands in the local language immediately on creation, rather than later during use)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I believe we discussed this and agreed to have it be this way for now because otherwise we would need the resource strings on the editor side

@PankajBhojwani PankajBhojwani merged commit f6303ac into main Sep 3, 2025
19 checks passed
@PankajBhojwani PankajBhojwani deleted the dev/pabhoj/settings_model_reflection branch September 3, 2025 20:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants