Skip to content

Commit ece0c04

Browse files
Refactor ActionMap and Command to use ActionIDs (#17162)
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
1 parent babd344 commit ece0c04

17 files changed

+1089
-726
lines changed

doc/cascadia/profiles.schema.json

+43-20
Original file line numberDiff line numberDiff line change
@@ -2058,7 +2058,7 @@
20582058
]
20592059
}
20602060
},
2061-
"Keybinding": {
2061+
"FullCommand": {
20622062
"additionalProperties": false,
20632063
"properties": {
20642064
"command": {
@@ -2186,21 +2186,6 @@
21862186
}
21872187
]
21882188
},
2189-
"keys": {
2190-
"description": "Defines the key combinations used to call the command. It must be composed of...\n -any number of modifiers (ctrl/alt/shift)\n -a non-modifier key",
2191-
"oneOf": [
2192-
{
2193-
"$ref": "#/$defs/KeyChordSegment"
2194-
},
2195-
{
2196-
"items": {
2197-
"$ref": "#/$defs/KeyChordSegment"
2198-
},
2199-
"minItems": 1,
2200-
"type": "array"
2201-
}
2202-
]
2203-
},
22042189
"icon": {
22052190
"$ref": "#/$defs/Icon"
22062191
},
@@ -2235,10 +2220,10 @@
22352220
"type": "object",
22362221
"properties": {
22372222
"command": {
2238-
"$ref": "#/$defs/Keybinding/properties/command"
2223+
"$ref": "#/$defs/FullCommand/properties/command"
22392224
},
22402225
"name": {
2241-
"$ref": "#/$defs/Keybinding/properties/name"
2226+
"$ref": "#/$defs/FullCommand/properties/name"
22422227
}
22432228
}
22442229
},
@@ -2261,6 +2246,44 @@
22612246
],
22622247
"type": "object"
22632248
},
2249+
"Keybinding": {
2250+
"additionalProperties": false,
2251+
"properties": {
2252+
"id": {
2253+
"description": "The ID of the command this keybinding should execute.",
2254+
"type": "string"
2255+
},
2256+
"keys": {
2257+
"description": "Defines the key combinations used to call the command. It must be composed of...\n -any number of modifiers (ctrl/alt/shift)\n -a non-modifier key",
2258+
"oneOf": [
2259+
{
2260+
"$ref": "#/$defs/KeyChordSegment"
2261+
},
2262+
{
2263+
"items": {
2264+
"$ref": "#/$defs/KeyChordSegment"
2265+
},
2266+
"minItems": 1,
2267+
"type": "array"
2268+
}
2269+
]
2270+
}
2271+
},
2272+
"anyOf": [
2273+
{
2274+
"required": [
2275+
"keys",
2276+
"id"
2277+
]
2278+
},
2279+
{
2280+
"required": [
2281+
"keys"
2282+
]
2283+
}
2284+
],
2285+
"type": "object"
2286+
},
22642287
"Globals": {
22652288
"additionalProperties": true,
22662289
"description": "Properties that affect the entire window, regardless of the profile settings.",
@@ -2464,12 +2487,12 @@
24642487
"actions": {
24652488
"description": "Properties are specific to each custom action.",
24662489
"items": {
2467-
"$ref": "#/$defs/Keybinding"
2490+
"$ref": "#/$defs/FullCommand"
24682491
},
24692492
"type": "array"
24702493
},
24712494
"keybindings": {
2472-
"description": "[deprecated] Use actions instead.",
2495+
"description": "A list of keychords bound to action IDs",
24732496
"deprecated": true,
24742497
"items": {
24752498
"$ref": "#/$defs/Keybinding"

src/cascadia/TerminalApp/TabBase.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,8 @@ namespace winrt::TerminalApp::implementation
192192
// - <none>
193193
void TabBase::_UpdateSwitchToTabKeyChord()
194194
{
195-
const auto keyChord = _actionMap ? _actionMap.GetKeyBindingForAction(ShortcutAction::SwitchToTab, SwitchToTabArgs{ _TabViewIndex }) : nullptr;
195+
const auto id = fmt::format(FMT_COMPILE(L"Terminal.SwitchToTab{}"), _TabViewIndex);
196+
const auto keyChord{ _actionMap.GetKeyBindingForAction(id) };
196197
const auto keyChordText = keyChord ? KeyChordSerialization::ToString(keyChord) : L"";
197198

198199
if (_keyChord == keyChordText)

src/cascadia/TerminalApp/TerminalPage.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,7 @@ namespace winrt::TerminalApp::implementation
826826
newTabFlyout.Items().Append(settingsItem);
827827

828828
auto actionMap = _settings.ActionMap();
829-
const auto settingsKeyChord{ actionMap.GetKeyBindingForAction(ShortcutAction::OpenSettings, OpenSettingsArgs{ SettingsTarget::SettingsUI }) };
829+
const auto settingsKeyChord{ actionMap.GetKeyBindingForAction(L"Terminal.OpenSettingsUI") };
830830
if (settingsKeyChord)
831831
{
832832
_SetAcceleratorForMenuItem(settingsItem, settingsKeyChord);
@@ -848,7 +848,7 @@ namespace winrt::TerminalApp::implementation
848848
commandPaletteFlyout.Click({ this, &TerminalPage::_CommandPaletteButtonOnClick });
849849
newTabFlyout.Items().Append(commandPaletteFlyout);
850850

851-
const auto commandPaletteKeyChord{ actionMap.GetKeyBindingForAction(ShortcutAction::ToggleCommandPalette) };
851+
const auto commandPaletteKeyChord{ actionMap.GetKeyBindingForAction(L"Terminal.ToggleCommandPalette") };
852852
if (commandPaletteKeyChord)
853853
{
854854
_SetAcceleratorForMenuItem(commandPaletteFlyout, commandPaletteKeyChord);
@@ -1023,7 +1023,8 @@ namespace winrt::TerminalApp::implementation
10231023
// NewTab(ProfileIndex=N) action
10241024
NewTerminalArgs newTerminalArgs{ profileIndex };
10251025
NewTabArgs newTabArgs{ newTerminalArgs };
1026-
auto profileKeyChord{ _settings.ActionMap().GetKeyBindingForAction(ShortcutAction::NewTab, newTabArgs) };
1026+
const auto id = fmt::format(FMT_COMPILE(L"Terminal.OpenNewTabProfile{}"), profileIndex);
1027+
const auto profileKeyChord{ _settings.ActionMap().GetKeyBindingForAction(id) };
10271028

10281029
// make sure we find one to display
10291030
if (profileKeyChord)

0 commit comments

Comments
 (0)