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 support for the Command Palette #6635

Merged
69 commits merged into from
Jun 26, 2020
Merged
Show file tree
Hide file tree
Changes from 68 commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
c56eb8f
Add a ton of text regarding Commandline Mode vs Action Mode
zadjii-msft Apr 30, 2020
fe640ff
move this spec out of `drafts/`
zadjii-msft Apr 30, 2020
614d1b2
last little todos for review
zadjii-msft Apr 30, 2020
ead76d7
Merge remote-tracking branch 'origin/master' into dev/migrie/s/5400-C…
zadjii-msft May 7, 2020
2e56436
Move this section to 'future considerations'
zadjii-msft May 7, 2020
0886e8f
Merge remote-tracking branch 'origin/master' into dev/migrie/s/5400-C…
zadjii-msft May 20, 2020
11130a4
Add some notes about the advanced tab switcher and how that might int…
zadjii-msft May 20, 2020
f53553f
Merge remote-tracking branch 'origin/master' into dev/migrie/s/5400-C…
zadjii-msft May 28, 2020
0672812
good bot
zadjii-msft May 28, 2020
43bd483
Blind port these files from the old branch
zadjii-msft May 28, 2020
75af4ca
Hook up all the parsing once again
zadjii-msft May 28, 2020
33a9e32
Get names from the resources if provided as an object, not a string
zadjii-msft May 28, 2020
3627d8a
This should have been in the previous commit
zadjii-msft May 28, 2020
0416a94
Hook up the parsing of `ActionAndArgs`s to the command palette
zadjii-msft May 28, 2020
6905065
Merge remote-tracking branch 'origin/master' into dev/migrie/f/2046-C…
zadjii-msft May 28, 2020
02f47f4
Make the action names map public, so the ToJson in AKBSerialization c…
zadjii-msft May 28, 2020
62b9a0d
Move the action into it's own sub-object
zadjii-msft May 28, 2020
207666e
Add a ton of default commands
zadjii-msft May 29, 2020
b88be45
Make sure to scroll the selected item into view
zadjii-msft May 29, 2020
00763fd
Add duplicate pane to the default commands
zadjii-msft May 29, 2020
bc546db
Add some stability
zadjii-msft May 29, 2020
e1be26b
Do this in WinRTUtils instead of hackily doing it manually
zadjii-msft May 29, 2020
a309191
Rename private methods, fix wraparound logic
zadjii-msft May 29, 2020
9905945
Return focus to the active control when closed
zadjii-msft May 29, 2020
cf6e1f2
Try to do this with a shadow, but it crashes inexplicably
zadjii-msft May 29, 2020
fa93fdc
Well, this is neat, and works, but requires 18362 and also casts a sh…
zadjii-msft May 29, 2020
1fbe8e4
Turns out, the shadow on the menuflyout isn't my fault, it's on every…
zadjii-msft May 29, 2020
6e6979a
Extract ActionAndArgs::FromJson into it's own class, so it can be re-…
zadjii-msft Jun 4, 2020
829beda
Merge remote-tracking branch 'origin/master' into dev/migrie/f/2046-C…
zadjii-msft Jun 4, 2020
487f33e
Merge commit '6e6979abe' into dev/migrie/f/2046-Command-Palette-v2
zadjii-msft Jun 4, 2020
58be8cd
Tons of commenting
zadjii-msft Jun 4, 2020
9d411d4
Make the commands a map, so we can override on "name"
zadjii-msft Jun 4, 2020
d71d8d7
Ready for review.
zadjii-msft Jun 4, 2020
b3d8f0e
Merge remote-tracking branch 'origin/master' into dev/migrie/f/2046-C…
zadjii-msft Jun 9, 2020
67c7969
I couldn't tell you how long this took
zadjii-msft Jun 9, 2020
82f968d
If a key is bound to that action, then display the keybinding in the …
zadjii-msft Jun 9, 2020
edc8b55
Add much better key chord text to the command palette
zadjii-msft Jun 10, 2020
dd684cb
implement a weighted ordering for command palette entries
zadjii-msft Jun 10, 2020
7ac7fd1
Merge remote-tracking branch 'origin/master' into dev/migrie/f/2046-C…
zadjii-msft Jun 11, 2020
e2f5f75
start adding tests
zadjii-msft Jun 11, 2020
7a94b8f
stash these tests in progress
zadjii-msft Jun 11, 2020
8b094fd
Merge commit 'db518c0' into dev/migrie/f/2046-Command-Palette-v2
zadjii-msft Jun 19, 2020
52eb2e5
Merge commit '827cc42' into dev/migrie/f/2046-Command-Palette-v2
zadjii-msft Jun 19, 2020
45243bb
Merge remote-tracking branch 'origin/master' into dev/migrie/f/2046-C…
zadjii-msft Jun 19, 2020
cc2fd9b
fix this build
zadjii-msft Jun 19, 2020
3e5eb73
proof of concept - have the names auto-generated from actions
zadjii-msft Jun 19, 2020
d1a7261
Use resources for the majority of command names
zadjii-msft Jun 19, 2020
10e91a8
strings for every possible action, and args value
zadjii-msft Jun 19, 2020
cee5fc9
This is a ton of new tests
zadjii-msft Jun 22, 2020
e25da60
fix the last case of CommandTests::LayerCommand
zadjii-msft Jun 22, 2020
92b3453
clean up these tests
zadjii-msft Jun 22, 2020
b90cc38
Merge remote-tracking branch 'origin/master' into dev/migrie/f/2046-C…
zadjii-msft Jun 22, 2020
f892e52
align visuals with the SearchBoxControl
zadjii-msft Jun 23, 2020
264618a
a ton of code cleanup from review
zadjii-msft Jun 23, 2020
48d4e24
misc fixes from PR
zadjii-msft Jun 23, 2020
b5be04c
only the simplest remaining feedback
zadjii-msft Jun 24, 2020
6f1dc5c
Make command fuzzy-searching heaps better
zadjii-msft Jun 24, 2020
6ca7d0e
use iterators, because this isn't 1999
zadjii-msft Jun 24, 2020
8a93b1d
Merge remote-tracking branch 'origin/master' into dev/migrie/f/2046-C…
zadjii-msft Jun 25, 2020
137aea3
unordered_maps, mad genius sorting, and a good idea about ESC
zadjii-msft Jun 25, 2020
eae88a9
light dismiss on click, better sizing
zadjii-msft Jun 25, 2020
860a3c7
add support for clicking on individual items in the command palette
zadjii-msft Jun 25, 2020
33860f7
good bot
zadjii-msft Jun 25, 2020
50cfd84
add a little message when no matches are found
zadjii-msft Jun 25, 2020
e967801
actually, just do all of #6645
zadjii-msft Jun 25, 2020
76cb965
hey, why not use keybindings directly from the command palette?
zadjii-msft Jun 25, 2020
75473c5
Use the visibility changed event, not the ToggleVisibility function.
zadjii-msft Jun 26, 2020
177cf1c
use a border instead of a grid
zadjii-msft Jun 26, 2020
ecae4f1
Fix the tests
zadjii-msft Jun 26, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
349 changes: 349 additions & 0 deletions src/cascadia/LocalTests_TerminalApp/CommandTests.cpp

Large diffs are not rendered by default.

202 changes: 202 additions & 0 deletions src/cascadia/LocalTests_TerminalApp/SettingsTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ namespace TerminalAppLocalTests

TEST_METHOD(TestTrailingCommas);

TEST_METHOD(TestCommandsAndKeybindings);

TEST_CLASS_SETUP(ClassSetup)
{
InitializeJsonReader();
Expand Down Expand Up @@ -2331,4 +2333,204 @@ namespace TerminalAppLocalTests
VERIFY_IS_TRUE(false, L"This call to LayerJson should succeed, even with the trailing comma");
}
}

void SettingsTests::TestCommandsAndKeybindings()
{
const std::string settingsJson{ R"(
{
"defaultProfile": "{6239a42c-0000-49a3-80bd-e8fdd045185c}",
"profiles": [
{
"name": "profile0",
"guid": "{6239a42c-0000-49a3-80bd-e8fdd045185c}",
"historySize": 1,
"commandline": "cmd.exe"
},
{
"name": "profile1",
"guid": "{6239a42c-1111-49a3-80bd-e8fdd045185c}",
"historySize": 2,
"commandline": "pwsh.exe"
},
{
"name": "profile2",
"historySize": 3,
"commandline": "wsl.exe"
}
],
"bindings": [
{ "keys": "ctrl+a", "command": { "action": "splitPane", "split": "vertical" } },
{ "name": "ctrl+b", "command": { "action": "splitPane", "split": "vertical" } },
{ "keys": "ctrl+c", "name": "ctrl+c", "command": { "action": "splitPane", "split": "vertical" } },
{ "keys": "ctrl+d", "command": { "action": "splitPane", "split": "vertical" } },
{ "keys": "ctrl+e", "command": { "action": "splitPane", "split": "horizontal" } },
{ "keys": "ctrl+f", "name":null, "command": { "action": "splitPane", "split": "horizontal" } }
]
})" };

const auto guid0 = Microsoft::Console::Utils::GuidFromString(L"{6239a42c-0000-49a3-80bd-e8fdd045185c}");
const auto guid1 = Microsoft::Console::Utils::GuidFromString(L"{6239a42c-1111-49a3-80bd-e8fdd045185c}");

VerifyParseSucceeded(settingsJson);
CascadiaSettings settings{};
settings._ParseJsonString(settingsJson, false);
settings.LayerJson(settings._userSettings);
settings._ValidateSettings();

VERIFY_ARE_EQUAL(3u, settings.GetProfiles().size());

const auto profile2Guid = settings._profiles.at(2).GetGuid();
VERIFY_ARE_NOT_EQUAL(GUID{ 0 }, profile2Guid);

auto appKeyBindings = settings._globals._keybindings;
VERIFY_ARE_EQUAL(5u, appKeyBindings->_keyShortcuts.size());

// A/D, B, C, E will be in the list of commands, for 4 total.
// * A and D share the same name, so they'll only generate a single action.
// * F's name is set manually to `null`
auto commands = settings._globals.GetCommands();
VERIFY_ARE_EQUAL(4u, commands.size());

{
KeyChord kc{ true, false, false, static_cast<int32_t>('A') };
auto actionAndArgs = TestUtils::GetActionAndArgs(*appKeyBindings, kc);
VERIFY_ARE_EQUAL(ShortcutAction::SplitPane, actionAndArgs.Action());
const auto& realArgs = actionAndArgs.Args().try_as<SplitPaneArgs>();
VERIFY_IS_NOT_NULL(realArgs);
// Verify the args have the expected value
VERIFY_ARE_EQUAL(winrt::TerminalApp::SplitState::Vertical, realArgs.SplitStyle());
VERIFY_IS_NOT_NULL(realArgs.TerminalArgs());
VERIFY_IS_TRUE(realArgs.TerminalArgs().Commandline().empty());
VERIFY_IS_TRUE(realArgs.TerminalArgs().StartingDirectory().empty());
VERIFY_IS_TRUE(realArgs.TerminalArgs().TabTitle().empty());
VERIFY_IS_TRUE(realArgs.TerminalArgs().Profile().empty());
}

Log::Comment(L"Note that we're skipping ctrl+B, since that doesn't have `keys` set.");

{
KeyChord kc{ true, false, false, static_cast<int32_t>('C') };
auto actionAndArgs = TestUtils::GetActionAndArgs(*appKeyBindings, kc);
VERIFY_ARE_EQUAL(ShortcutAction::SplitPane, actionAndArgs.Action());
const auto& realArgs = actionAndArgs.Args().try_as<SplitPaneArgs>();
VERIFY_IS_NOT_NULL(realArgs);
// Verify the args have the expected value
VERIFY_ARE_EQUAL(winrt::TerminalApp::SplitState::Vertical, realArgs.SplitStyle());
VERIFY_IS_NOT_NULL(realArgs.TerminalArgs());
VERIFY_IS_TRUE(realArgs.TerminalArgs().Commandline().empty());
VERIFY_IS_TRUE(realArgs.TerminalArgs().StartingDirectory().empty());
VERIFY_IS_TRUE(realArgs.TerminalArgs().TabTitle().empty());
VERIFY_IS_TRUE(realArgs.TerminalArgs().Profile().empty());
}
{
KeyChord kc{ true, false, false, static_cast<int32_t>('D') };
auto actionAndArgs = TestUtils::GetActionAndArgs(*appKeyBindings, kc);
VERIFY_ARE_EQUAL(ShortcutAction::SplitPane, actionAndArgs.Action());
const auto& realArgs = actionAndArgs.Args().try_as<SplitPaneArgs>();
VERIFY_IS_NOT_NULL(realArgs);
// Verify the args have the expected value
VERIFY_ARE_EQUAL(winrt::TerminalApp::SplitState::Vertical, realArgs.SplitStyle());
VERIFY_IS_NOT_NULL(realArgs.TerminalArgs());
VERIFY_IS_TRUE(realArgs.TerminalArgs().Commandline().empty());
VERIFY_IS_TRUE(realArgs.TerminalArgs().StartingDirectory().empty());
VERIFY_IS_TRUE(realArgs.TerminalArgs().TabTitle().empty());
VERIFY_IS_TRUE(realArgs.TerminalArgs().Profile().empty());
}
{
KeyChord kc{ true, false, false, static_cast<int32_t>('E') };
auto actionAndArgs = TestUtils::GetActionAndArgs(*appKeyBindings, kc);
VERIFY_ARE_EQUAL(ShortcutAction::SplitPane, actionAndArgs.Action());
const auto& realArgs = actionAndArgs.Args().try_as<SplitPaneArgs>();
VERIFY_IS_NOT_NULL(realArgs);
// Verify the args have the expected value
VERIFY_ARE_EQUAL(winrt::TerminalApp::SplitState::Horizontal, realArgs.SplitStyle());
VERIFY_IS_NOT_NULL(realArgs.TerminalArgs());
VERIFY_IS_TRUE(realArgs.TerminalArgs().Commandline().empty());
VERIFY_IS_TRUE(realArgs.TerminalArgs().StartingDirectory().empty());
VERIFY_IS_TRUE(realArgs.TerminalArgs().TabTitle().empty());
VERIFY_IS_TRUE(realArgs.TerminalArgs().Profile().empty());
}
{
KeyChord kc{ true, false, false, static_cast<int32_t>('F') };
auto actionAndArgs = TestUtils::GetActionAndArgs(*appKeyBindings, kc);
VERIFY_ARE_EQUAL(ShortcutAction::SplitPane, actionAndArgs.Action());
const auto& realArgs = actionAndArgs.Args().try_as<SplitPaneArgs>();
VERIFY_IS_NOT_NULL(realArgs);
// Verify the args have the expected value
VERIFY_ARE_EQUAL(winrt::TerminalApp::SplitState::Horizontal, realArgs.SplitStyle());
VERIFY_IS_NOT_NULL(realArgs.TerminalArgs());
VERIFY_IS_TRUE(realArgs.TerminalArgs().Commandline().empty());
VERIFY_IS_TRUE(realArgs.TerminalArgs().StartingDirectory().empty());
VERIFY_IS_TRUE(realArgs.TerminalArgs().TabTitle().empty());
VERIFY_IS_TRUE(realArgs.TerminalArgs().Profile().empty());
}

Log::Comment(L"Now verify the commands");

{
auto command = commands.at(L"Split pane, direction: Vertical");
VERIFY_IS_NOT_NULL(command);
auto actionAndArgs = command.Action();
VERIFY_IS_NOT_NULL(actionAndArgs);
VERIFY_ARE_EQUAL(ShortcutAction::SplitPane, actionAndArgs.Action());
const auto& realArgs = actionAndArgs.Args().try_as<SplitPaneArgs>();
VERIFY_IS_NOT_NULL(realArgs);
// Verify the args have the expected value
VERIFY_ARE_EQUAL(winrt::TerminalApp::SplitState::Vertical, realArgs.SplitStyle());
VERIFY_IS_NOT_NULL(realArgs.TerminalArgs());
VERIFY_IS_TRUE(realArgs.TerminalArgs().Commandline().empty());
VERIFY_IS_TRUE(realArgs.TerminalArgs().StartingDirectory().empty());
VERIFY_IS_TRUE(realArgs.TerminalArgs().TabTitle().empty());
VERIFY_IS_TRUE(realArgs.TerminalArgs().Profile().empty());
}
{
auto command = commands.at(L"ctrl+b");
VERIFY_IS_NOT_NULL(command);
auto actionAndArgs = command.Action();
VERIFY_IS_NOT_NULL(actionAndArgs);
VERIFY_ARE_EQUAL(ShortcutAction::SplitPane, actionAndArgs.Action());
const auto& realArgs = actionAndArgs.Args().try_as<SplitPaneArgs>();
VERIFY_IS_NOT_NULL(realArgs);
// Verify the args have the expected value
VERIFY_ARE_EQUAL(winrt::TerminalApp::SplitState::Vertical, realArgs.SplitStyle());
VERIFY_IS_NOT_NULL(realArgs.TerminalArgs());
VERIFY_IS_TRUE(realArgs.TerminalArgs().Commandline().empty());
VERIFY_IS_TRUE(realArgs.TerminalArgs().StartingDirectory().empty());
VERIFY_IS_TRUE(realArgs.TerminalArgs().TabTitle().empty());
VERIFY_IS_TRUE(realArgs.TerminalArgs().Profile().empty());
}
{
auto command = commands.at(L"ctrl+c");
VERIFY_IS_NOT_NULL(command);
auto actionAndArgs = command.Action();
VERIFY_IS_NOT_NULL(actionAndArgs);
VERIFY_ARE_EQUAL(ShortcutAction::SplitPane, actionAndArgs.Action());
const auto& realArgs = actionAndArgs.Args().try_as<SplitPaneArgs>();
VERIFY_IS_NOT_NULL(realArgs);
// Verify the args have the expected value
VERIFY_ARE_EQUAL(winrt::TerminalApp::SplitState::Vertical, realArgs.SplitStyle());
VERIFY_IS_NOT_NULL(realArgs.TerminalArgs());
VERIFY_IS_TRUE(realArgs.TerminalArgs().Commandline().empty());
VERIFY_IS_TRUE(realArgs.TerminalArgs().StartingDirectory().empty());
VERIFY_IS_TRUE(realArgs.TerminalArgs().TabTitle().empty());
VERIFY_IS_TRUE(realArgs.TerminalArgs().Profile().empty());
}
{
auto command = commands.at(L"Split pane, direction: Horizontal");
VERIFY_IS_NOT_NULL(command);
auto actionAndArgs = command.Action();
VERIFY_IS_NOT_NULL(actionAndArgs);
VERIFY_ARE_EQUAL(ShortcutAction::SplitPane, actionAndArgs.Action());
const auto& realArgs = actionAndArgs.Args().try_as<SplitPaneArgs>();
VERIFY_IS_NOT_NULL(realArgs);
// Verify the args have the expected value
VERIFY_ARE_EQUAL(winrt::TerminalApp::SplitState::Horizontal, realArgs.SplitStyle());
VERIFY_IS_NOT_NULL(realArgs.TerminalArgs());
VERIFY_IS_TRUE(realArgs.TerminalArgs().Commandline().empty());
VERIFY_IS_TRUE(realArgs.TerminalArgs().StartingDirectory().empty());
VERIFY_IS_TRUE(realArgs.TerminalArgs().TabTitle().empty());
VERIFY_IS_TRUE(realArgs.TerminalArgs().Profile().empty());
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
<ClCompile Include="ProfileTests.cpp" />
<ClCompile Include="ColorSchemeTests.cpp" />
<ClCompile Include="KeyBindingsTests.cpp" />
<ClCompile Include="CommandTests.cpp" />
<ClCompile Include="TabTests.cpp" />
<ClCompile Include="pch.cpp">
<PrecompiledHeader>Create</PrecompiledHeader>
Expand Down
72 changes: 63 additions & 9 deletions src/cascadia/TerminalApp/ActionAndArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
#include "ActionArgs.h"
#include "ActionAndArgs.h"
#include "ActionAndArgs.g.cpp"

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" };
#include <LibraryResources.h>

static constexpr std::string_view CopyTextKey{ "copy" };
static constexpr std::string_view PasteTextKey{ "paste" };
Expand Down Expand Up @@ -36,6 +32,12 @@ static constexpr std::string_view ToggleFullscreenKey{ "toggleFullscreen" };
static constexpr std::string_view SetTabColorKey{ "setTabColor" };
static constexpr std::string_view OpenTabColorPickerKey{ "openTabColorPicker" };
static constexpr std::string_view RenameTabKey{ "renameTab" };
static constexpr std::string_view ToggleCommandPaletteKey{ "commandPalette" };

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" };

namespace winrt::TerminalApp::implementation
{
Expand All @@ -47,7 +49,7 @@ namespace winrt::TerminalApp::implementation
// 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.
const std::map<std::string_view, ShortcutAction, std::less<>> ActionAndArgs::ActionNamesMap{
const std::map<std::string_view, ShortcutAction, std::less<>> ActionAndArgs::ActionKeyNamesMap{
{ CopyTextKey, ShortcutAction::CopyText },
{ PasteTextKey, ShortcutAction::PasteText },
{ OpenNewTabDropdownKey, ShortcutAction::OpenNewTabDropdown },
Expand Down Expand Up @@ -75,7 +77,8 @@ namespace winrt::TerminalApp::implementation
{ OpenTabColorPickerKey, ShortcutAction::OpenTabColorPicker },
{ UnboundKey, ShortcutAction::Invalid },
{ FindKey, ShortcutAction::Find },
{ RenameTabKey, ShortcutAction::RenameTab }
{ RenameTabKey, ShortcutAction::RenameTab },
{ ToggleCommandPaletteKey, ShortcutAction::ToggleCommandPalette },
};

using ParseResult = std::tuple<IActionArgs, std::vector<::TerminalApp::SettingsLoadWarnings>>;
Expand Down Expand Up @@ -121,8 +124,8 @@ namespace winrt::TerminalApp::implementation
{
// 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.
const auto found = ActionAndArgs::ActionNamesMap.find(actionString);
return found != ActionAndArgs::ActionNamesMap.end() ? found->second : ShortcutAction::Invalid;
const auto found = ActionAndArgs::ActionKeyNamesMap.find(actionString);
return found != ActionAndArgs::ActionKeyNamesMap.end() ? found->second : ShortcutAction::Invalid;
}

// Method Description:
Expand Down Expand Up @@ -219,4 +222,55 @@ namespace winrt::TerminalApp::implementation
}
}

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>{
{ ShortcutAction::CopyText, RS_(L"CopyTextCommandKey") },
{ ShortcutAction::PasteText, RS_(L"PasteTextCommandKey") },
{ ShortcutAction::OpenNewTabDropdown, RS_(L"OpenNewTabDropdownCommandKey") },
{ ShortcutAction::DuplicateTab, RS_(L"DuplicateTabCommandKey") },
{ ShortcutAction::NewTab, RS_(L"NewTabCommandKey") },
{ ShortcutAction::NewWindow, RS_(L"NewWindowCommandKey") },
{ ShortcutAction::CloseWindow, RS_(L"CloseWindowCommandKey") },
{ ShortcutAction::CloseTab, RS_(L"CloseTabCommandKey") },
{ ShortcutAction::ClosePane, RS_(L"ClosePaneCommandKey") },
{ ShortcutAction::NextTab, RS_(L"NextTabCommandKey") },
{ ShortcutAction::PrevTab, RS_(L"PrevTabCommandKey") },
{ ShortcutAction::AdjustFontSize, RS_(L"AdjustFontSizeCommandKey") },
{ ShortcutAction::ResetFontSize, RS_(L"ResetFontSizeCommandKey") },
{ ShortcutAction::ScrollUp, RS_(L"ScrollUpCommandKey") },
{ ShortcutAction::ScrollDown, RS_(L"ScrollDownCommandKey") },
{ ShortcutAction::ScrollUpPage, RS_(L"ScrollUpPageCommandKey") },
{ ShortcutAction::ScrollDownPage, RS_(L"ScrollDownPageCommandKey") },
{ ShortcutAction::SwitchToTab, RS_(L"SwitchToTabCommandKey") },
{ ShortcutAction::ResizePane, RS_(L"ResizePaneCommandKey") },
{ ShortcutAction::MoveFocus, RS_(L"MoveFocusCommandKey") },
{ ShortcutAction::OpenSettings, RS_(L"OpenSettingsCommandKey") },
{ ShortcutAction::ToggleFullscreen, RS_(L"ToggleFullscreenCommandKey") },
{ ShortcutAction::SplitPane, RS_(L"SplitPaneCommandKey") },
{ ShortcutAction::Invalid, L"" },
{ ShortcutAction::Find, RS_(L"FindCommandKey") },
{ ShortcutAction::SetTabColor, RS_(L"ResetTabColorCommandKey") },
{ ShortcutAction::OpenTabColorPicker, RS_(L"OpenTabColorPickerCommandKey") },
{ ShortcutAction::RenameTab, RS_(L"ResetTabNameCommandKey") },
{ ShortcutAction::ToggleCommandPalette, RS_(L"ToggleCommandPaletteCommandKey") },
};
}();

if (_Args)
{
auto nameFromArgs = _Args.GenerateName();
if (!nameFromArgs.empty())
{
return nameFromArgs;
}
}

const auto found = GeneratedActionNames.find(_Action);
return found != GeneratedActionNames.end() ? found->second : L"";
}

}
4 changes: 3 additions & 1 deletion src/cascadia/TerminalApp/ActionAndArgs.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ namespace winrt::TerminalApp::implementation
{
struct ActionAndArgs : public ActionAndArgsT<ActionAndArgs>
{
static const std::map<std::string_view, ShortcutAction, std::less<>> ActionNamesMap;
static const std::map<std::string_view, ShortcutAction, std::less<>> ActionKeyNamesMap;
zadjii-msft marked this conversation as resolved.
Show resolved Hide resolved
static winrt::com_ptr<ActionAndArgs> FromJson(const Json::Value& json,
std::vector<::TerminalApp::SettingsLoadWarnings>& warnings);

ActionAndArgs() = default;
hstring GenerateName() const;

GETSET_PROPERTY(TerminalApp::ShortcutAction, Action, TerminalApp::ShortcutAction::Invalid);
GETSET_PROPERTY(IActionArgs, Args, nullptr);
};
Expand Down
Loading