Add support for arbitrary args in keybindings (#3391)
## Summary of the Pull Request
Enables the user to provide arbitrary argument values to shortcut actions through a new `args` member of keybindings. For some keybindings, like `NewTabWithProfile<N>`, we previously needed 9 different `ShortcutAction`s, one for each value of `Index`. If a user wanted to have a `NewTabWithProfile11` keybinding, that was simply impossible. Now that the args are in their own separate json object, each binding can accept any number of arbitrary argument values.
So instead of:
```json
{ "command": "newTab", "keys": ["ctrl+shift+t"] },
{ "command": "newTabProfile0", "keys": ["ctrl+shift+1"] },
{ "command": "newTabProfile1", "keys": ["ctrl+shift+2"] },
{ "command": "newTabProfile2", "keys": ["ctrl+shift+3"] },
{ "command": "newTabProfile3", "keys": ["ctrl+shift+4"] },
```
We can now use:
```json
{ "command": "newTab", "keys": ["ctrl+shift+t"] },
{ "command": { "action": "newTab", "index": 0 }, "keys": ["ctrl+shift+1"] },
{ "command": { "action": "newTab", "index": 1 }, "keys": ["ctrl+shift+2"] },
{ "command": { "action": "newTab", "index": 2 }, "keys": ["ctrl+shift+3"] },
```
Initially, this does seem more verbose. However, for cases where there are multiple args, or there's a large range of values for the args, this will quickly become a more powerful system of expressing keybindings.
The "legacy" keybindings are _left in_ in this PR. They have helper methods to generate appropriate `IActionArgs` values. Prior to releasing 1.0, I think we should remove them, if only to remove some code bloat.
## References
See [the spec](https://github.com/microsoft/terminal/blob/master/doc/specs/%231142%20-%20Keybinding%20Arguments.md) for more details.
This is part two of the implementation, part one was #2446
## PR Checklist
* [x] Closes #1142
* [x] I work here
* [x] Tests added/passed
* [x] Schema updated
## Validation Steps Performed
* Ran Tests
* Removed the legacy keybindings from the `defaults.json`, everything still works
* Tried leaving the legacy keybingings in my `profiles.json`, everything still works.
-------------------------------------------------
* this is a start, but there's a weird linker bug if I take the SetKeybinding(ShortcutAction, KeyChord) implementation out, which I don't totally understand
* a good old-fashioned clean will fix that right up
* all these things work
* hey this actually _functionally_ works
* Mostly cleanup and completion of implementation
* Hey I bet we could just make NewTab the handler for NewTabWithProfile
* Start writing tests for Keybinding args
* Add tests
* Revert a bad sln change, and clean out dead code
* Change to include "command" as a single object
This is a change to make @dhowett-msft happy. Changes the args to be a part
of the "command" object, as opposed to an object on their own.
EX:
```jsonc
// Old style
{ "command": "switchToTab0", "keys": ["ctrl+1"] },
{ "command": { "action": "switchToTab", "index": 0 }, "keys": ["ctrl+alt+1"] },
// new style
{ "command": "switchToTab0", "keys": ["ctrl+1"] },
{ "command": "switchToTab", "args": { "index": 0 } "keys": ["ctrl+alt+1"] },
```
* schemas are hard yo
* Fix the build?
* wonder why my -Wall settings are different than CI...
* this makes me hate things
* Comments from PR
* Add a `Direction::None`
* LOAD BEARING
* add some GH ids to TODOs
* add a comment
* PR nits from carlos
2019-11-14 23:23:40 +01:00
|
|
|
#include "pch.h"
|
2020-06-15 15:33:30 +02:00
|
|
|
#include "ActionArgs.h"
|
Add support for arbitrary args in keybindings (#3391)
## Summary of the Pull Request
Enables the user to provide arbitrary argument values to shortcut actions through a new `args` member of keybindings. For some keybindings, like `NewTabWithProfile<N>`, we previously needed 9 different `ShortcutAction`s, one for each value of `Index`. If a user wanted to have a `NewTabWithProfile11` keybinding, that was simply impossible. Now that the args are in their own separate json object, each binding can accept any number of arbitrary argument values.
So instead of:
```json
{ "command": "newTab", "keys": ["ctrl+shift+t"] },
{ "command": "newTabProfile0", "keys": ["ctrl+shift+1"] },
{ "command": "newTabProfile1", "keys": ["ctrl+shift+2"] },
{ "command": "newTabProfile2", "keys": ["ctrl+shift+3"] },
{ "command": "newTabProfile3", "keys": ["ctrl+shift+4"] },
```
We can now use:
```json
{ "command": "newTab", "keys": ["ctrl+shift+t"] },
{ "command": { "action": "newTab", "index": 0 }, "keys": ["ctrl+shift+1"] },
{ "command": { "action": "newTab", "index": 1 }, "keys": ["ctrl+shift+2"] },
{ "command": { "action": "newTab", "index": 2 }, "keys": ["ctrl+shift+3"] },
```
Initially, this does seem more verbose. However, for cases where there are multiple args, or there's a large range of values for the args, this will quickly become a more powerful system of expressing keybindings.
The "legacy" keybindings are _left in_ in this PR. They have helper methods to generate appropriate `IActionArgs` values. Prior to releasing 1.0, I think we should remove them, if only to remove some code bloat.
## References
See [the spec](https://github.com/microsoft/terminal/blob/master/doc/specs/%231142%20-%20Keybinding%20Arguments.md) for more details.
This is part two of the implementation, part one was #2446
## PR Checklist
* [x] Closes #1142
* [x] I work here
* [x] Tests added/passed
* [x] Schema updated
## Validation Steps Performed
* Ran Tests
* Removed the legacy keybindings from the `defaults.json`, everything still works
* Tried leaving the legacy keybingings in my `profiles.json`, everything still works.
-------------------------------------------------
* this is a start, but there's a weird linker bug if I take the SetKeybinding(ShortcutAction, KeyChord) implementation out, which I don't totally understand
* a good old-fashioned clean will fix that right up
* all these things work
* hey this actually _functionally_ works
* Mostly cleanup and completion of implementation
* Hey I bet we could just make NewTab the handler for NewTabWithProfile
* Start writing tests for Keybinding args
* Add tests
* Revert a bad sln change, and clean out dead code
* Change to include "command" as a single object
This is a change to make @dhowett-msft happy. Changes the args to be a part
of the "command" object, as opposed to an object on their own.
EX:
```jsonc
// Old style
{ "command": "switchToTab0", "keys": ["ctrl+1"] },
{ "command": { "action": "switchToTab", "index": 0 }, "keys": ["ctrl+alt+1"] },
// new style
{ "command": "switchToTab0", "keys": ["ctrl+1"] },
{ "command": "switchToTab", "args": { "index": 0 } "keys": ["ctrl+alt+1"] },
```
* schemas are hard yo
* Fix the build?
* wonder why my -Wall settings are different than CI...
* this makes me hate things
* Comments from PR
* Add a `Direction::None`
* LOAD BEARING
* add some GH ids to TODOs
* add a comment
* PR nits from carlos
2019-11-14 23:23:40 +01:00
|
|
|
#include "ActionAndArgs.h"
|
|
|
|
#include "ActionAndArgs.g.cpp"
|
2020-07-17 03:31:09 +02:00
|
|
|
|
|
|
|
#include "JsonUtils.h"
|
|
|
|
|
2020-06-26 22:38:02 +02:00
|
|
|
#include <LibraryResources.h>
|
2020-06-15 15:33:30 +02:00
|
|
|
|
2020-08-20 03:02:10 +02:00
|
|
|
static constexpr std::string_view AdjustFontSizeKey{ "adjustFontSize" };
|
|
|
|
static constexpr std::string_view CloseOtherTabsKey{ "closeOtherTabs" };
|
|
|
|
static constexpr std::string_view ClosePaneKey{ "closePane" };
|
|
|
|
static constexpr std::string_view CloseTabKey{ "closeTab" };
|
|
|
|
static constexpr std::string_view CloseTabsAfterKey{ "closeTabsAfter" };
|
|
|
|
static constexpr std::string_view CloseWindowKey{ "closeWindow" };
|
2020-06-15 15:33:30 +02:00
|
|
|
static constexpr std::string_view CopyTextKey{ "copy" };
|
|
|
|
static constexpr std::string_view DuplicateTabKey{ "duplicateTab" };
|
2020-08-20 03:02:10 +02:00
|
|
|
static constexpr std::string_view ExecuteCommandlineKey{ "wt" };
|
|
|
|
static constexpr std::string_view FindKey{ "find" };
|
|
|
|
static constexpr std::string_view MoveFocusKey{ "moveFocus" };
|
2020-06-15 15:33:30 +02:00
|
|
|
static constexpr std::string_view NewTabKey{ "newTab" };
|
|
|
|
static constexpr std::string_view NextTabKey{ "nextTab" };
|
2020-08-20 03:02:10 +02:00
|
|
|
static constexpr std::string_view OpenNewTabDropdownKey{ "openNewTabDropdown" };
|
2021-02-24 01:14:13 +01:00
|
|
|
static constexpr std::string_view OpenSettingsKey{ "openSettings" };
|
2020-08-20 03:02:10 +02:00
|
|
|
static constexpr std::string_view OpenTabColorPickerKey{ "openTabColorPicker" };
|
|
|
|
static constexpr std::string_view PasteTextKey{ "paste" };
|
2020-06-15 15:33:30 +02:00
|
|
|
static constexpr std::string_view PrevTabKey{ "prevTab" };
|
2020-08-20 03:02:10 +02:00
|
|
|
static constexpr std::string_view RenameTabKey{ "renameTab" };
|
2020-10-28 20:36:30 +01:00
|
|
|
static constexpr std::string_view OpenTabRenamerKey{ "openTabRenamer" };
|
2020-06-15 15:33:30 +02:00
|
|
|
static constexpr std::string_view ResetFontSizeKey{ "resetFontSize" };
|
2020-08-20 03:02:10 +02:00
|
|
|
static constexpr std::string_view ResizePaneKey{ "resizePane" };
|
2020-06-15 15:33:30 +02:00
|
|
|
static constexpr std::string_view ScrolldownKey{ "scrollDown" };
|
|
|
|
static constexpr std::string_view ScrolldownpageKey{ "scrollDownPage" };
|
2020-08-20 03:02:10 +02:00
|
|
|
static constexpr std::string_view ScrollupKey{ "scrollUp" };
|
|
|
|
static constexpr std::string_view ScrolluppageKey{ "scrollUpPage" };
|
2020-12-08 18:28:41 +01:00
|
|
|
static constexpr std::string_view ScrollToTopKey{ "scrollToTop" };
|
|
|
|
static constexpr std::string_view ScrollToBottomKey{ "scrollToBottom" };
|
2020-08-12 15:46:53 +02:00
|
|
|
static constexpr std::string_view SendInputKey{ "sendInput" };
|
2020-08-10 18:21:56 +02:00
|
|
|
static constexpr std::string_view SetColorSchemeKey{ "setColorScheme" };
|
Add `setTabColor` and `openTabColorPicker` actions (#6567)
## Summary of the Pull Request
Adds a pair of `ShortcutAction`s for setting the tab color.
* `setTabColor`: This changes the color of the current tab to the provided color, or can be used to clear the color.
* `openTabColorPicker`: This keybinding immediately activates the tab color picker for the currently focused tab.
## References
## PR Checklist
* [x] scratches my own itch
* [x] I work here
* [x] Tests added/passed
* [x] https://github.com/MicrosoftDocs/terminal/pull/69
## Detailed Description of the Pull Request / Additional comments
## Validation Steps Performed
* hey look there are tests
* Tested with the following:
```json
// { "command": "setTabColor", "keys": [ "alt+c" ] },
{ "keys": "ctrl+alt+c", "command": { "action": "setTabColor", "color": "#123456" } },
{ "keys": "alt+shift+c", "command": { "action": "setTabColor", "color": null} },
{ "keys": "alt+c", "command": "openTabColorPicker" },
```
2020-06-25 15:06:21 +02:00
|
|
|
static constexpr std::string_view SetTabColorKey{ "setTabColor" };
|
2020-08-20 03:02:10 +02:00
|
|
|
static constexpr std::string_view SplitPaneKey{ "splitPane" };
|
|
|
|
static constexpr std::string_view SwitchToTabKey{ "switchToTab" };
|
2020-08-21 17:39:40 +02:00
|
|
|
static constexpr std::string_view TabSearchKey{ "tabSearch" };
|
2020-08-20 03:02:10 +02:00
|
|
|
static constexpr std::string_view ToggleAlwaysOnTopKey{ "toggleAlwaysOnTop" };
|
2020-06-26 22:38:02 +02:00
|
|
|
static constexpr std::string_view ToggleCommandPaletteKey{ "commandPalette" };
|
2020-08-20 03:02:10 +02:00
|
|
|
static constexpr std::string_view ToggleFocusModeKey{ "toggleFocusMode" };
|
|
|
|
static constexpr std::string_view ToggleFullscreenKey{ "toggleFullscreen" };
|
|
|
|
static constexpr std::string_view TogglePaneZoomKey{ "togglePaneZoom" };
|
Implement user-specified pixel shaders, redux (#8565)
Co-authored-by: mrange <marten_range@hotmail.com>
I loved the pixel shaders in #7058, but that PR needed a bit of polish
to be ready for ingestion. This PR is almost _exactly_ that PR, with
some small changes.
* It adds a new pre-profile setting `"experimental.pixelShaderPath"`,
which lets the user set a pixel shader to use with the Terminal.
- CHANGED FROM #7058: It does _not_ add any built-in shaders.
- CHANGED FROM #7058: it will _override_
`experimental.retroTerminalEffect`
* It adds a bunch of sample shaders in `samples/shaders`. Included:
- A NOP shader as a base to build from.
- An "invert" shader that inverts the colors, as a simple example
- An "grayscale" shader that converts all colors to grayscale, as a
simple example
- An "raster bars" shader that draws some colored bars on the screen
with a drop shadow, as a more involved example
- The original retro terminal effects, as a more involved example
- It also includes a broken shader, as an example of what heppens
when the shader fails to compile
- CHANGED FROM #7058: It does _not_ add the "retroII" shader we were
all worried about.
* When a shader fails to be found or fails to compile, we'll display an
error dialog to the user with a relevant error message.
- CHANGED FROM #7058: Originally, #7058 would display "error bars"
on the screen. I've removed that, and had the Terminal disable the
shader entirely then.
* Renames the `toggleRetroEffect` action to `toggleShaderEffect`.
(`toggleRetroEffect` is now an alias to `toggleShaderEffect`). This
action will turn the shader OR the retro effects on/off.
`toggleShaderEffect` works the way you'd expect it to, but the mental
math on _how_ is a little weird. The logic is basically:
```
useShader = shaderEffectsEnabled ?
(pixelShaderProvided ?
pixelShader :
(retroEffectEnabled ?
retroEffect : null
)
) :
null
```
and `toggleShaderEffect` toggles `shaderEffectsEnabled`.
* If you've got both a shader and retro enabled, `toggleShaderEffect`
will toggle between the shader on/off.
* If you've got a shader and retro disabled, `toggleShaderEffect` will
toggle between the shader on/off.
References #6191
References #7058
Closes #7013
Closes #3930 "Add setting to retro terminal shader to control blur
radius, color"
Closes #3929 "Add setting to retro terminal shader to enable drawing
scanlines"
- At this point, just roll your own version of the shader.
2020-12-15 21:40:22 +01:00
|
|
|
static constexpr std::string_view LegacyToggleRetroEffectKey{ "toggleRetroEffect" };
|
|
|
|
static constexpr std::string_view ToggleShaderEffectsKey{ "toggleShaderEffects" };
|
2020-11-25 23:09:27 +01:00
|
|
|
static constexpr std::string_view MoveTabKey{ "moveTab" };
|
2020-12-05 00:54:59 +01:00
|
|
|
static constexpr std::string_view BreakIntoDebuggerKey{ "breakIntoDebugger" };
|
Add `findNext`, `findPrev` actions (#8917)
This PR is a resurrection of #8522. @Hegunumo has apparently deleted
their account, but the contribution was still valuable. I'm just here to
get it across the finish line.
This PR adds new action for navigating to the next & previous search
results. These actions are unbound by default. These actions can be used
from directly within the search dialog also, to immediately navigate the
results.
Furthermore, if you have a search started, and close the search box,
then press this keybinding, _it will still perform the search_. So you
can just hit <kbd>F3</kbd> repeatedly with the dialog closed to keep
searching new results. Neat!
If you dispatch the action on the key down, then dismiss a selection on
a key up, we'll end up immediately destroying the selection when you
release the bound key. That's annoying. It also bothers @carlos-zamora
in #3758. However, I _think_ we can just only dismiss the selection on a
key up. I _think_ that's fine. It _seems_ fine so far. We've got an
entire release cycle to futz with it.
## Validation Steps Performed
I've played with it all day and it seems _crisp_.
Closes #7695
Co-authored-by: Kiminori Kaburagi <yukawa_hidenori@icloud.com>
2021-02-18 20:21:35 +01:00
|
|
|
static constexpr std::string_view FindMatchKey{ "findMatch" };
|
2021-02-08 19:03:55 +01:00
|
|
|
static constexpr std::string_view TogglePaneReadOnlyKey{ "toggleReadOnlyMode" };
|
2021-02-20 00:51:30 +01:00
|
|
|
static constexpr std::string_view NewWindowKey{ "newWindow" };
|
2021-03-30 18:08:03 +02:00
|
|
|
static constexpr std::string_view IdentifyWindowKey{ "identifyWindow" };
|
|
|
|
static constexpr std::string_view IdentifyWindowsKey{ "identifyWindows" };
|
Add support for renaming windows (#9662)
## Summary of the Pull Request
This PR adds support for renaming windows.
![window-renaming-000](https://user-images.githubusercontent.com/18356694/113034344-9a30be00-9157-11eb-9443-975f3c294f56.gif)
![window-renaming-001](https://user-images.githubusercontent.com/18356694/113034452-b5033280-9157-11eb-9e35-e5ac80fef0bc.gif)
It does so through two new actions:
* `renameWindow` takes a `name` parameter, and attempts to set the window's name
to the provided name. This is useful if you always want to hit <kbd>F3</kbd>
and rename a window to "foo" (READ: probably not that useful)
* `openWindowRenamer` is more interesting: it opens a `TeachingTip` with a
`TextBox`. When the user hits Ok, it'll request a rename for the provided
value. This lets the user pick a new name for the window at runtime.
In both cases, if there's already a window with that name, then the monarch will
reject the rename, and pop a `Toast` in the window informing the user that the
rename failed. Nifty!
## References
* Builds on the toasts from #9523
* #5000 - process model megathread
## PR Checklist
* [x] Closes https://github.com/microsoft/terminal/projects/5#card-50771747
* [x] I work here
* [x] Tests addded (and pass with the help of #9660)
* [ ] Requires documentation to be updated
## Detailed Description of the Pull Request / Additional comments
I'm sending this PR while finishing up the tests. I figured I'll have time to sneak them in before I get the necessary reviews.
> PAIN: We can't immediately focus the textbox in the TeachingTip. It's
> not technically focusable until it is opened. However, it doesn't
> provide an even tto tell us when it is opened. That's tracked in
> microsoft/microsoft-ui-xaml#1607. So for now, the user _needs_ to
> click on the text box manually.
> We're also not using a ContentDialog for this, because in Xaml
> Islands a text box in a ContentDialog won't recieve _any_ keypresses.
> Fun!
## Validation Steps Performed
I've been playing with
```json
{ "keys": "f1", "command": "identifyWindow" },
{ "keys": "f2", "command": "identifyWindows" },
{ "keys": "f3", "command": "openWindowRenamer" },
{ "keys": "f4", "command": { "action": "renameWindow", "name": "foo" } },
{ "keys": "f5", "command": { "action": "renameWindow", "name": "bar" } },
```
and they seem to work as expected
2021-04-02 18:00:04 +02:00
|
|
|
static constexpr std::string_view RenameWindowKey{ "renameWindow" };
|
|
|
|
static constexpr std::string_view OpenWindowRenamerKey{ "openWindowRenamer" };
|
2020-06-26 22:38:02 +02:00
|
|
|
|
|
|
|
static constexpr std::string_view ActionKey{ "action" };
|
|
|
|
|
|
|
|
// This key is reserved to remove a keybinding, instead of mapping it to an action.
|
|
|
|
static constexpr std::string_view UnboundKey{ "unbound" };
|
Add support for arbitrary args in keybindings (#3391)
## Summary of the Pull Request
Enables the user to provide arbitrary argument values to shortcut actions through a new `args` member of keybindings. For some keybindings, like `NewTabWithProfile<N>`, we previously needed 9 different `ShortcutAction`s, one for each value of `Index`. If a user wanted to have a `NewTabWithProfile11` keybinding, that was simply impossible. Now that the args are in their own separate json object, each binding can accept any number of arbitrary argument values.
So instead of:
```json
{ "command": "newTab", "keys": ["ctrl+shift+t"] },
{ "command": "newTabProfile0", "keys": ["ctrl+shift+1"] },
{ "command": "newTabProfile1", "keys": ["ctrl+shift+2"] },
{ "command": "newTabProfile2", "keys": ["ctrl+shift+3"] },
{ "command": "newTabProfile3", "keys": ["ctrl+shift+4"] },
```
We can now use:
```json
{ "command": "newTab", "keys": ["ctrl+shift+t"] },
{ "command": { "action": "newTab", "index": 0 }, "keys": ["ctrl+shift+1"] },
{ "command": { "action": "newTab", "index": 1 }, "keys": ["ctrl+shift+2"] },
{ "command": { "action": "newTab", "index": 2 }, "keys": ["ctrl+shift+3"] },
```
Initially, this does seem more verbose. However, for cases where there are multiple args, or there's a large range of values for the args, this will quickly become a more powerful system of expressing keybindings.
The "legacy" keybindings are _left in_ in this PR. They have helper methods to generate appropriate `IActionArgs` values. Prior to releasing 1.0, I think we should remove them, if only to remove some code bloat.
## References
See [the spec](https://github.com/microsoft/terminal/blob/master/doc/specs/%231142%20-%20Keybinding%20Arguments.md) for more details.
This is part two of the implementation, part one was #2446
## PR Checklist
* [x] Closes #1142
* [x] I work here
* [x] Tests added/passed
* [x] Schema updated
## Validation Steps Performed
* Ran Tests
* Removed the legacy keybindings from the `defaults.json`, everything still works
* Tried leaving the legacy keybingings in my `profiles.json`, everything still works.
-------------------------------------------------
* this is a start, but there's a weird linker bug if I take the SetKeybinding(ShortcutAction, KeyChord) implementation out, which I don't totally understand
* a good old-fashioned clean will fix that right up
* all these things work
* hey this actually _functionally_ works
* Mostly cleanup and completion of implementation
* Hey I bet we could just make NewTab the handler for NewTabWithProfile
* Start writing tests for Keybinding args
* Add tests
* Revert a bad sln change, and clean out dead code
* Change to include "command" as a single object
This is a change to make @dhowett-msft happy. Changes the args to be a part
of the "command" object, as opposed to an object on their own.
EX:
```jsonc
// Old style
{ "command": "switchToTab0", "keys": ["ctrl+1"] },
{ "command": { "action": "switchToTab", "index": 0 }, "keys": ["ctrl+alt+1"] },
// new style
{ "command": "switchToTab0", "keys": ["ctrl+1"] },
{ "command": "switchToTab", "args": { "index": 0 } "keys": ["ctrl+alt+1"] },
```
* schemas are hard yo
* Fix the build?
* wonder why my -Wall settings are different than CI...
* this makes me hate things
* Comments from PR
* Add a `Direction::None`
* LOAD BEARING
* add some GH ids to TODOs
* add a comment
* PR nits from carlos
2019-11-14 23:23:40 +01:00
|
|
|
|
2020-10-06 18:56:59 +02:00
|
|
|
namespace winrt::Microsoft::Terminal::Settings::Model::implementation
|
Add support for arbitrary args in keybindings (#3391)
## Summary of the Pull Request
Enables the user to provide arbitrary argument values to shortcut actions through a new `args` member of keybindings. For some keybindings, like `NewTabWithProfile<N>`, we previously needed 9 different `ShortcutAction`s, one for each value of `Index`. If a user wanted to have a `NewTabWithProfile11` keybinding, that was simply impossible. Now that the args are in their own separate json object, each binding can accept any number of arbitrary argument values.
So instead of:
```json
{ "command": "newTab", "keys": ["ctrl+shift+t"] },
{ "command": "newTabProfile0", "keys": ["ctrl+shift+1"] },
{ "command": "newTabProfile1", "keys": ["ctrl+shift+2"] },
{ "command": "newTabProfile2", "keys": ["ctrl+shift+3"] },
{ "command": "newTabProfile3", "keys": ["ctrl+shift+4"] },
```
We can now use:
```json
{ "command": "newTab", "keys": ["ctrl+shift+t"] },
{ "command": { "action": "newTab", "index": 0 }, "keys": ["ctrl+shift+1"] },
{ "command": { "action": "newTab", "index": 1 }, "keys": ["ctrl+shift+2"] },
{ "command": { "action": "newTab", "index": 2 }, "keys": ["ctrl+shift+3"] },
```
Initially, this does seem more verbose. However, for cases where there are multiple args, or there's a large range of values for the args, this will quickly become a more powerful system of expressing keybindings.
The "legacy" keybindings are _left in_ in this PR. They have helper methods to generate appropriate `IActionArgs` values. Prior to releasing 1.0, I think we should remove them, if only to remove some code bloat.
## References
See [the spec](https://github.com/microsoft/terminal/blob/master/doc/specs/%231142%20-%20Keybinding%20Arguments.md) for more details.
This is part two of the implementation, part one was #2446
## PR Checklist
* [x] Closes #1142
* [x] I work here
* [x] Tests added/passed
* [x] Schema updated
## Validation Steps Performed
* Ran Tests
* Removed the legacy keybindings from the `defaults.json`, everything still works
* Tried leaving the legacy keybingings in my `profiles.json`, everything still works.
-------------------------------------------------
* this is a start, but there's a weird linker bug if I take the SetKeybinding(ShortcutAction, KeyChord) implementation out, which I don't totally understand
* a good old-fashioned clean will fix that right up
* all these things work
* hey this actually _functionally_ works
* Mostly cleanup and completion of implementation
* Hey I bet we could just make NewTab the handler for NewTabWithProfile
* Start writing tests for Keybinding args
* Add tests
* Revert a bad sln change, and clean out dead code
* Change to include "command" as a single object
This is a change to make @dhowett-msft happy. Changes the args to be a part
of the "command" object, as opposed to an object on their own.
EX:
```jsonc
// Old style
{ "command": "switchToTab0", "keys": ["ctrl+1"] },
{ "command": { "action": "switchToTab", "index": 0 }, "keys": ["ctrl+alt+1"] },
// new style
{ "command": "switchToTab0", "keys": ["ctrl+1"] },
{ "command": "switchToTab", "args": { "index": 0 } "keys": ["ctrl+alt+1"] },
```
* schemas are hard yo
* Fix the build?
* wonder why my -Wall settings are different than CI...
* this makes me hate things
* Comments from PR
* Add a `Direction::None`
* LOAD BEARING
* add some GH ids to TODOs
* add a comment
* PR nits from carlos
2019-11-14 23:23:40 +01:00
|
|
|
{
|
2020-10-06 18:56:59 +02:00
|
|
|
using namespace ::Microsoft::Terminal::Settings::Model;
|
2020-07-17 03:31:09 +02:00
|
|
|
|
2020-06-15 15:33:30 +02:00
|
|
|
// Specifically use a map here over an unordered_map. We want to be able to
|
|
|
|
// iterate over these entries in-order when we're serializing the keybindings.
|
|
|
|
// HERE BE DRAGONS:
|
|
|
|
// These are string_views that are being used as keys. These string_views are
|
|
|
|
// just pointers to other strings. This could be dangerous, if the map outlived
|
|
|
|
// the actual strings being pointed to. However, since both these strings and
|
|
|
|
// the map are all const for the lifetime of the app, we have nothing to worry
|
|
|
|
// about here.
|
2020-06-26 22:38:02 +02:00
|
|
|
const std::map<std::string_view, ShortcutAction, std::less<>> ActionAndArgs::ActionKeyNamesMap{
|
2020-08-20 03:02:10 +02:00
|
|
|
{ AdjustFontSizeKey, ShortcutAction::AdjustFontSize },
|
|
|
|
{ CloseOtherTabsKey, ShortcutAction::CloseOtherTabs },
|
|
|
|
{ ClosePaneKey, ShortcutAction::ClosePane },
|
|
|
|
{ CloseTabKey, ShortcutAction::CloseTab },
|
|
|
|
{ CloseTabsAfterKey, ShortcutAction::CloseTabsAfter },
|
|
|
|
{ CloseWindowKey, ShortcutAction::CloseWindow },
|
2020-06-15 15:33:30 +02:00
|
|
|
{ CopyTextKey, ShortcutAction::CopyText },
|
|
|
|
{ DuplicateTabKey, ShortcutAction::DuplicateTab },
|
2020-08-20 03:02:10 +02:00
|
|
|
{ ExecuteCommandlineKey, ShortcutAction::ExecuteCommandline },
|
|
|
|
{ FindKey, ShortcutAction::Find },
|
|
|
|
{ MoveFocusKey, ShortcutAction::MoveFocus },
|
2020-06-15 15:33:30 +02:00
|
|
|
{ NewTabKey, ShortcutAction::NewTab },
|
|
|
|
{ NextTabKey, ShortcutAction::NextTab },
|
2020-08-20 03:02:10 +02:00
|
|
|
{ OpenNewTabDropdownKey, ShortcutAction::OpenNewTabDropdown },
|
|
|
|
{ OpenSettingsKey, ShortcutAction::OpenSettings },
|
|
|
|
{ OpenTabColorPickerKey, ShortcutAction::OpenTabColorPicker },
|
|
|
|
{ PasteTextKey, ShortcutAction::PasteText },
|
2020-06-15 15:33:30 +02:00
|
|
|
{ PrevTabKey, ShortcutAction::PrevTab },
|
2020-08-20 03:02:10 +02:00
|
|
|
{ RenameTabKey, ShortcutAction::RenameTab },
|
2020-10-28 20:36:30 +01:00
|
|
|
{ OpenTabRenamerKey, ShortcutAction::OpenTabRenamer },
|
2020-06-15 15:33:30 +02:00
|
|
|
{ ResetFontSizeKey, ShortcutAction::ResetFontSize },
|
2020-08-20 03:02:10 +02:00
|
|
|
{ ResizePaneKey, ShortcutAction::ResizePane },
|
2020-06-15 15:33:30 +02:00
|
|
|
{ ScrolldownKey, ShortcutAction::ScrollDown },
|
|
|
|
{ ScrolldownpageKey, ShortcutAction::ScrollDownPage },
|
2020-08-20 03:02:10 +02:00
|
|
|
{ ScrollupKey, ShortcutAction::ScrollUp },
|
|
|
|
{ ScrolluppageKey, ShortcutAction::ScrollUpPage },
|
2020-12-08 18:28:41 +01:00
|
|
|
{ ScrollToTopKey, ShortcutAction::ScrollToTop },
|
|
|
|
{ ScrollToBottomKey, ShortcutAction::ScrollToBottom },
|
2020-08-20 03:02:10 +02:00
|
|
|
{ SendInputKey, ShortcutAction::SendInput },
|
2020-08-10 18:21:56 +02:00
|
|
|
{ SetColorSchemeKey, ShortcutAction::SetColorScheme },
|
2020-08-20 03:02:10 +02:00
|
|
|
{ SetTabColorKey, ShortcutAction::SetTabColor },
|
|
|
|
{ SplitPaneKey, ShortcutAction::SplitPane },
|
|
|
|
{ SwitchToTabKey, ShortcutAction::SwitchToTab },
|
2020-08-21 17:39:40 +02:00
|
|
|
{ TabSearchKey, ShortcutAction::TabSearch },
|
2020-08-20 03:02:10 +02:00
|
|
|
{ ToggleAlwaysOnTopKey, ShortcutAction::ToggleAlwaysOnTop },
|
|
|
|
{ ToggleCommandPaletteKey, ShortcutAction::ToggleCommandPalette },
|
2020-07-13 19:40:20 +02:00
|
|
|
{ ToggleFocusModeKey, ShortcutAction::ToggleFocusMode },
|
2020-06-15 15:33:30 +02:00
|
|
|
{ ToggleFullscreenKey, ShortcutAction::ToggleFullscreen },
|
2020-08-08 01:11:44 +02:00
|
|
|
{ TogglePaneZoomKey, ShortcutAction::TogglePaneZoom },
|
Implement user-specified pixel shaders, redux (#8565)
Co-authored-by: mrange <marten_range@hotmail.com>
I loved the pixel shaders in #7058, but that PR needed a bit of polish
to be ready for ingestion. This PR is almost _exactly_ that PR, with
some small changes.
* It adds a new pre-profile setting `"experimental.pixelShaderPath"`,
which lets the user set a pixel shader to use with the Terminal.
- CHANGED FROM #7058: It does _not_ add any built-in shaders.
- CHANGED FROM #7058: it will _override_
`experimental.retroTerminalEffect`
* It adds a bunch of sample shaders in `samples/shaders`. Included:
- A NOP shader as a base to build from.
- An "invert" shader that inverts the colors, as a simple example
- An "grayscale" shader that converts all colors to grayscale, as a
simple example
- An "raster bars" shader that draws some colored bars on the screen
with a drop shadow, as a more involved example
- The original retro terminal effects, as a more involved example
- It also includes a broken shader, as an example of what heppens
when the shader fails to compile
- CHANGED FROM #7058: It does _not_ add the "retroII" shader we were
all worried about.
* When a shader fails to be found or fails to compile, we'll display an
error dialog to the user with a relevant error message.
- CHANGED FROM #7058: Originally, #7058 would display "error bars"
on the screen. I've removed that, and had the Terminal disable the
shader entirely then.
* Renames the `toggleRetroEffect` action to `toggleShaderEffect`.
(`toggleRetroEffect` is now an alias to `toggleShaderEffect`). This
action will turn the shader OR the retro effects on/off.
`toggleShaderEffect` works the way you'd expect it to, but the mental
math on _how_ is a little weird. The logic is basically:
```
useShader = shaderEffectsEnabled ?
(pixelShaderProvided ?
pixelShader :
(retroEffectEnabled ?
retroEffect : null
)
) :
null
```
and `toggleShaderEffect` toggles `shaderEffectsEnabled`.
* If you've got both a shader and retro enabled, `toggleShaderEffect`
will toggle between the shader on/off.
* If you've got a shader and retro disabled, `toggleShaderEffect` will
toggle between the shader on/off.
References #6191
References #7058
Closes #7013
Closes #3930 "Add setting to retro terminal shader to control blur
radius, color"
Closes #3929 "Add setting to retro terminal shader to enable drawing
scanlines"
- At this point, just roll your own version of the shader.
2020-12-15 21:40:22 +01:00
|
|
|
{ LegacyToggleRetroEffectKey, ShortcutAction::ToggleShaderEffects },
|
|
|
|
{ ToggleShaderEffectsKey, ShortcutAction::ToggleShaderEffects },
|
2020-11-25 23:09:27 +01:00
|
|
|
{ MoveTabKey, ShortcutAction::MoveTab },
|
2020-12-05 00:54:59 +01:00
|
|
|
{ BreakIntoDebuggerKey, ShortcutAction::BreakIntoDebugger },
|
2020-06-15 15:33:30 +02:00
|
|
|
{ UnboundKey, ShortcutAction::Invalid },
|
Add `findNext`, `findPrev` actions (#8917)
This PR is a resurrection of #8522. @Hegunumo has apparently deleted
their account, but the contribution was still valuable. I'm just here to
get it across the finish line.
This PR adds new action for navigating to the next & previous search
results. These actions are unbound by default. These actions can be used
from directly within the search dialog also, to immediately navigate the
results.
Furthermore, if you have a search started, and close the search box,
then press this keybinding, _it will still perform the search_. So you
can just hit <kbd>F3</kbd> repeatedly with the dialog closed to keep
searching new results. Neat!
If you dispatch the action on the key down, then dismiss a selection on
a key up, we'll end up immediately destroying the selection when you
release the bound key. That's annoying. It also bothers @carlos-zamora
in #3758. However, I _think_ we can just only dismiss the selection on a
key up. I _think_ that's fine. It _seems_ fine so far. We've got an
entire release cycle to futz with it.
## Validation Steps Performed
I've played with it all day and it seems _crisp_.
Closes #7695
Co-authored-by: Kiminori Kaburagi <yukawa_hidenori@icloud.com>
2021-02-18 20:21:35 +01:00
|
|
|
{ FindMatchKey, ShortcutAction::FindMatch },
|
2021-02-08 19:03:55 +01:00
|
|
|
{ TogglePaneReadOnlyKey, ShortcutAction::TogglePaneReadOnly },
|
2021-02-20 00:51:30 +01:00
|
|
|
{ NewWindowKey, ShortcutAction::NewWindow },
|
2021-03-30 18:08:03 +02:00
|
|
|
{ IdentifyWindowKey, ShortcutAction::IdentifyWindow },
|
|
|
|
{ IdentifyWindowsKey, ShortcutAction::IdentifyWindows },
|
Add support for renaming windows (#9662)
## Summary of the Pull Request
This PR adds support for renaming windows.
![window-renaming-000](https://user-images.githubusercontent.com/18356694/113034344-9a30be00-9157-11eb-9443-975f3c294f56.gif)
![window-renaming-001](https://user-images.githubusercontent.com/18356694/113034452-b5033280-9157-11eb-9e35-e5ac80fef0bc.gif)
It does so through two new actions:
* `renameWindow` takes a `name` parameter, and attempts to set the window's name
to the provided name. This is useful if you always want to hit <kbd>F3</kbd>
and rename a window to "foo" (READ: probably not that useful)
* `openWindowRenamer` is more interesting: it opens a `TeachingTip` with a
`TextBox`. When the user hits Ok, it'll request a rename for the provided
value. This lets the user pick a new name for the window at runtime.
In both cases, if there's already a window with that name, then the monarch will
reject the rename, and pop a `Toast` in the window informing the user that the
rename failed. Nifty!
## References
* Builds on the toasts from #9523
* #5000 - process model megathread
## PR Checklist
* [x] Closes https://github.com/microsoft/terminal/projects/5#card-50771747
* [x] I work here
* [x] Tests addded (and pass with the help of #9660)
* [ ] Requires documentation to be updated
## Detailed Description of the Pull Request / Additional comments
I'm sending this PR while finishing up the tests. I figured I'll have time to sneak them in before I get the necessary reviews.
> PAIN: We can't immediately focus the textbox in the TeachingTip. It's
> not technically focusable until it is opened. However, it doesn't
> provide an even tto tell us when it is opened. That's tracked in
> microsoft/microsoft-ui-xaml#1607. So for now, the user _needs_ to
> click on the text box manually.
> We're also not using a ContentDialog for this, because in Xaml
> Islands a text box in a ContentDialog won't recieve _any_ keypresses.
> Fun!
## Validation Steps Performed
I've been playing with
```json
{ "keys": "f1", "command": "identifyWindow" },
{ "keys": "f2", "command": "identifyWindows" },
{ "keys": "f3", "command": "openWindowRenamer" },
{ "keys": "f4", "command": { "action": "renameWindow", "name": "foo" } },
{ "keys": "f5", "command": { "action": "renameWindow", "name": "bar" } },
```
and they seem to work as expected
2021-04-02 18:00:04 +02:00
|
|
|
{ RenameWindowKey, ShortcutAction::RenameWindow },
|
|
|
|
{ OpenWindowRenamerKey, ShortcutAction::OpenWindowRenamer },
|
2020-06-15 15:33:30 +02:00
|
|
|
};
|
|
|
|
|
2020-10-06 18:56:59 +02:00
|
|
|
using ParseResult = std::tuple<IActionArgs, std::vector<SettingsLoadWarnings>>;
|
2020-06-15 15:33:30 +02:00
|
|
|
using ParseActionFunction = std::function<ParseResult(const Json::Value&)>;
|
|
|
|
|
|
|
|
// This is a map of ShortcutAction->function<IActionArgs(Json::Value)>. It holds
|
|
|
|
// a set of deserializer functions that can be used to deserialize a IActionArgs
|
|
|
|
// from json. Each type of IActionArgs that can accept arbitrary args should be
|
|
|
|
// placed into this map, with the corresponding deserializer function as the
|
|
|
|
// value.
|
|
|
|
static const std::map<ShortcutAction, ParseActionFunction, std::less<>> argParsers{
|
2020-08-20 03:02:10 +02:00
|
|
|
{ ShortcutAction::AdjustFontSize, AdjustFontSizeArgs::FromJson },
|
|
|
|
{ ShortcutAction::CloseOtherTabs, CloseOtherTabsArgs::FromJson },
|
|
|
|
{ ShortcutAction::CloseTabsAfter, CloseTabsAfterArgs::FromJson },
|
|
|
|
{ ShortcutAction::CopyText, CopyTextArgs::FromJson },
|
|
|
|
{ ShortcutAction::ExecuteCommandline, ExecuteCommandlineArgs::FromJson },
|
|
|
|
{ ShortcutAction::MoveFocus, MoveFocusArgs::FromJson },
|
|
|
|
{ ShortcutAction::NewTab, NewTabArgs::FromJson },
|
|
|
|
{ ShortcutAction::OpenSettings, OpenSettingsArgs::FromJson },
|
|
|
|
{ ShortcutAction::RenameTab, RenameTabArgs::FromJson },
|
|
|
|
{ ShortcutAction::ResizePane, ResizePaneArgs::FromJson },
|
|
|
|
{ ShortcutAction::SendInput, SendInputArgs::FromJson },
|
|
|
|
{ ShortcutAction::SetColorScheme, SetColorSchemeArgs::FromJson },
|
|
|
|
{ ShortcutAction::SetTabColor, SetTabColorArgs::FromJson },
|
|
|
|
{ ShortcutAction::SplitPane, SplitPaneArgs::FromJson },
|
|
|
|
{ ShortcutAction::SwitchToTab, SwitchToTabArgs::FromJson },
|
2020-10-27 02:19:52 +01:00
|
|
|
{ ShortcutAction::ScrollUp, ScrollUpArgs::FromJson },
|
|
|
|
{ ShortcutAction::ScrollDown, ScrollDownArgs::FromJson },
|
2020-11-25 23:09:27 +01:00
|
|
|
{ ShortcutAction::MoveTab, MoveTabArgs::FromJson },
|
2020-12-03 17:15:31 +01:00
|
|
|
{ ShortcutAction::ToggleCommandPalette, ToggleCommandPaletteArgs::FromJson },
|
Add `findNext`, `findPrev` actions (#8917)
This PR is a resurrection of #8522. @Hegunumo has apparently deleted
their account, but the contribution was still valuable. I'm just here to
get it across the finish line.
This PR adds new action for navigating to the next & previous search
results. These actions are unbound by default. These actions can be used
from directly within the search dialog also, to immediately navigate the
results.
Furthermore, if you have a search started, and close the search box,
then press this keybinding, _it will still perform the search_. So you
can just hit <kbd>F3</kbd> repeatedly with the dialog closed to keep
searching new results. Neat!
If you dispatch the action on the key down, then dismiss a selection on
a key up, we'll end up immediately destroying the selection when you
release the bound key. That's annoying. It also bothers @carlos-zamora
in #3758. However, I _think_ we can just only dismiss the selection on a
key up. I _think_ that's fine. It _seems_ fine so far. We've got an
entire release cycle to futz with it.
## Validation Steps Performed
I've played with it all day and it seems _crisp_.
Closes #7695
Co-authored-by: Kiminori Kaburagi <yukawa_hidenori@icloud.com>
2021-02-18 20:21:35 +01:00
|
|
|
{ ShortcutAction::FindMatch, FindMatchArgs::FromJson },
|
2021-02-20 00:51:30 +01:00
|
|
|
{ ShortcutAction::NewWindow, NewWindowArgs::FromJson },
|
Allow overriding tab switcher mode on command level (#9507)
## Summary of the Pull Request
Currently, when the MRU is enabled we lose the keybinding allowing us to
go forward/backward (aka right/left in LTR) in the tab view.
To fix that, this PR introduces "tabSwitcherMode" optional parameter to
the prevTab / nextTab commands.
If it is not provided the global setting will be used.
So if you want to go to adjacent tabs, even if MRU is enabled on the
system level you can use:
```
{ "command": { "action": "prevTab", "tabSwitcherMode": "inOrder" }, "keys": "ctrl+f1"}
{ "command": { "action": "nextTab", "tabSwitcherMode": "inOrder" }, "keys": "ctrl+f2"}
```
or even
```
{"command": { "action": "prevTab", "tabSwitcherMode": "disabled" }, "keys": "ctrl+f1"}
{ "command": { "action": "nextTab", "tabSwitcherMode": "disabled" }, "keys": "ctrl+f2"}
```
if you don't want tab switcher to show up
<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist
* [x] Closes https://github.com/microsoft/terminal/issues/9330
* [x] CLA signed.
* [x] Tests added/passed
* [ ] Documentation updated - not yet. Waiting for approval.
* [x] Schema updated.
* [ ] I've discussed this with core contributors already.
2021-03-23 23:00:07 +01:00
|
|
|
{ ShortcutAction::PrevTab, PrevTabArgs::FromJson },
|
|
|
|
{ ShortcutAction::NextTab, NextTabArgs::FromJson },
|
Add support for renaming windows (#9662)
## Summary of the Pull Request
This PR adds support for renaming windows.
![window-renaming-000](https://user-images.githubusercontent.com/18356694/113034344-9a30be00-9157-11eb-9443-975f3c294f56.gif)
![window-renaming-001](https://user-images.githubusercontent.com/18356694/113034452-b5033280-9157-11eb-9e35-e5ac80fef0bc.gif)
It does so through two new actions:
* `renameWindow` takes a `name` parameter, and attempts to set the window's name
to the provided name. This is useful if you always want to hit <kbd>F3</kbd>
and rename a window to "foo" (READ: probably not that useful)
* `openWindowRenamer` is more interesting: it opens a `TeachingTip` with a
`TextBox`. When the user hits Ok, it'll request a rename for the provided
value. This lets the user pick a new name for the window at runtime.
In both cases, if there's already a window with that name, then the monarch will
reject the rename, and pop a `Toast` in the window informing the user that the
rename failed. Nifty!
## References
* Builds on the toasts from #9523
* #5000 - process model megathread
## PR Checklist
* [x] Closes https://github.com/microsoft/terminal/projects/5#card-50771747
* [x] I work here
* [x] Tests addded (and pass with the help of #9660)
* [ ] Requires documentation to be updated
## Detailed Description of the Pull Request / Additional comments
I'm sending this PR while finishing up the tests. I figured I'll have time to sneak them in before I get the necessary reviews.
> PAIN: We can't immediately focus the textbox in the TeachingTip. It's
> not technically focusable until it is opened. However, it doesn't
> provide an even tto tell us when it is opened. That's tracked in
> microsoft/microsoft-ui-xaml#1607. So for now, the user _needs_ to
> click on the text box manually.
> We're also not using a ContentDialog for this, because in Xaml
> Islands a text box in a ContentDialog won't recieve _any_ keypresses.
> Fun!
## Validation Steps Performed
I've been playing with
```json
{ "keys": "f1", "command": "identifyWindow" },
{ "keys": "f2", "command": "identifyWindows" },
{ "keys": "f3", "command": "openWindowRenamer" },
{ "keys": "f4", "command": { "action": "renameWindow", "name": "foo" } },
{ "keys": "f5", "command": { "action": "renameWindow", "name": "bar" } },
```
and they seem to work as expected
2021-04-02 18:00:04 +02:00
|
|
|
{ ShortcutAction::RenameWindow, RenameWindowArgs::FromJson },
|
2020-08-11 16:03:12 +02:00
|
|
|
|
2020-06-15 15:33:30 +02:00
|
|
|
{ ShortcutAction::Invalid, nullptr },
|
|
|
|
};
|
|
|
|
|
|
|
|
// Function Description:
|
|
|
|
// - Attempts to match a string to a ShortcutAction. If there's no match, then
|
|
|
|
// returns ShortcutAction::Invalid
|
|
|
|
// Arguments:
|
|
|
|
// - actionString: the string to match to a ShortcutAction
|
|
|
|
// Return Value:
|
|
|
|
// - The ShortcutAction corresponding to the given string, if a match exists.
|
|
|
|
static ShortcutAction GetActionFromString(const std::string_view actionString)
|
|
|
|
{
|
|
|
|
// Try matching the command to one we have. If we can't find the
|
|
|
|
// action name in our list of names, let's just unbind that key.
|
2020-06-26 22:38:02 +02:00
|
|
|
const auto found = ActionAndArgs::ActionKeyNamesMap.find(actionString);
|
|
|
|
return found != ActionAndArgs::ActionKeyNamesMap.end() ? found->second : ShortcutAction::Invalid;
|
2020-06-15 15:33:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Method Description:
|
|
|
|
// - Deserialize an ActionAndArgs from the provided json object or string `json`.
|
|
|
|
// * If json is a string, we'll attempt to treat it as an action name,
|
|
|
|
// without arguments.
|
|
|
|
// * If json is an object, we'll attempt to retrieve the action name from
|
|
|
|
// its "action" property, and we'll use that name to fine a deserializer
|
|
|
|
// to precess the rest of the arguments in the json object.
|
|
|
|
// - If the action name is null or "unbound", or we don't understand the
|
|
|
|
// action name, or we failed to parse the arguments to this action, we'll
|
|
|
|
// return null. This should indicate to the caller that the action should
|
|
|
|
// be unbound.
|
|
|
|
// - If there were any warnings while parsing arguments for the action,
|
|
|
|
// they'll be appended to the warnings parameter.
|
|
|
|
// Arguments:
|
|
|
|
// - json: The Json::Value to attempt to parse as an ActionAndArgs
|
|
|
|
// - warnings: If there were any warnings during parsing, they'll be
|
|
|
|
// appended to this vector.
|
|
|
|
// Return Value:
|
|
|
|
// - a deserialized ActionAndArgs corresponding to the values in json, or
|
|
|
|
// null if we failed to deserialize an action.
|
|
|
|
winrt::com_ptr<ActionAndArgs> ActionAndArgs::FromJson(const Json::Value& json,
|
2020-10-06 18:56:59 +02:00
|
|
|
std::vector<SettingsLoadWarnings>& warnings)
|
2020-06-15 15:33:30 +02:00
|
|
|
{
|
|
|
|
// Invalid is our placeholder that the action was not parsed.
|
|
|
|
ShortcutAction action = ShortcutAction::Invalid;
|
|
|
|
|
|
|
|
// Actions can be serialized in two styles:
|
|
|
|
// "action": "switchToTab0",
|
|
|
|
// "action": { "action": "switchToTab", "index": 0 },
|
|
|
|
// NOTE: For keybindings, the "action" param is actually "command"
|
|
|
|
|
|
|
|
// 1. In the first case, the json is a string, that's the
|
|
|
|
// action name. There are no provided args, so we'll pass
|
|
|
|
// Json::Value::null to the parse function.
|
|
|
|
// 2. In the second case, the json is an object. We'll use the
|
|
|
|
// "action" in that object as the action name. We'll then pass
|
|
|
|
// the json object to the arg parser, for further parsing.
|
|
|
|
|
|
|
|
auto argsVal = Json::Value::null;
|
|
|
|
|
|
|
|
// Only try to parse the action if it's actually a string value.
|
|
|
|
// `null` will not pass this check.
|
|
|
|
if (json.isString())
|
|
|
|
{
|
|
|
|
auto commandString = json.asString();
|
|
|
|
action = GetActionFromString(commandString);
|
|
|
|
}
|
|
|
|
else if (json.isObject())
|
|
|
|
{
|
2020-07-17 03:31:09 +02:00
|
|
|
if (const auto actionString{ JsonUtils::GetValueForKey<std::optional<std::string>>(json, ActionKey) })
|
2020-06-15 15:33:30 +02:00
|
|
|
{
|
2020-07-17 03:31:09 +02:00
|
|
|
action = GetActionFromString(*actionString);
|
2020-06-15 15:33:30 +02:00
|
|
|
argsVal = json;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Some keybindings can accept other arbitrary arguments. If it
|
|
|
|
// does, we'll try to deserialize any "args" that were provided with
|
|
|
|
// the binding.
|
|
|
|
IActionArgs args{ nullptr };
|
2020-10-06 18:56:59 +02:00
|
|
|
std::vector<Microsoft::Terminal::Settings::Model::SettingsLoadWarnings> parseWarnings;
|
2020-06-15 15:33:30 +02:00
|
|
|
const auto deserializersIter = argParsers.find(action);
|
|
|
|
if (deserializersIter != argParsers.end())
|
|
|
|
{
|
|
|
|
auto pfn = deserializersIter->second;
|
|
|
|
if (pfn)
|
|
|
|
{
|
|
|
|
std::tie(args, parseWarnings) = pfn(argsVal);
|
|
|
|
}
|
|
|
|
warnings.insert(warnings.end(), parseWarnings.begin(), parseWarnings.end());
|
|
|
|
|
|
|
|
// if an arg parser was registered, but failed, bail
|
|
|
|
if (pfn && args == nullptr)
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (action != ShortcutAction::Invalid)
|
|
|
|
{
|
|
|
|
auto actionAndArgs = winrt::make_self<ActionAndArgs>();
|
|
|
|
actionAndArgs->Action(action);
|
|
|
|
actionAndArgs->Args(args);
|
|
|
|
|
|
|
|
return actionAndArgs;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-17 00:14:11 +02:00
|
|
|
com_ptr<ActionAndArgs> ActionAndArgs::Copy() const
|
|
|
|
{
|
|
|
|
auto copy{ winrt::make_self<ActionAndArgs>() };
|
|
|
|
copy->_Action = _Action;
|
2020-10-23 02:26:54 +02:00
|
|
|
copy->_Args = _Args ? _Args.Copy() : IActionArgs{ nullptr };
|
2020-10-17 00:14:11 +02:00
|
|
|
return copy;
|
|
|
|
}
|
|
|
|
|
2020-06-26 22:38:02 +02:00
|
|
|
winrt::hstring ActionAndArgs::GenerateName() const
|
|
|
|
{
|
|
|
|
// Use a magic static to initialize this map, because we won't be able
|
|
|
|
// to load the resources at _init_, only at runtime.
|
|
|
|
static const auto GeneratedActionNames = []() {
|
|
|
|
return std::unordered_map<ShortcutAction, winrt::hstring>{
|
2020-08-20 03:02:10 +02:00
|
|
|
{ ShortcutAction::AdjustFontSize, RS_(L"AdjustFontSizeCommandKey") },
|
|
|
|
{ ShortcutAction::CloseOtherTabs, L"" }, // Intentionally omitted, must be generated by GenerateName
|
|
|
|
{ ShortcutAction::ClosePane, RS_(L"ClosePaneCommandKey") },
|
|
|
|
{ ShortcutAction::CloseTab, RS_(L"CloseTabCommandKey") },
|
|
|
|
{ ShortcutAction::CloseTabsAfter, L"" }, // Intentionally omitted, must be generated by GenerateName
|
|
|
|
{ ShortcutAction::CloseWindow, RS_(L"CloseWindowCommandKey") },
|
2020-06-26 22:38:02 +02:00
|
|
|
{ ShortcutAction::CopyText, RS_(L"CopyTextCommandKey") },
|
|
|
|
{ ShortcutAction::DuplicateTab, RS_(L"DuplicateTabCommandKey") },
|
2020-08-20 03:02:10 +02:00
|
|
|
{ ShortcutAction::ExecuteCommandline, RS_(L"ExecuteCommandlineCommandKey") },
|
|
|
|
{ ShortcutAction::Find, RS_(L"FindCommandKey") },
|
|
|
|
{ ShortcutAction::Invalid, L"" },
|
|
|
|
{ ShortcutAction::MoveFocus, RS_(L"MoveFocusCommandKey") },
|
2020-06-26 22:38:02 +02:00
|
|
|
{ ShortcutAction::NewTab, RS_(L"NewTabCommandKey") },
|
|
|
|
{ ShortcutAction::NextTab, RS_(L"NextTabCommandKey") },
|
2020-08-20 03:02:10 +02:00
|
|
|
{ ShortcutAction::OpenNewTabDropdown, RS_(L"OpenNewTabDropdownCommandKey") },
|
2021-02-24 01:14:13 +01:00
|
|
|
{ ShortcutAction::OpenSettings, RS_(L"OpenSettingsUICommandKey") },
|
2020-08-20 03:02:10 +02:00
|
|
|
{ ShortcutAction::OpenTabColorPicker, RS_(L"OpenTabColorPickerCommandKey") },
|
|
|
|
{ ShortcutAction::PasteText, RS_(L"PasteTextCommandKey") },
|
2020-06-26 22:38:02 +02:00
|
|
|
{ ShortcutAction::PrevTab, RS_(L"PrevTabCommandKey") },
|
2020-08-20 03:02:10 +02:00
|
|
|
{ ShortcutAction::RenameTab, RS_(L"ResetTabNameCommandKey") },
|
2020-10-28 20:36:30 +01:00
|
|
|
{ ShortcutAction::OpenTabRenamer, RS_(L"OpenTabRenamerCommandKey") },
|
2020-06-26 22:38:02 +02:00
|
|
|
{ ShortcutAction::ResetFontSize, RS_(L"ResetFontSizeCommandKey") },
|
2020-08-20 03:02:10 +02:00
|
|
|
{ ShortcutAction::ResizePane, RS_(L"ResizePaneCommandKey") },
|
2020-06-26 22:38:02 +02:00
|
|
|
{ ShortcutAction::ScrollDown, RS_(L"ScrollDownCommandKey") },
|
|
|
|
{ ShortcutAction::ScrollDownPage, RS_(L"ScrollDownPageCommandKey") },
|
2020-08-20 03:02:10 +02:00
|
|
|
{ ShortcutAction::ScrollUp, RS_(L"ScrollUpCommandKey") },
|
|
|
|
{ ShortcutAction::ScrollUpPage, RS_(L"ScrollUpPageCommandKey") },
|
2020-12-08 18:28:41 +01:00
|
|
|
{ ShortcutAction::ScrollToTop, RS_(L"ScrollToTopCommandKey") },
|
|
|
|
{ ShortcutAction::ScrollToBottom, RS_(L"ScrollToBottomCommandKey") },
|
2020-08-12 15:46:53 +02:00
|
|
|
{ ShortcutAction::SendInput, L"" },
|
2020-08-10 18:21:56 +02:00
|
|
|
{ ShortcutAction::SetColorScheme, L"" },
|
2020-06-26 22:38:02 +02:00
|
|
|
{ ShortcutAction::SetTabColor, RS_(L"ResetTabColorCommandKey") },
|
2020-08-20 03:02:10 +02:00
|
|
|
{ ShortcutAction::SplitPane, RS_(L"SplitPaneCommandKey") },
|
|
|
|
{ ShortcutAction::SwitchToTab, RS_(L"SwitchToTabCommandKey") },
|
2020-08-21 17:39:40 +02:00
|
|
|
{ ShortcutAction::TabSearch, RS_(L"TabSearchCommandKey") },
|
2020-08-20 03:02:10 +02:00
|
|
|
{ ShortcutAction::ToggleAlwaysOnTop, RS_(L"ToggleAlwaysOnTopCommandKey") },
|
2020-12-03 17:15:31 +01:00
|
|
|
{ ShortcutAction::ToggleCommandPalette, L"" },
|
2020-08-20 03:02:10 +02:00
|
|
|
{ ShortcutAction::ToggleFocusMode, RS_(L"ToggleFocusModeCommandKey") },
|
|
|
|
{ ShortcutAction::ToggleFullscreen, RS_(L"ToggleFullscreenCommandKey") },
|
|
|
|
{ ShortcutAction::TogglePaneZoom, RS_(L"TogglePaneZoomCommandKey") },
|
Implement user-specified pixel shaders, redux (#8565)
Co-authored-by: mrange <marten_range@hotmail.com>
I loved the pixel shaders in #7058, but that PR needed a bit of polish
to be ready for ingestion. This PR is almost _exactly_ that PR, with
some small changes.
* It adds a new pre-profile setting `"experimental.pixelShaderPath"`,
which lets the user set a pixel shader to use with the Terminal.
- CHANGED FROM #7058: It does _not_ add any built-in shaders.
- CHANGED FROM #7058: it will _override_
`experimental.retroTerminalEffect`
* It adds a bunch of sample shaders in `samples/shaders`. Included:
- A NOP shader as a base to build from.
- An "invert" shader that inverts the colors, as a simple example
- An "grayscale" shader that converts all colors to grayscale, as a
simple example
- An "raster bars" shader that draws some colored bars on the screen
with a drop shadow, as a more involved example
- The original retro terminal effects, as a more involved example
- It also includes a broken shader, as an example of what heppens
when the shader fails to compile
- CHANGED FROM #7058: It does _not_ add the "retroII" shader we were
all worried about.
* When a shader fails to be found or fails to compile, we'll display an
error dialog to the user with a relevant error message.
- CHANGED FROM #7058: Originally, #7058 would display "error bars"
on the screen. I've removed that, and had the Terminal disable the
shader entirely then.
* Renames the `toggleRetroEffect` action to `toggleShaderEffect`.
(`toggleRetroEffect` is now an alias to `toggleShaderEffect`). This
action will turn the shader OR the retro effects on/off.
`toggleShaderEffect` works the way you'd expect it to, but the mental
math on _how_ is a little weird. The logic is basically:
```
useShader = shaderEffectsEnabled ?
(pixelShaderProvided ?
pixelShader :
(retroEffectEnabled ?
retroEffect : null
)
) :
null
```
and `toggleShaderEffect` toggles `shaderEffectsEnabled`.
* If you've got both a shader and retro enabled, `toggleShaderEffect`
will toggle between the shader on/off.
* If you've got a shader and retro disabled, `toggleShaderEffect` will
toggle between the shader on/off.
References #6191
References #7058
Closes #7013
Closes #3930 "Add setting to retro terminal shader to control blur
radius, color"
Closes #3929 "Add setting to retro terminal shader to enable drawing
scanlines"
- At this point, just roll your own version of the shader.
2020-12-15 21:40:22 +01:00
|
|
|
{ ShortcutAction::ToggleShaderEffects, RS_(L"ToggleShaderEffectsCommandKey") },
|
2020-11-25 23:09:27 +01:00
|
|
|
{ ShortcutAction::MoveTab, L"" }, // Intentionally omitted, must be generated by GenerateName
|
2020-12-05 00:54:59 +01:00
|
|
|
{ ShortcutAction::BreakIntoDebugger, RS_(L"BreakIntoDebuggerCommandKey") },
|
Add `findNext`, `findPrev` actions (#8917)
This PR is a resurrection of #8522. @Hegunumo has apparently deleted
their account, but the contribution was still valuable. I'm just here to
get it across the finish line.
This PR adds new action for navigating to the next & previous search
results. These actions are unbound by default. These actions can be used
from directly within the search dialog also, to immediately navigate the
results.
Furthermore, if you have a search started, and close the search box,
then press this keybinding, _it will still perform the search_. So you
can just hit <kbd>F3</kbd> repeatedly with the dialog closed to keep
searching new results. Neat!
If you dispatch the action on the key down, then dismiss a selection on
a key up, we'll end up immediately destroying the selection when you
release the bound key. That's annoying. It also bothers @carlos-zamora
in #3758. However, I _think_ we can just only dismiss the selection on a
key up. I _think_ that's fine. It _seems_ fine so far. We've got an
entire release cycle to futz with it.
## Validation Steps Performed
I've played with it all day and it seems _crisp_.
Closes #7695
Co-authored-by: Kiminori Kaburagi <yukawa_hidenori@icloud.com>
2021-02-18 20:21:35 +01:00
|
|
|
{ ShortcutAction::FindMatch, L"" }, // Intentionally omitted, must be generated by GenerateName
|
2021-02-08 19:03:55 +01:00
|
|
|
{ ShortcutAction::TogglePaneReadOnly, RS_(L"TogglePaneReadOnlyCommandKey") },
|
2021-02-20 00:51:30 +01:00
|
|
|
{ ShortcutAction::NewWindow, RS_(L"NewWindowCommandKey") },
|
2021-03-30 18:08:03 +02:00
|
|
|
{ ShortcutAction::IdentifyWindow, RS_(L"IdentifyWindowCommandKey") },
|
|
|
|
{ ShortcutAction::IdentifyWindows, RS_(L"IdentifyWindowsCommandKey") },
|
Add support for renaming windows (#9662)
## Summary of the Pull Request
This PR adds support for renaming windows.
![window-renaming-000](https://user-images.githubusercontent.com/18356694/113034344-9a30be00-9157-11eb-9443-975f3c294f56.gif)
![window-renaming-001](https://user-images.githubusercontent.com/18356694/113034452-b5033280-9157-11eb-9e35-e5ac80fef0bc.gif)
It does so through two new actions:
* `renameWindow` takes a `name` parameter, and attempts to set the window's name
to the provided name. This is useful if you always want to hit <kbd>F3</kbd>
and rename a window to "foo" (READ: probably not that useful)
* `openWindowRenamer` is more interesting: it opens a `TeachingTip` with a
`TextBox`. When the user hits Ok, it'll request a rename for the provided
value. This lets the user pick a new name for the window at runtime.
In both cases, if there's already a window with that name, then the monarch will
reject the rename, and pop a `Toast` in the window informing the user that the
rename failed. Nifty!
## References
* Builds on the toasts from #9523
* #5000 - process model megathread
## PR Checklist
* [x] Closes https://github.com/microsoft/terminal/projects/5#card-50771747
* [x] I work here
* [x] Tests addded (and pass with the help of #9660)
* [ ] Requires documentation to be updated
## Detailed Description of the Pull Request / Additional comments
I'm sending this PR while finishing up the tests. I figured I'll have time to sneak them in before I get the necessary reviews.
> PAIN: We can't immediately focus the textbox in the TeachingTip. It's
> not technically focusable until it is opened. However, it doesn't
> provide an even tto tell us when it is opened. That's tracked in
> microsoft/microsoft-ui-xaml#1607. So for now, the user _needs_ to
> click on the text box manually.
> We're also not using a ContentDialog for this, because in Xaml
> Islands a text box in a ContentDialog won't recieve _any_ keypresses.
> Fun!
## Validation Steps Performed
I've been playing with
```json
{ "keys": "f1", "command": "identifyWindow" },
{ "keys": "f2", "command": "identifyWindows" },
{ "keys": "f3", "command": "openWindowRenamer" },
{ "keys": "f4", "command": { "action": "renameWindow", "name": "foo" } },
{ "keys": "f5", "command": { "action": "renameWindow", "name": "bar" } },
```
and they seem to work as expected
2021-04-02 18:00:04 +02:00
|
|
|
{ ShortcutAction::RenameWindow, RS_(L"ResetWindowNameCommandKey") },
|
|
|
|
{ ShortcutAction::OpenWindowRenamer, RS_(L"OpenWindowRenamerCommandKey") },
|
2020-06-26 22:38:02 +02:00
|
|
|
};
|
|
|
|
}();
|
|
|
|
|
|
|
|
if (_Args)
|
|
|
|
{
|
|
|
|
auto nameFromArgs = _Args.GenerateName();
|
|
|
|
if (!nameFromArgs.empty())
|
|
|
|
{
|
|
|
|
return nameFromArgs;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto found = GeneratedActionNames.find(_Action);
|
|
|
|
return found != GeneratedActionNames.end() ? found->second : L"";
|
|
|
|
}
|
Add support for arbitrary args in keybindings (#3391)
## Summary of the Pull Request
Enables the user to provide arbitrary argument values to shortcut actions through a new `args` member of keybindings. For some keybindings, like `NewTabWithProfile<N>`, we previously needed 9 different `ShortcutAction`s, one for each value of `Index`. If a user wanted to have a `NewTabWithProfile11` keybinding, that was simply impossible. Now that the args are in their own separate json object, each binding can accept any number of arbitrary argument values.
So instead of:
```json
{ "command": "newTab", "keys": ["ctrl+shift+t"] },
{ "command": "newTabProfile0", "keys": ["ctrl+shift+1"] },
{ "command": "newTabProfile1", "keys": ["ctrl+shift+2"] },
{ "command": "newTabProfile2", "keys": ["ctrl+shift+3"] },
{ "command": "newTabProfile3", "keys": ["ctrl+shift+4"] },
```
We can now use:
```json
{ "command": "newTab", "keys": ["ctrl+shift+t"] },
{ "command": { "action": "newTab", "index": 0 }, "keys": ["ctrl+shift+1"] },
{ "command": { "action": "newTab", "index": 1 }, "keys": ["ctrl+shift+2"] },
{ "command": { "action": "newTab", "index": 2 }, "keys": ["ctrl+shift+3"] },
```
Initially, this does seem more verbose. However, for cases where there are multiple args, or there's a large range of values for the args, this will quickly become a more powerful system of expressing keybindings.
The "legacy" keybindings are _left in_ in this PR. They have helper methods to generate appropriate `IActionArgs` values. Prior to releasing 1.0, I think we should remove them, if only to remove some code bloat.
## References
See [the spec](https://github.com/microsoft/terminal/blob/master/doc/specs/%231142%20-%20Keybinding%20Arguments.md) for more details.
This is part two of the implementation, part one was #2446
## PR Checklist
* [x] Closes #1142
* [x] I work here
* [x] Tests added/passed
* [x] Schema updated
## Validation Steps Performed
* Ran Tests
* Removed the legacy keybindings from the `defaults.json`, everything still works
* Tried leaving the legacy keybingings in my `profiles.json`, everything still works.
-------------------------------------------------
* this is a start, but there's a weird linker bug if I take the SetKeybinding(ShortcutAction, KeyChord) implementation out, which I don't totally understand
* a good old-fashioned clean will fix that right up
* all these things work
* hey this actually _functionally_ works
* Mostly cleanup and completion of implementation
* Hey I bet we could just make NewTab the handler for NewTabWithProfile
* Start writing tests for Keybinding args
* Add tests
* Revert a bad sln change, and clean out dead code
* Change to include "command" as a single object
This is a change to make @dhowett-msft happy. Changes the args to be a part
of the "command" object, as opposed to an object on their own.
EX:
```jsonc
// Old style
{ "command": "switchToTab0", "keys": ["ctrl+1"] },
{ "command": { "action": "switchToTab", "index": 0 }, "keys": ["ctrl+alt+1"] },
// new style
{ "command": "switchToTab0", "keys": ["ctrl+1"] },
{ "command": "switchToTab", "args": { "index": 0 } "keys": ["ctrl+alt+1"] },
```
* schemas are hard yo
* Fix the build?
* wonder why my -Wall settings are different than CI...
* this makes me hate things
* Comments from PR
* Add a `Direction::None`
* LOAD BEARING
* add some GH ids to TODOs
* add a comment
* PR nits from carlos
2019-11-14 23:23:40 +01:00
|
|
|
}
|