Add a splitPane option to duplicate current profile (#4683)
This change adds the ability to configure a pane to split by duplicating the current profile Closes #1756
This commit is contained in:
parent
d8f7aac4ca
commit
cc35c83e6a
|
@ -331,13 +331,26 @@ namespace winrt::TerminalApp::implementation
|
|||
return TerminalApp::SplitState::None;
|
||||
};
|
||||
|
||||
// Possible SplitType values
|
||||
static constexpr std::string_view DuplicateKey{ "duplicate" };
|
||||
static TerminalApp::SplitType ParseSplitModeState(const std::string& stateString)
|
||||
{
|
||||
if (stateString == DuplicateKey)
|
||||
{
|
||||
return TerminalApp::SplitType::Duplicate;
|
||||
}
|
||||
return TerminalApp::SplitType::Manual;
|
||||
}
|
||||
|
||||
struct SplitPaneArgs : public SplitPaneArgsT<SplitPaneArgs>
|
||||
{
|
||||
SplitPaneArgs() = default;
|
||||
GETSET_PROPERTY(winrt::TerminalApp::SplitState, SplitStyle, winrt::TerminalApp::SplitState::None);
|
||||
GETSET_PROPERTY(winrt::TerminalApp::NewTerminalArgs, TerminalArgs, nullptr);
|
||||
GETSET_PROPERTY(winrt::TerminalApp::SplitType, SplitMode, winrt::TerminalApp::SplitType::Manual);
|
||||
|
||||
static constexpr std::string_view SplitKey{ "split" };
|
||||
static constexpr std::string_view SplitModeKey{ "splitMode" };
|
||||
|
||||
public:
|
||||
bool Equals(const IActionArgs& other)
|
||||
|
@ -346,7 +359,8 @@ namespace winrt::TerminalApp::implementation
|
|||
if (otherAsUs)
|
||||
{
|
||||
return otherAsUs->_SplitStyle == _SplitStyle &&
|
||||
otherAsUs->_TerminalArgs == _TerminalArgs;
|
||||
otherAsUs->_TerminalArgs == _TerminalArgs &&
|
||||
otherAsUs->_SplitMode == _SplitMode;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
@ -359,6 +373,10 @@ namespace winrt::TerminalApp::implementation
|
|||
{
|
||||
args->_SplitStyle = ParseSplitState(jsonStyle.asString());
|
||||
}
|
||||
if (auto jsonStyle{ json[JsonKey(SplitModeKey)] })
|
||||
{
|
||||
args->_SplitMode = ParseSplitModeState(jsonStyle.asString());
|
||||
}
|
||||
return { *args, {} };
|
||||
}
|
||||
};
|
||||
|
|
|
@ -31,6 +31,12 @@ namespace TerminalApp
|
|||
Horizontal = 2
|
||||
};
|
||||
|
||||
enum SplitType
|
||||
{
|
||||
Manual = 0,
|
||||
Duplicate = 1
|
||||
};
|
||||
|
||||
[default_interface] runtimeclass NewTerminalArgs {
|
||||
NewTerminalArgs();
|
||||
String Commandline;
|
||||
|
@ -82,5 +88,6 @@ namespace TerminalApp
|
|||
{
|
||||
SplitState SplitStyle { get; };
|
||||
NewTerminalArgs TerminalArgs { get; };
|
||||
SplitType SplitMode { get; };
|
||||
};
|
||||
}
|
||||
|
|
|
@ -98,7 +98,7 @@ namespace winrt::TerminalApp::implementation
|
|||
}
|
||||
else if (const auto& realArgs = args.ActionArgs().try_as<TerminalApp::SplitPaneArgs>())
|
||||
{
|
||||
_SplitPane(realArgs.SplitStyle(), realArgs.TerminalArgs());
|
||||
_SplitPane(realArgs.SplitStyle(), realArgs.SplitMode(), realArgs.TerminalArgs());
|
||||
args.Handled(true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1045,10 +1045,12 @@ namespace winrt::TerminalApp::implementation
|
|||
// Arguments:
|
||||
// - splitType: one value from the TerminalApp::SplitState enum, indicating how the
|
||||
// new pane should be split from its parent.
|
||||
// - splitMode: value from TerminalApp::SplitType enum, indicating the profile to be used in the newly split pane.
|
||||
// - newTerminalArgs: An object that may contain a blob of parameters to
|
||||
// control which profile is created and with possible other
|
||||
// configurations. See CascadiaSettings::BuildSettings for more details.
|
||||
void TerminalPage::_SplitPane(const TerminalApp::SplitState splitType,
|
||||
const TerminalApp::SplitType splitMode,
|
||||
const winrt::TerminalApp::NewTerminalArgs& newTerminalArgs)
|
||||
{
|
||||
// Do nothing if we're requesting no split.
|
||||
|
@ -1067,7 +1069,24 @@ namespace winrt::TerminalApp::implementation
|
|||
|
||||
auto focusedTab = _GetStrongTabImpl(*indexOpt);
|
||||
|
||||
const auto [realGuid, controlSettings] = _settings->BuildSettings(newTerminalArgs);
|
||||
winrt::Microsoft::Terminal::Settings::TerminalSettings controlSettings;
|
||||
GUID realGuid;
|
||||
bool profileFound = false;
|
||||
|
||||
if (splitMode == TerminalApp::SplitType::Duplicate)
|
||||
{
|
||||
std::optional<GUID> current_guid = focusedTab->GetFocusedProfile();
|
||||
if (current_guid)
|
||||
{
|
||||
profileFound = true;
|
||||
controlSettings = _settings->BuildSettings(current_guid.value());
|
||||
realGuid = current_guid.value();
|
||||
}
|
||||
}
|
||||
if (!profileFound)
|
||||
{
|
||||
std::tie(realGuid, controlSettings) = _settings->BuildSettings(newTerminalArgs);
|
||||
}
|
||||
|
||||
const auto controlConnection = _CreateConnectionFromSettings(realGuid, controlSettings);
|
||||
|
||||
|
|
|
@ -122,7 +122,7 @@ namespace winrt::TerminalApp::implementation
|
|||
// Todo: add more event implementations here
|
||||
// MSFT:20641986: Add keybindings for New Window
|
||||
void _Scroll(int delta);
|
||||
void _SplitPane(const winrt::TerminalApp::SplitState splitType, const winrt::TerminalApp::NewTerminalArgs& newTerminalArgs = nullptr);
|
||||
void _SplitPane(const winrt::TerminalApp::SplitState splitType, const winrt::TerminalApp::SplitType splitMode = winrt::TerminalApp::SplitType::Manual, const winrt::TerminalApp::NewTerminalArgs& newTerminalArgs = nullptr);
|
||||
void _ResizePane(const Direction& direction);
|
||||
void _ScrollPage(int delta);
|
||||
void _SetAcceleratorForMenuItem(Windows::UI::Xaml::Controls::MenuFlyoutItem& menuItem, const winrt::Microsoft::Terminal::Settings::KeyChord& keyChord);
|
||||
|
|
Loading…
Reference in a new issue