Description
While working on #3391, I felt like there was a ton of boilerplate that was needed for each and every keybindings. The thought crossed my mind that we could do better, but I wasn't sure how. In my mind, I imagined a single file that described each of the ShortcutAction
s and their possible args, and a small script that just automatically generated all the necessary code to parse them, their args, and hook them up to the TerminalApp
.
Now that I've thought on it more, here are some of the steps that'll be needed:
- Take code from my command palette branch for
ShortcutActionDispatch
. This is a class that just handles the dispatching of actions. In that branch, I needed it because both keybindings and commands needed to be able to dispatchShortcutAction
s, but onlyAppKeyBindings
needed to do aKeyChord
lookup. This code being encapsulated will be necessary for a future step. - Add more _templated_ JsonUtils #2550 Add more templated json utils. We'll need this to be able to automagically generate the code to parse a given type from a
Json::Value
- Move the code around so that anything having to do with the entirety of the list of
ShortcutAction
s is in single files by themselves:- AppKeybindingSerialization should only deal with parsing keychords. Lets put the
ShortcutAction
s and their keys in another file - Add a
IShortcutActionHandler
interface, with_Handle{{SomeShortcutAction}}(auto&& sender, ActionArgs args)
methods for eachShortcutAction
. It should declare all the event handlers, but not the definitions. - Make
TerminalPage
extendIShortcutActionHandler
. This will be necessary to make sure TerminalPage implements each of them. - That one method that hooks up the
TerminalPage
to theShortcutActionDispatch
. Pull that into it's own file as well.
- AppKeybindingSerialization should only deal with parsing keychords. Lets put the
- Write a script that parses
profiles.schema.json
for each of the "*ShortcutAction" definitions, and turns them into code in all the necessary files-
ShortcutActionKeys.h
-
ActionAndArgs.idl
/.h
/.cpp
-
ShortcutActionDispatch.idl
/.h
/.cpp
-
IShortcutActionHandler.h
- For actions that are listed in
ShortcutAction
s but don't have a properArgs
type, then make sure that they're still dispatched correctly - When the number of args changes, write the above files, and display a message that the developer needs to update
AppActionHandlers.cpp
to add implementations for the new types. - Validate that all "*ShortcutAction"s listed in the schema actually show up in the
onOf
schema forKeybinding
-
Each top-level box could be it's own task here.
In the end, the developer should be able to modify the schema for add their new argument or ShortcutAction
, and run a script, and the script should automatically write all the modifications necessary.
I'll probably need to do this in powershell. cmd
would be impossible, and as much as I love python
, I don't think that's really a part of our toolchain at all currently.