Don't copy text if there's no selection (#2446)

This commit also transitions our keybinding events and event handlers to a
TypedEventHandler model with an "event args" class, as specified in the
keybinding arguments specification (#1349). In short, every event can be marked
Handled independently, and a Handled event will stop bubbling out to the
terminal. An unhandled event will be passed off to the terminal as a standard
keypress.

This unifies our keybinding event model and provides a convenient place for
binding arguments to live.

Fixes #2285.
Related to #1349, #1142.
This commit is contained in:
Mike Griese 2019-08-16 17:43:51 -05:00 committed by Dustin L. Howett (MSFT)
parent c70fb49ab5
commit 734fc1dcc6
14 changed files with 773 additions and 237 deletions

View file

@ -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"

View file

@ -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>
{
ActionEventArgs() = default;
ActionEventArgs(const TerminalApp::IActionArgs& args) :
_ActionArgs{ args } {};
GETSET_PROPERTY(IActionArgs, ActionArgs, nullptr);
GETSET_PROPERTY(bool, Handled, false);
};
struct CopyTextArgs : public CopyTextArgsT<CopyTextArgs>
{
CopyTextArgs() = default;
GETSET_PROPERTY(bool, TrimWhitespace, false);
};
struct NewTabWithProfileArgs : public NewTabWithProfileArgsT<NewTabWithProfileArgs>
{
NewTabWithProfileArgs() = default;
GETSET_PROPERTY(int32_t, ProfileIndex, 0);
};
struct SwitchToTabArgs : public SwitchToTabArgsT<SwitchToTabArgs>
{
SwitchToTabArgs() = default;
GETSET_PROPERTY(int32_t, TabIndex, 0);
};
struct ResizePaneArgs : public ResizePaneArgsT<ResizePaneArgs>
{
ResizePaneArgs() = default;
GETSET_PROPERTY(TerminalApp::Direction, Direction, TerminalApp::Direction::Left);
};
struct MoveFocusArgs : public MoveFocusArgsT<MoveFocusArgs>
{
MoveFocusArgs() = default;
GETSET_PROPERTY(TerminalApp::Direction, Direction, TerminalApp::Direction::Left);
};
}
namespace winrt::TerminalApp::factory_implementation
{
BASIC_FACTORY(ActionEventArgs);
}

View file

@ -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; };
};
}

View file

@ -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<decltype(tabIndex)>(_tabs.size()))
{
_SetFocusedTabIndex(tabIndex);
return true;
}
return false;
}
// Method Description:

View file

@ -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<GUID>& profileGuid);
void _SplitHorizontal(const std::optional<GUID>& 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
};
}

View file

@ -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<TerminalApp::NewTabWithProfileArgs>())
{
_OpenNewTab({ realArgs.ProfileIndex() });
args.Handled(true);
}
}
void App::_HandleSwitchToTab(const IInspectable& /*sender*/,
const TerminalApp::ActionEventArgs& args)
{
if (const auto& realArgs = args.ActionArgs().try_as<TerminalApp::SwitchToTabArgs>())
{
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<TerminalApp::ResizePaneArgs>())
{
_ResizePane(realArgs.Direction());
args.Handled(true);
}
}
void App::_HandleMoveFocus(const IInspectable& /*sender*/,
const TerminalApp::ActionEventArgs& args)
{
if (const auto& realArgs = args.ActionArgs().try_as<TerminalApp::MoveFocusArgs>())
{
_MoveFocus(realArgs.Direction());
args.Handled(true);
}
}
void App::_HandleCopyText(const IInspectable& /*sender*/,
const TerminalApp::ActionEventArgs& args)
{
if (const auto& realArgs = args.ActionArgs().try_as<TerminalApp::CopyTextArgs>())
{
const auto handled = _CopyText(realArgs.TrimWhitespace());
args.Handled(handled);
}
}
}

View file

@ -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<CopyTextArgs>();
args->TrimWhitespace(true);
auto eventArgs = winrt::make_self<ActionEventArgs>(*args);
_CopyTextHandlers(*this, *eventArgs);
return eventArgs->Handled();
}
case ShortcutAction::CopyTextWithoutNewlines:
_CopyTextHandlers(false);
return true;
{
auto args = winrt::make_self<CopyTextArgs>();
args->TrimWhitespace(false);
auto eventArgs = winrt::make_self<ActionEventArgs>(*args);
_CopyTextHandlers(*this, *eventArgs);
return eventArgs->Handled();
}
case ShortcutAction::PasteText:
_PasteTextHandlers();
return true;
{
auto eventArgs = winrt::make_self<ActionEventArgs>();
_PasteTextHandlers(*this, *eventArgs);
return eventArgs->Handled();
}
case ShortcutAction::NewTab:
_NewTabHandlers();
return true;
{
auto eventArgs = winrt::make_self<ActionEventArgs>();
_NewTabHandlers(*this, *eventArgs);
return eventArgs->Handled();
}
case ShortcutAction::OpenNewTabDropdown:
_OpenNewTabDropdownHandlers();
return true;
{
auto eventArgs = winrt::make_self<ActionEventArgs>();
_OpenNewTabDropdownHandlers(*this, *eventArgs);
return eventArgs->Handled();
}
case ShortcutAction::DuplicateTab:
_DuplicateTabHandlers();
return true;
{
auto eventArgs = winrt::make_self<ActionEventArgs>();
_DuplicateTabHandlers(*this, *eventArgs);
return eventArgs->Handled();
}
case ShortcutAction::OpenSettings:
_OpenSettingsHandlers();
return true;
{
auto eventArgs = winrt::make_self<ActionEventArgs>();
_OpenSettingsHandlers(*this, *eventArgs);
return eventArgs->Handled();
}
case ShortcutAction::NewTabProfile0:
_NewTabWithProfileHandlers(0);
return true;
{
auto args = winrt::make_self<NewTabWithProfileArgs>();
args->ProfileIndex(0);
auto eventArgs = winrt::make_self<ActionEventArgs>(*args);
_NewTabWithProfileHandlers(*this, *eventArgs);
return eventArgs->Handled();
}
case ShortcutAction::NewTabProfile1:
_NewTabWithProfileHandlers(1);
return true;
{
auto args = winrt::make_self<NewTabWithProfileArgs>();
args->ProfileIndex(1);
auto eventArgs = winrt::make_self<ActionEventArgs>(*args);
_NewTabWithProfileHandlers(*this, *eventArgs);
return eventArgs->Handled();
}
case ShortcutAction::NewTabProfile2:
_NewTabWithProfileHandlers(2);
return true;
{
auto args = winrt::make_self<NewTabWithProfileArgs>();
args->ProfileIndex(2);
auto eventArgs = winrt::make_self<ActionEventArgs>(*args);
_NewTabWithProfileHandlers(*this, *eventArgs);
return eventArgs->Handled();
}
case ShortcutAction::NewTabProfile3:
_NewTabWithProfileHandlers(3);
return true;
{
auto args = winrt::make_self<NewTabWithProfileArgs>();
args->ProfileIndex(3);
auto eventArgs = winrt::make_self<ActionEventArgs>(*args);
_NewTabWithProfileHandlers(*this, *eventArgs);
return eventArgs->Handled();
}
case ShortcutAction::NewTabProfile4:
_NewTabWithProfileHandlers(4);
return true;
{
auto args = winrt::make_self<NewTabWithProfileArgs>();
args->ProfileIndex(4);
auto eventArgs = winrt::make_self<ActionEventArgs>(*args);
_NewTabWithProfileHandlers(*this, *eventArgs);
return eventArgs->Handled();
}
case ShortcutAction::NewTabProfile5:
_NewTabWithProfileHandlers(5);
return true;
{
auto args = winrt::make_self<NewTabWithProfileArgs>();
args->ProfileIndex(5);
auto eventArgs = winrt::make_self<ActionEventArgs>(*args);
_NewTabWithProfileHandlers(*this, *eventArgs);
return eventArgs->Handled();
}
case ShortcutAction::NewTabProfile6:
_NewTabWithProfileHandlers(6);
return true;
{
auto args = winrt::make_self<NewTabWithProfileArgs>();
args->ProfileIndex(6);
auto eventArgs = winrt::make_self<ActionEventArgs>(*args);
_NewTabWithProfileHandlers(*this, *eventArgs);
return eventArgs->Handled();
}
case ShortcutAction::NewTabProfile7:
_NewTabWithProfileHandlers(7);
return true;
{
auto args = winrt::make_self<NewTabWithProfileArgs>();
args->ProfileIndex(7);
auto eventArgs = winrt::make_self<ActionEventArgs>(*args);
_NewTabWithProfileHandlers(*this, *eventArgs);
return eventArgs->Handled();
}
case ShortcutAction::NewTabProfile8:
_NewTabWithProfileHandlers(8);
return true;
{
auto args = winrt::make_self<NewTabWithProfileArgs>();
args->ProfileIndex(8);
auto eventArgs = winrt::make_self<ActionEventArgs>(*args);
_NewTabWithProfileHandlers(*this, *eventArgs);
return eventArgs->Handled();
}
case ShortcutAction::NewWindow:
_NewWindowHandlers();
return true;
{
auto eventArgs = winrt::make_self<ActionEventArgs>();
_NewWindowHandlers(*this, *eventArgs);
return eventArgs->Handled();
}
case ShortcutAction::CloseWindow:
_CloseWindowHandlers();
return true;
{
auto eventArgs = winrt::make_self<ActionEventArgs>();
_CloseWindowHandlers(*this, *eventArgs);
return eventArgs->Handled();
}
case ShortcutAction::CloseTab:
_CloseTabHandlers();
return true;
{
auto eventArgs = winrt::make_self<ActionEventArgs>();
_CloseTabHandlers(*this, *eventArgs);
return eventArgs->Handled();
}
case ShortcutAction::ClosePane:
_ClosePaneHandlers();
return true;
{
auto eventArgs = winrt::make_self<ActionEventArgs>();
_ClosePaneHandlers(*this, *eventArgs);
return eventArgs->Handled();
}
case ShortcutAction::ScrollUp:
_ScrollUpHandlers();
return true;
{
auto eventArgs = winrt::make_self<ActionEventArgs>();
_ScrollUpHandlers(*this, *eventArgs);
return eventArgs->Handled();
}
case ShortcutAction::ScrollDown:
_ScrollDownHandlers();
return true;
{
auto eventArgs = winrt::make_self<ActionEventArgs>();
_ScrollDownHandlers(*this, *eventArgs);
return eventArgs->Handled();
}
case ShortcutAction::ScrollUpPage:
_ScrollUpPageHandlers();
return true;
{
auto eventArgs = winrt::make_self<ActionEventArgs>();
_ScrollUpPageHandlers(*this, *eventArgs);
return eventArgs->Handled();
}
case ShortcutAction::ScrollDownPage:
_ScrollDownPageHandlers();
return true;
{
auto eventArgs = winrt::make_self<ActionEventArgs>();
_ScrollDownPageHandlers(*this, *eventArgs);
return eventArgs->Handled();
}
case ShortcutAction::NextTab:
_NextTabHandlers();
return true;
{
auto eventArgs = winrt::make_self<ActionEventArgs>();
_NextTabHandlers(*this, *eventArgs);
return eventArgs->Handled();
}
case ShortcutAction::PrevTab:
_PrevTabHandlers();
return true;
{
auto eventArgs = winrt::make_self<ActionEventArgs>();
_PrevTabHandlers(*this, *eventArgs);
return eventArgs->Handled();
}
case ShortcutAction::SplitVertical:
_SplitVerticalHandlers();
return true;
{
auto eventArgs = winrt::make_self<ActionEventArgs>();
_SplitVerticalHandlers(*this, *eventArgs);
return eventArgs->Handled();
}
case ShortcutAction::SplitHorizontal:
_SplitHorizontalHandlers();
return true;
{
auto eventArgs = winrt::make_self<ActionEventArgs>();
_SplitHorizontalHandlers(*this, *eventArgs);
return eventArgs->Handled();
}
case ShortcutAction::SwitchToTab0:
_SwitchToTabHandlers(0);
return true;
{
auto args = winrt::make_self<SwitchToTabArgs>();
args->TabIndex(0);
auto eventArgs = winrt::make_self<ActionEventArgs>(*args);
_SwitchToTabHandlers(*this, *eventArgs);
return eventArgs->Handled();
}
case ShortcutAction::SwitchToTab1:
_SwitchToTabHandlers(1);
return true;
{
auto args = winrt::make_self<SwitchToTabArgs>();
args->TabIndex(1);
auto eventArgs = winrt::make_self<ActionEventArgs>(*args);
_SwitchToTabHandlers(*this, *eventArgs);
return eventArgs->Handled();
}
case ShortcutAction::SwitchToTab2:
_SwitchToTabHandlers(2);
return true;
{
auto args = winrt::make_self<SwitchToTabArgs>();
args->TabIndex(2);
auto eventArgs = winrt::make_self<ActionEventArgs>(*args);
_SwitchToTabHandlers(*this, *eventArgs);
return eventArgs->Handled();
}
case ShortcutAction::SwitchToTab3:
_SwitchToTabHandlers(3);
return true;
{
auto args = winrt::make_self<SwitchToTabArgs>();
args->TabIndex(3);
auto eventArgs = winrt::make_self<ActionEventArgs>(*args);
_SwitchToTabHandlers(*this, *eventArgs);
return eventArgs->Handled();
}
case ShortcutAction::SwitchToTab4:
_SwitchToTabHandlers(4);
return true;
{
auto args = winrt::make_self<SwitchToTabArgs>();
args->TabIndex(4);
auto eventArgs = winrt::make_self<ActionEventArgs>(*args);
_SwitchToTabHandlers(*this, *eventArgs);
return eventArgs->Handled();
}
case ShortcutAction::SwitchToTab5:
_SwitchToTabHandlers(5);
return true;
{
auto args = winrt::make_self<SwitchToTabArgs>();
args->TabIndex(5);
auto eventArgs = winrt::make_self<ActionEventArgs>(*args);
_SwitchToTabHandlers(*this, *eventArgs);
return eventArgs->Handled();
}
case ShortcutAction::SwitchToTab6:
_SwitchToTabHandlers(6);
return true;
{
auto args = winrt::make_self<SwitchToTabArgs>();
args->TabIndex(6);
auto eventArgs = winrt::make_self<ActionEventArgs>(*args);
_SwitchToTabHandlers(*this, *eventArgs);
return eventArgs->Handled();
}
case ShortcutAction::SwitchToTab7:
_SwitchToTabHandlers(7);
return true;
{
auto args = winrt::make_self<SwitchToTabArgs>();
args->TabIndex(7);
auto eventArgs = winrt::make_self<ActionEventArgs>(*args);
_SwitchToTabHandlers(*this, *eventArgs);
return eventArgs->Handled();
}
case ShortcutAction::SwitchToTab8:
_SwitchToTabHandlers(8);
return true;
{
auto args = winrt::make_self<SwitchToTabArgs>();
args->TabIndex(8);
auto eventArgs = winrt::make_self<ActionEventArgs>(*args);
_SwitchToTabHandlers(*this, *eventArgs);
return eventArgs->Handled();
}
case ShortcutAction::ResizePaneLeft:
_ResizePaneHandlers(Direction::Left);
return true;
{
auto args = winrt::make_self<ResizePaneArgs>();
args->Direction(Direction::Left);
auto eventArgs = winrt::make_self<ActionEventArgs>(*args);
_ResizePaneHandlers(*this, *eventArgs);
return eventArgs->Handled();
}
case ShortcutAction::ResizePaneRight:
_ResizePaneHandlers(Direction::Right);
return true;
{
auto args = winrt::make_self<ResizePaneArgs>();
args->Direction(Direction::Right);
auto eventArgs = winrt::make_self<ActionEventArgs>(*args);
_ResizePaneHandlers(*this, *eventArgs);
return eventArgs->Handled();
}
case ShortcutAction::ResizePaneUp:
_ResizePaneHandlers(Direction::Up);
return true;
{
auto args = winrt::make_self<ResizePaneArgs>();
args->Direction(Direction::Up);
auto eventArgs = winrt::make_self<ActionEventArgs>(*args);
_ResizePaneHandlers(*this, *eventArgs);
return eventArgs->Handled();
}
case ShortcutAction::ResizePaneDown:
_ResizePaneHandlers(Direction::Down);
return true;
{
auto args = winrt::make_self<ResizePaneArgs>();
args->Direction(Direction::Down);
auto eventArgs = winrt::make_self<ActionEventArgs>(*args);
_ResizePaneHandlers(*this, *eventArgs);
return eventArgs->Handled();
}
case ShortcutAction::MoveFocusLeft:
_MoveFocusHandlers(Direction::Left);
return true;
{
auto args = winrt::make_self<MoveFocusArgs>();
args->Direction(Direction::Left);
auto eventArgs = winrt::make_self<ActionEventArgs>(*args);
_MoveFocusHandlers(*this, *eventArgs);
return eventArgs->Handled();
}
case ShortcutAction::MoveFocusRight:
_MoveFocusHandlers(Direction::Right);
return true;
{
auto args = winrt::make_self<MoveFocusArgs>();
args->Direction(Direction::Right);
auto eventArgs = winrt::make_self<ActionEventArgs>(*args);
_MoveFocusHandlers(*this, *eventArgs);
return eventArgs->Handled();
}
case ShortcutAction::MoveFocusUp:
_MoveFocusHandlers(Direction::Up);
return true;
{
auto args = winrt::make_self<MoveFocusArgs>();
args->Direction(Direction::Up);
auto eventArgs = winrt::make_self<ActionEventArgs>(*args);
_MoveFocusHandlers(*this, *eventArgs);
return eventArgs->Handled();
}
case ShortcutAction::MoveFocusDown:
_MoveFocusHandlers(Direction::Down);
return true;
{
auto args = winrt::make_self<MoveFocusArgs>();
args->Direction(Direction::Down);
auto eventArgs = winrt::make_self<ActionEventArgs>(*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
}

View file

@ -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:

View file

@ -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<AppKeyBindings, ActionEventArgs> CopyText;
event Windows.Foundation.TypedEventHandler<AppKeyBindings, ActionEventArgs> PasteText;
event Windows.Foundation.TypedEventHandler<AppKeyBindings, ActionEventArgs> NewTab;
event Windows.Foundation.TypedEventHandler<AppKeyBindings, ActionEventArgs> OpenNewTabDropdown;
event Windows.Foundation.TypedEventHandler<AppKeyBindings, ActionEventArgs> DuplicateTab;
event Windows.Foundation.TypedEventHandler<AppKeyBindings, ActionEventArgs> NewTabWithProfile;
event Windows.Foundation.TypedEventHandler<AppKeyBindings, ActionEventArgs> NewWindow;
event Windows.Foundation.TypedEventHandler<AppKeyBindings, ActionEventArgs> CloseWindow;
event Windows.Foundation.TypedEventHandler<AppKeyBindings, ActionEventArgs> CloseTab;
event Windows.Foundation.TypedEventHandler<AppKeyBindings, ActionEventArgs> ClosePane;
event Windows.Foundation.TypedEventHandler<AppKeyBindings, ActionEventArgs> SwitchToTab;
event Windows.Foundation.TypedEventHandler<AppKeyBindings, ActionEventArgs> NextTab;
event Windows.Foundation.TypedEventHandler<AppKeyBindings, ActionEventArgs> PrevTab;
event Windows.Foundation.TypedEventHandler<AppKeyBindings, ActionEventArgs> SplitVertical;
event Windows.Foundation.TypedEventHandler<AppKeyBindings, ActionEventArgs> SplitHorizontal;
event Windows.Foundation.TypedEventHandler<AppKeyBindings, ActionEventArgs> IncreaseFontSize;
event Windows.Foundation.TypedEventHandler<AppKeyBindings, ActionEventArgs> DecreaseFontSize;
event Windows.Foundation.TypedEventHandler<AppKeyBindings, ActionEventArgs> ScrollUp;
event Windows.Foundation.TypedEventHandler<AppKeyBindings, ActionEventArgs> ScrollDown;
event Windows.Foundation.TypedEventHandler<AppKeyBindings, ActionEventArgs> ScrollUpPage;
event Windows.Foundation.TypedEventHandler<AppKeyBindings, ActionEventArgs> ScrollDownPage;
event Windows.Foundation.TypedEventHandler<AppKeyBindings, ActionEventArgs> OpenSettings;
event Windows.Foundation.TypedEventHandler<AppKeyBindings, ActionEventArgs> ResizePane;
event Windows.Foundation.TypedEventHandler<AppKeyBindings, ActionEventArgs> MoveFocus;
}
}

View file

@ -70,7 +70,12 @@
<ClInclude Include="../Utils.h" />
<ClInclude Include="../TerminalWarnings.h" />
<ClInclude Include="pch.h" />
<ClInclude Include="../AppKeyBindings.h" />
<ClInclude Include="../ActionArgs.h" >
<DependentUpon>../ActionArgs.idl</DependentUpon>
</ClInclude>
<ClInclude Include="../AppKeyBindings.h" >
<DependentUpon>../AppKeyBindings.idl</DependentUpon>
</ClInclude>
<ClInclude Include="../App.h" >
<DependentUpon>../App.xaml</DependentUpon>
</ClInclude>
@ -109,9 +114,15 @@
<ClCompile Include="../AppKeyBindings.cpp" >
<DependentUpon>../AppKeyBindings.idl</DependentUpon>
</ClCompile>
<ClCompile Include="../ActionArgs.cpp" >
<DependentUpon>../ActionArgs.idl</DependentUpon>
</ClCompile>
<ClCompile Include="../App.cpp" >
<DependentUpon>../App.xaml</DependentUpon>
</ClCompile>
<ClCompile Include="../AppActionHandlers.cpp" >
<DependentUpon>../App.xaml</DependentUpon>
</ClCompile>
<!-- You _NEED_ to include this file and the jsoncpp IncludePath (below) if
you want to use jsoncpp -->
@ -129,6 +140,7 @@
<DependentUpon>../App.xaml</DependentUpon>
</Midl>
<Midl Include="../AppKeyBindings.idl" />
<Midl Include="../ActionArgs.idl" />
<Midl Include="../MinMaxCloseControl.idl">
<DependentUpon>../MinMaxCloseControl.xaml</DependentUpon>
<SubType>Code</SubType>

View file

@ -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:

View file

@ -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;

View file

@ -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<TermControl, PasteFromClipboardEventArgs> PasteFromClipboard;
String Title { get; };
void CopySelectionToClipboard(Boolean trimTrailingWhitespace);
Boolean CopySelectionToClipboard(Boolean trimTrailingWhitespace);
void PasteTextFromClipboard();
void Close();
Boolean ShouldCloseOnExit { get; };

View file

@ -57,6 +57,42 @@ private:
winrt::event_token className::name(Windows::Foundation::TypedEventHandler<sender, args> 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<sender, args> const& handler) { return _##name##Handlers.add(handler); } \
void name(winrt::event_token const& token) noexcept { _##name##Handlers.remove(token); } \
\
private: \
winrt::event<Windows::Foundation::TypedEventHandler<sender, args>> _##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<typeName, implementation::typeName> \
{ \
};
// This is a helper method for deserializing a SAFEARRAY of
// COM objects and converting it to a vector that
// owns the extracted COM objects