new tab, new window, split pane

This commit is contained in:
Pankaj Bhojwani
2025-04-28 16:48:23 -07:00
parent f1424a471b
commit c8e2e08763
15 changed files with 365 additions and 119 deletions

View File

@@ -25,17 +25,13 @@ using namespace winrt::Windows::UI::Xaml::Navigation;
using namespace winrt::Microsoft::Terminal::Settings::Model;
// todo:
// INewContentArgs
// multiple actions
// selection color
// the above arg types aren't implemented yet - they all have multiple values within them
// and require a different approach to binding/displaying. INewContentArgs is a bunch of args
// in one object, selected color has color and IsIndex16, multiple actions is... multiple actions
// and require a different approach to binding/displaying. Selection color has color and IsIndex16,
// multiple actions is... multiple actions
// for now, do not support these shortcut actions in the new action editor
inline const std::set<winrt::Microsoft::Terminal::Settings::Model::ShortcutAction> UnimplementedShortcutActions = {
winrt::Microsoft::Terminal::Settings::Model::ShortcutAction::NewTab,
winrt::Microsoft::Terminal::Settings::Model::ShortcutAction::SplitPane,
winrt::Microsoft::Terminal::Settings::Model::ShortcutAction::NewWindow,
winrt::Microsoft::Terminal::Settings::Model::ShortcutAction::MultipleActions,
winrt::Microsoft::Terminal::Settings::Model::ShortcutAction::ColorSelection
};
@@ -325,12 +321,10 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
const auto actionString = unbox_value<hstring>(ProposedShortcutAction());
const auto actionEnum = _NameToActionMap.at(actionString);
const auto emptyArgs = CascadiaSettings::GetEmptyArgsForAction(actionEnum);
// todo: for sendInput, where "input" is a required argument, this will set it to an empty string which does not satisfy the requirement
// todo: probably need some better default values for empty args
// eg. for sendInput, where "input" is a required argument, "input" gets set to an empty string which does not satisfy the requirement
// i.e. if the user hits "save" immediately after switching to sendInput as the action (without adding something to the input field), they'll get an error
if (emptyArgs)
{
emptyArgs.SetAllArgsToDefault();
}
// there are some other cases as well
Model::ActionAndArgs newActionAndArgs{ actionEnum, emptyArgs };
_command.ActionAndArgs(newActionAndArgs);
const auto actionArgsVM = make_self<ActionArgsViewModel>(newActionAndArgs);
@@ -483,6 +477,14 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
{
INITIALIZE_ENUM_LIST_AND_VALUE(SelectOutputDirection, Model::SelectOutputDirection, L"Actions_SelectOutputDirection", L"Content");
}
else if (_type == L"Model::SplitDirection")
{
INITIALIZE_ENUM_LIST_AND_VALUE(SplitDirection, Model::SplitDirection, L"Actions_SplitDirection", L"Content");
}
else if (_type == L"SplitType")
{
INITIALIZE_ENUM_LIST_AND_VALUE(SplitType, Model::SplitType, L"Actions_SplitType", L"Content");
}
else if (_type == L"Windows::Foundation::IReference<TabSwitcherMode>")
{
INITIALIZE_NULLABLE_ENUM_LIST_AND_VALUE(TabSwitcherMode, Model::TabSwitcherMode, L"Actions_TabSwitcherMode", L"Content");
@@ -512,11 +514,29 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
return winrt::unbox_value<winrt::hstring>(value);
}
winrt::hstring ArgWrapper::UnboxGuid(const Windows::Foundation::IInspectable& value)
{
return winrt::to_hstring(winrt::unbox_value<winrt::guid>(value));
}
int32_t ArgWrapper::UnboxInt32(const Windows::Foundation::IInspectable& value)
{
return winrt::unbox_value<int32_t>(value);
}
float ArgWrapper::UnboxInt32Optional(const Windows::Foundation::IInspectable& value)
{
const auto unboxed = winrt::unbox_value<winrt::Windows::Foundation::IReference<int32_t>>(value);
if (unboxed)
{
return static_cast<float>(unboxed.Value());
}
else
{
return NAN;
}
}
uint32_t ArgWrapper::UnboxUInt32(const Windows::Foundation::IInspectable& value)
{
return winrt::unbox_value<uint32_t>(value);
@@ -535,6 +555,11 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
}
}
float ArgWrapper::UnboxUInt64(const Windows::Foundation::IInspectable& value)
{
return static_cast<float>(winrt::unbox_value<uint64_t>(value));
}
float ArgWrapper::UnboxFloat(const Windows::Foundation::IInspectable& value)
{
return winrt::unbox_value<float>(value);
@@ -580,11 +605,29 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
Value(box_value(newValue));
}
void ArgWrapper::GuidBindBack(const winrt::hstring& newValue)
{
// todo: probably need some validation?
Value(box_value(winrt::guid{ newValue }));
}
void ArgWrapper::Int32BindBack(const double newValue)
{
Value(box_value(static_cast<int32_t>(newValue)));
}
void ArgWrapper::Int32OptionalBindBack(const double newValue)
{
if (!isnan(newValue))
{
Value(box_value(static_cast<int32_t>(newValue)));
}
else
{
Value(nullptr);
}
}
void ArgWrapper::UInt32BindBack(const double newValue)
{
Value(box_value(static_cast<uint32_t>(newValue)));
@@ -602,6 +645,11 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
}
}
void ArgWrapper::UInt64BindBack(const double newValue)
{
Value(box_value(static_cast<uint64_t>(newValue)));
}
void ArgWrapper::FloatBindBack(const double newValue)
{
Value(box_value(static_cast<float>(newValue)));

View File

@@ -183,9 +183,12 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
// unboxing functions
winrt::hstring UnboxString(const Windows::Foundation::IInspectable& value);
winrt::hstring UnboxGuid(const Windows::Foundation::IInspectable& value);
int32_t UnboxInt32(const Windows::Foundation::IInspectable& value);
float UnboxInt32Optional(const Windows::Foundation::IInspectable& value);
uint32_t UnboxUInt32(const Windows::Foundation::IInspectable& value);
float UnboxUInt32Optional(const Windows::Foundation::IInspectable& value);
float UnboxUInt64(const Windows::Foundation::IInspectable& value);
float UnboxFloat(const Windows::Foundation::IInspectable& value);
winrt::Windows::Foundation::IReference<bool> UnboxBoolOptional(const Windows::Foundation::IInspectable& value);
winrt::Windows::Foundation::IReference<Microsoft::Terminal::Core::Color> UnboxTerminalCoreColorOptional(const Windows::Foundation::IInspectable& value);
@@ -193,9 +196,12 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
// bind back functions
void StringBindBack(const winrt::hstring& newValue);
void GuidBindBack(const winrt::hstring& newValue);
void Int32BindBack(const double newValue);
void Int32OptionalBindBack(const double newValue);
void UInt32BindBack(const double newValue);
void UInt32OptionalBindBack(const double newValue);
void UInt64BindBack(const double newValue);
void FloatBindBack(const double newValue);
void BoolBindBack(const Windows::Foundation::IReference<bool> newValue);
void TerminalCoreColorBindBack(const winrt::Windows::Foundation::IReference<Microsoft::Terminal::Core::Color> newValue);

View File

@@ -91,9 +91,12 @@ namespace Microsoft.Terminal.Settings.Editor
// unboxing functions
String UnboxString(Object value);
String UnboxGuid(Object value);
UInt32 UnboxInt32(Object value);
Single UnboxInt32Optional(Object value);
UInt32 UnboxUInt32(Object value);
Single UnboxUInt32Optional(Object value);
Single UnboxUInt64(Object value);
Single UnboxFloat(Object value);
Windows.Foundation.IReference<Boolean> UnboxBoolOptional(Object value);
Windows.Foundation.IReference<Microsoft.Terminal.Core.Color> UnboxTerminalCoreColorOptional(Object value);
@@ -101,9 +104,12 @@ namespace Microsoft.Terminal.Settings.Editor
// bind back functions
void StringBindBack(String newValue);
void GuidBindBack(String newValue);
void Int32BindBack(Double newValue);
void Int32OptionalBindBack(Double newValue);
void UInt32BindBack(Double newValue);
void UInt32OptionalBindBack(Double newValue);
void UInt64BindBack(Double newValue);
void FloatBindBack(Double newValue);
void BoolBindBack(Windows.Foundation.IReference<Boolean> newValue);
void TerminalCoreColorBindBack(Windows.Foundation.IReference<Microsoft.Terminal.Core.Color> newValue);

View File

@@ -30,6 +30,10 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
{
return StringTemplate();
}
else if (argType == L"winrt::guid")
{
return GuidTemplate();
}
else if (argType == L"int32_t")
{
return Int32Template();
@@ -38,15 +42,24 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
{
return UInt32Template();
}
else if (argType == L"uint64_t")
{
return UInt64Template();
}
else if (argType == L"float")
{
return FloatTemplate();
}
else if (argType == L"bool")
else if (argType == L"bool" ||
argType == L"Windows::Foundation::IReference<bool>")
{
// we don't have any bool args that are required, so just use the optional template for all of them
return BoolOptionalTemplate();
}
else if (argType == L"Windows::Foundation::IReference<int32_t>")
{
return Int32OptionalTemplate();
}
else if (argType == L"Windows::Foundation::IReference<uint32_t>")
{
return UInt32OptionalTemplate();
@@ -62,7 +75,9 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
argType == L"Model::MonitorBehavior" ||
argType == L"winrt::Microsoft::Terminal::Control::ClearBufferType" ||
argType == L"SelectOutputDirection" ||
argType == L"Windows::Foundation::IReference<TabSwitcherMode>")
argType == L"Windows::Foundation::IReference<TabSwitcherMode>" ||
argType == L"Model::SplitDirection" ||
argType == L"SplitType")
{
return EnumTemplate();
}

View File

@@ -15,9 +15,12 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
Windows::UI::Xaml::DataTemplate SelectTemplateCore(const winrt::Windows::Foundation::IInspectable&);
WINRT_PROPERTY(winrt::Windows::UI::Xaml::DataTemplate, NoArgTemplate);
WINRT_PROPERTY(winrt::Windows::UI::Xaml::DataTemplate, GuidTemplate);
WINRT_PROPERTY(winrt::Windows::UI::Xaml::DataTemplate, Int32Template);
WINRT_PROPERTY(winrt::Windows::UI::Xaml::DataTemplate, Int32OptionalTemplate);
WINRT_PROPERTY(winrt::Windows::UI::Xaml::DataTemplate, UInt32Template);
WINRT_PROPERTY(winrt::Windows::UI::Xaml::DataTemplate, UInt32OptionalTemplate);
WINRT_PROPERTY(winrt::Windows::UI::Xaml::DataTemplate, UInt64Template);
WINRT_PROPERTY(winrt::Windows::UI::Xaml::DataTemplate, FloatTemplate);
WINRT_PROPERTY(winrt::Windows::UI::Xaml::DataTemplate, StringTemplate);
WINRT_PROPERTY(winrt::Windows::UI::Xaml::DataTemplate, BoolOptionalTemplate);

View File

@@ -8,9 +8,12 @@ namespace Microsoft.Terminal.Settings.Editor
ArgsTemplateSelectors();
Windows.UI.Xaml.DataTemplate NoArgTemplate;
Windows.UI.Xaml.DataTemplate GuidTemplate;
Windows.UI.Xaml.DataTemplate Int32Template;
Windows.UI.Xaml.DataTemplate Int32OptionalTemplate;
Windows.UI.Xaml.DataTemplate UInt32Template;
Windows.UI.Xaml.DataTemplate UInt32OptionalTemplate;
Windows.UI.Xaml.DataTemplate UInt64Template;
Windows.UI.Xaml.DataTemplate FloatTemplate;
Windows.UI.Xaml.DataTemplate StringTemplate;
Windows.UI.Xaml.DataTemplate BoolOptionalTemplate;

View File

@@ -298,6 +298,50 @@
</ListViewItem>
</DataTemplate>
<DataTemplate x:Key="UInt64Template"
x:DataType="local:ArgWrapper">
<ListViewItem>
<Grid ColumnSpacing="8">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="{StaticResource ArgumentNameWidth}" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBlock Text="{x:Bind Name}"
VerticalAlignment="Center"
Grid.Column="0"/>
<muxc:NumberBox Value="{x:Bind UnboxUInt64(Value), Mode=TwoWay, BindBack=UInt64BindBack}"
Style="{StaticResource NumberBoxSettingStyle}"
Minimum="0"
Maximum="999"
LargeChange="1"
SmallChange="1"
Grid.Column="1"/>
</Grid>
</ListViewItem>
</DataTemplate>
<DataTemplate x:Key="Int32OptionalTemplate"
x:DataType="local:ArgWrapper">
<ListViewItem>
<Grid ColumnSpacing="8">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="{StaticResource ArgumentNameWidth}" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBlock Text="{x:Bind Name}"
VerticalAlignment="Center"
Grid.Column="0"/>
<muxc:NumberBox Value="{x:Bind UnboxInt32Optional(Value), Mode=TwoWay, BindBack=Int32OptionalBindBack}"
Style="{StaticResource NumberBoxSettingStyle}"
Minimum="0"
Maximum="999"
LargeChange="1"
SmallChange="1"
Grid.Column="1"/>
</Grid>
</ListViewItem>
</DataTemplate>
<DataTemplate x:Key="FloatTemplate"
x:DataType="local:ArgWrapper">
<ListViewItem>
@@ -337,6 +381,23 @@
</ListViewItem>
</DataTemplate>
<DataTemplate x:Key="GuidTemplate"
x:DataType="local:ArgWrapper">
<ListViewItem>
<Grid ColumnSpacing="8">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="{StaticResource ArgumentNameWidth}" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBlock Text="{x:Bind Name}"
VerticalAlignment="Center"
Grid.Column="0"/>
<TextBox Text="{x:Bind UnboxGuid(Value), Mode=TwoWay, BindBack=GuidBindBack}"
Grid.Column="1"/>
</Grid>
</ListViewItem>
</DataTemplate>
<DataTemplate x:Key="BoolOptionalTemplate"
x:DataType="local:ArgWrapper">
<ListViewItem>
@@ -459,10 +520,13 @@
<local:ArgsTemplateSelectors x:Key="ArgsTemplateSelector"
NoArgTemplate="{StaticResource NoArgTemplate}"
Int32Template="{StaticResource Int32Template}"
Int32OptionalTemplate="{StaticResource Int32OptionalTemplate}"
UInt32Template="{StaticResource UInt32Template}"
UInt32OptionalTemplate="{StaticResource UInt32OptionalTemplate}"
UInt64Template="{StaticResource UInt64Template}"
FloatTemplate="{StaticResource FloatTemplate}"
StringTemplate="{StaticResource StringTemplate}"
GuidTemplate="{StaticResource GuidTemplate}"
BoolOptionalTemplate="{StaticResource BoolOptionalTemplate}"
EnumTemplate="{StaticResource EnumTemplate}"
FlagTemplate="{StaticResource FlagTemplate}"

View File

@@ -1884,6 +1884,42 @@
<value>RTF</value>
<comment>An option to choose from for the "copy format". Copies content in Rich Text Format (RTF).</comment>
</data>
<data name="Actions_SplitDirectionAuto.Content" xml:space="preserve">
<value>Automatic</value>
<comment>An option to choose from for the "split direction". Automatically determines the split direction.</comment>
</data>
<data name="Actions_SplitDirectionUp.Content" xml:space="preserve">
<value>Up</value>
<comment>An option to choose from for the "split direction". Splits upward.</comment>
</data>
<data name="Actions_SplitDirectionRight.Content" xml:space="preserve">
<value>Right</value>
<comment>An option to choose from for the "split direction". Splits to the right.</comment>
</data>
<data name="Actions_SplitDirectionDown.Content" xml:space="preserve">
<value>Down</value>
<comment>An option to choose from for the "split direction". Splits downward.</comment>
</data>
<data name="Actions_SplitDirectionLeft.Content" xml:space="preserve">
<value>Left</value>
<comment>An option to choose from for the "split direction". Splits to the left.</comment>
</data>
<data name="Actions_SplitDirectionVertical.Content" xml:space="preserve">
<value>Vertical</value>
<comment>An option to choose from for the "split direction". Splits to the left.</comment>
</data>
<data name="Actions_SplitDirectionHorizontal.Content" xml:space="preserve">
<value>Horizontal</value>
<comment>An option to choose from for the "split direction". Splits to the left.</comment>
</data>
<data name="Actions_SplitTypeManual.Content" xml:space="preserve">
<value>Manual</value>
<comment>An option to choose from for the "split type". Creates a manual split.</comment>
</data>
<data name="Actions_SplitTypeDuplicate.Content" xml:space="preserve">
<value>Duplicate</value>
<comment>An option to choose from for the "split type". Creates a split by duplicating the current session.</comment>
</data>
<data name="Actions_ResizeDirectionNone.Content" xml:space="preserve">
<value>None</value>
<comment>An option to choose from for the "resize direction". None option.</comment>

View File

@@ -286,6 +286,28 @@ protected: \
X(winrt::Microsoft::Terminal::Control::SelectionColor, Background, "background", false, nullptr) \
X(winrt::Microsoft::Terminal::Core::MatchMode, MatchMode, "matchMode", false, winrt::Microsoft::Terminal::Core::MatchMode::None)
////////////////////////////////////////////////////////////////////////////////
#define NEW_TERMINAL_ARGS(X) \
X(winrt::hstring, Commandline, "commandline", false, L"") \
X(winrt::hstring, StartingDirectory, "startingDirectory", false, L"") \
X(winrt::hstring, TabTitle, "tabTitle", false, L"") \
X(Windows::Foundation::IReference<Windows::UI::Color>, TabColor, "tabColor", false, nullptr) \
X(Windows::Foundation::IReference<int32_t>, ProfileIndex, "index", false, nullptr) \
X(winrt::hstring, Profile, "profile", false, L"") \
X(winrt::guid, SessionId, "sessionId", false, winrt::guid{}) \
X(bool, AppendCommandLine, "appendCommandLine", false, false) \
X(Windows::Foundation::IReference<bool>, SuppressApplicationTitle, "suppressApplicationTitle", false, nullptr) \
X(winrt::hstring, ColorScheme, "colorScheme", args->SchemeName().empty(), L"") \
X(Windows::Foundation::IReference<bool>, Elevate, "elevate", false, nullptr) \
X(Windows::Foundation::IReference<bool>, ReloadEnvironmentVariables, "reloadEnvironmentVariables", false, nullptr) \
X(uint64_t, ContentId, "__content", false, 0)
////////////////////////////////////////////////////////////////////////////////
#define SPLIT_PANE_ARGS(X) \
X(Model::SplitDirection, SplitDirection, "split", false, SplitDirection::Automatic) \
X(SplitType, SplitMode, "splitMode", false, SplitType::Manual) \
X(float, SplitSize, "size", false, 0.5f)
////////////////////////////////////////////////////////////////////////////////
namespace winrt::Microsoft::Terminal::Settings::Model::implementation
@@ -358,41 +380,14 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
// assumptions made in the macro.
struct NewTerminalArgs : public NewTerminalArgsT<NewTerminalArgs>
{
NewTerminalArgs() = default;
NewTerminalArgs(int32_t& profileIndex) :
_ProfileIndex{ profileIndex } {};
PARTIAL_ACTION_ARG_BODY(NewTerminalArgs, NEW_TERMINAL_ARGS);
ACTION_ARG(winrt::hstring, Type, L"");
ACTION_ARG(winrt::hstring, Commandline, L"");
ACTION_ARG(winrt::hstring, StartingDirectory, L"");
ACTION_ARG(winrt::hstring, TabTitle, L"");
ACTION_ARG(Windows::Foundation::IReference<Windows::UI::Color>, TabColor, nullptr);
ACTION_ARG(Windows::Foundation::IReference<int32_t>, ProfileIndex, nullptr);
ACTION_ARG(winrt::hstring, Profile, L"");
ACTION_ARG(winrt::guid, SessionId, winrt::guid{});
ACTION_ARG(bool, AppendCommandLine, false);
ACTION_ARG(Windows::Foundation::IReference<bool>, SuppressApplicationTitle, nullptr);
ACTION_ARG(winrt::hstring, ColorScheme);
ACTION_ARG(Windows::Foundation::IReference<bool>, Elevate, nullptr);
ACTION_ARG(Windows::Foundation::IReference<bool>, ReloadEnvironmentVariables, nullptr);
ACTION_ARG(uint64_t, ContentId);
static constexpr std::string_view CommandlineKey{ "commandline" };
static constexpr std::string_view StartingDirectoryKey{ "startingDirectory" };
static constexpr std::string_view TabTitleKey{ "tabTitle" };
static constexpr std::string_view TabColorKey{ "tabColor" };
static constexpr std::string_view ProfileIndexKey{ "index" };
static constexpr std::string_view ProfileKey{ "profile" };
static constexpr std::string_view SessionIdKey{ "sessionId" };
static constexpr std::string_view AppendCommandLineKey{ "appendCommandLine" };
static constexpr std::string_view SuppressApplicationTitleKey{ "suppressApplicationTitle" };
static constexpr std::string_view ColorSchemeKey{ "colorScheme" };
static constexpr std::string_view ElevateKey{ "elevate" };
static constexpr std::string_view ReloadEnvironmentVariablesKey{ "reloadEnvironmentVariables" };
static constexpr std::string_view ContentKey{ "__content" };
public:
NewTerminalArgs(int32_t& profileIndex) :
_ProfileIndex{ profileIndex } {
NEW_TERMINAL_ARGS(APPEND_ARG_DESCRIPTION);
};
hstring GenerateName() const;
hstring ToCommandline() const;
@@ -431,7 +426,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
JsonUtils::GetValueForKey(json, ColorSchemeKey, args->_ColorScheme);
JsonUtils::GetValueForKey(json, ElevateKey, args->_Elevate);
JsonUtils::GetValueForKey(json, ReloadEnvironmentVariablesKey, args->_ReloadEnvironmentVariables);
JsonUtils::GetValueForKey(json, ContentKey, args->_ContentId);
JsonUtils::GetValueForKey(json, ContentIdKey, args->_ContentId);
return *args;
}
static Json::Value ToJson(const Model::NewTerminalArgs& val)
@@ -453,7 +448,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
JsonUtils::SetValueForKey(json, ColorSchemeKey, args->_ColorScheme);
JsonUtils::SetValueForKey(json, ElevateKey, args->_Elevate);
JsonUtils::SetValueForKey(json, ReloadEnvironmentVariablesKey, args->_ReloadEnvironmentVariables);
JsonUtils::SetValueForKey(json, ContentKey, args->_ContentId);
JsonUtils::SetValueForKey(json, ContentIdKey, args->_ContentId);
return json;
}
Model::NewTerminalArgs Copy() const
@@ -471,6 +466,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
copy->_Elevate = _Elevate;
copy->_ReloadEnvironmentVariables = _ReloadEnvironmentVariables;
copy->_ContentId = _ContentId;
copy->_argDescriptions = _argDescriptions;
return *copy;
}
size_t Hash() const
@@ -589,7 +585,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
NewTabArgs() = default;
NewTabArgs(const Model::INewContentArgs& terminalArgs) :
_ContentArgs{ terminalArgs } {};
WINRT_PROPERTY(Model::INewContentArgs, ContentArgs, nullptr);
WINRT_PROPERTY(Model::INewContentArgs, ContentArgs, Model::NewTerminalArgs{});
public:
hstring GenerateName() const;
@@ -634,52 +630,52 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
}
uint32_t GetArgCount() const
{
return 2;
return _ContentArgs.as<NewTerminalArgs>()->GetArgCount();
}
Model::ArgDescription GetArgDescriptionAt(uint32_t /*index*/) const
Model::ArgDescription GetArgDescriptionAt(uint32_t index) const
{
return {};
return _ContentArgs.as<NewTerminalArgs>()->GetArgDescriptionAt(index);
}
IInspectable GetArgAt(uint32_t /*index*/) const
IInspectable GetArgAt(uint32_t index) const
{
return nullptr;
return _ContentArgs.as<NewTerminalArgs>()->GetArgAt(index);
}
void SetArgAt(uint32_t /*index*/, IInspectable /*value*/)
void SetArgAt(uint32_t index, IInspectable value)
{
throw winrt::hresult_not_implemented();
}
void SetAllArgsToDefault()
{
throw winrt::hresult_not_implemented();
_ContentArgs.as<NewTerminalArgs>()->SetArgAt(index, value);
}
};
struct SplitPaneArgs : public SplitPaneArgsT<SplitPaneArgs>
{
SplitPaneArgs() = default;
SplitPaneArgs() {
SPLIT_PANE_ARGS(APPEND_ARG_DESCRIPTION)
};
SplitPaneArgs(SplitType splitMode, SplitDirection direction, float size, const Model::INewContentArgs& terminalArgs) :
_SplitMode{ splitMode },
_SplitDirection{ direction },
_SplitSize{ size },
_ContentArgs{ terminalArgs } {};
_ContentArgs{ terminalArgs } {
SPLIT_PANE_ARGS(APPEND_ARG_DESCRIPTION)
};
SplitPaneArgs(SplitDirection direction, float size, const Model::INewContentArgs& terminalArgs) :
_SplitDirection{ direction },
_SplitSize{ size },
_ContentArgs{ terminalArgs } {};
_ContentArgs{ terminalArgs } {
SPLIT_PANE_ARGS(APPEND_ARG_DESCRIPTION)
};
SplitPaneArgs(SplitDirection direction, const Model::INewContentArgs& terminalArgs) :
_SplitDirection{ direction },
_ContentArgs{ terminalArgs } {};
_ContentArgs{ terminalArgs } {
SPLIT_PANE_ARGS(APPEND_ARG_DESCRIPTION)
};
SplitPaneArgs(SplitType splitMode) :
_SplitMode{ splitMode } {};
_SplitMode{ splitMode } {
SPLIT_PANE_ARGS(APPEND_ARG_DESCRIPTION)
};
ACTION_ARG(Model::SplitDirection, SplitDirection, SplitDirection::Automatic);
WINRT_PROPERTY(Model::INewContentArgs, ContentArgs, nullptr);
ACTION_ARG(SplitType, SplitMode, SplitType::Manual);
ACTION_ARG(float, SplitSize, 0.5f);
static constexpr std::string_view SplitKey{ "split" };
static constexpr std::string_view SplitModeKey{ "splitMode" };
static constexpr std::string_view SplitSizeKey{ "size" };
SPLIT_PANE_ARGS(DECLARE_ARGS);
WINRT_PROPERTY(Model::INewContentArgs, ContentArgs, Model::NewTerminalArgs{});
public:
hstring GenerateName() const;
@@ -701,7 +697,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
{
// LOAD BEARING: Not using make_self here _will_ break you in the future!
auto args = winrt::make_self<SplitPaneArgs>();
JsonUtils::GetValueForKey(json, SplitKey, args->_SplitDirection);
JsonUtils::GetValueForKey(json, SplitDirectionKey, args->_SplitDirection);
JsonUtils::GetValueForKey(json, SplitModeKey, args->_SplitMode);
JsonUtils::GetValueForKey(json, SplitSizeKey, args->_SplitSize);
if (args->SplitSize() >= 1 || args->SplitSize() <= 0)
@@ -721,7 +717,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
}
const auto args{ get_self<SplitPaneArgs>(val) };
auto json{ ContentArgsToJson(args->_ContentArgs) };
JsonUtils::SetValueForKey(json, SplitKey, args->_SplitDirection);
JsonUtils::SetValueForKey(json, SplitDirectionKey, args->_SplitDirection);
JsonUtils::SetValueForKey(json, SplitModeKey, args->_SplitMode);
JsonUtils::SetValueForKey(json, SplitSizeKey, args->_SplitSize);
return json;
@@ -733,6 +729,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
copy->_ContentArgs = _ContentArgs.Copy();
copy->_SplitMode = _SplitMode;
copy->_SplitSize = _SplitSize;
copy->_argDescriptions = _argDescriptions;
return *copy;
}
size_t Hash() const
@@ -746,24 +743,57 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
}
uint32_t GetArgCount() const
{
return 4;
if (const auto newTermArgs = _ContentArgs.try_as<NewTerminalArgs>())
{
return newTermArgs->GetArgCount() + gsl::narrow<uint32_t>(_argDescriptions.size());
}
else
{
return gsl::narrow<uint32_t>(_argDescriptions.size());
}
}
Model::ArgDescription GetArgDescriptionAt(uint32_t /*index*/) const
Model::ArgDescription GetArgDescriptionAt(uint32_t index) const
{
return {};
const auto additionalArgCount = gsl::narrow<uint32_t>(_argDescriptions.size());
if (index < additionalArgCount)
{
return _argDescriptions.at(index);
}
else
{
return _ContentArgs.as<NewTerminalArgs>()->GetArgDescriptionAt(index - additionalArgCount);
}
}
IInspectable GetArgAt(uint32_t /*index*/) const
IInspectable GetArgAt(uint32_t index) const
{
const auto additionalArgCount = gsl::narrow<uint32_t>(_argDescriptions.size());
if (index < additionalArgCount)
{
uint32_t curIndex{ 0 };
SPLIT_PANE_ARGS(GET_ARG_BY_INDEX);
}
else
{
return _ContentArgs.as<NewTerminalArgs>()->GetArgAt(index - additionalArgCount);
}
return nullptr;
}
void SetArgAt(uint32_t /*index*/, IInspectable /*value*/)
void SetArgAt(uint32_t index, IInspectable value)
{
throw winrt::hresult_not_implemented();
}
void SetAllArgsToDefault()
{
throw winrt::hresult_not_implemented();
const auto additionalArgCount = gsl::narrow<uint32_t>(_argDescriptions.size());
if (index < additionalArgCount)
{
uint32_t curIndex{ 0 };
SPLIT_PANE_ARGS(SET_ARG_BY_INDEX);
}
else
{
_ContentArgs.as<NewTerminalArgs>()->SetArgAt(index - additionalArgCount, value);
}
}
private:
std::vector<ArgDescription> _argDescriptions;
};
struct NewWindowArgs : public NewWindowArgsT<NewWindowArgs>
@@ -771,7 +801,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
NewWindowArgs() = default;
NewWindowArgs(const Model::INewContentArgs& terminalArgs) :
_ContentArgs{ terminalArgs } {};
WINRT_PROPERTY(Model::INewContentArgs, ContentArgs, nullptr);
WINRT_PROPERTY(Model::INewContentArgs, ContentArgs, Model::NewTerminalArgs{});
public:
hstring GenerateName() const;
@@ -816,23 +846,19 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
}
uint32_t GetArgCount() const
{
return 2;
return _ContentArgs.as<NewTerminalArgs>()->GetArgCount();
}
Model::ArgDescription GetArgDescriptionAt(uint32_t /*index*/) const
Model::ArgDescription GetArgDescriptionAt(uint32_t index) const
{
return {};
return _ContentArgs.as<NewTerminalArgs>()->GetArgDescriptionAt(index);
}
IInspectable GetArgAt(uint32_t /*index*/) const
IInspectable GetArgAt(uint32_t index) const
{
return nullptr;
return _ContentArgs.as<NewTerminalArgs>()->GetArgAt(index);
}
void SetArgAt(uint32_t /*index*/, IInspectable /*value*/)
void SetArgAt(uint32_t index, IInspectable value)
{
throw winrt::hresult_not_implemented();
}
void SetAllArgsToDefault()
{
throw winrt::hresult_not_implemented();
_ContentArgs.as<NewTerminalArgs>()->SetArgAt(index, value);
}
};
@@ -989,10 +1015,6 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
{
throw winrt::hresult_not_implemented();
}
void SetAllArgsToDefault()
{
throw winrt::hresult_not_implemented();
}
};
ACTION_ARGS_STRUCT(AdjustOpacityArgs, ADJUST_OPACITY_ARGS);

View File

@@ -23,7 +23,6 @@ namespace Microsoft.Terminal.Settings.Model
ArgDescription GetArgDescriptionAt(UInt32 index);
IInspectable GetArgAt(UInt32 index);
void SetArgAt(UInt32 index, Object value);
void SetAllArgsToDefault();
};
interface IActionEventArgs
@@ -181,6 +180,11 @@ namespace Microsoft.Terminal.Settings.Model
UInt64 ContentId{ get; set; };
String ToCommandline();
UInt32 GetArgCount();
ArgDescription GetArgDescriptionAt(UInt32 index);
IInspectable GetArgAt(UInt32 index);
void SetArgAt(UInt32 index, Object value);
};
[default_interface] runtimeclass ActionEventArgs : IActionEventArgs

View File

@@ -77,17 +77,17 @@ struct InitListPlaceholder
&&(otherAsUs->_##name == _##name)
// getter and setter for each property by index
#define GET_ARG_BY_INDEX(type, name, jsonKey, required, ...) \
if (index == curIndex++) \
{ \
if (_##name.has_value()) \
{ \
return winrt::box_value(_##name.value()); \
} \
else \
{ \
return nullptr; \
} \
#define GET_ARG_BY_INDEX(type, name, jsonKey, required, ...) \
if (index == curIndex++) \
{ \
if (_##name.has_value()) \
{ \
return winrt::box_value(_##name.value()); \
} \
else \
{ \
return winrt::box_value(static_cast<type>(__VA_ARGS__)); \
} \
}
#define SET_ARG_BY_INDEX(type, name, jsonKey, required, ...) \
@@ -103,9 +103,6 @@ struct InitListPlaceholder
} \
}
#define SET_ARG_TO_DEFAULT(type, name, jsonKey, required, ...) \
_##name = static_cast<type>(__VA_ARGS__);
// JSON deserialization. If the parameter is required to pass any validation,
// add that as the `required` parameter here, as the body of a conditional
// EX: For the RESIZE_PANE_ARGS
@@ -217,8 +214,38 @@ public: \
{ \
uint32_t curIndex{ 0 }; \
argsMacro(SET_ARG_BY_INDEX) \
} \
void SetAllArgsToDefault() \
{ \
argsMacro(SET_ARG_TO_DEFAULT) \
}
#define PARTIAL_ACTION_ARG_BODY(className, argsMacro) \
className(){ argsMacro(APPEND_ARG_DESCRIPTION) }; \
className( \
argsMacro(CTOR_PARAMS) InitListPlaceholder = {}) : \
argsMacro(CTOR_INIT) _placeholder{} { \
argsMacro(APPEND_ARG_DESCRIPTION) \
}; \
argsMacro(DECLARE_ARGS); \
\
private: \
InitListPlaceholder _placeholder; \
std::vector<ArgDescription> _argDescriptions; \
\
public: \
uint32_t GetArgCount() const \
{ \
return gsl::narrow<uint32_t>(_argDescriptions.size()); \
} \
ArgDescription GetArgDescriptionAt(uint32_t index) const \
{ \
return _argDescriptions.at(index); \
} \
IInspectable GetArgAt(uint32_t index) const \
{ \
uint32_t curIndex{ 0 }; \
argsMacro(GET_ARG_BY_INDEX) \
return nullptr; \
} \
void SetArgAt(uint32_t index, IInspectable value) \
{ \
uint32_t curIndex{ 0 }; \
argsMacro(SET_ARG_BY_INDEX) \
}

View File

@@ -1074,6 +1074,12 @@ Model::IActionArgs CascadiaSettings::GetEmptyArgsForAction(Model::ShortcutAction
return winrt::make<PrevTabArgs>();
case Model::ShortcutAction::NextTab:
return winrt::make<NextTabArgs>();
case Model::ShortcutAction::NewTab:
return winrt::make<NewTabArgs>();
case Model::ShortcutAction::NewWindow:
return winrt::make<NewWindowArgs>();
case Model::ShortcutAction::SplitPane:
return winrt::make<SplitPaneArgs>();
default:
return nullptr;
}

View File

@@ -56,6 +56,8 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
// Actions
DEFINE_ENUM_MAP(Microsoft::Terminal::Settings::Model::ResizeDirection, ResizeDirection);
DEFINE_ENUM_MAP(Microsoft::Terminal::Settings::Model::FocusDirection, FocusDirection);
DEFINE_ENUM_MAP(Microsoft::Terminal::Settings::Model::SplitDirection, SplitDirection);
DEFINE_ENUM_MAP(Microsoft::Terminal::Settings::Model::SplitType, SplitType);
DEFINE_ENUM_MAP(Microsoft::Terminal::Settings::Model::SettingsTarget, SettingsTarget);
DEFINE_ENUM_MAP(Microsoft::Terminal::Settings::Model::MoveTabDirection, MoveTabDirection);
DEFINE_ENUM_MAP(Microsoft::Terminal::Control::ScrollToMarkDirection, ScrollToMarkDirection);

View File

@@ -53,6 +53,8 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
// Actions
static winrt::Windows::Foundation::Collections::IMap<winrt::hstring, winrt::Microsoft::Terminal::Settings::Model::ResizeDirection> ResizeDirection();
static winrt::Windows::Foundation::Collections::IMap<winrt::hstring, winrt::Microsoft::Terminal::Settings::Model::FocusDirection> FocusDirection();
static winrt::Windows::Foundation::Collections::IMap<winrt::hstring, winrt::Microsoft::Terminal::Settings::Model::SplitDirection> SplitDirection();
static winrt::Windows::Foundation::Collections::IMap<winrt::hstring, winrt::Microsoft::Terminal::Settings::Model::SplitType> SplitType();
static winrt::Windows::Foundation::Collections::IMap<winrt::hstring, winrt::Microsoft::Terminal::Settings::Model::SettingsTarget> SettingsTarget();
static winrt::Windows::Foundation::Collections::IMap<winrt::hstring, winrt::Microsoft::Terminal::Settings::Model::MoveTabDirection> MoveTabDirection();
static winrt::Windows::Foundation::Collections::IMap<winrt::hstring, winrt::Microsoft::Terminal::Control::ScrollToMarkDirection> ScrollToMarkDirection();

View File

@@ -35,6 +35,8 @@ namespace Microsoft.Terminal.Settings.Model
// Actions
static Windows.Foundation.Collections.IMap<String, Microsoft.Terminal.Settings.Model.ResizeDirection> ResizeDirection { get; };
static Windows.Foundation.Collections.IMap<String, Microsoft.Terminal.Settings.Model.FocusDirection> FocusDirection { get; };
static Windows.Foundation.Collections.IMap<String, Microsoft.Terminal.Settings.Model.SplitDirection> SplitDirection { get; };
static Windows.Foundation.Collections.IMap<String, Microsoft.Terminal.Settings.Model.SplitType> SplitType { get; };
static Windows.Foundation.Collections.IMap<String, Microsoft.Terminal.Settings.Model.SettingsTarget> SettingsTarget { get; };
static Windows.Foundation.Collections.IMap<String, Microsoft.Terminal.Settings.Model.MoveTabDirection> MoveTabDirection { get; };
static Windows.Foundation.Collections.IMap<String, Microsoft.Terminal.Control.ScrollToMarkDirection> ScrollToMarkDirection { get; };