`KeyMapping` was introduced to break up `AppKeyBindings`. `KeyMapping` records the keybindings from the JSON and lets you query them. `AppKeyBindings` now just holds a `ShortcutActionDispatcher` to run actions, and a `KeyMapping` to record/query your existing keybindings. This refactor allows `KeyMapping` to be moved to the TerminalSettingsModel, and `ShortcutActionDispatcher` and `AppKeyBindings` will stay in TerminalApp. `AppKeyBindings` had to be passed down to a terminal via `TerminalSettings`. Since each settings object had its own responsibility to update/create a `TerminalSettings` object, I moved all of that logic to `TerminalSettings`. This helps with the TerminalSettingsModel refactor, and makes the construction of `TerminalSettings` a bit cleaner and more centralized. ## References #885 - this is all in preparation for the TerminalSettingsModel ## Validation Steps Performed - [x] Tests passed - [X] Deployment succeeded
35 lines
897 B
C++
35 lines
897 B
C++
// Copyright (c) Microsoft Corporation.
|
|
// Licensed under the MIT license.
|
|
|
|
#include "pch.h"
|
|
#include "AppKeyBindings.h"
|
|
|
|
#include "AppKeyBindings.g.cpp"
|
|
|
|
using namespace winrt::Microsoft::Terminal;
|
|
using namespace winrt::TerminalApp;
|
|
using namespace winrt::Microsoft::Terminal::TerminalControl;
|
|
|
|
namespace winrt::TerminalApp::implementation
|
|
{
|
|
bool AppKeyBindings::TryKeyChord(const KeyChord& kc)
|
|
{
|
|
const auto actionAndArgs = _keymap.TryLookup(kc);
|
|
if (actionAndArgs)
|
|
{
|
|
return _dispatch.DoAction(actionAndArgs);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
void AppKeyBindings::SetDispatch(const winrt::TerminalApp::ShortcutActionDispatch& dispatch)
|
|
{
|
|
_dispatch = dispatch;
|
|
}
|
|
|
|
void AppKeyBindings::SetKeyMapping(const winrt::TerminalApp::KeyMapping& keymap)
|
|
{
|
|
_keymap = keymap;
|
|
}
|
|
}
|