diff --git a/src/cascadia/TerminalApp/ActionArgs.cpp b/src/cascadia/TerminalApp/ActionArgs.cpp new file mode 100644 index 000000000..ff3e22981 --- /dev/null +++ b/src/cascadia/TerminalApp/ActionArgs.cpp @@ -0,0 +1,13 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +#include "pch.h" + +#include "ActionArgs.h" + +#include "ActionEventArgs.g.cpp" +#include "CopyTextArgs.g.cpp" +#include "NewTabWithProfileArgs.g.cpp" +#include "SwitchToTabArgs.g.cpp" +#include "ResizePaneArgs.g.cpp" +#include "MoveFocusArgs.g.cpp" diff --git a/src/cascadia/TerminalApp/ActionArgs.h b/src/cascadia/TerminalApp/ActionArgs.h new file mode 100644 index 000000000..3bd56fe0d --- /dev/null +++ b/src/cascadia/TerminalApp/ActionArgs.h @@ -0,0 +1,69 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +#pragma once + +// HEY YOU: When adding ActionArgs types, make sure to add the corresponding +// *.g.cpp to ActionArgs.cpp! +#include "ActionEventArgs.g.h" +#include "CopyTextArgs.g.h" +#include "NewTabWithProfileArgs.g.h" +#include "SwitchToTabArgs.g.h" +#include "ResizePaneArgs.g.h" +#include "MoveFocusArgs.g.h" + +#include "../../cascadia/inc/cppwinrt_utils.h" + +// Notes on defining ActionArgs and ActionEventArgs: +// * All properties specific to an action should be defined as an ActionArgs +// class that implements IActionArgs +// * ActionEventArgs holds a single IActionArgs. For events that don't need +// additional args, this can be nullptr. + +namespace winrt::TerminalApp::implementation +{ + struct ActionEventArgs : public ActionEventArgsT + { + ActionEventArgs() = default; + ActionEventArgs(const TerminalApp::IActionArgs& args) : + _ActionArgs{ args } {}; + GETSET_PROPERTY(IActionArgs, ActionArgs, nullptr); + GETSET_PROPERTY(bool, Handled, false); + }; + + struct CopyTextArgs : public CopyTextArgsT + { + CopyTextArgs() = default; + GETSET_PROPERTY(bool, TrimWhitespace, false); + }; + + struct NewTabWithProfileArgs : public NewTabWithProfileArgsT + { + NewTabWithProfileArgs() = default; + GETSET_PROPERTY(int32_t, ProfileIndex, 0); + }; + + struct SwitchToTabArgs : public SwitchToTabArgsT + { + SwitchToTabArgs() = default; + GETSET_PROPERTY(int32_t, TabIndex, 0); + }; + + struct ResizePaneArgs : public ResizePaneArgsT + { + ResizePaneArgs() = default; + GETSET_PROPERTY(TerminalApp::Direction, Direction, TerminalApp::Direction::Left); + }; + + struct MoveFocusArgs : public MoveFocusArgsT + { + MoveFocusArgs() = default; + GETSET_PROPERTY(TerminalApp::Direction, Direction, TerminalApp::Direction::Left); + }; + +} + +namespace winrt::TerminalApp::factory_implementation +{ + BASIC_FACTORY(ActionEventArgs); +} diff --git a/src/cascadia/TerminalApp/ActionArgs.idl b/src/cascadia/TerminalApp/ActionArgs.idl new file mode 100644 index 000000000..58be7ea26 --- /dev/null +++ b/src/cascadia/TerminalApp/ActionArgs.idl @@ -0,0 +1,54 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +namespace TerminalApp +{ + // An empty interface must specify an explicit [uuid] to ensure uniqueness. + // We also manually have to specify a "version" attribute to make the compiler happy. + [uuid("191C2BDE-1A60-4BAB-9765-D850F0EF2CAC")][version(1)] interface IActionArgs{}; + + interface IActionEventArgs + { + Boolean Handled; + IActionArgs ActionArgs { get; }; + }; + + enum Direction + { + Left = 0, + Right, + Up, + Down + }; + + [default_interface] runtimeclass ActionEventArgs : IActionEventArgs + { + ActionEventArgs(IActionArgs args); + }; + + [default_interface] runtimeclass CopyTextArgs : IActionArgs + { + Boolean TrimWhitespace { get; }; + }; + + [default_interface] runtimeclass NewTabWithProfileArgs : IActionArgs + { + Int32 ProfileIndex { get; }; + }; + + [default_interface] runtimeclass SwitchToTabArgs : IActionArgs + { + Int32 TabIndex { get; }; + }; + + [default_interface] runtimeclass ResizePaneArgs : IActionArgs + { + Direction Direction { get; }; + }; + + [default_interface] runtimeclass MoveFocusArgs : IActionArgs + { + Direction Direction { get; }; + }; + +} diff --git a/src/cascadia/TerminalApp/App.cpp b/src/cascadia/TerminalApp/App.cpp index cbe289af1..da2fe34c8 100644 --- a/src/cascadia/TerminalApp/App.cpp +++ b/src/cascadia/TerminalApp/App.cpp @@ -655,26 +655,27 @@ namespace winrt::TerminalApp::implementation // Hook up the KeyBinding object's events to our handlers. // They should all be hooked up here, regardless of whether or not // there's an actual keychord for them. - bindings.NewTab([this]() { _OpenNewTab(std::nullopt); }); - bindings.OpenNewTabDropdown([this]() { _OpenNewTabDropdown(); }); - bindings.DuplicateTab([this]() { _DuplicateTabViewItem(); }); - bindings.CloseTab([this]() { _CloseFocusedTab(); }); - bindings.ClosePane([this]() { _CloseFocusedPane(); }); - bindings.NewTabWithProfile([this](const auto index) { _OpenNewTab({ index }); }); - bindings.ScrollUp([this]() { _Scroll(-1); }); - bindings.ScrollDown([this]() { _Scroll(1); }); - bindings.NextTab([this]() { _SelectNextTab(true); }); - bindings.PrevTab([this]() { _SelectNextTab(false); }); - bindings.SplitVertical([this]() { _SplitVertical(std::nullopt); }); - bindings.SplitHorizontal([this]() { _SplitHorizontal(std::nullopt); }); - bindings.ScrollUpPage([this]() { _ScrollPage(-1); }); - bindings.ScrollDownPage([this]() { _ScrollPage(1); }); - bindings.SwitchToTab([this](const auto index) { _SelectTab({ index }); }); - bindings.OpenSettings([this]() { _OpenSettings(); }); - bindings.ResizePane([this](const auto direction) { _ResizePane(direction); }); - bindings.MoveFocus([this](const auto direction) { _MoveFocus(direction); }); - bindings.CopyText([this](const auto trimWhitespace) { _CopyText(trimWhitespace); }); - bindings.PasteText([this]() { _PasteText(); }); + + bindings.NewTab({ this, &App::_HandleNewTab }); + bindings.OpenNewTabDropdown({ this, &App::_HandleOpenNewTabDropdown }); + bindings.DuplicateTab({ this, &App::_HandleDuplicateTab }); + bindings.CloseTab({ this, &App::_HandleCloseTab }); + bindings.ClosePane({ this, &App::_HandleClosePane }); + bindings.ScrollUp({ this, &App::_HandleScrollUp }); + bindings.ScrollDown({ this, &App::_HandleScrollDown }); + bindings.NextTab({ this, &App::_HandleNextTab }); + bindings.PrevTab({ this, &App::_HandlePrevTab }); + bindings.SplitVertical({ this, &App::_HandleSplitVertical }); + bindings.SplitHorizontal({ this, &App::_HandleSplitHorizontal }); + bindings.ScrollUpPage({ this, &App::_HandleScrollUpPage }); + bindings.ScrollDownPage({ this, &App::_HandleScrollDownPage }); + bindings.OpenSettings({ this, &App::_HandleOpenSettings }); + bindings.PasteText({ this, &App::_HandlePasteText }); + bindings.NewTabWithProfile({ this, &App::_HandleNewTabWithProfile }); + bindings.SwitchToTab({ this, &App::_HandleSwitchToTab }); + bindings.ResizePane({ this, &App::_HandleResizePane }); + bindings.MoveFocus({ this, &App::_HandleMoveFocus }); + bindings.CopyText({ this, &App::_HandleCopyText }); } // Method Description: @@ -1233,10 +1234,12 @@ namespace winrt::TerminalApp::implementation // Arguments: // - trimTrailingWhitespace: enable removing any whitespace from copied selection // and get text to appear on separate lines. - void App::_CopyText(const bool trimTrailingWhitespace) + // Return Value: + // - true iff we we able to copy text (if a selection was active) + bool App::_CopyText(const bool trimTrailingWhitespace) { const auto control = _GetFocusedControl(); - control.CopySelectionToClipboard(trimTrailingWhitespace); + return control.CopySelectionToClipboard(trimTrailingWhitespace); } // Method Description: @@ -1261,13 +1264,18 @@ namespace winrt::TerminalApp::implementation } // Method Description: - // - Sets focus to the desired tab. - void App::_SelectTab(const int tabIndex) + // - Sets focus to the desired tab. Returns false if the provided tabIndex + // is greater than the number of tabs we have. + // Return Value: + // true iff we were able to select that tab index, false otherwise + bool App::_SelectTab(const int tabIndex) { if (tabIndex >= 0 && tabIndex < gsl::narrow_cast(_tabs.size())) { _SetFocusedTabIndex(tabIndex); + return true; } + return false; } // Method Description: diff --git a/src/cascadia/TerminalApp/App.h b/src/cascadia/TerminalApp/App.h index c6620e990..5d993e341 100644 --- a/src/cascadia/TerminalApp/App.h +++ b/src/cascadia/TerminalApp/App.h @@ -113,13 +113,13 @@ namespace winrt::TerminalApp::implementation void _CloseFocusedTab(); void _CloseFocusedPane(); void _SelectNextTab(const bool bMoveRight); - void _SelectTab(const int tabIndex); + bool _SelectTab(const int tabIndex); void _SetFocusedTabIndex(int tabIndex); int _GetFocusedTabIndex() const; void _Scroll(int delta); - void _CopyText(const bool trimTrailingWhitespace); + bool _CopyText(const bool trimTrailingWhitespace); void _PasteText(); void _SplitVertical(const std::optional& profileGuid); void _SplitHorizontal(const std::optional& profileGuid); @@ -150,6 +150,30 @@ namespace winrt::TerminalApp::implementation void _PasteFromClipboardHandler(const IInspectable& sender, const Microsoft::Terminal::TerminalControl::PasteFromClipboardEventArgs& eventArgs); static void _SetAcceleratorForMenuItem(Windows::UI::Xaml::Controls::MenuFlyoutItem& menuItem, const winrt::Microsoft::Terminal::Settings::KeyChord& keyChord); + +#pragma region ActionHandlers + // These are all defined in AppActionHandlers.cpp + void _HandleNewTab(const IInspectable& sender, const TerminalApp::ActionEventArgs& args); + void _HandleOpenNewTabDropdown(const IInspectable& sender, const TerminalApp::ActionEventArgs& args); + void _HandleDuplicateTab(const IInspectable& sender, const TerminalApp::ActionEventArgs& args); + void _HandleCloseTab(const IInspectable& sender, const TerminalApp::ActionEventArgs& args); + void _HandleClosePane(const IInspectable& sender, const TerminalApp::ActionEventArgs& args); + void _HandleScrollUp(const IInspectable& sender, const TerminalApp::ActionEventArgs& args); + void _HandleScrollDown(const IInspectable& sender, const TerminalApp::ActionEventArgs& args); + void _HandleNextTab(const IInspectable& sender, const TerminalApp::ActionEventArgs& args); + void _HandlePrevTab(const IInspectable& sender, const TerminalApp::ActionEventArgs& args); + void _HandleSplitVertical(const IInspectable& sender, const TerminalApp::ActionEventArgs& args); + void _HandleSplitHorizontal(const IInspectable& sender, const TerminalApp::ActionEventArgs& args); + void _HandleScrollUpPage(const IInspectable& sender, const TerminalApp::ActionEventArgs& args); + void _HandleScrollDownPage(const IInspectable& sender, const TerminalApp::ActionEventArgs& args); + void _HandleOpenSettings(const IInspectable& sender, const TerminalApp::ActionEventArgs& args); + void _HandlePasteText(const IInspectable& sender, const TerminalApp::ActionEventArgs& args); + void _HandleNewTabWithProfile(const IInspectable& sender, const TerminalApp::ActionEventArgs& args); + void _HandleSwitchToTab(const IInspectable& sender, const TerminalApp::ActionEventArgs& args); + void _HandleResizePane(const IInspectable& sender, const TerminalApp::ActionEventArgs& args); + void _HandleMoveFocus(const IInspectable& sender, const TerminalApp::ActionEventArgs& args); + void _HandleCopyText(const IInspectable& sender, const TerminalApp::ActionEventArgs& args); +#pragma endregion }; } diff --git a/src/cascadia/TerminalApp/AppActionHandlers.cpp b/src/cascadia/TerminalApp/AppActionHandlers.cpp new file mode 100644 index 000000000..cec06ee8f --- /dev/null +++ b/src/cascadia/TerminalApp/AppActionHandlers.cpp @@ -0,0 +1,183 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +#include "pch.h" +#include "App.h" + +#include "TerminalPage.h" +#include "Utils.h" + +using namespace winrt::Windows::ApplicationModel::DataTransfer; +using namespace winrt::Windows::UI::Xaml; +using namespace winrt::Windows::UI::Text; +using namespace winrt::Windows::UI::Core; +using namespace winrt::Windows::System; +using namespace winrt::Microsoft::Terminal; +using namespace winrt::Microsoft::Terminal::Settings; +using namespace winrt::Microsoft::Terminal::TerminalControl; +using namespace winrt::Microsoft::Terminal::TerminalConnection; +using namespace ::TerminalApp; + +namespace winrt +{ + namespace MUX = Microsoft::UI::Xaml; + using IInspectable = Windows::Foundation::IInspectable; +} + +namespace winrt::TerminalApp::implementation +{ + void App::_HandleNewTab(const IInspectable& /*sender*/, + const TerminalApp::ActionEventArgs& args) + { + _OpenNewTab(std::nullopt); + args.Handled(true); + } + void App::_HandleOpenNewTabDropdown(const IInspectable& /*sender*/, + const TerminalApp::ActionEventArgs& args) + { + _OpenNewTabDropdown(); + args.Handled(true); + } + + void App::_HandleDuplicateTab(const IInspectable& /*sender*/, + const TerminalApp::ActionEventArgs& args) + { + _DuplicateTabViewItem(); + args.Handled(true); + } + + void App::_HandleCloseTab(const IInspectable& /*sender*/, + const TerminalApp::ActionEventArgs& args) + { + _CloseFocusedTab(); + args.Handled(true); + } + + void App::_HandleClosePane(const IInspectable& /*sender*/, + const TerminalApp::ActionEventArgs& args) + { + _CloseFocusedPane(); + args.Handled(true); + } + + void App::_HandleScrollUp(const IInspectable& /*sender*/, + const TerminalApp::ActionEventArgs& args) + { + _Scroll(-1); + args.Handled(true); + } + + void App::_HandleScrollDown(const IInspectable& /*sender*/, + const TerminalApp::ActionEventArgs& args) + { + _Scroll(1); + args.Handled(true); + } + + void App::_HandleNextTab(const IInspectable& /*sender*/, + const TerminalApp::ActionEventArgs& args) + { + _SelectNextTab(true); + args.Handled(true); + } + + void App::_HandlePrevTab(const IInspectable& /*sender*/, + const TerminalApp::ActionEventArgs& args) + { + _SelectNextTab(false); + args.Handled(true); + } + + void App::_HandleSplitVertical(const IInspectable& /*sender*/, + const TerminalApp::ActionEventArgs& args) + { + _SplitVertical(std::nullopt); + args.Handled(true); + } + + void App::_HandleSplitHorizontal(const IInspectable& /*sender*/, + const TerminalApp::ActionEventArgs& args) + { + _SplitHorizontal(std::nullopt); + args.Handled(true); + } + + void App::_HandleScrollUpPage(const IInspectable& /*sender*/, + const TerminalApp::ActionEventArgs& args) + { + _ScrollPage(-1); + args.Handled(true); + } + + void App::_HandleScrollDownPage(const IInspectable& /*sender*/, + const TerminalApp::ActionEventArgs& args) + { + _ScrollPage(1); + args.Handled(true); + } + + void App::_HandleOpenSettings(const IInspectable& /*sender*/, + const TerminalApp::ActionEventArgs& args) + { + _OpenSettings(); + args.Handled(true); + } + + void App::_HandlePasteText(const IInspectable& /*sender*/, + const TerminalApp::ActionEventArgs& args) + { + _PasteText(); + args.Handled(true); + } + + void App::_HandleNewTabWithProfile(const IInspectable& /*sender*/, + const TerminalApp::ActionEventArgs& args) + { + if (const auto& realArgs = args.ActionArgs().try_as()) + { + _OpenNewTab({ realArgs.ProfileIndex() }); + args.Handled(true); + } + } + + void App::_HandleSwitchToTab(const IInspectable& /*sender*/, + const TerminalApp::ActionEventArgs& args) + { + if (const auto& realArgs = args.ActionArgs().try_as()) + { + const auto handled = _SelectTab({ realArgs.TabIndex() }); + args.Handled(handled); + } + } + + void App::_HandleResizePane(const IInspectable& /*sender*/, + const TerminalApp::ActionEventArgs& args) + { + if (const auto& realArgs = args.ActionArgs().try_as()) + { + _ResizePane(realArgs.Direction()); + args.Handled(true); + } + } + + void App::_HandleMoveFocus(const IInspectable& /*sender*/, + const TerminalApp::ActionEventArgs& args) + { + if (const auto& realArgs = args.ActionArgs().try_as()) + { + _MoveFocus(realArgs.Direction()); + args.Handled(true); + } + } + + void App::_HandleCopyText(const IInspectable& /*sender*/, + const TerminalApp::ActionEventArgs& args) + { + if (const auto& realArgs = args.ActionArgs().try_as()) + { + const auto handled = _CopyText(realArgs.TrimWhitespace()); + args.Handled(handled); + } + } + +} diff --git a/src/cascadia/TerminalApp/AppKeyBindings.cpp b/src/cascadia/TerminalApp/AppKeyBindings.cpp index 8a6f25b21..7e35e139e 100644 --- a/src/cascadia/TerminalApp/AppKeyBindings.cpp +++ b/src/cascadia/TerminalApp/AppKeyBindings.cpp @@ -9,7 +9,6 @@ using namespace winrt::Microsoft::Terminal; using namespace winrt::TerminalApp; -using namespace winrt::Windows::Data::Json; namespace winrt::TerminalApp::implementation { @@ -47,146 +46,337 @@ namespace winrt::TerminalApp::implementation switch (action) { case ShortcutAction::CopyText: - _CopyTextHandlers(true); - return true; + { + auto args = winrt::make_self(); + args->TrimWhitespace(true); + auto eventArgs = winrt::make_self(*args); + _CopyTextHandlers(*this, *eventArgs); + return eventArgs->Handled(); + } case ShortcutAction::CopyTextWithoutNewlines: - _CopyTextHandlers(false); - return true; + { + auto args = winrt::make_self(); + args->TrimWhitespace(false); + auto eventArgs = winrt::make_self(*args); + _CopyTextHandlers(*this, *eventArgs); + return eventArgs->Handled(); + } case ShortcutAction::PasteText: - _PasteTextHandlers(); - return true; + { + auto eventArgs = winrt::make_self(); + _PasteTextHandlers(*this, *eventArgs); + return eventArgs->Handled(); + } case ShortcutAction::NewTab: - _NewTabHandlers(); - return true; + { + auto eventArgs = winrt::make_self(); + _NewTabHandlers(*this, *eventArgs); + return eventArgs->Handled(); + } case ShortcutAction::OpenNewTabDropdown: - _OpenNewTabDropdownHandlers(); - return true; + { + auto eventArgs = winrt::make_self(); + _OpenNewTabDropdownHandlers(*this, *eventArgs); + return eventArgs->Handled(); + } case ShortcutAction::DuplicateTab: - _DuplicateTabHandlers(); - return true; + { + auto eventArgs = winrt::make_self(); + _DuplicateTabHandlers(*this, *eventArgs); + return eventArgs->Handled(); + } case ShortcutAction::OpenSettings: - _OpenSettingsHandlers(); - return true; + { + auto eventArgs = winrt::make_self(); + _OpenSettingsHandlers(*this, *eventArgs); + return eventArgs->Handled(); + } case ShortcutAction::NewTabProfile0: - _NewTabWithProfileHandlers(0); - return true; + { + auto args = winrt::make_self(); + args->ProfileIndex(0); + auto eventArgs = winrt::make_self(*args); + _NewTabWithProfileHandlers(*this, *eventArgs); + return eventArgs->Handled(); + } case ShortcutAction::NewTabProfile1: - _NewTabWithProfileHandlers(1); - return true; + { + auto args = winrt::make_self(); + args->ProfileIndex(1); + auto eventArgs = winrt::make_self(*args); + _NewTabWithProfileHandlers(*this, *eventArgs); + return eventArgs->Handled(); + } case ShortcutAction::NewTabProfile2: - _NewTabWithProfileHandlers(2); - return true; + { + auto args = winrt::make_self(); + args->ProfileIndex(2); + auto eventArgs = winrt::make_self(*args); + _NewTabWithProfileHandlers(*this, *eventArgs); + return eventArgs->Handled(); + } case ShortcutAction::NewTabProfile3: - _NewTabWithProfileHandlers(3); - return true; + { + auto args = winrt::make_self(); + args->ProfileIndex(3); + auto eventArgs = winrt::make_self(*args); + _NewTabWithProfileHandlers(*this, *eventArgs); + return eventArgs->Handled(); + } case ShortcutAction::NewTabProfile4: - _NewTabWithProfileHandlers(4); - return true; + { + auto args = winrt::make_self(); + args->ProfileIndex(4); + auto eventArgs = winrt::make_self(*args); + _NewTabWithProfileHandlers(*this, *eventArgs); + return eventArgs->Handled(); + } case ShortcutAction::NewTabProfile5: - _NewTabWithProfileHandlers(5); - return true; + { + auto args = winrt::make_self(); + args->ProfileIndex(5); + auto eventArgs = winrt::make_self(*args); + _NewTabWithProfileHandlers(*this, *eventArgs); + return eventArgs->Handled(); + } case ShortcutAction::NewTabProfile6: - _NewTabWithProfileHandlers(6); - return true; + { + auto args = winrt::make_self(); + args->ProfileIndex(6); + auto eventArgs = winrt::make_self(*args); + _NewTabWithProfileHandlers(*this, *eventArgs); + return eventArgs->Handled(); + } case ShortcutAction::NewTabProfile7: - _NewTabWithProfileHandlers(7); - return true; + { + auto args = winrt::make_self(); + args->ProfileIndex(7); + auto eventArgs = winrt::make_self(*args); + _NewTabWithProfileHandlers(*this, *eventArgs); + return eventArgs->Handled(); + } case ShortcutAction::NewTabProfile8: - _NewTabWithProfileHandlers(8); - return true; + { + auto args = winrt::make_self(); + args->ProfileIndex(8); + auto eventArgs = winrt::make_self(*args); + _NewTabWithProfileHandlers(*this, *eventArgs); + return eventArgs->Handled(); + } case ShortcutAction::NewWindow: - _NewWindowHandlers(); - return true; + { + auto eventArgs = winrt::make_self(); + _NewWindowHandlers(*this, *eventArgs); + return eventArgs->Handled(); + } case ShortcutAction::CloseWindow: - _CloseWindowHandlers(); - return true; + { + auto eventArgs = winrt::make_self(); + _CloseWindowHandlers(*this, *eventArgs); + return eventArgs->Handled(); + } case ShortcutAction::CloseTab: - _CloseTabHandlers(); - return true; + { + auto eventArgs = winrt::make_self(); + _CloseTabHandlers(*this, *eventArgs); + return eventArgs->Handled(); + } case ShortcutAction::ClosePane: - _ClosePaneHandlers(); - return true; + { + auto eventArgs = winrt::make_self(); + _ClosePaneHandlers(*this, *eventArgs); + return eventArgs->Handled(); + } case ShortcutAction::ScrollUp: - _ScrollUpHandlers(); - return true; + { + auto eventArgs = winrt::make_self(); + _ScrollUpHandlers(*this, *eventArgs); + return eventArgs->Handled(); + } case ShortcutAction::ScrollDown: - _ScrollDownHandlers(); - return true; + { + auto eventArgs = winrt::make_self(); + _ScrollDownHandlers(*this, *eventArgs); + return eventArgs->Handled(); + } case ShortcutAction::ScrollUpPage: - _ScrollUpPageHandlers(); - return true; + { + auto eventArgs = winrt::make_self(); + _ScrollUpPageHandlers(*this, *eventArgs); + return eventArgs->Handled(); + } case ShortcutAction::ScrollDownPage: - _ScrollDownPageHandlers(); - return true; + { + auto eventArgs = winrt::make_self(); + _ScrollDownPageHandlers(*this, *eventArgs); + return eventArgs->Handled(); + } case ShortcutAction::NextTab: - _NextTabHandlers(); - return true; + { + auto eventArgs = winrt::make_self(); + _NextTabHandlers(*this, *eventArgs); + return eventArgs->Handled(); + } case ShortcutAction::PrevTab: - _PrevTabHandlers(); - return true; + { + auto eventArgs = winrt::make_self(); + _PrevTabHandlers(*this, *eventArgs); + return eventArgs->Handled(); + } case ShortcutAction::SplitVertical: - _SplitVerticalHandlers(); - return true; + { + auto eventArgs = winrt::make_self(); + _SplitVerticalHandlers(*this, *eventArgs); + return eventArgs->Handled(); + } case ShortcutAction::SplitHorizontal: - _SplitHorizontalHandlers(); - return true; + { + auto eventArgs = winrt::make_self(); + _SplitHorizontalHandlers(*this, *eventArgs); + return eventArgs->Handled(); + } case ShortcutAction::SwitchToTab0: - _SwitchToTabHandlers(0); - return true; + { + auto args = winrt::make_self(); + args->TabIndex(0); + auto eventArgs = winrt::make_self(*args); + _SwitchToTabHandlers(*this, *eventArgs); + return eventArgs->Handled(); + } case ShortcutAction::SwitchToTab1: - _SwitchToTabHandlers(1); - return true; + { + auto args = winrt::make_self(); + args->TabIndex(1); + auto eventArgs = winrt::make_self(*args); + _SwitchToTabHandlers(*this, *eventArgs); + return eventArgs->Handled(); + } case ShortcutAction::SwitchToTab2: - _SwitchToTabHandlers(2); - return true; + { + auto args = winrt::make_self(); + args->TabIndex(2); + auto eventArgs = winrt::make_self(*args); + _SwitchToTabHandlers(*this, *eventArgs); + return eventArgs->Handled(); + } case ShortcutAction::SwitchToTab3: - _SwitchToTabHandlers(3); - return true; + { + auto args = winrt::make_self(); + args->TabIndex(3); + auto eventArgs = winrt::make_self(*args); + _SwitchToTabHandlers(*this, *eventArgs); + return eventArgs->Handled(); + } case ShortcutAction::SwitchToTab4: - _SwitchToTabHandlers(4); - return true; + { + auto args = winrt::make_self(); + args->TabIndex(4); + auto eventArgs = winrt::make_self(*args); + _SwitchToTabHandlers(*this, *eventArgs); + return eventArgs->Handled(); + } case ShortcutAction::SwitchToTab5: - _SwitchToTabHandlers(5); - return true; + { + auto args = winrt::make_self(); + args->TabIndex(5); + auto eventArgs = winrt::make_self(*args); + _SwitchToTabHandlers(*this, *eventArgs); + return eventArgs->Handled(); + } case ShortcutAction::SwitchToTab6: - _SwitchToTabHandlers(6); - return true; + { + auto args = winrt::make_self(); + args->TabIndex(6); + auto eventArgs = winrt::make_self(*args); + _SwitchToTabHandlers(*this, *eventArgs); + return eventArgs->Handled(); + } case ShortcutAction::SwitchToTab7: - _SwitchToTabHandlers(7); - return true; + { + auto args = winrt::make_self(); + args->TabIndex(7); + auto eventArgs = winrt::make_self(*args); + _SwitchToTabHandlers(*this, *eventArgs); + return eventArgs->Handled(); + } case ShortcutAction::SwitchToTab8: - _SwitchToTabHandlers(8); - return true; + { + auto args = winrt::make_self(); + args->TabIndex(8); + auto eventArgs = winrt::make_self(*args); + _SwitchToTabHandlers(*this, *eventArgs); + return eventArgs->Handled(); + } case ShortcutAction::ResizePaneLeft: - _ResizePaneHandlers(Direction::Left); - return true; + { + auto args = winrt::make_self(); + args->Direction(Direction::Left); + auto eventArgs = winrt::make_self(*args); + _ResizePaneHandlers(*this, *eventArgs); + return eventArgs->Handled(); + } case ShortcutAction::ResizePaneRight: - _ResizePaneHandlers(Direction::Right); - return true; + { + auto args = winrt::make_self(); + args->Direction(Direction::Right); + auto eventArgs = winrt::make_self(*args); + _ResizePaneHandlers(*this, *eventArgs); + return eventArgs->Handled(); + } case ShortcutAction::ResizePaneUp: - _ResizePaneHandlers(Direction::Up); - return true; + { + auto args = winrt::make_self(); + args->Direction(Direction::Up); + auto eventArgs = winrt::make_self(*args); + _ResizePaneHandlers(*this, *eventArgs); + return eventArgs->Handled(); + } case ShortcutAction::ResizePaneDown: - _ResizePaneHandlers(Direction::Down); - return true; + { + auto args = winrt::make_self(); + args->Direction(Direction::Down); + auto eventArgs = winrt::make_self(*args); + _ResizePaneHandlers(*this, *eventArgs); + return eventArgs->Handled(); + } case ShortcutAction::MoveFocusLeft: - _MoveFocusHandlers(Direction::Left); - return true; + { + auto args = winrt::make_self(); + args->Direction(Direction::Left); + auto eventArgs = winrt::make_self(*args); + _MoveFocusHandlers(*this, *eventArgs); + return eventArgs->Handled(); + } case ShortcutAction::MoveFocusRight: - _MoveFocusHandlers(Direction::Right); - return true; + { + auto args = winrt::make_self(); + args->Direction(Direction::Right); + auto eventArgs = winrt::make_self(*args); + _MoveFocusHandlers(*this, *eventArgs); + return eventArgs->Handled(); + } case ShortcutAction::MoveFocusUp: - _MoveFocusHandlers(Direction::Up); - return true; + { + auto args = winrt::make_self(); + args->Direction(Direction::Up); + auto eventArgs = winrt::make_self(*args); + _MoveFocusHandlers(*this, *eventArgs); + return eventArgs->Handled(); + } case ShortcutAction::MoveFocusDown: - _MoveFocusHandlers(Direction::Down); - return true; + { + auto args = winrt::make_self(); + args->Direction(Direction::Down); + auto eventArgs = winrt::make_self(*args); + _MoveFocusHandlers(*this, *eventArgs); + return eventArgs->Handled(); + } default: return false; } @@ -217,32 +407,4 @@ namespace winrt::TerminalApp::implementation return keyModifiers; } - - // -------------------------------- Events --------------------------------- - // clang-format off - DEFINE_EVENT(AppKeyBindings, CopyText, _CopyTextHandlers, TerminalApp::CopyTextEventArgs); - DEFINE_EVENT(AppKeyBindings, PasteText, _PasteTextHandlers, TerminalApp::PasteTextEventArgs); - DEFINE_EVENT(AppKeyBindings, NewTab, _NewTabHandlers, TerminalApp::NewTabEventArgs); - DEFINE_EVENT(AppKeyBindings, OpenNewTabDropdown,_OpenNewTabDropdownHandlers,TerminalApp::OpenNewTabDropdownEventArgs); - DEFINE_EVENT(AppKeyBindings, DuplicateTab, _DuplicateTabHandlers, TerminalApp::DuplicateTabEventArgs); - DEFINE_EVENT(AppKeyBindings, NewTabWithProfile, _NewTabWithProfileHandlers, TerminalApp::NewTabWithProfileEventArgs); - DEFINE_EVENT(AppKeyBindings, NewWindow, _NewWindowHandlers, TerminalApp::NewWindowEventArgs); - DEFINE_EVENT(AppKeyBindings, CloseWindow, _CloseWindowHandlers, TerminalApp::CloseWindowEventArgs); - DEFINE_EVENT(AppKeyBindings, CloseTab, _CloseTabHandlers, TerminalApp::CloseTabEventArgs); - DEFINE_EVENT(AppKeyBindings, ClosePane, _ClosePaneHandlers, TerminalApp::ClosePaneEventArgs); - DEFINE_EVENT(AppKeyBindings, SwitchToTab, _SwitchToTabHandlers, TerminalApp::SwitchToTabEventArgs); - DEFINE_EVENT(AppKeyBindings, NextTab, _NextTabHandlers, TerminalApp::NextTabEventArgs); - DEFINE_EVENT(AppKeyBindings, PrevTab, _PrevTabHandlers, TerminalApp::PrevTabEventArgs); - DEFINE_EVENT(AppKeyBindings, SplitVertical, _SplitVerticalHandlers, TerminalApp::SplitVerticalEventArgs); - DEFINE_EVENT(AppKeyBindings, SplitHorizontal, _SplitHorizontalHandlers, TerminalApp::SplitHorizontalEventArgs); - DEFINE_EVENT(AppKeyBindings, IncreaseFontSize, _IncreaseFontSizeHandlers, TerminalApp::IncreaseFontSizeEventArgs); - DEFINE_EVENT(AppKeyBindings, DecreaseFontSize, _DecreaseFontSizeHandlers, TerminalApp::DecreaseFontSizeEventArgs); - DEFINE_EVENT(AppKeyBindings, ScrollUp, _ScrollUpHandlers, TerminalApp::ScrollUpEventArgs); - DEFINE_EVENT(AppKeyBindings, ScrollDown, _ScrollDownHandlers, TerminalApp::ScrollDownEventArgs); - DEFINE_EVENT(AppKeyBindings, ScrollUpPage, _ScrollUpPageHandlers, TerminalApp::ScrollUpPageEventArgs); - DEFINE_EVENT(AppKeyBindings, ScrollDownPage, _ScrollDownPageHandlers, TerminalApp::ScrollDownPageEventArgs); - DEFINE_EVENT(AppKeyBindings, OpenSettings, _OpenSettingsHandlers, TerminalApp::OpenSettingsEventArgs); - DEFINE_EVENT(AppKeyBindings, ResizePane, _ResizePaneHandlers, TerminalApp::ResizePaneEventArgs); - DEFINE_EVENT(AppKeyBindings, MoveFocus, _MoveFocusHandlers, TerminalApp::MoveFocusEventArgs); - // clang-format on } diff --git a/src/cascadia/TerminalApp/AppKeyBindings.h b/src/cascadia/TerminalApp/AppKeyBindings.h index 8f51c9241..0ad405378 100644 --- a/src/cascadia/TerminalApp/AppKeyBindings.h +++ b/src/cascadia/TerminalApp/AppKeyBindings.h @@ -4,6 +4,7 @@ #pragma once #include "AppKeyBindings.g.h" +#include "ActionArgs.h" #include "..\inc\cppwinrt_utils.h" namespace winrt::TerminalApp::implementation @@ -39,30 +40,30 @@ namespace winrt::TerminalApp::implementation static Windows::System::VirtualKeyModifiers ConvertVKModifiers(winrt::Microsoft::Terminal::Settings::KeyModifiers modifiers); // clang-format off - DECLARE_EVENT(CopyText, _CopyTextHandlers, TerminalApp::CopyTextEventArgs); - DECLARE_EVENT(PasteText, _PasteTextHandlers, TerminalApp::PasteTextEventArgs); - DECLARE_EVENT(NewTab, _NewTabHandlers, TerminalApp::NewTabEventArgs); - DECLARE_EVENT(OpenNewTabDropdown,_OpenNewTabDropdownHandlers,TerminalApp::OpenNewTabDropdownEventArgs); - DECLARE_EVENT(DuplicateTab, _DuplicateTabHandlers, TerminalApp::DuplicateTabEventArgs); - DECLARE_EVENT(NewTabWithProfile, _NewTabWithProfileHandlers, TerminalApp::NewTabWithProfileEventArgs); - DECLARE_EVENT(NewWindow, _NewWindowHandlers, TerminalApp::NewWindowEventArgs); - DECLARE_EVENT(CloseWindow, _CloseWindowHandlers, TerminalApp::CloseWindowEventArgs); - DECLARE_EVENT(CloseTab, _CloseTabHandlers, TerminalApp::CloseTabEventArgs); - DECLARE_EVENT(ClosePane, _ClosePaneHandlers, TerminalApp::ClosePaneEventArgs); - DECLARE_EVENT(SwitchToTab, _SwitchToTabHandlers, TerminalApp::SwitchToTabEventArgs); - DECLARE_EVENT(NextTab, _NextTabHandlers, TerminalApp::NextTabEventArgs); - DECLARE_EVENT(PrevTab, _PrevTabHandlers, TerminalApp::PrevTabEventArgs); - DECLARE_EVENT(SplitVertical, _SplitVerticalHandlers, TerminalApp::SplitVerticalEventArgs); - DECLARE_EVENT(SplitHorizontal, _SplitHorizontalHandlers, TerminalApp::SplitHorizontalEventArgs); - DECLARE_EVENT(IncreaseFontSize, _IncreaseFontSizeHandlers, TerminalApp::IncreaseFontSizeEventArgs); - DECLARE_EVENT(DecreaseFontSize, _DecreaseFontSizeHandlers, TerminalApp::DecreaseFontSizeEventArgs); - DECLARE_EVENT(ScrollUp, _ScrollUpHandlers, TerminalApp::ScrollUpEventArgs); - DECLARE_EVENT(ScrollDown, _ScrollDownHandlers, TerminalApp::ScrollDownEventArgs); - DECLARE_EVENT(ScrollUpPage, _ScrollUpPageHandlers, TerminalApp::ScrollUpPageEventArgs); - DECLARE_EVENT(ScrollDownPage, _ScrollDownPageHandlers, TerminalApp::ScrollDownPageEventArgs); - DECLARE_EVENT(OpenSettings, _OpenSettingsHandlers, TerminalApp::OpenSettingsEventArgs); - DECLARE_EVENT(ResizePane, _ResizePaneHandlers, TerminalApp::ResizePaneEventArgs); - DECLARE_EVENT(MoveFocus, _MoveFocusHandlers, TerminalApp::MoveFocusEventArgs); + TYPED_EVENT(CopyText, TerminalApp::AppKeyBindings, TerminalApp::ActionEventArgs); + TYPED_EVENT(PasteText, TerminalApp::AppKeyBindings, TerminalApp::ActionEventArgs); + TYPED_EVENT(NewTab, TerminalApp::AppKeyBindings, TerminalApp::ActionEventArgs); + TYPED_EVENT(OpenNewTabDropdown,TerminalApp::AppKeyBindings, TerminalApp::ActionEventArgs); + TYPED_EVENT(DuplicateTab, TerminalApp::AppKeyBindings, TerminalApp::ActionEventArgs); + TYPED_EVENT(NewTabWithProfile, TerminalApp::AppKeyBindings, TerminalApp::ActionEventArgs); + TYPED_EVENT(NewWindow, TerminalApp::AppKeyBindings, TerminalApp::ActionEventArgs); + TYPED_EVENT(CloseWindow, TerminalApp::AppKeyBindings, TerminalApp::ActionEventArgs); + TYPED_EVENT(CloseTab, TerminalApp::AppKeyBindings, TerminalApp::ActionEventArgs); + TYPED_EVENT(ClosePane, TerminalApp::AppKeyBindings, TerminalApp::ActionEventArgs); + TYPED_EVENT(SwitchToTab, TerminalApp::AppKeyBindings, TerminalApp::ActionEventArgs); + TYPED_EVENT(NextTab, TerminalApp::AppKeyBindings, TerminalApp::ActionEventArgs); + TYPED_EVENT(PrevTab, TerminalApp::AppKeyBindings, TerminalApp::ActionEventArgs); + TYPED_EVENT(SplitVertical, TerminalApp::AppKeyBindings, TerminalApp::ActionEventArgs); + TYPED_EVENT(SplitHorizontal, TerminalApp::AppKeyBindings, TerminalApp::ActionEventArgs); + TYPED_EVENT(IncreaseFontSize, TerminalApp::AppKeyBindings, TerminalApp::ActionEventArgs); + TYPED_EVENT(DecreaseFontSize, TerminalApp::AppKeyBindings, TerminalApp::ActionEventArgs); + TYPED_EVENT(ScrollUp, TerminalApp::AppKeyBindings, TerminalApp::ActionEventArgs); + TYPED_EVENT(ScrollDown, TerminalApp::AppKeyBindings, TerminalApp::ActionEventArgs); + TYPED_EVENT(ScrollUpPage, TerminalApp::AppKeyBindings, TerminalApp::ActionEventArgs); + TYPED_EVENT(ScrollDownPage, TerminalApp::AppKeyBindings, TerminalApp::ActionEventArgs); + TYPED_EVENT(OpenSettings, TerminalApp::AppKeyBindings, TerminalApp::ActionEventArgs); + TYPED_EVENT(ResizePane, TerminalApp::AppKeyBindings, TerminalApp::ActionEventArgs); + TYPED_EVENT(MoveFocus, TerminalApp::AppKeyBindings, TerminalApp::ActionEventArgs); // clang-format on private: diff --git a/src/cascadia/TerminalApp/AppKeyBindings.idl b/src/cascadia/TerminalApp/AppKeyBindings.idl index 225e9e479..8786d44ab 100644 --- a/src/cascadia/TerminalApp/AppKeyBindings.idl +++ b/src/cascadia/TerminalApp/AppKeyBindings.idl @@ -1,16 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. +import "../ActionArgs.idl"; namespace TerminalApp { - enum Direction - { - Left = 0, - Right, - Up, - Down - }; - enum ShortcutAction { CopyText = 0, @@ -62,31 +55,6 @@ namespace TerminalApp OpenSettings }; - delegate void CopyTextEventArgs(Boolean trimWhitespace); - delegate void PasteTextEventArgs(); - delegate void NewTabEventArgs(); - delegate void OpenNewTabDropdownEventArgs(); - delegate void DuplicateTabEventArgs(); - delegate void NewTabWithProfileEventArgs(Int32 profileIndex); - delegate void NewWindowEventArgs(); - delegate void CloseWindowEventArgs(); - delegate void CloseTabEventArgs(); - delegate void ClosePaneEventArgs(); - delegate void NextTabEventArgs(); - delegate void PrevTabEventArgs(); - delegate void SplitVerticalEventArgs(); - delegate void SplitHorizontalEventArgs(); - delegate void SwitchToTabEventArgs(Int32 profileIndex); - delegate void IncreaseFontSizeEventArgs(); - delegate void DecreaseFontSizeEventArgs(); - delegate void ScrollUpEventArgs(); - delegate void ScrollDownEventArgs(); - delegate void ScrollUpPageEventArgs(); - delegate void ScrollDownPageEventArgs(); - delegate void OpenSettingsEventArgs(); - delegate void ResizePaneEventArgs(Direction direction); - delegate void MoveFocusEventArgs(Direction direction); - [default_interface] runtimeclass AppKeyBindings : Microsoft.Terminal.Settings.IKeyBindings { AppKeyBindings(); @@ -94,29 +62,29 @@ namespace TerminalApp void SetKeyBinding(ShortcutAction action, Microsoft.Terminal.Settings.KeyChord chord); Microsoft.Terminal.Settings.KeyChord GetKeyBinding(ShortcutAction action); - event CopyTextEventArgs CopyText; - event PasteTextEventArgs PasteText; - event NewTabEventArgs NewTab; - event OpenNewTabDropdownEventArgs OpenNewTabDropdown; - event DuplicateTabEventArgs DuplicateTab; - event NewTabWithProfileEventArgs NewTabWithProfile; - event NewWindowEventArgs NewWindow; - event CloseWindowEventArgs CloseWindow; - event CloseTabEventArgs CloseTab; - event ClosePaneEventArgs ClosePane; - event SwitchToTabEventArgs SwitchToTab; - event NextTabEventArgs NextTab; - event PrevTabEventArgs PrevTab; - event SplitVerticalEventArgs SplitVertical; - event SplitHorizontalEventArgs SplitHorizontal; - event IncreaseFontSizeEventArgs IncreaseFontSize; - event DecreaseFontSizeEventArgs DecreaseFontSize; - event ScrollUpEventArgs ScrollUp; - event ScrollDownEventArgs ScrollDown; - event ScrollUpPageEventArgs ScrollUpPage; - event ScrollDownPageEventArgs ScrollDownPage; - event OpenSettingsEventArgs OpenSettings; - event ResizePaneEventArgs ResizePane; - event MoveFocusEventArgs MoveFocus; + event Windows.Foundation.TypedEventHandler CopyText; + event Windows.Foundation.TypedEventHandler PasteText; + event Windows.Foundation.TypedEventHandler NewTab; + event Windows.Foundation.TypedEventHandler OpenNewTabDropdown; + event Windows.Foundation.TypedEventHandler DuplicateTab; + event Windows.Foundation.TypedEventHandler NewTabWithProfile; + event Windows.Foundation.TypedEventHandler NewWindow; + event Windows.Foundation.TypedEventHandler CloseWindow; + event Windows.Foundation.TypedEventHandler CloseTab; + event Windows.Foundation.TypedEventHandler ClosePane; + event Windows.Foundation.TypedEventHandler SwitchToTab; + event Windows.Foundation.TypedEventHandler NextTab; + event Windows.Foundation.TypedEventHandler PrevTab; + event Windows.Foundation.TypedEventHandler SplitVertical; + event Windows.Foundation.TypedEventHandler SplitHorizontal; + event Windows.Foundation.TypedEventHandler IncreaseFontSize; + event Windows.Foundation.TypedEventHandler DecreaseFontSize; + event Windows.Foundation.TypedEventHandler ScrollUp; + event Windows.Foundation.TypedEventHandler ScrollDown; + event Windows.Foundation.TypedEventHandler ScrollUpPage; + event Windows.Foundation.TypedEventHandler ScrollDownPage; + event Windows.Foundation.TypedEventHandler OpenSettings; + event Windows.Foundation.TypedEventHandler ResizePane; + event Windows.Foundation.TypedEventHandler MoveFocus; } } diff --git a/src/cascadia/TerminalApp/lib/TerminalAppLib.vcxproj b/src/cascadia/TerminalApp/lib/TerminalAppLib.vcxproj index 80c61d203..b53faad8e 100644 --- a/src/cascadia/TerminalApp/lib/TerminalAppLib.vcxproj +++ b/src/cascadia/TerminalApp/lib/TerminalAppLib.vcxproj @@ -70,7 +70,12 @@ - + + ../ActionArgs.idl + + + ../AppKeyBindings.idl + ../App.xaml @@ -109,9 +114,15 @@ ../AppKeyBindings.idl + + ../ActionArgs.idl + ../App.xaml + + ../App.xaml + @@ -129,6 +140,7 @@ ../App.xaml + ../MinMaxCloseControl.xaml Code diff --git a/src/cascadia/TerminalControl/TermControl.cpp b/src/cascadia/TerminalControl/TermControl.cpp index a6469af3a..3adda2dc7 100644 --- a/src/cascadia/TerminalControl/TermControl.cpp +++ b/src/cascadia/TerminalControl/TermControl.cpp @@ -1391,15 +1391,20 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation // Arguments: // - trimTrailingWhitespace: enable removing any whitespace from copied selection // and get text to appear on separate lines. - void TermControl::CopySelectionToClipboard(bool trimTrailingWhitespace) + bool TermControl::CopySelectionToClipboard(bool trimTrailingWhitespace) { - // extract text from buffer - const auto copiedData = _terminal->RetrieveSelectedTextFromBuffer(trimTrailingWhitespace); + if (_terminal != nullptr && _terminal->IsAreaSelected()) + { + // extract text from buffer + const auto copiedData = _terminal->RetrieveSelectedTextFromBuffer(trimTrailingWhitespace); - _terminal->ClearSelection(); + _terminal->ClearSelection(); - // send data up for clipboard - _clipboardCopyHandlers(copiedData); + // send data up for clipboard + _clipboardCopyHandlers(copiedData); + return true; + } + return false; } // Method Description: diff --git a/src/cascadia/TerminalControl/TermControl.h b/src/cascadia/TerminalControl/TermControl.h index 84104c2ed..d4af3cc22 100644 --- a/src/cascadia/TerminalControl/TermControl.h +++ b/src/cascadia/TerminalControl/TermControl.h @@ -38,7 +38,8 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation void UpdateSettings(Settings::IControlSettings newSettings); hstring Title(); - void CopySelectionToClipboard(bool trimTrailingWhitespace); + + bool CopySelectionToClipboard(bool trimTrailingWhitespace); void PasteTextFromClipboard(); void Close(); bool ShouldCloseOnExit() const noexcept; diff --git a/src/cascadia/TerminalControl/TermControl.idl b/src/cascadia/TerminalControl/TermControl.idl index d9d238063..e37b6bca3 100644 --- a/src/cascadia/TerminalControl/TermControl.idl +++ b/src/cascadia/TerminalControl/TermControl.idl @@ -13,8 +13,7 @@ namespace Microsoft.Terminal.TerminalControl void HandleClipboardData(String data); } - [default_interface] - runtimeclass TermControl : Windows.UI.Xaml.Controls.UserControl + [default_interface] runtimeclass TermControl : Windows.UI.Xaml.Controls.UserControl { TermControl(); TermControl(Microsoft.Terminal.Settings.IControlSettings settings, Microsoft.Terminal.TerminalConnection.ITerminalConnection connection); @@ -29,7 +28,8 @@ namespace Microsoft.Terminal.TerminalControl event Windows.Foundation.TypedEventHandler PasteFromClipboard; String Title { get; }; - void CopySelectionToClipboard(Boolean trimTrailingWhitespace); + + Boolean CopySelectionToClipboard(Boolean trimTrailingWhitespace); void PasteTextFromClipboard(); void Close(); Boolean ShouldCloseOnExit { get; }; diff --git a/src/cascadia/inc/cppwinrt_utils.h b/src/cascadia/inc/cppwinrt_utils.h index 8609698df..810436114 100644 --- a/src/cascadia/inc/cppwinrt_utils.h +++ b/src/cascadia/inc/cppwinrt_utils.h @@ -57,6 +57,42 @@ private: winrt::event_token className::name(Windows::Foundation::TypedEventHandler const& handler) { return eventHandler.add(handler); } \ void className::name(winrt::event_token const& token) noexcept { eventHandler.remove(token); } +// This is a helper macro for both declaring the signature of an event, and +// defining the body. Winrt events need a method for adding a callback to the +// event and removing the callback. This macro will both declare the method +// signatures and define them both for you, because they don't really vary from +// event to event. +// Use this in a classes header if you have a Windows.Foundation.TypedEventHandler +#define TYPED_EVENT(name, sender, args) \ +public: \ + winrt::event_token name(Windows::Foundation::TypedEventHandler const& handler) { return _##name##Handlers.add(handler); } \ + void name(winrt::event_token const& token) noexcept { _##name##Handlers.remove(token); } \ + \ +private: \ + winrt::event> _##name##Handlers; + +// Use this macro to quick implement both the getter and setter for a property. +// This should only be used for simple types where there's no logic in the +// getter/setter beyond just accessing/updating the value. +#define GETSET_PROPERTY(type, name, ...) \ +public: \ + type name() const { return _##name; } \ + void name(const type& value) { _##name = value; } \ + \ +private: \ + type _##name{ __VA_ARGS__ }; + +// Use this macro for quickly defining the factory_implementation part of a +// class. CppWinrt requires these for the compiler, but more often than not, +// they require no customization. See +// https://docs.microsoft.com/en-us/uwp/cpp-ref-for-winrt/implements#marker-types +// and https://docs.microsoft.com/en-us/uwp/cpp-ref-for-winrt/static-lifetime +// for examples of when you might _not_ want to use this. +#define BASIC_FACTORY(typeName) \ + struct typeName : typeName##T \ + { \ + }; + // This is a helper method for deserializing a SAFEARRAY of // COM objects and converting it to a vector that // owns the extracted COM objects