terminal/src/cascadia/TerminalApp/ShortcutActionDispatch.cpp
Mike Griese 03ea0f49ad
Add an action for identifying windows (#9523)
## Summary of the Pull Request

This is a follow up to #9300. Now that we have names on our windows, it would be nice to see who is named what. So this adds two actions:

* `identifyWindow`: This action will pop up a little toast (#8592) displaying the name and ID of the window, and is bound by default.
![identify-window-toast-000](https://user-images.githubusercontent.com/18356694/111529085-bf710580-872f-11eb-8880-b0b617596cfc.gif)

* `identifyWindows`: This action will request that ALL windows pop up that toast. This is meant to feel like the "Identify" button on the Windows display settings. However, sometimes, it's wonky. 
  ![teaching-tip-dismiss-001](https://user-images.githubusercontent.com/18356694/111529292-fe06c000-872f-11eb-8d4a-5688e4ce1175.gif)
  That's being tracked upstream on https://github.com/microsoft/microsoft-ui-xaml/issues/4382
  Because it's so wonky, we won't bind that by default. Maybe if we get that fixed, then we'll change the default binding from `identifyWindow` to `identifyWindows`


## References

## PR Checklist
* [x] Closes https://github.com/microsoft/terminal/projects/5#card-51431492
* [x] I work here
* [x] Tests added/passed
* [ ] Requires documentation to be updated

## Detailed Description of the Pull Request / Additional comments

You may note that there are some macros to make interacting with lots and lots of actions easier. There's a lot of boilerplate whenever you need to make a new action, so I thought: "Can we make that easier?" 

Turns out you can make it a _LOT_ easier, but that work is still behind another PR after this one. Get excited
2021-03-30 16:08:03 +00:00

106 lines
3.6 KiB
C++

// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
#include "pch.h"
#include "ShortcutActionDispatch.h"
#include "ShortcutActionDispatch.g.cpp"
using namespace winrt::Microsoft::Terminal;
using namespace winrt::Microsoft::Terminal::Settings::Model;
using namespace winrt::TerminalApp;
#define ACTION_CASE(action) \
case ShortcutAction::action: \
{ \
_##action##Handlers(*this, eventArgs); \
break; \
}
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)
{
if (!actionAndArgs)
{
return false;
}
const auto& action = actionAndArgs.Action();
const auto& args = actionAndArgs.Args();
auto eventArgs = args ? ActionEventArgs{ args } :
ActionEventArgs{};
switch (action)
{
ACTION_CASE(CopyText);
ACTION_CASE(PasteText);
ACTION_CASE(OpenNewTabDropdown);
ACTION_CASE(DuplicateTab);
ACTION_CASE(OpenSettings);
ACTION_CASE(NewTab);
ACTION_CASE(CloseWindow);
ACTION_CASE(CloseTab);
ACTION_CASE(ClosePane);
ACTION_CASE(ScrollUp);
ACTION_CASE(ScrollDown);
ACTION_CASE(ScrollUpPage);
ACTION_CASE(ScrollDownPage);
ACTION_CASE(ScrollToTop);
ACTION_CASE(ScrollToBottom);
ACTION_CASE(NextTab);
ACTION_CASE(PrevTab);
ACTION_CASE(SendInput);
case ShortcutAction::SplitVertical:
case ShortcutAction::SplitHorizontal:
case ShortcutAction::SplitPane:
{
_SplitPaneHandlers(*this, eventArgs);
break;
}
ACTION_CASE(TogglePaneZoom);
ACTION_CASE(SwitchToTab);
ACTION_CASE(ResizePane);
ACTION_CASE(MoveFocus);
ACTION_CASE(AdjustFontSize);
ACTION_CASE(Find);
ACTION_CASE(ResetFontSize);
ACTION_CASE(ToggleShaderEffects);
ACTION_CASE(ToggleFocusMode);
ACTION_CASE(ToggleFullscreen);
ACTION_CASE(ToggleAlwaysOnTop);
ACTION_CASE(ToggleCommandPalette);
ACTION_CASE(SetColorScheme);
ACTION_CASE(SetTabColor);
ACTION_CASE(OpenTabColorPicker);
ACTION_CASE(RenameTab);
ACTION_CASE(OpenTabRenamer);
ACTION_CASE(ExecuteCommandline);
ACTION_CASE(CloseOtherTabs);
ACTION_CASE(CloseTabsAfter);
ACTION_CASE(MoveTab);
ACTION_CASE(TabSearch);
ACTION_CASE(BreakIntoDebugger);
ACTION_CASE(FindMatch);
ACTION_CASE(TogglePaneReadOnly);
ACTION_CASE(NewWindow);
ACTION_CASE(IdentifyWindow);
ACTION_CASE(IdentifyWindows);
default:
return false;
}
return eventArgs.Handled();
}
}