From 5f272804c4ff6c4788324a48ddfd9e44dd91a163 Mon Sep 17 00:00:00 2001 From: PankajBhojwani Date: Tue, 19 Mar 2024 15:00:59 -0700 Subject: [PATCH] Add OriginTag to Command (#16823) ## Summary of the Pull Request As outlined in #16816 , adding `OriginTag` to `Command` is one of the prerequisites to implementing Action IDs. This PR does that. ## Validation Steps Performed Actions/Commands still get parsed and work ## PR Checklist - [ ] Closes #xxx - [ ] Tests added/passed - [ ] Documentation updated - If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/terminal) and link it here: #xxx - [ ] Schema updated (if necessary) --- .../TerminalSettingsModel/ActionMap.h | 4 +- .../ActionMapSerialization.cpp | 8 +- .../CascadiaSettingsSerialization.cpp | 6 +- .../TerminalSettingsModel/Command.cpp | 12 ++- src/cascadia/TerminalSettingsModel/Command.h | 5 +- .../TerminalSettingsModel/Command.idl | 2 +- .../GlobalAppSettings.cpp | 12 +-- .../TerminalSettingsModel/GlobalAppSettings.h | 6 +- .../UnitTests_SettingsModel/CommandTests.cpp | 26 +++--- .../KeyBindingsTests.cpp | 80 +++++++++---------- 10 files changed, 84 insertions(+), 77 deletions(-) diff --git a/src/cascadia/TerminalSettingsModel/ActionMap.h b/src/cascadia/TerminalSettingsModel/ActionMap.h index 937d79f66cb..de9b9ca2361 100644 --- a/src/cascadia/TerminalSettingsModel/ActionMap.h +++ b/src/cascadia/TerminalSettingsModel/ActionMap.h @@ -66,8 +66,8 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation void AddAction(const Model::Command& cmd); // JSON - static com_ptr FromJson(const Json::Value& json); - std::vector LayerJson(const Json::Value& json, const bool withKeybindings = true); + static com_ptr FromJson(const Json::Value& json, const OriginTag origin = OriginTag::None); + std::vector LayerJson(const Json::Value& json, const OriginTag origin, const bool withKeybindings = true); Json::Value ToJson() const; // modification diff --git a/src/cascadia/TerminalSettingsModel/ActionMapSerialization.cpp b/src/cascadia/TerminalSettingsModel/ActionMapSerialization.cpp index 248a0023d00..c03fecd82f5 100644 --- a/src/cascadia/TerminalSettingsModel/ActionMapSerialization.cpp +++ b/src/cascadia/TerminalSettingsModel/ActionMapSerialization.cpp @@ -19,10 +19,10 @@ using namespace winrt::Microsoft::Terminal::Settings::Model; namespace winrt::Microsoft::Terminal::Settings::Model::implementation { - com_ptr ActionMap::FromJson(const Json::Value& json) + com_ptr ActionMap::FromJson(const Json::Value& json, const OriginTag origin) { auto result = make_self(); - result->LayerJson(json); + result->LayerJson(json, origin); return result; } @@ -35,7 +35,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation // - json: an array of Json::Value's to deserialize into our ActionMap. // Return value: // - a list of warnings encountered while deserializing the json - std::vector ActionMap::LayerJson(const Json::Value& json, const bool withKeybindings) + std::vector ActionMap::LayerJson(const Json::Value& json, const OriginTag origin, const bool withKeybindings) { // It's possible that the user provided keybindings have some warnings in // them - problems that we should alert the user to, but we can recover @@ -50,7 +50,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation continue; } - AddAction(*Command::FromJson(cmdJson, warnings, withKeybindings)); + AddAction(*Command::FromJson(cmdJson, warnings, origin, withKeybindings)); } return warnings; diff --git a/src/cascadia/TerminalSettingsModel/CascadiaSettingsSerialization.cpp b/src/cascadia/TerminalSettingsModel/CascadiaSettingsSerialization.cpp index fc2cc562621..244c200dad8 100644 --- a/src/cascadia/TerminalSettingsModel/CascadiaSettingsSerialization.cpp +++ b/src/cascadia/TerminalSettingsModel/CascadiaSettingsSerialization.cpp @@ -345,7 +345,7 @@ void SettingsLoader::FinalizeLayering() if (userSettings.globals->EnableColorSelection()) { const auto json = _parseJson(LoadStringResource(IDR_ENABLE_COLOR_SELECTION)); - const auto globals = GlobalAppSettings::FromJson(json.root); + const auto globals = GlobalAppSettings::FromJson(json.root, OriginTag::InBox); userSettings.globals->AddLeastImportantParent(globals); } @@ -611,7 +611,7 @@ void SettingsLoader::_parse(const OriginTag origin, const winrt::hstring& source settings.clear(); { - settings.globals = GlobalAppSettings::FromJson(json.root); + settings.globals = GlobalAppSettings::FromJson(json.root, origin); for (const auto& schemeJson : json.colorSchemes) { @@ -699,7 +699,7 @@ void SettingsLoader::_parseFragment(const winrt::hstring& source, const std::str // Parse out actions from the fragment. Manually opt-out of keybinding // parsing - fragments shouldn't be allowed to bind actions to keys // directly. We may want to revisit circa GH#2205 - settings.globals->LayerActionsFrom(json.root, false); + settings.globals->LayerActionsFrom(json.root, OriginTag::Fragment, false); } { diff --git a/src/cascadia/TerminalSettingsModel/Command.cpp b/src/cascadia/TerminalSettingsModel/Command.cpp index 3b2f4075c5d..516d767481b 100644 --- a/src/cascadia/TerminalSettingsModel/Command.cpp +++ b/src/cascadia/TerminalSettingsModel/Command.cpp @@ -40,6 +40,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation { auto command{ winrt::make_self() }; command->_name = _name; + command->_Origin = OriginTag::User; command->_ActionAndArgs = *get_self(_ActionAndArgs)->Copy(); command->_keyMappings = _keyMappings; command->_iconPath = _iconPath; @@ -259,9 +260,11 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation // - the newly constructed Command object. winrt::com_ptr Command::FromJson(const Json::Value& json, std::vector& warnings, + const OriginTag origin, const bool parseKeys) { auto result = winrt::make_self(); + result->_Origin = origin; auto nested = false; JsonUtils::GetValueForKey(json, IterateOnKey, result->_IterateOn); @@ -274,7 +277,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation // Initialize our list of subcommands. result->_subcommands = winrt::single_threaded_map(); result->_nestedCommand = true; - auto nestedWarnings = Command::LayerJson(result->_subcommands, nestedCommandsJson); + auto nestedWarnings = Command::LayerJson(result->_subcommands, nestedCommandsJson, origin); // It's possible that the nested commands have some warnings warnings.insert(warnings.end(), nestedWarnings.begin(), nestedWarnings.end()); @@ -362,7 +365,8 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation // Return Value: // - A vector containing any warnings detected while parsing std::vector Command::LayerJson(IMap& commands, - const Json::Value& json) + const Json::Value& json, + const OriginTag origin) { std::vector warnings; @@ -372,7 +376,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation { try { - const auto result = Command::FromJson(value, warnings); + const auto result = Command::FromJson(value, warnings, origin); if (result->ActionAndArgs().Action() == ShortcutAction::Invalid && !result->HasNestedCommands()) { // If there wasn't a parsed command, then try to get the @@ -583,7 +587,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation // warnings, but ultimately, we don't care about warnings during // expansion. std::vector unused; - if (auto newCmd{ Command::FromJson(newJsonValue, unused) }) + if (auto newCmd{ Command::FromJson(newJsonValue, unused, expandable->_Origin) }) { newCommands.push_back(*newCmd); } diff --git a/src/cascadia/TerminalSettingsModel/Command.h b/src/cascadia/TerminalSettingsModel/Command.h index a432fe9a370..5e94ae721c8 100644 --- a/src/cascadia/TerminalSettingsModel/Command.h +++ b/src/cascadia/TerminalSettingsModel/Command.h @@ -40,6 +40,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation static winrt::com_ptr FromJson(const Json::Value& json, std::vector& warnings, + const OriginTag origin, const bool parseKeys = true); static void ExpandCommands(Windows::Foundation::Collections::IMap& commands, @@ -47,7 +48,8 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation Windows::Foundation::Collections::IVectorView schemes); static std::vector LayerJson(Windows::Foundation::Collections::IMap& commands, - const Json::Value& json); + const Json::Value& json, + const OriginTag origin); Json::Value ToJson() const; bool HasNestedCommands() const; @@ -75,6 +77,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation WINRT_PROPERTY(ExpandCommandType, IterateOn, ExpandCommandType::None); WINRT_PROPERTY(Model::ActionAndArgs, ActionAndArgs); + WINRT_PROPERTY(OriginTag, Origin); private: Json::Value _originalJson; diff --git a/src/cascadia/TerminalSettingsModel/Command.idl b/src/cascadia/TerminalSettingsModel/Command.idl index e92f459e69d..c9cec5012a4 100644 --- a/src/cascadia/TerminalSettingsModel/Command.idl +++ b/src/cascadia/TerminalSettingsModel/Command.idl @@ -31,7 +31,7 @@ namespace Microsoft.Terminal.Settings.Model ShortcutAction Action; }; - [default_interface] runtimeclass Command + [default_interface] runtimeclass Command : ISettingsModelObject { Command(); diff --git a/src/cascadia/TerminalSettingsModel/GlobalAppSettings.cpp b/src/cascadia/TerminalSettingsModel/GlobalAppSettings.cpp index a720c261b39..7238d38c0cd 100644 --- a/src/cascadia/TerminalSettingsModel/GlobalAppSettings.cpp +++ b/src/cascadia/TerminalSettingsModel/GlobalAppSettings.cpp @@ -117,14 +117,14 @@ winrt::Microsoft::Terminal::Settings::Model::ActionMap GlobalAppSettings::Action // - json: an object which should be a serialization of a GlobalAppSettings object. // Return Value: // - a new GlobalAppSettings instance created from the values in `json` -winrt::com_ptr GlobalAppSettings::FromJson(const Json::Value& json) +winrt::com_ptr GlobalAppSettings::FromJson(const Json::Value& json, const OriginTag origin) { auto result = winrt::make_self(); - result->LayerJson(json); + result->LayerJson(json, origin); return result; } -void GlobalAppSettings::LayerJson(const Json::Value& json) +void GlobalAppSettings::LayerJson(const Json::Value& json, const OriginTag origin) { JsonUtils::GetValueForKey(json, DefaultProfileKey, _UnparsedDefaultProfile); // GH#8076 - when adding enum values to this key, we also changed it from @@ -137,19 +137,19 @@ void GlobalAppSettings::LayerJson(const Json::Value& json) MTSM_GLOBAL_SETTINGS(GLOBAL_SETTINGS_LAYER_JSON) #undef GLOBAL_SETTINGS_LAYER_JSON - LayerActionsFrom(json, true); + LayerActionsFrom(json, origin, true); JsonUtils::GetValueForKey(json, LegacyReloadEnvironmentVariablesKey, _legacyReloadEnvironmentVariables); } -void GlobalAppSettings::LayerActionsFrom(const Json::Value& json, const bool withKeybindings) +void GlobalAppSettings::LayerActionsFrom(const Json::Value& json, const OriginTag origin, const bool withKeybindings) { static constexpr std::array bindingsKeys{ LegacyKeybindingsKey, ActionsKey }; for (const auto& jsonKey : bindingsKeys) { if (auto bindings{ json[JsonKey(jsonKey)] }) { - auto warnings = _actionMap->LayerJson(bindings, withKeybindings); + auto warnings = _actionMap->LayerJson(bindings, origin, withKeybindings); // It's possible that the user provided keybindings have some warnings // in them - problems that we should alert the user to, but we can diff --git a/src/cascadia/TerminalSettingsModel/GlobalAppSettings.h b/src/cascadia/TerminalSettingsModel/GlobalAppSettings.h index 79f40342254..aa7d8c0147f 100644 --- a/src/cascadia/TerminalSettingsModel/GlobalAppSettings.h +++ b/src/cascadia/TerminalSettingsModel/GlobalAppSettings.h @@ -48,9 +48,9 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation Model::ActionMap ActionMap() const noexcept; - static com_ptr FromJson(const Json::Value& json); - void LayerJson(const Json::Value& json); - void LayerActionsFrom(const Json::Value& json, const bool withKeybindings = true); + static com_ptr FromJson(const Json::Value& json, const OriginTag origin = OriginTag::None); + void LayerJson(const Json::Value& json, const OriginTag origin); + void LayerActionsFrom(const Json::Value& json, const OriginTag origin, const bool withKeybindings = true); Json::Value ToJson() const; diff --git a/src/cascadia/UnitTests_SettingsModel/CommandTests.cpp b/src/cascadia/UnitTests_SettingsModel/CommandTests.cpp index f68b0224a47..8db1141736f 100644 --- a/src/cascadia/UnitTests_SettingsModel/CommandTests.cpp +++ b/src/cascadia/UnitTests_SettingsModel/CommandTests.cpp @@ -48,19 +48,19 @@ namespace SettingsModelUnitTests auto commands = winrt::single_threaded_map(); VERIFY_ARE_EQUAL(0u, commands.Size()); { - auto warnings = implementation::Command::LayerJson(commands, commands0Json); + auto warnings = implementation::Command::LayerJson(commands, commands0Json, OriginTag::None); VERIFY_ARE_EQUAL(0u, warnings.size()); } VERIFY_ARE_EQUAL(1u, commands.Size()); { - auto warnings = implementation::Command::LayerJson(commands, commands1Json); + auto warnings = implementation::Command::LayerJson(commands, commands1Json, OriginTag::None); VERIFY_ARE_EQUAL(0u, warnings.size()); } VERIFY_ARE_EQUAL(2u, commands.Size()); { - auto warnings = implementation::Command::LayerJson(commands, commands2Json); + auto warnings = implementation::Command::LayerJson(commands, commands2Json, OriginTag::None); VERIFY_ARE_EQUAL(0u, warnings.size()); } VERIFY_ARE_EQUAL(4u, commands.Size()); @@ -82,7 +82,7 @@ namespace SettingsModelUnitTests auto commands = winrt::single_threaded_map(); VERIFY_ARE_EQUAL(0u, commands.Size()); { - auto warnings = implementation::Command::LayerJson(commands, commands0Json); + auto warnings = implementation::Command::LayerJson(commands, commands0Json, OriginTag::None); VERIFY_ARE_EQUAL(0u, warnings.size()); VERIFY_ARE_EQUAL(1u, commands.Size()); auto command = commands.Lookup(L"action0"); @@ -93,7 +93,7 @@ namespace SettingsModelUnitTests VERIFY_IS_NOT_NULL(realArgs); } { - auto warnings = implementation::Command::LayerJson(commands, commands1Json); + auto warnings = implementation::Command::LayerJson(commands, commands1Json, OriginTag::None); VERIFY_ARE_EQUAL(0u, warnings.size()); VERIFY_ARE_EQUAL(1u, commands.Size()); auto command = commands.Lookup(L"action0"); @@ -103,7 +103,7 @@ namespace SettingsModelUnitTests VERIFY_IS_NULL(command.ActionAndArgs().Args()); } { - auto warnings = implementation::Command::LayerJson(commands, commands2Json); + auto warnings = implementation::Command::LayerJson(commands, commands2Json, OriginTag::None); VERIFY_ARE_EQUAL(0u, warnings.size()); VERIFY_ARE_EQUAL(1u, commands.Size()); auto command = commands.Lookup(L"action0"); @@ -115,7 +115,7 @@ namespace SettingsModelUnitTests } { // This last command should "unbind" the action. - auto warnings = implementation::Command::LayerJson(commands, commands3Json); + auto warnings = implementation::Command::LayerJson(commands, commands3Json, OriginTag::None); VERIFY_ARE_EQUAL(0u, warnings.size()); VERIFY_ARE_EQUAL(0u, commands.Size()); } @@ -143,7 +143,7 @@ namespace SettingsModelUnitTests auto commands = winrt::single_threaded_map(); VERIFY_ARE_EQUAL(0u, commands.Size()); - auto warnings = implementation::Command::LayerJson(commands, commands0Json); + auto warnings = implementation::Command::LayerJson(commands, commands0Json, OriginTag::None); VERIFY_ARE_EQUAL(0u, warnings.size()); VERIFY_ARE_EQUAL(9u, commands.Size()); @@ -261,7 +261,7 @@ namespace SettingsModelUnitTests auto commands = winrt::single_threaded_map(); VERIFY_ARE_EQUAL(0u, commands.Size()); - auto warnings = implementation::Command::LayerJson(commands, commands0Json); + auto warnings = implementation::Command::LayerJson(commands, commands0Json, OriginTag::None); VERIFY_ARE_EQUAL(3u, warnings.size()); VERIFY_ARE_EQUAL(1u, commands.Size()); @@ -288,7 +288,7 @@ namespace SettingsModelUnitTests auto commands = winrt::single_threaded_map(); VERIFY_ARE_EQUAL(0u, commands.Size()); { - auto warnings = implementation::Command::LayerJson(commands, commands0Json); + auto warnings = implementation::Command::LayerJson(commands, commands0Json, OriginTag::None); VERIFY_ARE_EQUAL(0u, warnings.size()); VERIFY_ARE_EQUAL(1u, commands.Size()); @@ -329,7 +329,7 @@ namespace SettingsModelUnitTests auto commands = winrt::single_threaded_map(); VERIFY_ARE_EQUAL(0u, commands.Size()); - auto warnings = implementation::Command::LayerJson(commands, commands0Json); + auto warnings = implementation::Command::LayerJson(commands, commands0Json, OriginTag::None); VERIFY_ARE_EQUAL(0u, warnings.size()); // There are only 5 commands here: all of the `"none"`, `"auto"`, @@ -399,7 +399,7 @@ namespace SettingsModelUnitTests auto commands = winrt::single_threaded_map(); VERIFY_ARE_EQUAL(0u, commands.Size()); - auto warnings = implementation::Command::LayerJson(commands, commands0Json); + auto warnings = implementation::Command::LayerJson(commands, commands0Json, OriginTag::None); VERIFY_ARE_EQUAL(0u, warnings.size()); VERIFY_ARE_EQUAL(1u, commands.Size()); @@ -462,7 +462,7 @@ namespace SettingsModelUnitTests auto commands = winrt::single_threaded_map(); VERIFY_ARE_EQUAL(0u, commands.Size()); - auto warnings = implementation::Command::LayerJson(commands, commands0Json); + auto warnings = implementation::Command::LayerJson(commands, commands0Json, OriginTag::None); VERIFY_ARE_EQUAL(0u, warnings.size()); VERIFY_ARE_EQUAL(9u, commands.Size()); diff --git a/src/cascadia/UnitTests_SettingsModel/KeyBindingsTests.cpp b/src/cascadia/UnitTests_SettingsModel/KeyBindingsTests.cpp index 8eed7276f1b..c5f4be49045 100644 --- a/src/cascadia/UnitTests_SettingsModel/KeyBindingsTests.cpp +++ b/src/cascadia/UnitTests_SettingsModel/KeyBindingsTests.cpp @@ -120,13 +120,13 @@ namespace SettingsModelUnitTests auto actionMap = winrt::make_self(); VERIFY_ARE_EQUAL(0u, actionMap->_KeyMap.size()); - actionMap->LayerJson(bindings0Json); + actionMap->LayerJson(bindings0Json, OriginTag::None); VERIFY_ARE_EQUAL(1u, actionMap->_KeyMap.size()); - actionMap->LayerJson(bindings1Json); + actionMap->LayerJson(bindings1Json, OriginTag::None); VERIFY_ARE_EQUAL(2u, actionMap->_KeyMap.size()); - actionMap->LayerJson(bindings2Json); + actionMap->LayerJson(bindings2Json, OriginTag::None); VERIFY_ARE_EQUAL(4u, actionMap->_KeyMap.size()); } @@ -143,21 +143,21 @@ namespace SettingsModelUnitTests auto actionMap = winrt::make_self(); VERIFY_ARE_EQUAL(0u, actionMap->_KeyMap.size()); - actionMap->LayerJson(bindings0Json); + actionMap->LayerJson(bindings0Json, OriginTag::None); VERIFY_ARE_EQUAL(1u, actionMap->_KeyMap.size()); - actionMap->LayerJson(bindings1Json); + actionMap->LayerJson(bindings1Json, OriginTag::None); VERIFY_ARE_EQUAL(1u, actionMap->_KeyMap.size()); - actionMap->LayerJson(bindings2Json); + actionMap->LayerJson(bindings2Json, OriginTag::None); VERIFY_ARE_EQUAL(2u, actionMap->_KeyMap.size()); } void KeyBindingsTests::HashDeduplication() { const auto actionMap = winrt::make_self(); - actionMap->LayerJson(VerifyParseSucceeded(R"([ { "command": "splitPane", "keys": ["ctrl+c"] } ])")); - actionMap->LayerJson(VerifyParseSucceeded(R"([ { "command": "splitPane", "keys": ["ctrl+c"] } ])")); + actionMap->LayerJson(VerifyParseSucceeded(R"([ { "command": "splitPane", "keys": ["ctrl+c"] } ])"), OriginTag::None); + actionMap->LayerJson(VerifyParseSucceeded(R"([ { "command": "splitPane", "keys": ["ctrl+c"] } ])"), OriginTag::None); VERIFY_ARE_EQUAL(1u, actionMap->_ActionMap.size()); } @@ -180,51 +180,51 @@ namespace SettingsModelUnitTests auto actionMap = winrt::make_self(); VERIFY_ARE_EQUAL(0u, actionMap->_KeyMap.size()); - actionMap->LayerJson(bindings0Json); + actionMap->LayerJson(bindings0Json, OriginTag::None); VERIFY_ARE_EQUAL(1u, actionMap->_KeyMap.size()); - actionMap->LayerJson(bindings1Json); + actionMap->LayerJson(bindings1Json, OriginTag::None); VERIFY_ARE_EQUAL(1u, actionMap->_KeyMap.size()); Log::Comment(NoThrowString().Format( L"Try unbinding a key using `\"unbound\"` to unbind the key")); - actionMap->LayerJson(bindings2Json); + actionMap->LayerJson(bindings2Json, OriginTag::None); VERIFY_ARE_EQUAL(1u, actionMap->_KeyMap.size()); VERIFY_IS_NULL(actionMap->GetActionByKeyChord({ VirtualKeyModifiers::Control, static_cast('C'), 0 })); Log::Comment(NoThrowString().Format( L"Try unbinding a key using `null` to unbind the key")); // First add back a good binding - actionMap->LayerJson(bindings0Json); + actionMap->LayerJson(bindings0Json, OriginTag::None); VERIFY_ARE_EQUAL(1u, actionMap->_KeyMap.size()); // Then try layering in the bad setting - actionMap->LayerJson(bindings3Json); + actionMap->LayerJson(bindings3Json, OriginTag::None); VERIFY_ARE_EQUAL(1u, actionMap->_KeyMap.size()); VERIFY_IS_NULL(actionMap->GetActionByKeyChord({ VirtualKeyModifiers::Control, static_cast('C'), 0 })); Log::Comment(NoThrowString().Format( L"Try unbinding a key using an unrecognized command to unbind the key")); // First add back a good binding - actionMap->LayerJson(bindings0Json); + actionMap->LayerJson(bindings0Json, OriginTag::None); VERIFY_ARE_EQUAL(1u, actionMap->_KeyMap.size()); // Then try layering in the bad setting - actionMap->LayerJson(bindings4Json); + actionMap->LayerJson(bindings4Json, OriginTag::None); VERIFY_ARE_EQUAL(1u, actionMap->_KeyMap.size()); VERIFY_IS_NULL(actionMap->GetActionByKeyChord({ VirtualKeyModifiers::Control, static_cast('C'), 0 })); Log::Comment(NoThrowString().Format( L"Try unbinding a key using a straight up invalid value to unbind the key")); // First add back a good binding - actionMap->LayerJson(bindings0Json); + actionMap->LayerJson(bindings0Json, OriginTag::None); VERIFY_ARE_EQUAL(1u, actionMap->_KeyMap.size()); // Then try layering in the bad setting - actionMap->LayerJson(bindings5Json); + actionMap->LayerJson(bindings5Json, OriginTag::None); VERIFY_ARE_EQUAL(1u, actionMap->_KeyMap.size()); VERIFY_IS_NULL(actionMap->GetActionByKeyChord({ VirtualKeyModifiers::Control, static_cast('C'), 0 })); Log::Comment(NoThrowString().Format( L"Try unbinding a key that wasn't bound at all")); - actionMap->LayerJson(bindings2Json); + actionMap->LayerJson(bindings2Json, OriginTag::None); VERIFY_ARE_EQUAL(1u, actionMap->_KeyMap.size()); VERIFY_IS_NULL(actionMap->GetActionByKeyChord({ VirtualKeyModifiers::Control, static_cast('C'), 0 })); } @@ -244,13 +244,13 @@ namespace SettingsModelUnitTests auto actionMap = winrt::make_self(); VERIFY_IS_FALSE(actionMap->IsKeyChordExplicitlyUnbound(keyChord)); - actionMap->LayerJson(bindings0Json); + actionMap->LayerJson(bindings0Json, OriginTag::None); VERIFY_IS_FALSE(actionMap->IsKeyChordExplicitlyUnbound(keyChord)); - actionMap->LayerJson(bindings1Json); + actionMap->LayerJson(bindings1Json, OriginTag::None); VERIFY_IS_TRUE(actionMap->IsKeyChordExplicitlyUnbound(keyChord)); - actionMap->LayerJson(bindings2Json); + actionMap->LayerJson(bindings2Json, OriginTag::None); VERIFY_IS_FALSE(actionMap->IsKeyChordExplicitlyUnbound(keyChord)); } @@ -277,7 +277,7 @@ namespace SettingsModelUnitTests auto actionMap = winrt::make_self(); VERIFY_ARE_EQUAL(0u, actionMap->_KeyMap.size()); - actionMap->LayerJson(bindings0Json); + actionMap->LayerJson(bindings0Json, OriginTag::None); VERIFY_ARE_EQUAL(10u, actionMap->_KeyMap.size()); { @@ -405,7 +405,7 @@ namespace SettingsModelUnitTests auto actionMap = winrt::make_self(); VERIFY_ARE_EQUAL(0u, actionMap->_KeyMap.size()); - actionMap->LayerJson(bindings0Json); + actionMap->LayerJson(bindings0Json, OriginTag::None); VERIFY_ARE_EQUAL(4u, actionMap->_KeyMap.size()); { @@ -454,7 +454,7 @@ namespace SettingsModelUnitTests auto actionMap = winrt::make_self(); VERIFY_ARE_EQUAL(0u, actionMap->_KeyMap.size()); - actionMap->LayerJson(bindings0Json); + actionMap->LayerJson(bindings0Json, OriginTag::None); VERIFY_ARE_EQUAL(3u, actionMap->_KeyMap.size()); { @@ -495,7 +495,7 @@ namespace SettingsModelUnitTests auto actionMap = winrt::make_self(); VERIFY_ARE_EQUAL(0u, actionMap->_KeyMap.size()); - actionMap->LayerJson(bindings0Json); + actionMap->LayerJson(bindings0Json, OriginTag::None); VERIFY_ARE_EQUAL(1u, actionMap->_KeyMap.size()); { @@ -522,7 +522,7 @@ namespace SettingsModelUnitTests auto actionMap = winrt::make_self(); VERIFY_ARE_EQUAL(0u, actionMap->_KeyMap.size()); - actionMap->LayerJson(bindings0Json); + actionMap->LayerJson(bindings0Json, OriginTag::None); VERIFY_ARE_EQUAL(6u, actionMap->_KeyMap.size()); { @@ -580,7 +580,7 @@ namespace SettingsModelUnitTests const auto bindingsInvalidJson = VerifyParseSucceeded(bindingsInvalidString); auto invalidActionMap = winrt::make_self(); VERIFY_ARE_EQUAL(0u, invalidActionMap->_KeyMap.size()); - VERIFY_THROWS(invalidActionMap->LayerJson(bindingsInvalidJson);, std::exception); + VERIFY_THROWS(invalidActionMap->LayerJson(bindingsInvalidJson, OriginTag::None);, std::exception); } } @@ -595,7 +595,7 @@ namespace SettingsModelUnitTests auto actionMap = winrt::make_self(); VERIFY_ARE_EQUAL(0u, actionMap->_KeyMap.size()); - actionMap->LayerJson(bindings0Json); + actionMap->LayerJson(bindings0Json, OriginTag::None); VERIFY_ARE_EQUAL(2u, actionMap->_KeyMap.size()); { @@ -617,7 +617,7 @@ namespace SettingsModelUnitTests { const std::string bindingsInvalidString{ R"([{ "keys": ["up"], "command": "moveTab" }])" }; auto actionMapNoArgs = winrt::make_self(); - actionMapNoArgs->LayerJson(bindingsInvalidString); + actionMapNoArgs->LayerJson(bindingsInvalidString, OriginTag::None); VERIFY_ARE_EQUAL(0u, actionMapNoArgs->_KeyMap.size()); } { @@ -625,7 +625,7 @@ namespace SettingsModelUnitTests const auto bindingsInvalidJson = VerifyParseSucceeded(bindingsInvalidString); auto invalidActionMap = winrt::make_self(); VERIFY_ARE_EQUAL(0u, invalidActionMap->_KeyMap.size()); - VERIFY_THROWS(invalidActionMap->LayerJson(bindingsInvalidJson);, std::exception); + VERIFY_THROWS(invalidActionMap->LayerJson(bindingsInvalidJson, OriginTag::None);, std::exception); } } @@ -641,7 +641,7 @@ namespace SettingsModelUnitTests auto actionMap = winrt::make_self(); VERIFY_ARE_EQUAL(0u, actionMap->_KeyMap.size()); - actionMap->LayerJson(bindings0Json); + actionMap->LayerJson(bindings0Json, OriginTag::None); VERIFY_ARE_EQUAL(3u, actionMap->_KeyMap.size()); { @@ -673,7 +673,7 @@ namespace SettingsModelUnitTests const auto bindingsInvalidJson = VerifyParseSucceeded(bindingsInvalidString); auto invalidActionMap = winrt::make_self(); VERIFY_ARE_EQUAL(0u, invalidActionMap->_KeyMap.size()); - VERIFY_THROWS(invalidActionMap->LayerJson(bindingsInvalidJson);, std::exception); + VERIFY_THROWS(invalidActionMap->LayerJson(bindingsInvalidJson, OriginTag::None);, std::exception); } } @@ -707,14 +707,14 @@ namespace SettingsModelUnitTests { Log::Comment(L"simple command: no args"); - actionMap->LayerJson(bindings0Json); + actionMap->LayerJson(bindings0Json, OriginTag::None); VERIFY_ARE_EQUAL(1u, actionMap->_KeyMap.size()); const auto& kbd{ actionMap->GetKeyBindingForAction(ShortcutAction::CloseWindow) }; VerifyKeyChordEquality({ VirtualKeyModifiers::Control, static_cast('A'), 0 }, kbd); } { Log::Comment(L"command with args"); - actionMap->LayerJson(bindings1Json); + actionMap->LayerJson(bindings1Json, OriginTag::None); VERIFY_ARE_EQUAL(2u, actionMap->_KeyMap.size()); auto args{ winrt::make_self() }; @@ -725,7 +725,7 @@ namespace SettingsModelUnitTests } { Log::Comment(L"command with new terminal args"); - actionMap->LayerJson(bindings2Json); + actionMap->LayerJson(bindings2Json, OriginTag::None); VERIFY_ARE_EQUAL(3u, actionMap->_KeyMap.size()); auto newTerminalArgs{ winrt::make_self() }; @@ -737,7 +737,7 @@ namespace SettingsModelUnitTests } { Log::Comment(L"command with hidden args"); - actionMap->LayerJson(bindings3Json); + actionMap->LayerJson(bindings3Json, OriginTag::None); VERIFY_ARE_EQUAL(4u, actionMap->_KeyMap.size()); const auto& kbd{ actionMap->GetKeyBindingForAction(ShortcutAction::ToggleCommandPalette) }; @@ -762,13 +762,13 @@ namespace SettingsModelUnitTests auto actionMap = winrt::make_self(); VERIFY_ARE_EQUAL(0u, actionMap->_KeyMap.size()); - actionMap->LayerJson(bindings0Json); + actionMap->LayerJson(bindings0Json, OriginTag::None); VERIFY_ARE_EQUAL(1u, actionMap->_KeyMap.size()); - actionMap->LayerJson(bindings1Json); + actionMap->LayerJson(bindings1Json, OriginTag::None); VERIFY_ARE_EQUAL(1u, actionMap->_KeyMap.size(), L"Layering the second action should replace the first one."); - actionMap->LayerJson(bindings2Json); + actionMap->LayerJson(bindings2Json, OriginTag::None); VERIFY_ARE_EQUAL(2u, actionMap->_KeyMap.size()); } @@ -777,7 +777,7 @@ namespace SettingsModelUnitTests const auto json = VerifyParseSucceeded(R"!([{"command": "quakeMode", "keys":"shift+sc(255)"}])!"); const auto actionMap = winrt::make_self(); - actionMap->LayerJson(json); + actionMap->LayerJson(json, OriginTag::None); const auto action = actionMap->GetActionByKeyChord({ VirtualKeyModifiers::Shift, 0, 255 }); VERIFY_IS_NOT_NULL(action);