2019-11-27 22:51:38 +01:00
|
|
|
// Copyright (c) Microsoft Corporation.
|
|
|
|
// Licensed under the MIT license.
|
|
|
|
|
|
|
|
#include "pch.h"
|
|
|
|
#include "ShortcutActionDispatch.h"
|
|
|
|
|
|
|
|
#include "ShortcutActionDispatch.g.cpp"
|
|
|
|
|
|
|
|
using namespace winrt::Microsoft::Terminal;
|
2020-10-06 18:56:59 +02:00
|
|
|
using namespace winrt::Microsoft::Terminal::Settings::Model;
|
2019-11-27 22:51:38 +01:00
|
|
|
using namespace winrt::TerminalApp;
|
|
|
|
|
2021-03-30 18:08:03 +02:00
|
|
|
#define ACTION_CASE(action) \
|
|
|
|
case ShortcutAction::action: \
|
|
|
|
{ \
|
|
|
|
_##action##Handlers(*this, eventArgs); \
|
|
|
|
break; \
|
|
|
|
}
|
|
|
|
|
2019-11-27 22:51:38 +01:00
|
|
|
namespace winrt::TerminalApp::implementation
|
|
|
|
{
|
|
|
|
// Method Description:
|
|
|
|
// - Dispatch the appropriate event for the given ActionAndArgs. Constructs
|
|
|
|
// an ActionEventArgs to hold the IActionArgs payload for the event, and
|
|
|
|
// calls the matching handlers for that event.
|
|
|
|
// Arguments:
|
|
|
|
// - actionAndArgs: the ShortcutAction and associated args to raise an event for.
|
|
|
|
// Return Value:
|
|
|
|
// - true if we handled the event was handled, else false.
|
|
|
|
bool ShortcutActionDispatch::DoAction(const ActionAndArgs& actionAndArgs)
|
|
|
|
{
|
2021-03-15 17:34:06 +01:00
|
|
|
if (!actionAndArgs)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-11-27 22:51:38 +01:00
|
|
|
const auto& action = actionAndArgs.Action();
|
|
|
|
const auto& args = actionAndArgs.Args();
|
2020-10-06 18:56:59 +02:00
|
|
|
auto eventArgs = args ? ActionEventArgs{ args } :
|
|
|
|
ActionEventArgs{};
|
2019-11-27 22:51:38 +01:00
|
|
|
|
|
|
|
switch (action)
|
|
|
|
{
|
2021-03-31 18:38:25 +02:00
|
|
|
#define ON_ALL_ACTIONS(id) ACTION_CASE(id);
|
|
|
|
ALL_SHORTCUT_ACTIONS
|
|
|
|
#undef ON_ALL_ACTIONS
|
2019-11-27 22:51:38 +01:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
2020-10-06 18:56:59 +02:00
|
|
|
return eventArgs.Handled();
|
2019-11-27 22:51:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|