mirror of
https://github.com/microsoft/terminal.git
synced 2026-05-20 22:06:56 +00:00
resize pane works
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
#include "KeyChordViewModel.g.cpp"
|
||||
#include "LibraryResources.h"
|
||||
#include "../TerminalSettingsModel/AllShortcutActions.h"
|
||||
#include "EnumEntry.h"
|
||||
|
||||
using namespace winrt::Windows::Foundation;
|
||||
using namespace winrt::Windows::Foundation::Collections;
|
||||
@@ -22,6 +23,23 @@ using namespace winrt::Windows::UI::Xaml::Data;
|
||||
using namespace winrt::Windows::UI::Xaml::Navigation;
|
||||
using namespace winrt::Microsoft::Terminal::Settings::Model;
|
||||
|
||||
#define INITIALIZE_ENUM_LIST_AND_VALUE(enumMappingsName, enumType, resourceSectionAndType, resourceProperty) \
|
||||
std::vector<winrt::Microsoft::Terminal::Settings::Editor::EnumEntry> enumList; \
|
||||
const auto mappings = winrt::Microsoft::Terminal::Settings::Model::EnumMappings::enumMappingsName(); \
|
||||
const auto unboxedValue = unbox_value<enumType>(value); \
|
||||
for (const auto [enumKey, enumValue] : mappings) \
|
||||
{ \
|
||||
const auto enumName = LocalizedNameForEnumName(resourceSectionAndType, enumKey, resourceProperty); \
|
||||
auto entry = winrt::make<winrt::Microsoft::Terminal::Settings::Editor::implementation::EnumEntry>(enumName, winrt::box_value<enumType>(enumValue)); \
|
||||
enumList.emplace_back(entry); \
|
||||
if (unboxedValue == enumValue) \
|
||||
{ \
|
||||
EnumValue(entry); \
|
||||
} \
|
||||
} \
|
||||
std::sort(enumList.begin(), enumList.end(), EnumEntryReverseComparator<enumType>()); \
|
||||
_EnumList = winrt::single_threaded_observable_vector<winrt::Microsoft::Terminal::Settings::Editor::EnumEntry>(std::move(enumList));
|
||||
|
||||
namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
|
||||
{
|
||||
KeyBindingViewModel::KeyBindingViewModel(const IObservableVector<hstring>& availableActions) :
|
||||
@@ -153,7 +171,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
|
||||
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
|
||||
// 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
|
||||
emptyArgs.SetRequiredArgsToDefault();
|
||||
emptyArgs.SetAllArgsToDefault();
|
||||
Model::ActionAndArgs newActionAndArgs{ actionEnum, emptyArgs };
|
||||
_command.ActionAndArgs(newActionAndArgs);
|
||||
ActionArgsVM(make<ActionArgsViewModel>(newActionAndArgs));
|
||||
@@ -234,6 +252,26 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
|
||||
});
|
||||
}
|
||||
|
||||
ArgWrapper::ArgWrapper(const winrt::hstring& type, const bool required, const Windows::Foundation::IInspectable& value)
|
||||
{
|
||||
Value(value);
|
||||
_type = type;
|
||||
_required = required;
|
||||
if (_type == L"Model::ResizeDirection")
|
||||
{
|
||||
INITIALIZE_ENUM_LIST_AND_VALUE(ResizeDirection, Model::ResizeDirection, L"Actions_ResizeDirection", L"Content");
|
||||
}
|
||||
}
|
||||
|
||||
void ArgWrapper::EnumValue(const Windows::Foundation::IInspectable& enumValue)
|
||||
{
|
||||
if (_EnumValue != enumValue)
|
||||
{
|
||||
_EnumValue = enumValue;
|
||||
Value(enumValue.as<Editor::EnumEntry>().EnumValue());
|
||||
}
|
||||
}
|
||||
|
||||
ActionArgsViewModel::ActionArgsViewModel(const Model::ActionAndArgs actionAndArgs) :
|
||||
_actionAndArgs{ actionAndArgs }
|
||||
{
|
||||
|
||||
@@ -168,36 +168,20 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
|
||||
struct ArgWrapper : ArgWrapperT<ArgWrapper>, ViewModelHelper<ArgWrapper>
|
||||
{
|
||||
public:
|
||||
ArgWrapper(const winrt::hstring& type, const bool required, const Windows::Foundation::IInspectable& value)
|
||||
{
|
||||
Value(value);
|
||||
_type = type;
|
||||
_required = required;
|
||||
};
|
||||
ArgWrapper(const winrt::hstring& type, const bool required, const Windows::Foundation::IInspectable& value);
|
||||
|
||||
winrt::hstring Type()
|
||||
{
|
||||
return _type;
|
||||
}
|
||||
winrt::hstring Type() const noexcept { return _type; };
|
||||
|
||||
bool Required()
|
||||
{
|
||||
return _required;
|
||||
}
|
||||
bool Required() const noexcept { return _required; };
|
||||
|
||||
void StringBindBack(const winrt::hstring& newValue)
|
||||
{
|
||||
Value(box_value(newValue));
|
||||
}
|
||||
Windows::Foundation::Collections::IObservableVector<Microsoft::Terminal::Settings::Editor::EnumEntry> EnumList() const noexcept { return _EnumList; };
|
||||
|
||||
void DoubleBindBack(const double newValue)
|
||||
{
|
||||
Value(box_value(static_cast<uint32_t>(newValue)));
|
||||
}
|
||||
void StringBindBack(const winrt::hstring& newValue) { Value(box_value(newValue)); };
|
||||
|
||||
void DoubleBindBack(const double newValue) { Value(box_value(static_cast<uint32_t>(newValue))); };
|
||||
|
||||
void BoolBindBack(const Windows::Foundation::IReference<bool> newValue)
|
||||
{
|
||||
// todo: bool doesn't work fully - 3-state checkbox not working? possibly because it's binding to a bool
|
||||
if (newValue)
|
||||
{
|
||||
Value(box_value(newValue));
|
||||
@@ -208,11 +192,17 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
|
||||
}
|
||||
}
|
||||
|
||||
// We cannot use the macro here because we need to implement additional logic for the setter
|
||||
Windows::Foundation::IInspectable EnumValue() const noexcept { return _EnumValue; };
|
||||
void EnumValue(const Windows::Foundation::IInspectable& value);
|
||||
|
||||
VIEW_MODEL_OBSERVABLE_PROPERTY(Windows::Foundation::IInspectable, Value, nullptr);
|
||||
|
||||
private:
|
||||
winrt::hstring _type;
|
||||
bool _required;
|
||||
Windows::Foundation::IInspectable _EnumValue{ nullptr };
|
||||
Windows::Foundation::Collections::IObservableVector<Microsoft::Terminal::Settings::Editor::EnumEntry> _EnumList;
|
||||
};
|
||||
|
||||
struct ActionArgsViewModel : ActionArgsViewModelT<ActionArgsViewModel>, ViewModelHelper<ActionArgsViewModel>
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
import "EnumEntry.idl";
|
||||
|
||||
namespace Microsoft.Terminal.Settings.Editor
|
||||
{
|
||||
runtimeclass ModifyKeyBindingEventArgs
|
||||
@@ -79,6 +81,8 @@ namespace Microsoft.Terminal.Settings.Editor
|
||||
String Type { get; };
|
||||
Boolean Required { get; };
|
||||
IInspectable Value;
|
||||
IInspectable EnumValue;
|
||||
Windows.Foundation.Collections.IObservableVector<Microsoft.Terminal.Settings.Editor.EnumEntry> EnumList { get; };
|
||||
void StringBindBack(String newValue);
|
||||
void DoubleBindBack(Double newValue);
|
||||
void BoolBindBack(Windows.Foundation.IReference<Boolean> newValue);
|
||||
|
||||
@@ -49,6 +49,10 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
|
||||
{
|
||||
return UInt32Template();
|
||||
}
|
||||
else if (argType == L"Model::ResizeDirection")
|
||||
{
|
||||
return EnumTemplate();
|
||||
}
|
||||
else if (argType == L"Windows::Foundation::IReference<Control::CopyFormat>")
|
||||
{
|
||||
return nullptr;
|
||||
|
||||
@@ -18,6 +18,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
|
||||
WINRT_PROPERTY(winrt::Windows::UI::Xaml::DataTemplate, StringTemplate);
|
||||
WINRT_PROPERTY(winrt::Windows::UI::Xaml::DataTemplate, BoolTemplate);
|
||||
WINRT_PROPERTY(winrt::Windows::UI::Xaml::DataTemplate, BoolOptionalTemplate);
|
||||
WINRT_PROPERTY(winrt::Windows::UI::Xaml::DataTemplate, EnumTemplate);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -11,5 +11,6 @@ namespace Microsoft.Terminal.Settings.Editor
|
||||
Windows.UI.Xaml.DataTemplate StringTemplate;
|
||||
Windows.UI.Xaml.DataTemplate BoolTemplate;
|
||||
Windows.UI.Xaml.DataTemplate BoolOptionalTemplate;
|
||||
Windows.UI.Xaml.DataTemplate EnumTemplate;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -267,11 +267,30 @@
|
||||
</ListViewItem>
|
||||
</DataTemplate>
|
||||
|
||||
<DataTemplate x:Key="EnumComboBoxTemplate"
|
||||
x:DataType="local:EnumEntry">
|
||||
<TextBlock Text="{x:Bind EnumName, Mode=OneWay}" />
|
||||
</DataTemplate>
|
||||
|
||||
<DataTemplate x:Key="EnumTemplate"
|
||||
x:DataType="local:ArgWrapper">
|
||||
<ListViewItem>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<ComboBox ItemTemplate="{StaticResource EnumComboBoxTemplate}"
|
||||
ItemsSource="{x:Bind EnumList, Mode=OneWay}"
|
||||
SelectedItem="{x:Bind EnumValue, Mode=TwoWay}"
|
||||
Style="{StaticResource ComboBoxSettingStyle}" />
|
||||
</StackPanel>
|
||||
</ListViewItem>
|
||||
</DataTemplate>
|
||||
|
||||
<local:ArgsTemplateSelectors x:Key="ArgsTemplateSelector"
|
||||
UInt32Template="{StaticResource UInt32Template}"
|
||||
StringTemplate="{StaticResource StringTemplate}"
|
||||
BoolTemplate="{StaticResource BoolTemplate}"
|
||||
BoolOptionalTemplate="{StaticResource BoolOptionalTemplate}" />
|
||||
BoolOptionalTemplate="{StaticResource BoolOptionalTemplate}"
|
||||
EnumTemplate="{StaticResource EnumTemplate}" />
|
||||
|
||||
</ResourceDictionary>
|
||||
</Page.Resources>
|
||||
|
||||
|
||||
@@ -1844,6 +1844,26 @@
|
||||
<value>Action</value>
|
||||
<comment>Label for a control that sets the action of a key binding.</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>
|
||||
</data>
|
||||
<data name="Actions_ResizeDirectionLeft.Content" xml:space="preserve">
|
||||
<value>Left</value>
|
||||
<comment>An option to choose from for the "resize direction". Left option.</comment>
|
||||
</data>
|
||||
<data name="Actions_ResizeDirectionRight.Content" xml:space="preserve">
|
||||
<value>Right</value>
|
||||
<comment>An option to choose from for the "resize direction". Right option.</comment>
|
||||
</data>
|
||||
<data name="Actions_ResizeDirectionUp.Content" xml:space="preserve">
|
||||
<value>Up</value>
|
||||
<comment>An option to choose from for the "resize direction". Up option.</comment>
|
||||
</data>
|
||||
<data name="Actions_ResizeDirectionDown.Content" xml:space="preserve">
|
||||
<value>Down</value>
|
||||
<comment>An option to choose from for the "resize direction". Down option.</comment>
|
||||
</data>
|
||||
<data name="ShortcutAction_SendInput" xml:space="preserve">
|
||||
<value>Send input</value>
|
||||
<comment>One of the possible shortcut action types. This represents the "Send input" action.</comment>
|
||||
|
||||
@@ -998,6 +998,10 @@ Model::IActionArgs CascadiaSettings::GetEmptyArgsForAction(Model::ShortcutAction
|
||||
{
|
||||
switch (shortcutAction)
|
||||
{
|
||||
case Model::ShortcutAction::SwitchToTab:
|
||||
return winrt::make<SwitchToTabArgs>();
|
||||
case Model::ShortcutAction::ResizePane:
|
||||
return winrt::make<ResizePaneArgs>();
|
||||
case Model::ShortcutAction::SendInput:
|
||||
return winrt::make<SendInputArgs>();
|
||||
case Model::ShortcutAction::MovePane:
|
||||
|
||||
Reference in New Issue
Block a user