Compare commits

...

11 commits

Author SHA1 Message Date
Mike Griese 75375d721c Merge remote-tracking branch 'origin/master' into dev/migrie/f/2046-command-palette
# Conflicts:
#	src/cascadia/inc/cppwinrt_utils.h
2019-08-08 17:40:47 -05:00
Mike Griese ffcbbe58f0 Merge branch 'master' into dev/migrie/f/2046-command-palette
# Conflicts:
#	src/cascadia/TerminalApp/App.cpp
#	src/cascadia/TerminalApp/AppKeyBindings.cpp
2019-07-30 09:59:38 -05:00
Mike Griese da92fef1e1 Polish the appearance a bit 2019-07-24 11:49:18 -05:00
Mike Griese d1abbdf019 Implement a rudimentary fuzzy search for commands 2019-07-24 08:02:47 -05:00
Mike Griese ea6b0337ac Dispatch actions on enter, navigate with arrows 2019-07-24 07:44:51 -05:00
Mike Griese 49df3cd7a6 Really basic searching 2019-07-23 15:51:09 -05:00
Mike Griese c6dccdaf5c Hook up the list of actions to the command palette 2019-07-23 15:38:16 -05:00
Mike Griese 846778b288 Create a toggleable comamnd palette 2019-07-23 14:59:35 -05:00
Mike Griese 77fc58b7ea serialize and deserialize actions 2019-07-23 10:55:26 -05:00
Mike Griese 999eda3a60 Create an Action class 2019-07-23 10:01:48 -05:00
Mike Griese fa276f7c52 add a ShortcutDispatch class to encapsulate action dispatching 2019-07-23 09:36:45 -05:00
26 changed files with 1114 additions and 439 deletions

@ -1 +1 @@
Subproject commit 1212beae777dba02c230ece8c0c0ec12790047ea
Subproject commit b74b286d5e333561b0f1ef1abd18de2606624455

@ -1 +1 @@
Subproject commit e8c599bca6c56c44b6730ad93f6abbc9ecd60fc1
Subproject commit fbcd1d2abb558da4564ce343b688f7a658f51318

View file

@ -0,0 +1,21 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
#include "pch.h"
#include "Action.h"
#include "KeyChordSerialization.h"
#include "Action.g.cpp"
using namespace winrt::Microsoft::Terminal;
using namespace winrt::TerminalApp;
using namespace winrt::Windows::Data::Json;
namespace winrt::TerminalApp::implementation
{
// DEFINE_GETSET_PROPERTY(Action, winrt::hstring, Name);
DEFINE_GETSET_PROPERTY(Action, winrt::hstring, IconPath);
DEFINE_GETSET_PROPERTY(Action, winrt::TerminalApp::ShortcutAction, Command);
DEFINE_EVENT(Action, PropertyChanged, _propertyChanged, Windows::UI::Xaml::Data::PropertyChangedEventHandler);
}

View file

@ -0,0 +1,29 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
#pragma once
#include "Action.g.h"
#include "..\inc\cppwinrt_utils.h"
namespace winrt::TerminalApp::implementation
{
struct Action : ActionT<Action>
{
Action() = default;
// DECLARE_GETSET_PROPERTY(winrt::hstring, Name);
DECLARE_GETSET_PROPERTY(winrt::hstring, IconPath);
DECLARE_GETSET_PROPERTY(winrt::TerminalApp::ShortcutAction, Command);
DECLARE_EVENT(PropertyChanged, _propertyChanged, Windows::UI::Xaml::Data::PropertyChangedEventHandler);
DEFINE_OBSERVABLE_GETSET_PROPERTY(winrt::hstring, Name, _propertyChanged);
};
}
namespace winrt::TerminalApp::factory_implementation
{
struct Action : ActionT<Action, implementation::Action>
{
};
}

View file

@ -0,0 +1,16 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import "../ShortcutActionDispatch.idl";
namespace TerminalApp
{
[default_interface] runtimeclass Action : Windows.UI.Xaml.Data.INotifyPropertyChanged
{
Action();
String Name;
String IconPath;
ShortcutAction Command;
}
}

View file

@ -0,0 +1,153 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
#include "pch.h"
#include "ActionList.h"
#include "ActionList.g.cpp"
using namespace winrt;
using namespace winrt::TerminalApp;
using namespace Windows::UI::Xaml;
using namespace Windows::System;
namespace winrt::TerminalApp::implementation
{
ActionList::ActionList()
{
InitializeComponent();
_filteredActions = winrt::single_threaded_observable_vector<winrt::TerminalApp::Action>();
_allActions = winrt::single_threaded_vector<winrt::TerminalApp::Action>();
_SearchBox().TextChanged({ this, &ActionList::_FilterTextChanged });
_SearchBox().KeyDown({ this, &ActionList::_KeyDownHandler });
}
void ActionList::ToggleVisibility()
{
const bool isVisible = Visibility() == Visibility::Visible;
if (!isVisible)
{
// Become visible
Visibility(Visibility::Visible);
_SearchBox().Focus(FocusState::Programmatic);
_FilteredActionsView().SelectedIndex(0);
}
else
{
_Close();
}
}
void ActionList::_KeyDownHandler(Windows::Foundation::IInspectable const& sender,
Windows::UI::Xaml::Input::KeyRoutedEventArgs const& e)
{
auto key = e.OriginalKey();
if (key == VirtualKey::Up)
{
auto selected = _FilteredActionsView().SelectedIndex();
selected = (selected - 1) % _FilteredActionsView().Items().Size();
_FilteredActionsView().SelectedIndex(selected);
e.Handled(true);
}
else if (key == VirtualKey::Down)
{
auto selected = _FilteredActionsView().SelectedIndex();
selected = (selected + 1) % _FilteredActionsView().Items().Size();
_FilteredActionsView().SelectedIndex(selected);
e.Handled(true);
}
else if (key == VirtualKey::Enter)
{
auto selectedItem = _FilteredActionsView().SelectedItem();
if (selectedItem)
{
auto data = selectedItem.try_as<Action>();
if (data)
{
auto command = data.Command();
_dispatch.DoAction(command);
_Close();
}
}
e.Handled(true);
}
else if (key == VirtualKey::Escape)
{
_Close();
}
}
void ActionList::_FilterTextChanged(Windows::Foundation::IInspectable const& sender,
Windows::UI::Xaml::RoutedEventArgs const& args)
{
_UpdateFilteredActions();
_FilteredActionsView().SelectedIndex(0);
}
Windows::Foundation::Collections::IObservableVector<Action> ActionList::FilteredActions()
{
return _filteredActions;
}
void ActionList::SetActions(Windows::Foundation::Collections::IVector<TerminalApp::Action> const& actions)
{
_allActions = actions;
_UpdateFilteredActions();
}
void ActionList::_UpdateFilteredActions()
{
_filteredActions.Clear();
auto searchText = _SearchBox().Text();
const bool addAll = searchText.empty();
for (auto action : _allActions)
{
if (addAll || ActionList::_FilterMatchesName(searchText, action.Name()))
{
_filteredActions.Append(action);
}
}
}
bool ActionList::_FilterMatchesName(winrt::hstring searchText, winrt::hstring name)
{
std::wstring lowercaseSearchText{ searchText.c_str() };
std::wstring lowercaseName{ name.c_str() };
std::transform(lowercaseSearchText.begin(), lowercaseSearchText.end(), lowercaseSearchText.begin(), std::towlower);
std::transform(lowercaseName.begin(), lowercaseName.end(), lowercaseName.begin(), std::towlower);
const wchar_t* namePtr = lowercaseName.c_str();
const wchar_t* endOfName = lowercaseName.c_str() + lowercaseName.size();
for (const auto& wch : lowercaseSearchText)
{
while (wch != *namePtr)
{
// increment the character to look at in the name string
namePtr++;
if (namePtr >= endOfName)
{
// If we are at the end of the name string, we haven't found all the search chars
return false;
}
}
}
return true;
}
void ActionList::SetDispatch(const winrt::TerminalApp::ShortcutActionDispatch& dispatch)
{
_dispatch = dispatch;
}
void ActionList::_Close()
{
Visibility(Visibility::Collapsed);
_SearchBox().Text(L"");
_closeHandlers(*this, RoutedEventArgs{});
}
DEFINE_EVENT_WITH_TYPED_EVENT_HANDLER(ActionList, Closed, _closeHandlers, TerminalApp::ActionList, winrt::Windows::UI::Xaml::RoutedEventArgs);
}

View file

@ -0,0 +1,45 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
#pragma once
#include "winrt/Microsoft.UI.Xaml.Controls.h"
#include "ActionList.g.h"
#include "../../cascadia/inc/cppwinrt_utils.h"
namespace winrt::TerminalApp::implementation
{
struct ActionList : ActionListT<ActionList>
{
ActionList();
Windows::Foundation::Collections::IObservableVector<TerminalApp::Action> FilteredActions();
void SetActions(Windows::Foundation::Collections::IVector<TerminalApp::Action> const& actions);
void ToggleVisibility();
void SetDispatch(const winrt::TerminalApp::ShortcutActionDispatch& dispatch);
DECLARE_EVENT_WITH_TYPED_EVENT_HANDLER(Closed, _closeHandlers, TerminalApp::ActionList, winrt::Windows::UI::Xaml::RoutedEventArgs);
private:
Windows::Foundation::Collections::IObservableVector<TerminalApp::Action> _filteredActions{ nullptr };
Windows::Foundation::Collections::IVector<TerminalApp::Action> _allActions{ nullptr };
winrt::TerminalApp::ShortcutActionDispatch _dispatch;
void _FilterTextChanged(Windows::Foundation::IInspectable const& sender,
Windows::UI::Xaml::RoutedEventArgs const& args);
void _KeyDownHandler(Windows::Foundation::IInspectable const& sender,
Windows::UI::Xaml::Input::KeyRoutedEventArgs const& e);
void _UpdateFilteredActions();
static bool _FilterMatchesName(winrt::hstring searchText, winrt::hstring name);
void _Close();
};
}
namespace winrt::TerminalApp::factory_implementation
{
struct ActionList : ActionListT<ActionList, implementation::ActionList>
{
};
}

View file

@ -0,0 +1,21 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import "../Action.idl";
namespace TerminalApp
{
[default_interface] runtimeclass ActionList : Windows.UI.Xaml.Controls.Grid
{
ActionList();
Windows.Foundation.Collections.IObservableVector<Action> FilteredActions { get; };
void SetActions(Windows.Foundation.Collections.IVector<Action> actions);
void ToggleVisibility();
void SetDispatch(ShortcutActionDispatch dispatch);
event Windows.Foundation.TypedEventHandler<ActionList, Windows.UI.Xaml.RoutedEventArgs> Closed;
}
}

View file

@ -0,0 +1,65 @@
<!-- Copyright (c) Microsoft Corporation. All rights reserved. Licensed under
the MIT License. See LICENSE in the project root for license information. -->
<Grid
x:Class="TerminalApp.ActionList"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:TerminalApp"
xmlns:mux="using:Microsoft.UI.Xaml.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="8*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="9*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid
Background="{ThemeResource SystemChromeMediumLowColor}"
Grid.Column="1"
Grid.Row="0"
Padding="8"
MaxWidth="400"
MaxHeight="400"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBox
Grid.Row="0"
x:Name="_SearchBox"
PlaceholderText="Type a command name"
Text="">
</TextBox>
<ListView
Grid.Row="1"
x:Name="_FilteredActionsView"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
SelectionMode="Single"
CanReorderItems="False"
AllowDrop="False"
ItemsSource="{x:Bind FilteredActions}">
<ItemsControl.ItemTemplate>
<DataTemplate x:DataType="local:Action">
<TextBlock Text="{x:Bind Name, Mode=OneWay}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ListView>
</Grid>
</Grid>

View file

@ -0,0 +1,87 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
#include "pch.h"
#include "ActionSerialization.h"
#include "KeyChordSerialization.h"
#include "Utils.h"
#include "ShortcutActionSerializationKeys.h"
#include <winrt/Microsoft.Terminal.Settings.h>
using namespace winrt::Microsoft::Terminal::Settings;
using namespace winrt::TerminalApp;
static constexpr std::string_view NameKey{ "name" };
static constexpr std::string_view IconPathKey{ "iconPath" };
static constexpr std::string_view CommandKey{ "command" };
// Method Description:
// - TODO Serialize this AppKeyBindings to a json array of objects. Each object in
// the array represents a single keybinding, mapping a KeyChord to a
// ShortcutAction.
// Return Value:
// - a Json::Value which is an equivalent serialization of this object.
Json::Value ActionSerialization::ToJson(const winrt::TerminalApp::Action& action)
{
Json::Value jsonObject;
jsonObject[JsonKey(NameKey)] = winrt::to_string(action.Name());
jsonObject[JsonKey(IconPathKey)] = winrt::to_string(action.IconPath());
// Iterate over all the possible actions in the names list, to find the name for our command
for (auto& nameAndAction : commandNames)
{
const auto searchedForName = nameAndAction.first;
const auto searchedForAction = nameAndAction.second;
if (searchedForAction == action.Command())
{
// We found the name, we serialized successfully.
jsonObject[JsonKey(CommandKey)] = searchedForName.data(); //winrt::to_string(action.IconPath());
return jsonObject;
}
}
// We did not find a name, throw an error
throw winrt::hresult_invalid_argument();
}
// Method Description:
// - Deserialize an AppKeyBindings from the key mappings that are in the array
// `json`. The json array should contain an array of objects with both a
// `command` string and a `keys` array, where `command` is one of the names
// listed in `commandNames`, and `keys` is an array of keypresses. Currently,
// the array should contain a single string, which can be deserialized into a
// KeyChord.
// Arguments:
// - json: and array of JsonObject's to deserialize into our _keyShortcuts mapping.
// Return Value:
// - the newly constructed AppKeyBindings object.
winrt::TerminalApp::Action ActionSerialization::FromJson(const Json::Value& json)
{
winrt::TerminalApp::Action result{};
if (auto name{ json[JsonKey(NameKey)] })
{
result.Name(winrt::to_hstring(name.asString()));
}
if (auto iconPath{ json[JsonKey(IconPathKey)] })
{
result.IconPath(winrt::to_hstring(iconPath.asString()));
}
if (auto commandString{ json[JsonKey(CommandKey)] })
{
// Try matching the command to one we have
const auto found = commandNames.find(commandString.asString());
if (found != commandNames.end())
{
result.Command(found->second);
}
else
{
// We did not find a matching name, throw an error
throw winrt::hresult_invalid_argument();
}
}
return result;
}

View file

@ -0,0 +1,28 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
//
// Module Name:
// - ActionSerialization.h
//
// Abstract:
// - A couple helper functions for serializing/deserializing an Actions
// to/from json. We need this to exist as external helper functions, rather
// than defining these as methods on the Action class, because
// Action is a winrt type. When we're working with an Action
// object, we only have access to methods defined on the winrt interface (in
// the idl). We don't have access to methods we define on the
// implementation. Since JsonValue is not a winrt type, we can't define any
// methods that operate on it in the idl.
//
// Author(s):
// - Mike Griese - July 2019
#pragma once
#include "Action.h"
class ActionSerialization final
{
public:
static winrt::TerminalApp::Action FromJson(const Json::Value& json);
static Json::Value ToJson(const winrt::TerminalApp::Action& action);
};

View file

@ -33,6 +33,7 @@ namespace winrt::TerminalApp::implementation
_loadedInitialSettings{ false },
_settingsLoadedResult{ S_OK },
_dialogLock{},
_actionDispatch{},
_resourceLoader{ L"TerminalApp/Resources" }
{
// For your own sanity, it's better to do setup outside the ctor.
@ -73,6 +74,7 @@ namespace winrt::TerminalApp::implementation
_tabRow = terminalPage->TabRow();
_tabView = _tabRow.TabView();
_newTabButton = _tabRow.NewTabButton();
_commandPalette = terminalPage->_ActionList();
if (_settings->GlobalSettings().GetShowTabsInTitlebar())
{
@ -88,6 +90,18 @@ namespace winrt::TerminalApp::implementation
_setTitleBarContentHandlers(*this, _tabRow);
}
_RegisterActionCallbacks();
// TODO: Update the command palette when settings reload
auto actionsCollection = winrt::single_threaded_vector<winrt::TerminalApp::Action>();
for (auto& action : _settings->GlobalSettings().GetActions())
{
actionsCollection.Append(action);
}
_commandPalette.SetActions(actionsCollection);
_commandPalette.SetDispatch(_actionDispatch);
_commandPalette.Closed({ this, &App::_CommandPaletteClosed });
// Event Bindings (Early)
_newTabButton.Click([this](auto&&, auto&&) {
this->_OpenNewTab(std::nullopt);
@ -462,6 +476,37 @@ namespace winrt::TerminalApp::implementation
_ShowAboutDialog();
}
// Method Description:
// - TODO
// Arguments:
// - bindings: A AppKeyBindings object to wire up with our event handlers
void App::_RegisterActionCallbacks()
{
// 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.
_actionDispatch.NewTab([this]() { _OpenNewTab(std::nullopt); });
_actionDispatch.DuplicateTab([this]() { _DuplicateTabViewItem(); });
_actionDispatch.CloseTab([this]() { _CloseFocusedTab(); });
_actionDispatch.ClosePane([this]() { _CloseFocusedPane(); });
_actionDispatch.NewTabWithProfile([this](const auto index) { _OpenNewTab({ index }); });
_actionDispatch.ScrollUp([this]() { _Scroll(-1); });
_actionDispatch.ScrollDown([this]() { _Scroll(1); });
_actionDispatch.NextTab([this]() { _SelectNextTab(true); });
_actionDispatch.PrevTab([this]() { _SelectNextTab(false); });
_actionDispatch.SplitVertical([this]() { _SplitVertical(std::nullopt); });
_actionDispatch.SplitHorizontal([this]() { _SplitHorizontal(std::nullopt); });
_actionDispatch.ScrollUpPage([this]() { _ScrollPage(-1); });
_actionDispatch.ScrollDownPage([this]() { _ScrollPage(1); });
_actionDispatch.SwitchToTab([this](const auto index) { _SelectTab({ index }); });
_actionDispatch.OpenSettings([this]() { _OpenSettings(); });
_actionDispatch.ResizePane([this](const auto direction) { _ResizePane(direction); });
_actionDispatch.MoveFocus([this](const auto direction) { _MoveFocus(direction); });
_actionDispatch.CopyText([this](const auto trimWhitespace) { _CopyText(trimWhitespace); });
_actionDispatch.PasteText([this]() { _PasteText(); });
_actionDispatch.ToggleCommandPalette([this]() { _ToggleCommandPalette(); });
}
// Method Description:
// - Register our event handlers with the given keybindings object. This
// should be done regardless of what the events are actually bound to -
@ -471,28 +516,7 @@ namespace winrt::TerminalApp::implementation
// - bindings: A AppKeyBindings object to wire up with our event handlers
void App::_HookupKeyBindings(TerminalApp::AppKeyBindings bindings) noexcept
{
// 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.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.SetDispatch(_actionDispatch);
}
// Method Description:
@ -1089,6 +1113,11 @@ namespace winrt::TerminalApp::implementation
}
}
void App::_ToggleCommandPalette()
{
_commandPalette.ToggleVisibility();
}
// Method Description:
// - Responds to the TabView control's Selection Changed event (to move a
// new terminal control into focus.)
@ -1451,6 +1480,15 @@ namespace winrt::TerminalApp::implementation
}
}
void App::_CommandPaletteClosed(const IInspectable& /*sender*/,
const RoutedEventArgs& /*eventArgs*/)
{
// TODO return focus to the active control
// const int focusedTabIndex = _GetFocusedTabIndex();
// auto focusedTab = _tabs[focusedTabIndex];
// focusedTab->SetFocused(true);
}
// Method Description:
// - Creates a new connection based on the profile settings
// Arguments:

View file

@ -56,6 +56,7 @@ namespace winrt::TerminalApp::implementation
TerminalApp::TabRowControl _tabRow{ nullptr };
Windows::UI::Xaml::Controls::Grid _tabContent{ nullptr };
Windows::UI::Xaml::Controls::SplitButton _newTabButton{ nullptr };
TerminalApp::ActionList _commandPalette{ nullptr };
std::vector<std::shared_ptr<Tab>> _tabs;
@ -72,6 +73,8 @@ namespace winrt::TerminalApp::implementation
std::atomic<bool> _settingsReloadQueued{ false };
winrt::TerminalApp::ShortcutActionDispatch _actionDispatch{ nullptr };
void _CreateNewTabFlyout();
fire_and_forget _ShowDialog(const winrt::Windows::Foundation::IInspectable& titleElement,
@ -85,6 +88,7 @@ namespace winrt::TerminalApp::implementation
void _OpenSettings();
void _HookupKeyBindings(TerminalApp::AppKeyBindings bindings) noexcept;
void _RegisterActionCallbacks();
void _RegisterSettingsChange();
fire_and_forget _DispatchReloadSettings();
@ -125,6 +129,7 @@ namespace winrt::TerminalApp::implementation
void _ScrollPage(int delta);
void _ResizePane(const Direction& direction);
void _MoveFocus(const Direction& direction);
void _ToggleCommandPalette();
void _OnLoaded(const IInspectable& sender, const Windows::UI::Xaml::RoutedEventArgs& eventArgs);
void _OnTabSelectionChanged(const IInspectable& sender, const Windows::UI::Xaml::Controls::SelectionChangedEventArgs& eventArgs);
@ -132,6 +137,7 @@ namespace winrt::TerminalApp::implementation
void _OnTabItemsChanged(const IInspectable& sender, const Windows::Foundation::Collections::IVectorChangedEventArgs& eventArgs);
void _OnTabClick(const IInspectable& sender, const Windows::UI::Xaml::Input::PointerRoutedEventArgs& eventArgs);
void _OnContentSizeChanged(const IInspectable& sender, Windows::UI::Xaml::SizeChangedEventArgs const& e);
void _CommandPaletteClosed(const IInspectable& sender, const Windows::UI::Xaml::RoutedEventArgs& eventArgs);
void _RemoveTabViewItem(const IInspectable& tabViewItem);

View file

@ -9,10 +9,14 @@
using namespace winrt::Microsoft::Terminal;
using namespace winrt::TerminalApp;
using namespace winrt::Windows::Data::Json;
namespace winrt::TerminalApp::implementation
{
void AppKeyBindings::SetDispatch(const winrt::TerminalApp::ShortcutActionDispatch& dispatch)
{
_dispatch = dispatch;
}
void AppKeyBindings::SetKeyBinding(const TerminalApp::ShortcutAction& action,
const Settings::KeyChord& chord)
{
@ -37,155 +41,7 @@ namespace winrt::TerminalApp::implementation
if (keyIter != _keyShortcuts.end())
{
const auto action = keyIter->second;
return _DoAction(action);
}
return false;
}
bool AppKeyBindings::_DoAction(ShortcutAction action)
{
switch (action)
{
case ShortcutAction::CopyText:
_CopyTextHandlers(true);
return true;
case ShortcutAction::CopyTextWithoutNewlines:
_CopyTextHandlers(false);
return true;
case ShortcutAction::PasteText:
_PasteTextHandlers();
return true;
case ShortcutAction::NewTab:
_NewTabHandlers();
return true;
case ShortcutAction::DuplicateTab:
_DuplicateTabHandlers();
return true;
case ShortcutAction::OpenSettings:
_OpenSettingsHandlers();
return true;
case ShortcutAction::NewTabProfile0:
_NewTabWithProfileHandlers(0);
return true;
case ShortcutAction::NewTabProfile1:
_NewTabWithProfileHandlers(1);
return true;
case ShortcutAction::NewTabProfile2:
_NewTabWithProfileHandlers(2);
return true;
case ShortcutAction::NewTabProfile3:
_NewTabWithProfileHandlers(3);
return true;
case ShortcutAction::NewTabProfile4:
_NewTabWithProfileHandlers(4);
return true;
case ShortcutAction::NewTabProfile5:
_NewTabWithProfileHandlers(5);
return true;
case ShortcutAction::NewTabProfile6:
_NewTabWithProfileHandlers(6);
return true;
case ShortcutAction::NewTabProfile7:
_NewTabWithProfileHandlers(7);
return true;
case ShortcutAction::NewTabProfile8:
_NewTabWithProfileHandlers(8);
return true;
case ShortcutAction::NewWindow:
_NewWindowHandlers();
return true;
case ShortcutAction::CloseWindow:
_CloseWindowHandlers();
return true;
case ShortcutAction::CloseTab:
_CloseTabHandlers();
return true;
case ShortcutAction::ClosePane:
_ClosePaneHandlers();
return true;
case ShortcutAction::ScrollUp:
_ScrollUpHandlers();
return true;
case ShortcutAction::ScrollDown:
_ScrollDownHandlers();
return true;
case ShortcutAction::ScrollUpPage:
_ScrollUpPageHandlers();
return true;
case ShortcutAction::ScrollDownPage:
_ScrollDownPageHandlers();
return true;
case ShortcutAction::NextTab:
_NextTabHandlers();
return true;
case ShortcutAction::PrevTab:
_PrevTabHandlers();
return true;
case ShortcutAction::SplitVertical:
_SplitVerticalHandlers();
return true;
case ShortcutAction::SplitHorizontal:
_SplitHorizontalHandlers();
return true;
case ShortcutAction::SwitchToTab0:
_SwitchToTabHandlers(0);
return true;
case ShortcutAction::SwitchToTab1:
_SwitchToTabHandlers(1);
return true;
case ShortcutAction::SwitchToTab2:
_SwitchToTabHandlers(2);
return true;
case ShortcutAction::SwitchToTab3:
_SwitchToTabHandlers(3);
return true;
case ShortcutAction::SwitchToTab4:
_SwitchToTabHandlers(4);
return true;
case ShortcutAction::SwitchToTab5:
_SwitchToTabHandlers(5);
return true;
case ShortcutAction::SwitchToTab6:
_SwitchToTabHandlers(6);
return true;
case ShortcutAction::SwitchToTab7:
_SwitchToTabHandlers(7);
return true;
case ShortcutAction::SwitchToTab8:
_SwitchToTabHandlers(8);
return true;
case ShortcutAction::ResizePaneLeft:
_ResizePaneHandlers(Direction::Left);
return true;
case ShortcutAction::ResizePaneRight:
_ResizePaneHandlers(Direction::Right);
return true;
case ShortcutAction::ResizePaneUp:
_ResizePaneHandlers(Direction::Up);
return true;
case ShortcutAction::ResizePaneDown:
_ResizePaneHandlers(Direction::Down);
return true;
case ShortcutAction::MoveFocusLeft:
_MoveFocusHandlers(Direction::Left);
return true;
case ShortcutAction::MoveFocusRight:
_MoveFocusHandlers(Direction::Right);
return true;
case ShortcutAction::MoveFocusUp:
_MoveFocusHandlers(Direction::Up);
return true;
case ShortcutAction::MoveFocusDown:
_MoveFocusHandlers(Direction::Down);
return true;
default:
return false;
return _dispatch.DoAction(action);
}
return false;
}
@ -215,30 +71,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, 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

@ -31,6 +31,7 @@ namespace winrt::TerminalApp::implementation
struct AppKeyBindings : AppKeyBindingsT<AppKeyBindings>
{
AppKeyBindings() = default;
void SetDispatch(const winrt::TerminalApp::ShortcutActionDispatch& dispatch);
bool TryKeyChord(winrt::Microsoft::Terminal::Settings::KeyChord const& kc);
void SetKeyBinding(TerminalApp::ShortcutAction const& action, winrt::Microsoft::Terminal::Settings::KeyChord const& chord);
@ -38,35 +39,9 @@ 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(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);
// clang-format on
private:
std::unordered_map<winrt::Microsoft::Terminal::Settings::KeyChord, TerminalApp::ShortcutAction, KeyChordHash, KeyChordEquality> _keyShortcuts;
bool _DoAction(ShortcutAction action);
winrt::TerminalApp::ShortcutActionDispatch _dispatch{ nullptr };
};
}

View file

@ -1,119 +1,16 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import "../ShortcutActionDispatch.idl";
namespace TerminalApp
{
enum Direction
{
Left = 0,
Right,
Up,
Down
};
enum ShortcutAction
{
CopyText = 0,
CopyTextWithoutNewlines,
PasteText,
NewTab,
DuplicateTab,
NewTabProfile0,
NewTabProfile1,
NewTabProfile2,
NewTabProfile3,
NewTabProfile4,
NewTabProfile5,
NewTabProfile6,
NewTabProfile7,
NewTabProfile8,
NewWindow,
CloseWindow,
CloseTab,
ClosePane,
NextTab,
PrevTab,
SplitVertical,
SplitHorizontal,
SwitchToTab0,
SwitchToTab1,
SwitchToTab2,
SwitchToTab3,
SwitchToTab4,
SwitchToTab5,
SwitchToTab6,
SwitchToTab7,
SwitchToTab8,
IncreaseFontSize,
DecreaseFontSize,
ScrollUp,
ScrollDown,
ScrollUpPage,
ScrollDownPage,
ResizePaneLeft,
ResizePaneRight,
ResizePaneUp,
ResizePaneDown,
MoveFocusLeft,
MoveFocusRight,
MoveFocusUp,
MoveFocusDown,
OpenSettings
};
delegate void CopyTextEventArgs(Boolean trimWhitespace);
delegate void PasteTextEventArgs();
delegate void NewTabEventArgs();
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();
void SetDispatch(ShortcutActionDispatch dispatch);
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 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;
}
}

View file

@ -5,6 +5,7 @@
#include "AppKeyBindingsSerialization.h"
#include "KeyChordSerialization.h"
#include "Utils.h"
#include "ShortcutActionSerializationKeys.h"
#include <winrt/Microsoft.Terminal.Settings.h>
using namespace winrt::Microsoft::Terminal::Settings;
@ -13,111 +14,6 @@ using namespace winrt::TerminalApp;
static constexpr std::string_view KeysKey{ "keys" };
static constexpr std::string_view CommandKey{ "command" };
static constexpr std::string_view CopyTextKey{ "copy" };
static constexpr std::string_view CopyTextWithoutNewlinesKey{ "copyTextWithoutNewlines" };
static constexpr std::string_view PasteTextKey{ "paste" };
static constexpr std::string_view NewTabKey{ "newTab" };
static constexpr std::string_view DuplicateTabKey{ "duplicateTab" };
static constexpr std::string_view NewTabWithProfile0Key{ "newTabProfile0" };
static constexpr std::string_view NewTabWithProfile1Key{ "newTabProfile1" };
static constexpr std::string_view NewTabWithProfile2Key{ "newTabProfile2" };
static constexpr std::string_view NewTabWithProfile3Key{ "newTabProfile3" };
static constexpr std::string_view NewTabWithProfile4Key{ "newTabProfile4" };
static constexpr std::string_view NewTabWithProfile5Key{ "newTabProfile5" };
static constexpr std::string_view NewTabWithProfile6Key{ "newTabProfile6" };
static constexpr std::string_view NewTabWithProfile7Key{ "newTabProfile7" };
static constexpr std::string_view NewTabWithProfile8Key{ "newTabProfile8" };
static constexpr std::string_view NewWindowKey{ "newWindow" };
static constexpr std::string_view CloseWindowKey{ "closeWindow" };
static constexpr std::string_view CloseTabKey{ "closeTab" };
static constexpr std::string_view ClosePaneKey{ "closePane" };
static constexpr std::string_view SwitchtoTabKey{ "switchToTab" };
static constexpr std::string_view NextTabKey{ "nextTab" };
static constexpr std::string_view PrevTabKey{ "prevTab" };
static constexpr std::string_view IncreaseFontSizeKey{ "increaseFontSize" };
static constexpr std::string_view DecreaseFontSizeKey{ "decreaseFontSize" };
static constexpr std::string_view ScrollupKey{ "scrollUp" };
static constexpr std::string_view ScrolldownKey{ "scrollDown" };
static constexpr std::string_view ScrolluppageKey{ "scrollUpPage" };
static constexpr std::string_view ScrolldownpageKey{ "scrollDownPage" };
static constexpr std::string_view SwitchToTab0Key{ "switchToTab0" };
static constexpr std::string_view SwitchToTab1Key{ "switchToTab1" };
static constexpr std::string_view SwitchToTab2Key{ "switchToTab2" };
static constexpr std::string_view SwitchToTab3Key{ "switchToTab3" };
static constexpr std::string_view SwitchToTab4Key{ "switchToTab4" };
static constexpr std::string_view SwitchToTab5Key{ "switchToTab5" };
static constexpr std::string_view SwitchToTab6Key{ "switchToTab6" };
static constexpr std::string_view SwitchToTab7Key{ "switchToTab7" };
static constexpr std::string_view SwitchToTab8Key{ "switchToTab8" };
static constexpr std::string_view OpenSettingsKey{ "openSettings" };
static constexpr std::string_view SplitHorizontalKey{ "splitHorizontal" };
static constexpr std::string_view SplitVerticalKey{ "splitVertical" };
static constexpr std::string_view ResizePaneLeftKey{ "resizePaneLeft" };
static constexpr std::string_view ResizePaneRightKey{ "resizePaneRight" };
static constexpr std::string_view ResizePaneUpKey{ "resizePaneUp" };
static constexpr std::string_view ResizePaneDownKey{ "resizePaneDown" };
static constexpr std::string_view MoveFocusLeftKey{ "moveFocusLeft" };
static constexpr std::string_view MoveFocusRightKey{ "moveFocusRight" };
static constexpr std::string_view MoveFocusUpKey{ "moveFocusUp" };
static constexpr std::string_view MoveFocusDownKey{ "moveFocusDown" };
// Specifically use a map here over an unordered_map. We want to be able to
// iterate over these entries in-order when we're serializing the keybindings.
// HERE BE DRAGONS:
// These are string_views that are being used as keys. These string_views are
// just pointers to other strings. This could be dangerous, if the map outlived
// the actual strings being pointed to. However, since both these strings and
// the map are all const for the lifetime of the app, we have nothing to worry
// about here.
static const std::map<std::string_view, ShortcutAction, std::less<>> commandNames{
{ CopyTextKey, ShortcutAction::CopyText },
{ CopyTextWithoutNewlinesKey, ShortcutAction::CopyTextWithoutNewlines },
{ PasteTextKey, ShortcutAction::PasteText },
{ NewTabKey, ShortcutAction::NewTab },
{ DuplicateTabKey, ShortcutAction::DuplicateTab },
{ NewTabWithProfile0Key, ShortcutAction::NewTabProfile0 },
{ NewTabWithProfile1Key, ShortcutAction::NewTabProfile1 },
{ NewTabWithProfile2Key, ShortcutAction::NewTabProfile2 },
{ NewTabWithProfile3Key, ShortcutAction::NewTabProfile3 },
{ NewTabWithProfile4Key, ShortcutAction::NewTabProfile4 },
{ NewTabWithProfile5Key, ShortcutAction::NewTabProfile5 },
{ NewTabWithProfile6Key, ShortcutAction::NewTabProfile6 },
{ NewTabWithProfile7Key, ShortcutAction::NewTabProfile7 },
{ NewTabWithProfile8Key, ShortcutAction::NewTabProfile8 },
{ NewWindowKey, ShortcutAction::NewWindow },
{ CloseWindowKey, ShortcutAction::CloseWindow },
{ CloseTabKey, ShortcutAction::CloseTab },
{ ClosePaneKey, ShortcutAction::ClosePane },
{ NextTabKey, ShortcutAction::NextTab },
{ PrevTabKey, ShortcutAction::PrevTab },
{ IncreaseFontSizeKey, ShortcutAction::IncreaseFontSize },
{ DecreaseFontSizeKey, ShortcutAction::DecreaseFontSize },
{ ScrollupKey, ShortcutAction::ScrollUp },
{ ScrolldownKey, ShortcutAction::ScrollDown },
{ ScrolluppageKey, ShortcutAction::ScrollUpPage },
{ ScrolldownpageKey, ShortcutAction::ScrollDownPage },
{ SwitchToTab0Key, ShortcutAction::SwitchToTab0 },
{ SwitchToTab1Key, ShortcutAction::SwitchToTab1 },
{ SwitchToTab2Key, ShortcutAction::SwitchToTab2 },
{ SwitchToTab3Key, ShortcutAction::SwitchToTab3 },
{ SwitchToTab4Key, ShortcutAction::SwitchToTab4 },
{ SwitchToTab5Key, ShortcutAction::SwitchToTab5 },
{ SwitchToTab6Key, ShortcutAction::SwitchToTab6 },
{ SwitchToTab7Key, ShortcutAction::SwitchToTab7 },
{ SwitchToTab8Key, ShortcutAction::SwitchToTab8 },
{ SplitHorizontalKey, ShortcutAction::SplitHorizontal },
{ SplitVerticalKey, ShortcutAction::SplitVertical },
{ ResizePaneLeftKey, ShortcutAction::ResizePaneLeft },
{ ResizePaneRightKey, ShortcutAction::ResizePaneRight },
{ ResizePaneUpKey, ShortcutAction::ResizePaneUp },
{ ResizePaneDownKey, ShortcutAction::ResizePaneDown },
{ MoveFocusLeftKey, ShortcutAction::MoveFocusLeft },
{ MoveFocusRightKey, ShortcutAction::MoveFocusRight },
{ MoveFocusUpKey, ShortcutAction::MoveFocusUp },
{ MoveFocusDownKey, ShortcutAction::MoveFocusDown },
{ OpenSettingsKey, ShortcutAction::OpenSettings },
};
// Function Description:
// - Small helper to create a json value serialization of a single
// KeyBinding->Action maping. The created object is of schema:

View file

@ -6,16 +6,17 @@
#include "../../types/inc/Utils.hpp"
#include "../../inc/DefaultSettings.h"
#include "AppKeyBindingsSerialization.h"
#include "ActionSerialization.h"
#include "Utils.h"
using namespace TerminalApp;
using namespace winrt::Microsoft::Terminal::Settings;
using namespace winrt::TerminalApp;
using namespace winrt::Windows::Data::Json;
using namespace winrt::Windows::UI::Xaml;
using namespace ::Microsoft::Console;
static constexpr std::string_view KeybindingsKey{ "keybindings" };
static constexpr std::string_view ActionsKey{ "actions" };
static constexpr std::string_view DefaultProfileKey{ "defaultProfile" };
static constexpr std::string_view AlwaysShowTabsKey{ "alwaysShowTabs" };
static constexpr std::string_view InitialRowsKey{ "initialRows" };
@ -31,6 +32,7 @@ static constexpr std::wstring_view SystemThemeValue{ L"system" };
GlobalAppSettings::GlobalAppSettings() :
_keybindings{},
_actions{},
_colorSchemes{},
_defaultProfile{},
_alwaysShowTabs{ true },
@ -57,6 +59,11 @@ std::vector<ColorScheme>& GlobalAppSettings::GetColorSchemes() noexcept
return _colorSchemes;
}
const std::vector<winrt::TerminalApp::Action>& GlobalAppSettings::GetActions() const noexcept
{
return _actions;
}
void GlobalAppSettings::SetDefaultProfile(const GUID defaultProfile) noexcept
{
_defaultProfile = defaultProfile;
@ -163,6 +170,17 @@ Json::Value GlobalAppSettings::ToJson() const
jsonObject[JsonKey(RequestedThemeKey)] = winrt::to_string(_SerializeTheme(_requestedTheme));
jsonObject[JsonKey(KeybindingsKey)] = AppKeyBindingsSerialization::ToJson(_keybindings);
Json::Value actionsArrayJson;
for (const auto& action : _actions)
{
try
{
actionsArrayJson.append(ActionSerialization::ToJson(action));
}
CATCH_LOG();
}
jsonObject[JsonKey(ActionsKey)] = actionsArrayJson;
return jsonObject;
}
@ -220,6 +238,21 @@ GlobalAppSettings GlobalAppSettings::FromJson(const Json::Value& json)
result._keybindings = AppKeyBindingsSerialization::FromJson(keybindings);
}
if (auto actionsArray{ json[JsonKey(ActionsKey)] })
{
for (const auto& value : actionsArray)
{
if (value.isObject())
{
try
{
result._actions.push_back(ActionSerialization::FromJson(value));
}
CATCH_LOG();
}
}
}
return result;
}

View file

@ -16,6 +16,7 @@ Author(s):
#pragma once
#include "AppKeyBindings.h"
#include "ColorScheme.h"
#include "Action.h"
namespace TerminalApp
{
@ -57,11 +58,14 @@ public:
void ApplyToSettings(winrt::Microsoft::Terminal::Settings::TerminalSettings& settings) const noexcept;
const std::vector<winrt::TerminalApp::Action>& GetActions() const noexcept;
private:
GUID _defaultProfile;
winrt::TerminalApp::AppKeyBindings _keybindings;
std::vector<ColorScheme> _colorSchemes;
std::vector<winrt::TerminalApp::Action> _actions;
int32_t _initialRows;
int32_t _initialCols;

View file

@ -0,0 +1,195 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
#include "pch.h"
#include "ShortcutActionDispatch.h"
#include "KeyChordSerialization.h"
#include "ShortcutActionDispatch.g.cpp"
using namespace winrt::Microsoft::Terminal;
using namespace winrt::TerminalApp;
using namespace winrt::Windows::Data::Json;
namespace winrt::TerminalApp::implementation
{
bool ShortcutActionDispatch::DoAction(ShortcutAction action)
{
switch (action)
{
case ShortcutAction::CopyText:
_CopyTextHandlers(true);
return true;
case ShortcutAction::CopyTextWithoutNewlines:
_CopyTextHandlers(false);
return true;
case ShortcutAction::PasteText:
_PasteTextHandlers();
return true;
case ShortcutAction::NewTab:
_NewTabHandlers();
return true;
case ShortcutAction::DuplicateTab:
_DuplicateTabHandlers();
return true;
case ShortcutAction::OpenSettings:
_OpenSettingsHandlers();
return true;
case ShortcutAction::NewTabProfile0:
_NewTabWithProfileHandlers(0);
return true;
case ShortcutAction::NewTabProfile1:
_NewTabWithProfileHandlers(1);
return true;
case ShortcutAction::NewTabProfile2:
_NewTabWithProfileHandlers(2);
return true;
case ShortcutAction::NewTabProfile3:
_NewTabWithProfileHandlers(3);
return true;
case ShortcutAction::NewTabProfile4:
_NewTabWithProfileHandlers(4);
return true;
case ShortcutAction::NewTabProfile5:
_NewTabWithProfileHandlers(5);
return true;
case ShortcutAction::NewTabProfile6:
_NewTabWithProfileHandlers(6);
return true;
case ShortcutAction::NewTabProfile7:
_NewTabWithProfileHandlers(7);
return true;
case ShortcutAction::NewTabProfile8:
_NewTabWithProfileHandlers(8);
return true;
case ShortcutAction::NewWindow:
_NewWindowHandlers();
return true;
case ShortcutAction::CloseWindow:
_CloseWindowHandlers();
return true;
case ShortcutAction::CloseTab:
_CloseTabHandlers();
return true;
case ShortcutAction::ClosePane:
_ClosePaneHandlers();
return true;
case ShortcutAction::ScrollUp:
_ScrollUpHandlers();
return true;
case ShortcutAction::ScrollDown:
_ScrollDownHandlers();
return true;
case ShortcutAction::ScrollUpPage:
_ScrollUpPageHandlers();
return true;
case ShortcutAction::ScrollDownPage:
_ScrollDownPageHandlers();
return true;
case ShortcutAction::NextTab:
_NextTabHandlers();
return true;
case ShortcutAction::PrevTab:
_PrevTabHandlers();
return true;
case ShortcutAction::SplitVertical:
_SplitVerticalHandlers();
return true;
case ShortcutAction::SplitHorizontal:
_SplitHorizontalHandlers();
return true;
case ShortcutAction::SwitchToTab0:
_SwitchToTabHandlers(0);
return true;
case ShortcutAction::SwitchToTab1:
_SwitchToTabHandlers(1);
return true;
case ShortcutAction::SwitchToTab2:
_SwitchToTabHandlers(2);
return true;
case ShortcutAction::SwitchToTab3:
_SwitchToTabHandlers(3);
return true;
case ShortcutAction::SwitchToTab4:
_SwitchToTabHandlers(4);
return true;
case ShortcutAction::SwitchToTab5:
_SwitchToTabHandlers(5);
return true;
case ShortcutAction::SwitchToTab6:
_SwitchToTabHandlers(6);
return true;
case ShortcutAction::SwitchToTab7:
_SwitchToTabHandlers(7);
return true;
case ShortcutAction::SwitchToTab8:
_SwitchToTabHandlers(8);
return true;
case ShortcutAction::ResizePaneLeft:
_ResizePaneHandlers(Direction::Left);
return true;
case ShortcutAction::ResizePaneRight:
_ResizePaneHandlers(Direction::Right);
return true;
case ShortcutAction::ResizePaneUp:
_ResizePaneHandlers(Direction::Up);
return true;
case ShortcutAction::ResizePaneDown:
_ResizePaneHandlers(Direction::Down);
return true;
case ShortcutAction::MoveFocusLeft:
_MoveFocusHandlers(Direction::Left);
return true;
case ShortcutAction::MoveFocusRight:
_MoveFocusHandlers(Direction::Right);
return true;
case ShortcutAction::MoveFocusUp:
_MoveFocusHandlers(Direction::Up);
return true;
case ShortcutAction::MoveFocusDown:
_MoveFocusHandlers(Direction::Down);
return true;
case ShortcutAction::ToggleCommandPalette:
_ToggleCommandPaletteHandlers();
return true;
default:
return false;
}
return false;
}
// -------------------------------- Events ---------------------------------
// clang-format off
DEFINE_EVENT(ShortcutActionDispatch, CopyText, _CopyTextHandlers, TerminalApp::CopyTextEventArgs);
DEFINE_EVENT(ShortcutActionDispatch, PasteText, _PasteTextHandlers, TerminalApp::PasteTextEventArgs);
DEFINE_EVENT(ShortcutActionDispatch, NewTab, _NewTabHandlers, TerminalApp::NewTabEventArgs);
DEFINE_EVENT(ShortcutActionDispatch, DuplicateTab, _DuplicateTabHandlers, TerminalApp::DuplicateTabEventArgs);
DEFINE_EVENT(ShortcutActionDispatch, NewTabWithProfile, _NewTabWithProfileHandlers, TerminalApp::NewTabWithProfileEventArgs);
DEFINE_EVENT(ShortcutActionDispatch, NewWindow, _NewWindowHandlers, TerminalApp::NewWindowEventArgs);
DEFINE_EVENT(ShortcutActionDispatch, CloseWindow, _CloseWindowHandlers, TerminalApp::CloseWindowEventArgs);
DEFINE_EVENT(ShortcutActionDispatch, CloseTab, _CloseTabHandlers, TerminalApp::CloseTabEventArgs);
DEFINE_EVENT(ShortcutActionDispatch, ClosePane, _ClosePaneHandlers, TerminalApp::ClosePaneEventArgs);
DEFINE_EVENT(ShortcutActionDispatch, SwitchToTab, _SwitchToTabHandlers, TerminalApp::SwitchToTabEventArgs);
DEFINE_EVENT(ShortcutActionDispatch, NextTab, _NextTabHandlers, TerminalApp::NextTabEventArgs);
DEFINE_EVENT(ShortcutActionDispatch, PrevTab, _PrevTabHandlers, TerminalApp::PrevTabEventArgs);
DEFINE_EVENT(ShortcutActionDispatch, SplitVertical, _SplitVerticalHandlers, TerminalApp::SplitVerticalEventArgs);
DEFINE_EVENT(ShortcutActionDispatch, SplitHorizontal, _SplitHorizontalHandlers, TerminalApp::SplitHorizontalEventArgs);
DEFINE_EVENT(ShortcutActionDispatch, IncreaseFontSize, _IncreaseFontSizeHandlers, TerminalApp::IncreaseFontSizeEventArgs);
DEFINE_EVENT(ShortcutActionDispatch, DecreaseFontSize, _DecreaseFontSizeHandlers, TerminalApp::DecreaseFontSizeEventArgs);
DEFINE_EVENT(ShortcutActionDispatch, ScrollUp, _ScrollUpHandlers, TerminalApp::ScrollUpEventArgs);
DEFINE_EVENT(ShortcutActionDispatch, ScrollDown, _ScrollDownHandlers, TerminalApp::ScrollDownEventArgs);
DEFINE_EVENT(ShortcutActionDispatch, ScrollUpPage, _ScrollUpPageHandlers, TerminalApp::ScrollUpPageEventArgs);
DEFINE_EVENT(ShortcutActionDispatch, ScrollDownPage, _ScrollDownPageHandlers, TerminalApp::ScrollDownPageEventArgs);
DEFINE_EVENT(ShortcutActionDispatch, OpenSettings, _OpenSettingsHandlers, TerminalApp::OpenSettingsEventArgs);
DEFINE_EVENT(ShortcutActionDispatch, ResizePane, _ResizePaneHandlers, TerminalApp::ResizePaneEventArgs);
DEFINE_EVENT(ShortcutActionDispatch, MoveFocus, _MoveFocusHandlers, TerminalApp::MoveFocusEventArgs);
DEFINE_EVENT(ShortcutActionDispatch, ToggleCommandPalette, _ToggleCommandPaletteHandlers, TerminalApp::ToggleCommandPaletteEventArgs);
// Adding an event here? make sure to add to ShortcutActionSerializationKeys too!
// clang-format on
}

View file

@ -0,0 +1,51 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
#pragma once
#include "ShortcutActionDispatch.g.h"
#include "..\inc\cppwinrt_utils.h"
namespace winrt::TerminalApp::implementation
{
struct ShortcutActionDispatch : ShortcutActionDispatchT<ShortcutActionDispatch>
{
ShortcutActionDispatch() = default;
bool DoAction(ShortcutAction action);
// clang-format off
DECLARE_EVENT(CopyText, _CopyTextHandlers, TerminalApp::CopyTextEventArgs);
DECLARE_EVENT(PasteText, _PasteTextHandlers, TerminalApp::PasteTextEventArgs);
DECLARE_EVENT(NewTab, _NewTabHandlers, TerminalApp::NewTabEventArgs);
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);
DECLARE_EVENT(ToggleCommandPalette, _ToggleCommandPaletteHandlers, TerminalApp::ToggleCommandPaletteEventArgs);
// clang-format on
};
}
namespace winrt::TerminalApp::factory_implementation
{
struct ShortcutActionDispatch : ShortcutActionDispatchT<ShortcutActionDispatch, implementation::ShortcutActionDispatch>
{
};
}

View file

@ -0,0 +1,120 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
namespace TerminalApp
{
enum Direction
{
Left = 0,
Right,
Up,
Down
};
enum ShortcutAction
{
CopyText = 0,
CopyTextWithoutNewlines,
PasteText,
NewTab,
DuplicateTab,
NewTabProfile0,
NewTabProfile1,
NewTabProfile2,
NewTabProfile3,
NewTabProfile4,
NewTabProfile5,
NewTabProfile6,
NewTabProfile7,
NewTabProfile8,
NewWindow,
CloseWindow,
CloseTab,
ClosePane,
NextTab,
PrevTab,
SplitVertical,
SplitHorizontal,
SwitchToTab0,
SwitchToTab1,
SwitchToTab2,
SwitchToTab3,
SwitchToTab4,
SwitchToTab5,
SwitchToTab6,
SwitchToTab7,
SwitchToTab8,
IncreaseFontSize,
DecreaseFontSize,
ScrollUp,
ScrollDown,
ScrollUpPage,
ScrollDownPage,
ResizePaneLeft,
ResizePaneRight,
ResizePaneUp,
ResizePaneDown,
MoveFocusLeft,
MoveFocusRight,
MoveFocusUp,
MoveFocusDown,
ToggleCommandPalette,
OpenSettings
};
delegate void CopyTextEventArgs(Boolean trimWhitespace);
delegate void PasteTextEventArgs();
delegate void NewTabEventArgs();
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);
delegate void ToggleCommandPaletteEventArgs();
[default_interface] runtimeclass ShortcutActionDispatch {
ShortcutActionDispatch();
Boolean DoAction(ShortcutAction action);
event CopyTextEventArgs CopyText;
event PasteTextEventArgs PasteText;
event NewTabEventArgs NewTab;
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 ToggleCommandPaletteEventArgs ToggleCommandPalette;
}
}

View file

@ -0,0 +1,109 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
constexpr std::string_view CopyTextKey{ "copy" };
constexpr std::string_view CopyTextWithoutNewlinesKey{ "copyTextWithoutNewlines" };
constexpr std::string_view PasteTextKey{ "paste" };
constexpr std::string_view NewTabKey{ "newTab" };
constexpr std::string_view DuplicateTabKey{ "duplicateTab" };
constexpr std::string_view NewTabWithProfile0Key{ "newTabProfile0" };
constexpr std::string_view NewTabWithProfile1Key{ "newTabProfile1" };
constexpr std::string_view NewTabWithProfile2Key{ "newTabProfile2" };
constexpr std::string_view NewTabWithProfile3Key{ "newTabProfile3" };
constexpr std::string_view NewTabWithProfile4Key{ "newTabProfile4" };
constexpr std::string_view NewTabWithProfile5Key{ "newTabProfile5" };
constexpr std::string_view NewTabWithProfile6Key{ "newTabProfile6" };
constexpr std::string_view NewTabWithProfile7Key{ "newTabProfile7" };
constexpr std::string_view NewTabWithProfile8Key{ "newTabProfile8" };
constexpr std::string_view NewWindowKey{ "newWindow" };
constexpr std::string_view CloseWindowKey{ "closeWindow" };
constexpr std::string_view CloseTabKey{ "closeTab" };
constexpr std::string_view ClosePaneKey{ "closePane" };
constexpr std::string_view SwitchtoTabKey{ "switchToTab" };
constexpr std::string_view NextTabKey{ "nextTab" };
constexpr std::string_view PrevTabKey{ "prevTab" };
constexpr std::string_view IncreaseFontSizeKey{ "increaseFontSize" };
constexpr std::string_view DecreaseFontSizeKey{ "decreaseFontSize" };
constexpr std::string_view ScrollupKey{ "scrollUp" };
constexpr std::string_view ScrolldownKey{ "scrollDown" };
constexpr std::string_view ScrolluppageKey{ "scrollUpPage" };
constexpr std::string_view ScrolldownpageKey{ "scrollDownPage" };
constexpr std::string_view SwitchToTab0Key{ "switchToTab0" };
constexpr std::string_view SwitchToTab1Key{ "switchToTab1" };
constexpr std::string_view SwitchToTab2Key{ "switchToTab2" };
constexpr std::string_view SwitchToTab3Key{ "switchToTab3" };
constexpr std::string_view SwitchToTab4Key{ "switchToTab4" };
constexpr std::string_view SwitchToTab5Key{ "switchToTab5" };
constexpr std::string_view SwitchToTab6Key{ "switchToTab6" };
constexpr std::string_view SwitchToTab7Key{ "switchToTab7" };
constexpr std::string_view SwitchToTab8Key{ "switchToTab8" };
constexpr std::string_view OpenSettingsKey{ "openSettings" };
constexpr std::string_view SplitHorizontalKey{ "splitHorizontal" };
constexpr std::string_view SplitVerticalKey{ "splitVertical" };
constexpr std::string_view ResizePaneLeftKey{ "resizePaneLeft" };
constexpr std::string_view ResizePaneRightKey{ "resizePaneRight" };
constexpr std::string_view ResizePaneUpKey{ "resizePaneUp" };
constexpr std::string_view ResizePaneDownKey{ "resizePaneDown" };
constexpr std::string_view MoveFocusLeftKey{ "moveFocusLeft" };
constexpr std::string_view MoveFocusRightKey{ "moveFocusRight" };
constexpr std::string_view MoveFocusUpKey{ "moveFocusUp" };
constexpr std::string_view MoveFocusDownKey{ "moveFocusDown" };
constexpr std::string_view ToggleCommandPaletteKey{ "toggleCommandPalette" };
// Specifically use a map here over an unordered_map. We want to be able to
// iterate over these entries in-order when we're serializing the keybindings.
// HERE BE DRAGONS:
// These are string_views that are being used as keys. These string_views are
// just pointers to other strings. This could be dangerous, if the map outlived
// the actual strings being pointed to. However, since both these strings and
// the map are all const for the lifetime of the app, we have nothing to worry
// about here.
const std::map<std::string_view, winrt::TerminalApp::ShortcutAction, std::less<>> commandNames{
{ CopyTextKey, winrt::TerminalApp::ShortcutAction::CopyText },
{ CopyTextWithoutNewlinesKey, winrt::TerminalApp::ShortcutAction::CopyTextWithoutNewlines },
{ PasteTextKey, winrt::TerminalApp::ShortcutAction::PasteText },
{ NewTabKey, winrt::TerminalApp::ShortcutAction::NewTab },
{ DuplicateTabKey, winrt::TerminalApp::ShortcutAction::DuplicateTab },
{ NewTabWithProfile0Key, winrt::TerminalApp::ShortcutAction::NewTabProfile0 },
{ NewTabWithProfile1Key, winrt::TerminalApp::ShortcutAction::NewTabProfile1 },
{ NewTabWithProfile2Key, winrt::TerminalApp::ShortcutAction::NewTabProfile2 },
{ NewTabWithProfile3Key, winrt::TerminalApp::ShortcutAction::NewTabProfile3 },
{ NewTabWithProfile4Key, winrt::TerminalApp::ShortcutAction::NewTabProfile4 },
{ NewTabWithProfile5Key, winrt::TerminalApp::ShortcutAction::NewTabProfile5 },
{ NewTabWithProfile6Key, winrt::TerminalApp::ShortcutAction::NewTabProfile6 },
{ NewTabWithProfile7Key, winrt::TerminalApp::ShortcutAction::NewTabProfile7 },
{ NewTabWithProfile8Key, winrt::TerminalApp::ShortcutAction::NewTabProfile8 },
{ NewWindowKey, winrt::TerminalApp::ShortcutAction::NewWindow },
{ CloseWindowKey, winrt::TerminalApp::ShortcutAction::CloseWindow },
{ CloseTabKey, winrt::TerminalApp::ShortcutAction::CloseTab },
{ ClosePaneKey, winrt::TerminalApp::ShortcutAction::ClosePane },
{ NextTabKey, winrt::TerminalApp::ShortcutAction::NextTab },
{ PrevTabKey, winrt::TerminalApp::ShortcutAction::PrevTab },
{ IncreaseFontSizeKey, winrt::TerminalApp::ShortcutAction::IncreaseFontSize },
{ DecreaseFontSizeKey, winrt::TerminalApp::ShortcutAction::DecreaseFontSize },
{ ScrollupKey, winrt::TerminalApp::ShortcutAction::ScrollUp },
{ ScrolldownKey, winrt::TerminalApp::ShortcutAction::ScrollDown },
{ ScrolluppageKey, winrt::TerminalApp::ShortcutAction::ScrollUpPage },
{ ScrolldownpageKey, winrt::TerminalApp::ShortcutAction::ScrollDownPage },
{ SwitchToTab0Key, winrt::TerminalApp::ShortcutAction::SwitchToTab0 },
{ SwitchToTab1Key, winrt::TerminalApp::ShortcutAction::SwitchToTab1 },
{ SwitchToTab2Key, winrt::TerminalApp::ShortcutAction::SwitchToTab2 },
{ SwitchToTab3Key, winrt::TerminalApp::ShortcutAction::SwitchToTab3 },
{ SwitchToTab4Key, winrt::TerminalApp::ShortcutAction::SwitchToTab4 },
{ SwitchToTab5Key, winrt::TerminalApp::ShortcutAction::SwitchToTab5 },
{ SwitchToTab6Key, winrt::TerminalApp::ShortcutAction::SwitchToTab6 },
{ SwitchToTab7Key, winrt::TerminalApp::ShortcutAction::SwitchToTab7 },
{ SwitchToTab8Key, winrt::TerminalApp::ShortcutAction::SwitchToTab8 },
{ SplitHorizontalKey, winrt::TerminalApp::ShortcutAction::SplitHorizontal },
{ SplitVerticalKey, winrt::TerminalApp::ShortcutAction::SplitVertical },
{ ResizePaneLeftKey, winrt::TerminalApp::ShortcutAction::ResizePaneLeft },
{ ResizePaneRightKey, winrt::TerminalApp::ShortcutAction::ResizePaneRight },
{ ResizePaneUpKey, winrt::TerminalApp::ShortcutAction::ResizePaneUp },
{ ResizePaneDownKey, winrt::TerminalApp::ShortcutAction::ResizePaneDown },
{ MoveFocusLeftKey, winrt::TerminalApp::ShortcutAction::MoveFocusLeft },
{ MoveFocusRightKey, winrt::TerminalApp::ShortcutAction::MoveFocusRight },
{ MoveFocusUpKey, winrt::TerminalApp::ShortcutAction::MoveFocusUp },
{ MoveFocusDownKey, winrt::TerminalApp::ShortcutAction::MoveFocusDown },
{ OpenSettingsKey, winrt::TerminalApp::ShortcutAction::OpenSettings },
{ ToggleCommandPaletteKey, winrt::TerminalApp::ShortcutAction::ToggleCommandPalette },
};

View file

@ -19,5 +19,11 @@ the MIT License. See LICENSE in the project root for license information. -->
<local:TabRowControl x:Name="TabRow" Grid.Row="0" />
<Grid x:Name="TabContent" Grid.Row="1" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" />
<local:ActionList
x:Name="_ActionList"
Grid.Row="1"
Visibility="Collapsed"
VerticalAlignment="Top" />
</Grid>
</Page>

View file

@ -41,6 +41,9 @@
<Page Include="../TabRowControl.xaml">
<SubType>Designer</SubType>
</Page>
<Page Include="../ActionList.xaml">
<SubType>Designer</SubType>
</Page>
</ItemGroup>
<!-- ========================= Headers ======================== -->
@ -59,6 +62,9 @@
<ClInclude Include="../TabRowControl.h">
<DependentUpon>../TabRowControl.xaml</DependentUpon>
</ClInclude>
<ClInclude Include="../ActionList.h">
<DependentUpon>../ActionList.xaml</DependentUpon>
</ClInclude>
<ClInclude Include="../Tab.h" />
<ClInclude Include="../Pane.h" />
<ClInclude Include="../ColorScheme.h" />
@ -66,10 +72,14 @@
<ClInclude Include="../Profile.h" />
<ClInclude Include="../CascadiaSettings.h" />
<ClInclude Include="../AppKeyBindingsSerialization.h" />
<ClInclude Include="../ActionSerialization.h" />
<ClInclude Include="../KeyChordSerialization.h" />
<ClInclude Include="../ShortcutActionSerializationKeys.h" />
<ClInclude Include="../Utils.h" />
<ClInclude Include="pch.h" />
<ClInclude Include="../AppKeyBindings.h" />
<ClInclude Include="../Action.h" />
<ClInclude Include="../ShortcutActionDispatch.h" />
<ClInclude Include="../App.h" >
<DependentUpon>../App.xaml</DependentUpon>
</ClInclude>
@ -91,6 +101,9 @@
<ClCompile Include="../TabRowControl.cpp">
<DependentUpon>../TabRowControl.xaml</DependentUpon>
</ClCompile>
<ClCompile Include="../ActionList.cpp">
<DependentUpon>../ActionList.xaml</DependentUpon>
</ClCompile>
<ClCompile Include="../Tab.cpp" />
<ClCompile Include="../Pane.cpp" />
<ClCompile Include="../ColorScheme.cpp" />
@ -99,6 +112,7 @@
<ClCompile Include="../CascadiaSettings.cpp" />
<ClCompile Include="../CascadiaSettingsSerialization.cpp" />
<ClCompile Include="../AppKeyBindingsSerialization.cpp" />
<ClCompile Include="../ActionSerialization.cpp" />
<ClCompile Include="../KeyChordSerialization.cpp" />
<ClCompile Include="../Utils.cpp" />
<ClCompile Include="../ScopedResourceLoader.cpp" />
@ -108,6 +122,12 @@
<ClCompile Include="../AppKeyBindings.cpp" >
<DependentUpon>../AppKeyBindings.idl</DependentUpon>
</ClCompile>
<ClCompile Include="../Action.cpp" >
<DependentUpon>../Action.idl</DependentUpon>
</ClCompile>
<ClCompile Include="../ShortcutActionDispatch.cpp" >
<DependentUpon>../ShortcutActionDispatch.idl</DependentUpon>
</ClCompile>
<ClCompile Include="../App.cpp" >
<DependentUpon>../App.xaml</DependentUpon>
</ClCompile>
@ -128,6 +148,8 @@
<DependentUpon>../App.xaml</DependentUpon>
</Midl>
<Midl Include="../AppKeyBindings.idl" />
<Midl Include="../Action.idl" />
<Midl Include="../ShortcutActionDispatch.idl" />
<Midl Include="../MinMaxCloseControl.idl">
<DependentUpon>../MinMaxCloseControl.xaml</DependentUpon>
<SubType>Code</SubType>
@ -144,6 +166,10 @@
<DependentUpon>../TabRowControl.xaml</DependentUpon>
<SubType>Code</SubType>
</Midl>
<Midl Include="../ActionList.idl">
<DependentUpon>../ActionList.xaml</DependentUpon>
<SubType>Code</SubType>
</Midl>
</ItemGroup>
<!-- ========================= Misc Files ======================== -->

View file

@ -57,6 +57,30 @@ 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); }
#define DECLARE_GETSET_PROPERTY(type, name) \
public: \
type name(); \
void name(const type& value); \
\
private: \
type _##name;
#define DEFINE_GETSET_PROPERTY(className, type, name) \
type className::name() { return _##name; } \
void className::name(const type& value) { _##name = value; }
#define DEFINE_OBSERVABLE_GETSET_PROPERTY(type, name, event) \
public: \
type name() { return _##name; }; \
void name(const type& value) \
{ \
_##name = value; \
event(*this, Windows::UI::Xaml::Data::PropertyChangedEventArgs{ L#name }); \
}; \
\
private: \
type _##name;
// This is a helper method for deserializing a SAFEARRAY of
// COM objects and converting it to a vector that
// owns the extracted COM objects