[PR #9667] [MERGED] Add X Macro for fun and for profit #27691

Open
opened 2026-01-31 09:23:32 +00:00 by claunia · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/microsoft/terminal/pull/9667
Author: @zadjii-msft
Created: 3/30/2021
Status: Merged
Merged: 3/31/2021
Merged by: @undefined

Base: mainHead: dev/migrie/xmacros-2


📝 Commits (3)

  • d972c6a Did you know about X Macros? Now you do!
  • dab9a0a Update src/cascadia/TerminalSettingsModel/AllShortcutActions.h
  • 90afa91 Merge remote-tracking branch 'origin/main' into dev/migrie/xmacros-2

📊 Changes

7 files changed (+98 additions, -295 deletions)

View changed files

📝 src/cascadia/TerminalApp/ShortcutActionDispatch.cpp (+3 -55)
📝 src/cascadia/TerminalApp/ShortcutActionDispatch.h (+4 -49)
📝 src/cascadia/TerminalApp/ShortcutActionDispatch.idl (+5 -47)
📝 src/cascadia/TerminalApp/TerminalPage.cpp (+3 -47)
📝 src/cascadia/TerminalApp/TerminalPage.h (+3 -48)
src/cascadia/TerminalSettingsModel/AllShortcutActions.h (+73 -0)
📝 src/cascadia/TerminalSettingsModel/KeyMapping.idl (+7 -49)

📄 Description

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

  • Scratches an itch
  • I work here
  • 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!


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/microsoft/terminal/pull/9667 **Author:** [@zadjii-msft](https://github.com/zadjii-msft) **Created:** 3/30/2021 **Status:** ✅ Merged **Merged:** 3/31/2021 **Merged by:** [@undefined](undefined) **Base:** `main` ← **Head:** `dev/migrie/xmacros-2` --- ### 📝 Commits (3) - [`d972c6a`](https://github.com/microsoft/terminal/commit/d972c6a28412fc7319f447148184a379f1172c8d) Did you know about X Macros? Now you do! - [`dab9a0a`](https://github.com/microsoft/terminal/commit/dab9a0ab55cce4d496af6f9d76afccf18766ee40) Update src/cascadia/TerminalSettingsModel/AllShortcutActions.h - [`90afa91`](https://github.com/microsoft/terminal/commit/90afa91a3534b9459a0468ba102b4bb99ab9fb21) Merge remote-tracking branch 'origin/main' into dev/migrie/xmacros-2 ### 📊 Changes **7 files changed** (+98 additions, -295 deletions) <details> <summary>View changed files</summary> 📝 `src/cascadia/TerminalApp/ShortcutActionDispatch.cpp` (+3 -55) 📝 `src/cascadia/TerminalApp/ShortcutActionDispatch.h` (+4 -49) 📝 `src/cascadia/TerminalApp/ShortcutActionDispatch.idl` (+5 -47) 📝 `src/cascadia/TerminalApp/TerminalPage.cpp` (+3 -47) 📝 `src/cascadia/TerminalApp/TerminalPage.h` (+3 -48) ➕ `src/cascadia/TerminalSettingsModel/AllShortcutActions.h` (+73 -0) 📝 `src/cascadia/TerminalSettingsModel/KeyMapping.idl` (+7 -49) </details> ### 📄 Description **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! --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
claunia added the pull-request label 2026-01-31 09:23:32 +00:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#27691