c09472347c
**Summary of the Pull Request** This PR adds an X Macro for defining our ShortcutActions. This means that you can add the action in one place, and have the macro synthesize all sorts of boilerplate for you! From the `AllShortcutActions.h` file: > For a clearer explanation of how this file should be used, see: > https://en.wikipedia.org/wiki/X_Macro > > Include this file to be able to quickly define some code in the exact same > way for _every single shortcut action_. To use: > > 1. Include this file > 2. Define the ON_ALL_ACTIONS macro with what you want each action to show up > as. Ex: > > #define ON_ALL_ACTIONS(action) void action##Handler(); > > 3. Then, use the ALL_SHORTCUT_ACTIONS macro to get the ON_ALL_ACTIONS marcro > repeated once for every ShortcutAction > > This is used in KeyMapping.idl, ShortcutAction.*, TerminalPage.*, etc. to > reduce the number of places where we must copy-paste boiler-plate code for > each action. This is _NOT_ something that should be used when any individual > case should be customized. **PR Checklist** * [x] Scratches an itch * [x] I work here * [x] Tests passed * [n/a] Requires documentation to be updated **Detailed Description of the Pull Request / Additional comments** Originally I had this blocked as a follow up to #9662. However, I've grown tired after a month of merging main into this branch, and I'm just shipping it separately. It will inevitably conflict with anyone who has actions in flight currently. **Validation Steps Performed** The code still builds exactly as before!
41 lines
1.1 KiB
C++
41 lines
1.1 KiB
C++
// Copyright (c) Microsoft Corporation.
|
|
// Licensed under the MIT license.
|
|
|
|
#pragma once
|
|
|
|
#include "ShortcutActionDispatch.g.h"
|
|
#include "../inc/cppwinrt_utils.h"
|
|
#include "../TerminalSettingsModel/AllShortcutActions.h"
|
|
|
|
// fwdecl unittest classes
|
|
namespace TerminalAppLocalTests
|
|
{
|
|
class SettingsTests;
|
|
class KeyBindingsTests;
|
|
}
|
|
|
|
#define DECLARE_ACTION(action) TYPED_EVENT(action, TerminalApp::ShortcutActionDispatch, Microsoft::Terminal::Settings::Model::ActionEventArgs);
|
|
|
|
namespace winrt::TerminalApp::implementation
|
|
{
|
|
struct ShortcutActionDispatch : ShortcutActionDispatchT<ShortcutActionDispatch>
|
|
{
|
|
ShortcutActionDispatch() = default;
|
|
|
|
bool DoAction(const Microsoft::Terminal::Settings::Model::ActionAndArgs& actionAndArgs);
|
|
|
|
#define ON_ALL_ACTIONS(action) DECLARE_ACTION(action);
|
|
ALL_SHORTCUT_ACTIONS
|
|
#undef ON_ALL_ACTIONS
|
|
|
|
private:
|
|
friend class TerminalAppLocalTests::SettingsTests;
|
|
friend class TerminalAppLocalTests::KeyBindingsTests;
|
|
};
|
|
}
|
|
|
|
namespace winrt::TerminalApp::factory_implementation
|
|
{
|
|
BASIC_FACTORY(ShortcutActionDispatch);
|
|
}
|