ffcbbe58f0
# Conflicts: # src/cascadia/TerminalApp/App.cpp # src/cascadia/TerminalApp/AppKeyBindings.cpp
75 lines
2.4 KiB
C++
75 lines
2.4 KiB
C++
// Copyright (c) Microsoft Corporation.
|
|
// Licensed under the MIT license.
|
|
|
|
#include "pch.h"
|
|
#include "AppKeyBindings.h"
|
|
#include "KeyChordSerialization.h"
|
|
|
|
#include "AppKeyBindings.g.cpp"
|
|
|
|
using namespace winrt::Microsoft::Terminal;
|
|
using namespace winrt::TerminalApp;
|
|
|
|
namespace winrt::TerminalApp::implementation
|
|
{
|
|
void AppKeyBindings::SetDispatch(const winrt::TerminalApp::ShortcutActionDispatch& dispatch)
|
|
{
|
|
_dispatch = dispatch;
|
|
}
|
|
|
|
void AppKeyBindings::SetKeyBinding(const TerminalApp::ShortcutAction& action,
|
|
const Settings::KeyChord& chord)
|
|
{
|
|
_keyShortcuts[chord] = action;
|
|
}
|
|
|
|
Microsoft::Terminal::Settings::KeyChord AppKeyBindings::GetKeyBinding(TerminalApp::ShortcutAction const& action)
|
|
{
|
|
for (auto& kv : _keyShortcuts)
|
|
{
|
|
if (kv.second == action)
|
|
{
|
|
return kv.first;
|
|
}
|
|
}
|
|
return { nullptr };
|
|
}
|
|
|
|
bool AppKeyBindings::TryKeyChord(const Settings::KeyChord& kc)
|
|
{
|
|
const auto keyIter = _keyShortcuts.find(kc);
|
|
if (keyIter != _keyShortcuts.end())
|
|
{
|
|
const auto action = keyIter->second;
|
|
return _dispatch.DoAction(action);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
// Method Description:
|
|
// - Takes the KeyModifier flags from Terminal and maps them to the WinRT types which are used by XAML
|
|
// Return Value:
|
|
// - a Windows::System::VirtualKeyModifiers object with the flags of which modifiers used.
|
|
Windows::System::VirtualKeyModifiers AppKeyBindings::ConvertVKModifiers(Settings::KeyModifiers modifiers)
|
|
{
|
|
Windows::System::VirtualKeyModifiers keyModifiers = Windows::System::VirtualKeyModifiers::None;
|
|
|
|
if (WI_IsFlagSet(modifiers, Settings::KeyModifiers::Ctrl))
|
|
{
|
|
keyModifiers |= Windows::System::VirtualKeyModifiers::Control;
|
|
}
|
|
if (WI_IsFlagSet(modifiers, Settings::KeyModifiers::Shift))
|
|
{
|
|
keyModifiers |= Windows::System::VirtualKeyModifiers::Shift;
|
|
}
|
|
if (WI_IsFlagSet(modifiers, Settings::KeyModifiers::Alt))
|
|
{
|
|
// note: Menu is the Alt VK_MENU
|
|
keyModifiers |= Windows::System::VirtualKeyModifiers::Menu;
|
|
}
|
|
|
|
return keyModifiers;
|
|
}
|
|
|
|
}
|