**BE NOT AFRAID**. I know that there's 107 files in this PR, but almost all of it is just find/replacing `TerminalControl` with `Control`. This is the start of the work to move TermControl into multiple pieces, for #5000. The PR starts this work by: * Splits `TerminalControl` into separate lib and dll projects. We'll want control tests in the future, and for that, we'll need a lib. * Moves `ICoreSettings` back into the `Microsoft.Terminal.Core` namespace. We'll have other types in there soon too. * I could not tell you why this works suddenly. New VS versions? New cppwinrt version? Maybe we're just better at dealing with mdmerge bugs these days. * RENAMES `Microsoft.Terminal.TerminalControl` to `Microsoft.Terminal.Control`. This touches pretty much every file in the sln. Sorry about that (not sorry). An upcoming PR will move much of the logic in TermControl into a new `ControlCore` class that we'll add in `Microsoft.Terminal.Core`. `ControlCore` will then be unittest-able in the `UnitTests_TerminalCore`, which will help prevent regressions like #9455 ## Detailed Description of the Pull Request / Additional comments You're really gonna want to clean the sln first, then merge this into your branch, then rebuild. It's very likely that old winmds will get left behind. If you see something like ``` Error MDM2007 Cannot create type Microsoft.Terminal.TerminalControl.KeyModifiers in read-only metadata file Microsoft.Terminal.TerminalControl. ``` then that's what happened to you.
81 lines
2.5 KiB
C++
81 lines
2.5 KiB
C++
/*++
|
|
Copyright (c) Microsoft Corporation
|
|
Licensed under the MIT license.
|
|
|
|
Module Name:
|
|
- KeyMapping.h
|
|
|
|
Abstract:
|
|
- A mapping of key chords to actions. Includes (de)serialization logic.
|
|
|
|
Author(s):
|
|
- Carlos Zamora - September 2020
|
|
|
|
--*/
|
|
|
|
#pragma once
|
|
|
|
#include "KeyMapping.g.h"
|
|
#include "ActionArgs.h"
|
|
#include "../inc/cppwinrt_utils.h"
|
|
|
|
// fwdecl unittest classes
|
|
namespace SettingsModelLocalTests
|
|
{
|
|
class DeserializationTests;
|
|
class KeyBindingsTests;
|
|
class TestUtils;
|
|
}
|
|
|
|
namespace winrt::Microsoft::Terminal::Settings::Model::implementation
|
|
{
|
|
struct KeyChordHash
|
|
{
|
|
std::size_t operator()(const Control::KeyChord& key) const
|
|
{
|
|
std::hash<int32_t> keyHash;
|
|
std::hash<Control::KeyModifiers> modifiersHash;
|
|
std::size_t hashedKey = keyHash(key.Vkey());
|
|
std::size_t hashedMods = modifiersHash(key.Modifiers());
|
|
return hashedKey ^ hashedMods;
|
|
}
|
|
};
|
|
|
|
struct KeyChordEquality
|
|
{
|
|
bool operator()(const Control::KeyChord& lhs, const Control::KeyChord& rhs) const
|
|
{
|
|
return lhs.Modifiers() == rhs.Modifiers() && lhs.Vkey() == rhs.Vkey();
|
|
}
|
|
};
|
|
|
|
struct KeyMapping : KeyMappingT<KeyMapping>
|
|
{
|
|
KeyMapping() = default;
|
|
com_ptr<KeyMapping> Copy() const;
|
|
|
|
Model::ActionAndArgs TryLookup(Control::KeyChord const& chord) const;
|
|
uint64_t Size() const;
|
|
|
|
void SetKeyBinding(Model::ActionAndArgs const& actionAndArgs,
|
|
Control::KeyChord const& chord);
|
|
void ClearKeyBinding(Control::KeyChord const& chord);
|
|
Control::KeyChord GetKeyBindingForAction(Model::ShortcutAction const& action);
|
|
Control::KeyChord GetKeyBindingForActionWithArgs(Model::ActionAndArgs const& actionAndArgs);
|
|
|
|
static Windows::System::VirtualKeyModifiers ConvertVKModifiers(Control::KeyModifiers modifiers);
|
|
|
|
// Defined in KeyMappingSerialization.cpp
|
|
std::vector<Model::SettingsLoadWarnings> LayerJson(const Json::Value& json);
|
|
Json::Value ToJson();
|
|
|
|
private:
|
|
std::unordered_map<Control::KeyChord, Model::ActionAndArgs, KeyChordHash, KeyChordEquality> _keyShortcuts;
|
|
std::vector<std::pair<Control::KeyChord, Model::ActionAndArgs>> _keyShortcutsByInsertionOrder;
|
|
|
|
friend class SettingsModelLocalTests::DeserializationTests;
|
|
friend class SettingsModelLocalTests::KeyBindingsTests;
|
|
friend class SettingsModelLocalTests::TestUtils;
|
|
};
|
|
}
|