Add launchMode parameter to ToggleCommandPalette action (#8382)
## PR Checklist * [x] Closes https://github.com/microsoft/terminal/issues/8322 * [x] CLA signed. * [x] Tests added/passed * [x] Documentation updated - https://github.com/MicrosoftDocs/terminal/pull/202 * [x] Schema updated. * [x] I've discussed this with core contributors already. ## Detailed Description of the Pull Request / Additional comments Added an optional launchMode parameter to "commandPalette" command. The values of the launchMode are either "action" (default) or "command line". ## Validation Steps Performed * Manual tests
This commit is contained in:
parent
3181b6a517
commit
f072eaf9d8
|
@ -167,6 +167,13 @@
|
||||||
],
|
],
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
"CommandPaletteLaunchMode": {
|
||||||
|
"enum": [
|
||||||
|
"action",
|
||||||
|
"commandLine"
|
||||||
|
],
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
"NewTerminalArgs": {
|
"NewTerminalArgs": {
|
||||||
"properties": {
|
"properties": {
|
||||||
"commandline": {
|
"commandline": {
|
||||||
|
@ -522,6 +529,22 @@
|
||||||
],
|
],
|
||||||
"required": [ "direction" ]
|
"required": [ "direction" ]
|
||||||
},
|
},
|
||||||
|
"CommandPaletteAction": {
|
||||||
|
"description": "Arguments for a commandPalette action",
|
||||||
|
"allOf": [
|
||||||
|
{ "$ref": "#/definitions/ShortcutAction" },
|
||||||
|
{
|
||||||
|
"properties": {
|
||||||
|
"action": { "type": "string", "pattern": "commandPalette" },
|
||||||
|
"launchMode": {
|
||||||
|
"$ref": "#/definitions/CommandPaletteLaunchMode",
|
||||||
|
"default": "action",
|
||||||
|
"description": "Toggle command palette in either action or command line mode. If no value is provided, the palette will launch in action mode."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
"Keybinding": {
|
"Keybinding": {
|
||||||
"additionalProperties": false,
|
"additionalProperties": false,
|
||||||
"properties": {
|
"properties": {
|
||||||
|
|
|
@ -48,6 +48,7 @@ namespace SettingsModelLocalTests
|
||||||
|
|
||||||
TEST_METHOD(TestScrollArgs);
|
TEST_METHOD(TestScrollArgs);
|
||||||
|
|
||||||
|
TEST_METHOD(TestToggleCommandPaletteArgs);
|
||||||
TEST_METHOD(TestMoveTabArgs);
|
TEST_METHOD(TestMoveTabArgs);
|
||||||
|
|
||||||
TEST_CLASS_SETUP(ClassSetup)
|
TEST_CLASS_SETUP(ClassSetup)
|
||||||
|
@ -580,4 +581,57 @@ namespace SettingsModelLocalTests
|
||||||
VERIFY_THROWS(invalidKeyMap->LayerJson(bindingsInvalidJson);, std::exception);
|
VERIFY_THROWS(invalidKeyMap->LayerJson(bindingsInvalidJson);, std::exception);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void KeyBindingsTests::TestToggleCommandPaletteArgs()
|
||||||
|
{
|
||||||
|
const std::string bindings0String{ R"([
|
||||||
|
{ "keys": ["up"], "command": "commandPalette" },
|
||||||
|
{ "keys": ["ctrl+up"], "command": { "action": "commandPalette", "launchMode" : "action" } },
|
||||||
|
{ "keys": ["ctrl+shift+up"], "command": { "action": "commandPalette", "launchMode" : "commandLine" } }
|
||||||
|
])" };
|
||||||
|
|
||||||
|
const auto bindings0Json = VerifyParseSucceeded(bindings0String);
|
||||||
|
|
||||||
|
auto keymap = winrt::make_self<implementation::KeyMapping>();
|
||||||
|
VERIFY_IS_NOT_NULL(keymap);
|
||||||
|
VERIFY_ARE_EQUAL(0u, keymap->_keyShortcuts.size());
|
||||||
|
keymap->LayerJson(bindings0Json);
|
||||||
|
VERIFY_ARE_EQUAL(3u, keymap->_keyShortcuts.size());
|
||||||
|
|
||||||
|
{
|
||||||
|
KeyChord kc{ false, false, false, static_cast<int32_t>(VK_UP) };
|
||||||
|
auto actionAndArgs = ::TestUtils::GetActionAndArgs(*keymap, kc);
|
||||||
|
VERIFY_ARE_EQUAL(ShortcutAction::ToggleCommandPalette, actionAndArgs.Action());
|
||||||
|
const auto& realArgs = actionAndArgs.Args().try_as<ToggleCommandPaletteArgs>();
|
||||||
|
VERIFY_IS_NOT_NULL(realArgs);
|
||||||
|
// Verify the args have the expected value
|
||||||
|
VERIFY_ARE_EQUAL(realArgs.LaunchMode(), CommandPaletteLaunchMode::Action);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
KeyChord kc{ true, false, false, static_cast<int32_t>(VK_UP) };
|
||||||
|
auto actionAndArgs = ::TestUtils::GetActionAndArgs(*keymap, kc);
|
||||||
|
VERIFY_ARE_EQUAL(ShortcutAction::ToggleCommandPalette, actionAndArgs.Action());
|
||||||
|
const auto& realArgs = actionAndArgs.Args().try_as<ToggleCommandPaletteArgs>();
|
||||||
|
VERIFY_IS_NOT_NULL(realArgs);
|
||||||
|
// Verify the args have the expected value
|
||||||
|
VERIFY_ARE_EQUAL(realArgs.LaunchMode(), CommandPaletteLaunchMode::Action);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
KeyChord kc{ true, false, true, static_cast<int32_t>(VK_UP) };
|
||||||
|
auto actionAndArgs = ::TestUtils::GetActionAndArgs(*keymap, kc);
|
||||||
|
VERIFY_ARE_EQUAL(ShortcutAction::ToggleCommandPalette, actionAndArgs.Action());
|
||||||
|
const auto& realArgs = actionAndArgs.Args().try_as<ToggleCommandPaletteArgs>();
|
||||||
|
VERIFY_IS_NOT_NULL(realArgs);
|
||||||
|
// Verify the args have the expected value
|
||||||
|
VERIFY_ARE_EQUAL(realArgs.LaunchMode(), CommandPaletteLaunchMode::CommandLine);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const std::string bindingsInvalidString{ R"([{ "keys": ["up"], "command": { "action": "commandPalette", "launchMode": "bad" } }])" };
|
||||||
|
const auto bindingsInvalidJson = VerifyParseSucceeded(bindingsInvalidString);
|
||||||
|
auto invalidKeyMap = winrt::make_self<implementation::KeyMapping>();
|
||||||
|
VERIFY_IS_NOT_NULL(invalidKeyMap);
|
||||||
|
VERIFY_ARE_EQUAL(0u, invalidKeyMap->_keyShortcuts.size());
|
||||||
|
VERIFY_THROWS(invalidKeyMap->LayerJson(bindingsInvalidJson);, std::exception);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -313,13 +313,14 @@ namespace winrt::TerminalApp::implementation
|
||||||
void TerminalPage::_HandleToggleCommandPalette(const IInspectable& /*sender*/,
|
void TerminalPage::_HandleToggleCommandPalette(const IInspectable& /*sender*/,
|
||||||
const ActionEventArgs& args)
|
const ActionEventArgs& args)
|
||||||
{
|
{
|
||||||
// TODO GH#6677: When we add support for commandline mode, first set the
|
if (const auto& realArgs = args.ActionArgs().try_as<ToggleCommandPaletteArgs>())
|
||||||
// mode that the command palette should be in, before making it visible.
|
{
|
||||||
CommandPalette().EnableCommandPaletteMode();
|
CommandPalette().EnableCommandPaletteMode(realArgs.LaunchMode());
|
||||||
CommandPalette().Visibility(CommandPalette().Visibility() == Visibility::Visible ?
|
CommandPalette().Visibility(CommandPalette().Visibility() == Visibility::Visible ?
|
||||||
Visibility::Collapsed :
|
Visibility::Collapsed :
|
||||||
Visibility::Visible);
|
Visibility::Visible);
|
||||||
args.Handled(true);
|
args.Handled(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TerminalPage::_HandleSetColorScheme(const IInspectable& /*sender*/,
|
void TerminalPage::_HandleSetColorScheme(const IInspectable& /*sender*/,
|
||||||
|
|
|
@ -809,9 +809,13 @@ namespace winrt::TerminalApp::implementation
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CommandPalette::EnableCommandPaletteMode()
|
void CommandPalette::EnableCommandPaletteMode(CommandPaletteLaunchMode const launchMode)
|
||||||
{
|
{
|
||||||
_switchToMode(CommandPaletteMode::ActionMode);
|
const auto mode = (launchMode == CommandPaletteLaunchMode::CommandLine) ?
|
||||||
|
CommandPaletteMode::CommandlineMode :
|
||||||
|
CommandPaletteMode::ActionMode;
|
||||||
|
|
||||||
|
_switchToMode(mode);
|
||||||
_updateFilteredActions();
|
_updateFilteredActions();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ namespace winrt::TerminalApp::implementation
|
||||||
void SetTabActions(Windows::Foundation::Collections::IVector<Microsoft::Terminal::Settings::Model::Command> const& tabs, const bool clearList);
|
void SetTabActions(Windows::Foundation::Collections::IVector<Microsoft::Terminal::Settings::Model::Command> const& tabs, const bool clearList);
|
||||||
void SetKeyBindings(Microsoft::Terminal::TerminalControl::IKeyBindings bindings);
|
void SetKeyBindings(Microsoft::Terminal::TerminalControl::IKeyBindings bindings);
|
||||||
|
|
||||||
void EnableCommandPaletteMode();
|
void EnableCommandPaletteMode(Microsoft::Terminal::Settings::Model::CommandPaletteLaunchMode const launchMode);
|
||||||
|
|
||||||
void SetDispatch(const winrt::TerminalApp::ShortcutActionDispatch& dispatch);
|
void SetDispatch(const winrt::TerminalApp::ShortcutActionDispatch& dispatch);
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ namespace TerminalApp
|
||||||
void SetCommands(Windows.Foundation.Collections.IVector<Microsoft.Terminal.Settings.Model.Command> actions);
|
void SetCommands(Windows.Foundation.Collections.IVector<Microsoft.Terminal.Settings.Model.Command> actions);
|
||||||
void SetTabActions(Windows.Foundation.Collections.IVector<Microsoft.Terminal.Settings.Model.Command> tabs, Boolean clearList);
|
void SetTabActions(Windows.Foundation.Collections.IVector<Microsoft.Terminal.Settings.Model.Command> tabs, Boolean clearList);
|
||||||
void SetKeyBindings(Microsoft.Terminal.TerminalControl.IKeyBindings bindings);
|
void SetKeyBindings(Microsoft.Terminal.TerminalControl.IKeyBindings bindings);
|
||||||
void EnableCommandPaletteMode();
|
void EnableCommandPaletteMode(Microsoft.Terminal.Settings.Model.CommandPaletteLaunchMode launchMode);
|
||||||
|
|
||||||
void SelectNextItem(Boolean moveDown);
|
void SelectNextItem(Boolean moveDown);
|
||||||
|
|
||||||
|
|
|
@ -136,6 +136,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
|
||||||
{ ShortcutAction::ScrollUp, ScrollUpArgs::FromJson },
|
{ ShortcutAction::ScrollUp, ScrollUpArgs::FromJson },
|
||||||
{ ShortcutAction::ScrollDown, ScrollDownArgs::FromJson },
|
{ ShortcutAction::ScrollDown, ScrollDownArgs::FromJson },
|
||||||
{ ShortcutAction::MoveTab, MoveTabArgs::FromJson },
|
{ ShortcutAction::MoveTab, MoveTabArgs::FromJson },
|
||||||
|
{ ShortcutAction::ToggleCommandPalette, ToggleCommandPaletteArgs::FromJson },
|
||||||
|
|
||||||
{ ShortcutAction::Invalid, nullptr },
|
{ ShortcutAction::Invalid, nullptr },
|
||||||
};
|
};
|
||||||
|
@ -296,7 +297,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
|
||||||
{ ShortcutAction::SwitchToTab, RS_(L"SwitchToTabCommandKey") },
|
{ ShortcutAction::SwitchToTab, RS_(L"SwitchToTabCommandKey") },
|
||||||
{ ShortcutAction::TabSearch, RS_(L"TabSearchCommandKey") },
|
{ ShortcutAction::TabSearch, RS_(L"TabSearchCommandKey") },
|
||||||
{ ShortcutAction::ToggleAlwaysOnTop, RS_(L"ToggleAlwaysOnTopCommandKey") },
|
{ ShortcutAction::ToggleAlwaysOnTop, RS_(L"ToggleAlwaysOnTopCommandKey") },
|
||||||
{ ShortcutAction::ToggleCommandPalette, RS_(L"ToggleCommandPaletteCommandKey") },
|
{ ShortcutAction::ToggleCommandPalette, L"" },
|
||||||
{ ShortcutAction::ToggleFocusMode, RS_(L"ToggleFocusModeCommandKey") },
|
{ ShortcutAction::ToggleFocusMode, RS_(L"ToggleFocusModeCommandKey") },
|
||||||
{ ShortcutAction::ToggleFullscreen, RS_(L"ToggleFullscreenCommandKey") },
|
{ ShortcutAction::ToggleFullscreen, RS_(L"ToggleFullscreenCommandKey") },
|
||||||
{ ShortcutAction::TogglePaneZoom, RS_(L"TogglePaneZoomCommandKey") },
|
{ ShortcutAction::TogglePaneZoom, RS_(L"TogglePaneZoomCommandKey") },
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include "CloseOtherTabsArgs.g.cpp"
|
#include "CloseOtherTabsArgs.g.cpp"
|
||||||
#include "CloseTabsAfterArgs.g.cpp"
|
#include "CloseTabsAfterArgs.g.cpp"
|
||||||
#include "MoveTabArgs.g.cpp"
|
#include "MoveTabArgs.g.cpp"
|
||||||
|
#include "ToggleCommandPaletteArgs.g.cpp"
|
||||||
|
|
||||||
#include <LibraryResources.h>
|
#include <LibraryResources.h>
|
||||||
|
|
||||||
|
@ -412,4 +413,13 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
|
||||||
directionString)
|
directionString)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
winrt::hstring ToggleCommandPaletteArgs::GenerateName() const
|
||||||
|
{
|
||||||
|
if (_LaunchMode == CommandPaletteLaunchMode::CommandLine)
|
||||||
|
{
|
||||||
|
return RS_(L"ToggleCommandPaletteCommandLineModeCommandKey");
|
||||||
|
}
|
||||||
|
return RS_(L"ToggleCommandPaletteCommandKey");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#include "ScrollUpArgs.g.h"
|
#include "ScrollUpArgs.g.h"
|
||||||
#include "ScrollDownArgs.g.h"
|
#include "ScrollDownArgs.g.h"
|
||||||
#include "MoveTabArgs.g.h"
|
#include "MoveTabArgs.g.h"
|
||||||
|
#include "ToggleCommandPaletteArgs.g.h"
|
||||||
|
|
||||||
#include "../../cascadia/inc/cppwinrt_utils.h"
|
#include "../../cascadia/inc/cppwinrt_utils.h"
|
||||||
#include "JsonUtils.h"
|
#include "JsonUtils.h"
|
||||||
|
@ -786,6 +787,42 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
|
||||||
return *copy;
|
return *copy;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct ToggleCommandPaletteArgs : public ToggleCommandPaletteArgsT<ToggleCommandPaletteArgs>
|
||||||
|
{
|
||||||
|
ToggleCommandPaletteArgs() = default;
|
||||||
|
|
||||||
|
// To preserve backward compatibility the default is Action.
|
||||||
|
GETSET_PROPERTY(CommandPaletteLaunchMode, LaunchMode, CommandPaletteLaunchMode::Action);
|
||||||
|
|
||||||
|
static constexpr std::string_view LaunchModeKey{ "launchMode" };
|
||||||
|
|
||||||
|
public:
|
||||||
|
hstring GenerateName() const;
|
||||||
|
|
||||||
|
bool Equals(const IActionArgs& other)
|
||||||
|
{
|
||||||
|
auto otherAsUs = other.try_as<ToggleCommandPaletteArgs>();
|
||||||
|
if (otherAsUs)
|
||||||
|
{
|
||||||
|
return otherAsUs->_LaunchMode == _LaunchMode;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
static FromJsonResult FromJson(const Json::Value& json)
|
||||||
|
{
|
||||||
|
// LOAD BEARING: Not using make_self here _will_ break you in the future!
|
||||||
|
auto args = winrt::make_self<ToggleCommandPaletteArgs>();
|
||||||
|
JsonUtils::GetValueForKey(json, LaunchModeKey, args->_LaunchMode);
|
||||||
|
return { *args, {} };
|
||||||
|
}
|
||||||
|
IActionArgs Copy() const
|
||||||
|
{
|
||||||
|
auto copy{ winrt::make_self<ToggleCommandPaletteArgs>() };
|
||||||
|
copy->_LaunchMode = _LaunchMode;
|
||||||
|
return *copy;
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace winrt::Microsoft::Terminal::Settings::Model::factory_implementation
|
namespace winrt::Microsoft::Terminal::Settings::Model::factory_implementation
|
||||||
|
|
|
@ -53,6 +53,12 @@ namespace Microsoft.Terminal.Settings.Model
|
||||||
Backward
|
Backward
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum CommandPaletteLaunchMode
|
||||||
|
{
|
||||||
|
Action = 0,
|
||||||
|
CommandLine
|
||||||
|
};
|
||||||
|
|
||||||
[default_interface] runtimeclass NewTerminalArgs {
|
[default_interface] runtimeclass NewTerminalArgs {
|
||||||
NewTerminalArgs();
|
NewTerminalArgs();
|
||||||
NewTerminalArgs(Int32 profileIndex);
|
NewTerminalArgs(Int32 profileIndex);
|
||||||
|
@ -179,4 +185,9 @@ namespace Microsoft.Terminal.Settings.Model
|
||||||
{
|
{
|
||||||
Windows.Foundation.IReference<UInt32> RowsToScroll { get; };
|
Windows.Foundation.IReference<UInt32> RowsToScroll { get; };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
[default_interface] runtimeclass ToggleCommandPaletteArgs : IActionArgs
|
||||||
|
{
|
||||||
|
CommandPaletteLaunchMode LaunchMode { get; };
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -332,6 +332,9 @@
|
||||||
<data name="ToggleCommandPaletteCommandKey" xml:space="preserve">
|
<data name="ToggleCommandPaletteCommandKey" xml:space="preserve">
|
||||||
<value>Toggle command palette</value>
|
<value>Toggle command palette</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="ToggleCommandPaletteCommandLineModeCommandKey" xml:space="preserve">
|
||||||
|
<value>Toggle command palette in command line mode</value>
|
||||||
|
</data>
|
||||||
<data name="ToggleFocusModeCommandKey" xml:space="preserve">
|
<data name="ToggleFocusModeCommandKey" xml:space="preserve">
|
||||||
<value>Toggle focus mode</value>
|
<value>Toggle focus mode</value>
|
||||||
<comment>"Focus mode" is a mode with minimal UI elements, for a distraction-free experience</comment>
|
<comment>"Focus mode" is a mode with minimal UI elements, for a distraction-free experience</comment>
|
||||||
|
|
|
@ -406,3 +406,11 @@ JSON_ENUM_MAPPER(::winrt::Microsoft::Terminal::Settings::Model::MoveTabDirection
|
||||||
pair_type{ "backward", ValueType::Backward },
|
pair_type{ "backward", ValueType::Backward },
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
JSON_ENUM_MAPPER(::winrt::Microsoft::Terminal::Settings::Model::CommandPaletteLaunchMode)
|
||||||
|
{
|
||||||
|
JSON_MAPPINGS(2) = {
|
||||||
|
pair_type{ "action", ValueType::Action },
|
||||||
|
pair_type{ "commandLine", ValueType::CommandLine },
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
Loading…
Reference in a new issue