terminal/src/cascadia/TerminalApp/AppKeyBindings.h
msftbot[bot] 2cba4c628e
Add warning messages for bad keybindings (#4746)
## Summary of the Pull Request

Adds warning messages for a pair of keybindings-related scenarios. This covers the following two bugs:
* #4239 - If the user has supplied more than one key chord in their `"keys"` array.
* #3522 - If a keybinding has a _required_ argument, then we'll display a message to the user
  - currently, the only required parameter is the `direction` parameter for both `resizePane` and `moveFocus`

## References

When we get to #1334, we'll want to remove the `TooManyKeysForChord` warning.

## PR Checklist
* [x] Closes #4239
* [x] Closes #3522
* [x] I work here
* [x] Tests added/passed
* [n/a] Requires documentation to be updated

![image](https://user-images.githubusercontent.com/18356694/75593132-f18ec700-5a49-11ea-9d26-6acd0d28b0b7.png)


## Validation Steps Performed
Tested manually, added tests.
2020-03-05 21:06:58 +00:00

76 lines
2.7 KiB
C++

// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
#pragma once
#include "AppKeyBindings.g.h"
#include "ActionArgs.h"
#include "ShortcutActionDispatch.h"
#include "..\inc\cppwinrt_utils.h"
// fwdecl unittest classes
namespace TerminalAppLocalTests
{
class SettingsTests;
class KeyBindingsTests;
class TestUtils;
}
namespace winrt::TerminalApp::implementation
{
struct KeyChordHash
{
std::size_t operator()(const winrt::Microsoft::Terminal::Settings::KeyChord& key) const
{
std::hash<int32_t> keyHash;
std::hash<winrt::Microsoft::Terminal::Settings::KeyModifiers> modifiersHash;
std::size_t hashedKey = keyHash(key.Vkey());
std::size_t hashedMods = modifiersHash(key.Modifiers());
return hashedKey ^ hashedMods;
}
};
struct KeyChordEquality
{
bool operator()(const winrt::Microsoft::Terminal::Settings::KeyChord& lhs, const winrt::Microsoft::Terminal::Settings::KeyChord& rhs) const
{
return lhs.Modifiers() == rhs.Modifiers() && lhs.Vkey() == rhs.Vkey();
}
};
struct AppKeyBindings : AppKeyBindingsT<AppKeyBindings>
{
AppKeyBindings() = default;
bool TryKeyChord(winrt::Microsoft::Terminal::Settings::KeyChord const& kc);
void SetKeyBinding(TerminalApp::ActionAndArgs const& actionAndArgs,
winrt::Microsoft::Terminal::Settings::KeyChord const& chord);
void ClearKeyBinding(winrt::Microsoft::Terminal::Settings::KeyChord const& chord);
Microsoft::Terminal::Settings::KeyChord GetKeyBindingForAction(TerminalApp::ShortcutAction const& action);
Microsoft::Terminal::Settings::KeyChord GetKeyBindingForActionWithArgs(TerminalApp::ActionAndArgs const& actionAndArgs);
static Windows::System::VirtualKeyModifiers ConvertVKModifiers(winrt::Microsoft::Terminal::Settings::KeyModifiers modifiers);
// Defined in AppKeyBindingsSerialization.cpp
std::vector<::TerminalApp::SettingsLoadWarnings> LayerJson(const Json::Value& json);
Json::Value ToJson();
void SetDispatch(const winrt::TerminalApp::ShortcutActionDispatch& dispatch);
private:
std::unordered_map<winrt::Microsoft::Terminal::Settings::KeyChord, TerminalApp::ActionAndArgs, KeyChordHash, KeyChordEquality> _keyShortcuts;
winrt::TerminalApp::ShortcutActionDispatch _dispatch{ nullptr };
friend class TerminalAppLocalTests::SettingsTests;
friend class TerminalAppLocalTests::KeyBindingsTests;
friend class TerminalAppLocalTests::TestUtils;
};
}
namespace winrt::TerminalApp::factory_implementation
{
BASIC_FACTORY(AppKeyBindings);
}