Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a 'splitPane' ShortcutAction #3722

Merged
merged 7 commits into from
Nov 28, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/cascadia/TerminalApp/ActionArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@
#include "ResizePaneArgs.g.cpp"
#include "MoveFocusArgs.g.cpp"
#include "AdjustFontSizeArgs.g.cpp"
#include "SplitPaneArgs.g.cpp"
48 changes: 48 additions & 0 deletions src/cascadia/TerminalApp/ActionArgs.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "ResizePaneArgs.g.h"
#include "MoveFocusArgs.g.h"
#include "AdjustFontSizeArgs.g.h"
#include "SplitPaneArgs.g.h"

#include "../../cascadia/inc/cppwinrt_utils.h"
#include "Utils.h"
Expand Down Expand Up @@ -241,6 +242,53 @@ namespace winrt::TerminalApp::implementation
return *args;
}
};

// Possible SplitState values
// TODO:GH#2550/#3475 - move these to a centralized deserializing place
static constexpr std::string_view VerticalKey{ "vertical" };
static constexpr std::string_view HorizontalKey{ "horizontal" };
static TerminalApp::SplitState ParseSplitState(const std::string& stateString)
{
if (stateString == VerticalKey)
{
return TerminalApp::SplitState::Vertical;
}
else if (stateString == HorizontalKey)
{
return TerminalApp::SplitState::Horizontal;
}
// default behavior for invalid data
return TerminalApp::SplitState::None;
};

struct SplitPaneArgs : public SplitPaneArgsT<SplitPaneArgs>
{
SplitPaneArgs() = default;
GETSET_PROPERTY(winrt::TerminalApp::SplitState, SplitStyle, winrt::TerminalApp::SplitState::None);

static constexpr std::string_view StyleKey{ "style" };
zadjii-msft marked this conversation as resolved.
Show resolved Hide resolved

public:
bool Equals(const IActionArgs& other)
{
auto otherAsUs = other.try_as<SplitPaneArgs>();
if (otherAsUs)
{
return otherAsUs->_SplitStyle == _SplitStyle;
}
return false;
};
static winrt::TerminalApp::IActionArgs FromJson(const Json::Value& json)
{
// LOAD BEARING: Not using make_self here _will_ break you in the future!
auto args = winrt::make_self<SplitPaneArgs>();
if (auto jsonStyle{ json[JsonKey(StyleKey)] })
{
args->_SplitStyle = ParseSplitState(jsonStyle.asString());
}
return *args;
}
};
}

namespace winrt::TerminalApp::factory_implementation
Expand Down
11 changes: 11 additions & 0 deletions src/cascadia/TerminalApp/ActionArgs.idl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ namespace TerminalApp
Down
};

enum SplitState
{
None = 0,
Vertical = 1,
Horizontal = 2
};

[default_interface] runtimeclass ActionEventArgs : IActionEventArgs
{
ActionEventArgs(IActionArgs args);
Expand Down Expand Up @@ -60,4 +67,8 @@ namespace TerminalApp
Int32 Delta { get; };
};

[default_interface] runtimeclass SplitPaneArgs : IActionArgs
{
SplitState SplitStyle { get; };
};
}
22 changes: 11 additions & 11 deletions src/cascadia/TerminalApp/AppActionHandlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,18 @@ namespace winrt::TerminalApp::implementation
args.Handled(true);
}

void TerminalPage::_HandleSplitVertical(const IInspectable& /*sender*/,
const TerminalApp::ActionEventArgs& args)
{
_SplitVertical(std::nullopt);
args.Handled(true);
}

void TerminalPage::_HandleSplitHorizontal(const IInspectable& /*sender*/,
const TerminalApp::ActionEventArgs& args)
void TerminalPage::_HandleSplitPane(const IInspectable& /*sender*/,
const TerminalApp::ActionEventArgs& args)
{
_SplitHorizontal(std::nullopt);
args.Handled(true);
if (args == nullptr)
{
args.Handled(false);
}
else if (const auto& realArgs = args.ActionArgs().try_as<TerminalApp::SplitPaneArgs>())
{
_SplitPane(realArgs.SplitStyle(), std::nullopt);
args.Handled(true);
}
}

void TerminalPage::_HandleScrollUpPage(const IInspectable& /*sender*/,
Expand Down
7 changes: 2 additions & 5 deletions src/cascadia/TerminalApp/AppKeyBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,10 @@ namespace winrt::TerminalApp::implementation
}

case ShortcutAction::SplitVertical:
{
_SplitVerticalHandlers(*this, *eventArgs);
break;
}
case ShortcutAction::SplitHorizontal:
case ShortcutAction::SplitPane:
{
_SplitHorizontalHandlers(*this, *eventArgs);
_SplitPaneHandlers(*this, *eventArgs);
break;
}

Expand Down
3 changes: 1 addition & 2 deletions src/cascadia/TerminalApp/AppKeyBindings.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ namespace winrt::TerminalApp::implementation
TYPED_EVENT(SwitchToTab, TerminalApp::AppKeyBindings, TerminalApp::ActionEventArgs);
TYPED_EVENT(NextTab, TerminalApp::AppKeyBindings, TerminalApp::ActionEventArgs);
TYPED_EVENT(PrevTab, TerminalApp::AppKeyBindings, TerminalApp::ActionEventArgs);
TYPED_EVENT(SplitVertical, TerminalApp::AppKeyBindings, TerminalApp::ActionEventArgs);
TYPED_EVENT(SplitHorizontal, TerminalApp::AppKeyBindings, TerminalApp::ActionEventArgs);
TYPED_EVENT(SplitPane, TerminalApp::AppKeyBindings, TerminalApp::ActionEventArgs);
TYPED_EVENT(AdjustFontSize, TerminalApp::AppKeyBindings, TerminalApp::ActionEventArgs);
TYPED_EVENT(ResetFontSize, TerminalApp::AppKeyBindings, TerminalApp::ActionEventArgs);
TYPED_EVENT(ScrollUp, TerminalApp::AppKeyBindings, TerminalApp::ActionEventArgs);
Expand Down
8 changes: 4 additions & 4 deletions src/cascadia/TerminalApp/AppKeyBindings.idl
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ namespace TerminalApp
ClosePane,
NextTab,
PrevTab,
SplitVertical,
SplitHorizontal,
SplitVertical, // Legacy
SplitHorizontal, // Legacy
SplitPane,
SwitchToTab,
SwitchToTab0, // Legacy
SwitchToTab1, // Legacy
Expand Down Expand Up @@ -92,8 +93,7 @@ namespace TerminalApp
event Windows.Foundation.TypedEventHandler<AppKeyBindings, ActionEventArgs> SwitchToTab;
event Windows.Foundation.TypedEventHandler<AppKeyBindings, ActionEventArgs> NextTab;
event Windows.Foundation.TypedEventHandler<AppKeyBindings, ActionEventArgs> PrevTab;
event Windows.Foundation.TypedEventHandler<AppKeyBindings, ActionEventArgs> SplitVertical;
event Windows.Foundation.TypedEventHandler<AppKeyBindings, ActionEventArgs> SplitHorizontal;
event Windows.Foundation.TypedEventHandler<AppKeyBindings, ActionEventArgs> SplitPane;
event Windows.Foundation.TypedEventHandler<AppKeyBindings, ActionEventArgs> AdjustFontSize;
event Windows.Foundation.TypedEventHandler<AppKeyBindings, ActionEventArgs> ResetFontSize;
event Windows.Foundation.TypedEventHandler<AppKeyBindings, ActionEventArgs> ScrollUp;
Expand Down
31 changes: 29 additions & 2 deletions src/cascadia/TerminalApp/AppKeyBindingsSerialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ static constexpr std::string_view SwitchToTab6Key{ "switchToTab6" }; // Legacy
static constexpr std::string_view SwitchToTab7Key{ "switchToTab7" }; // Legacy
static constexpr std::string_view SwitchToTab8Key{ "switchToTab8" }; // Legacy
static constexpr std::string_view OpenSettingsKey{ "openSettings" }; // Legacy
static constexpr std::string_view SplitHorizontalKey{ "splitHorizontal" };
static constexpr std::string_view SplitVerticalKey{ "splitVertical" };
static constexpr std::string_view SplitHorizontalKey{ "splitHorizontal" }; // Legacy
static constexpr std::string_view SplitVerticalKey{ "splitVertical" }; // Legacy
static constexpr std::string_view ResizePaneKey{ "resizePane" };
static constexpr std::string_view ResizePaneLeftKey{ "resizePaneLeft" }; // Legacy
static constexpr std::string_view ResizePaneRightKey{ "resizePaneRight" }; // Legacy
Expand All @@ -77,6 +77,7 @@ static constexpr std::string_view MoveFocusRightKey{ "moveFocusRight" }; // Lega
static constexpr std::string_view MoveFocusUpKey{ "moveFocusUp" }; // Legacy
static constexpr std::string_view MoveFocusDownKey{ "moveFocusDown" }; // Legacy
static constexpr std::string_view ToggleFullscreenKey{ "toggleFullscreen" };
static constexpr std::string_view SplitPaneKey{ "splitPane" };
zadjii-msft marked this conversation as resolved.
Show resolved Hide resolved

// 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.
Expand Down Expand Up @@ -139,9 +140,31 @@ static const std::map<std::string_view, ShortcutAction, std::less<>> commandName
{ MoveFocusDownKey, ShortcutAction::MoveFocusDown },
{ OpenSettingsKey, ShortcutAction::OpenSettings },
{ ToggleFullscreenKey, ShortcutAction::ToggleFullscreen },
{ SplitPaneKey, ShortcutAction::SplitPane },
{ UnboundKey, ShortcutAction::Invalid },
};

// Function Description:
// - Creates a function that can be used to generate a SplitPaneArgs for the
// legacy Split[SplitState] actions. These actions don't accept args from
// json, instead, they just return a SplitPaneArgs with the style already
// pre-defined, based on the input param.
// - TODO: GH#1069 Remove this before 1.0, and force an upgrade to the new args.
// Arguments:
// - style: the split style to create the parse function for.
// Return Value:
// - A function that can be used to "parse" json into one of the legacy
// Split[SplitState] args.
std::function<IActionArgs(const Json::Value&)> LegacyParseSplitPaneArgs(SplitState style)
{
auto pfn = [style](const Json::Value & /*value*/) -> IActionArgs {
auto args = winrt::make_self<winrt::TerminalApp::implementation::SplitPaneArgs>();
args->SplitStyle(style);
return *args;
};
return pfn;
}

// Function Description:
// - Creates a function that can be used to generate a MoveFocusArgs for the
// legacy MoveFocus[Direction] actions. These actions don't accept args from
Expand Down Expand Up @@ -305,6 +328,10 @@ static const std::map<ShortcutAction, std::function<IActionArgs(const Json::Valu
{ ShortcutAction::DecreaseFontSize, LegacyParseAdjustFontSizeArgs(-1) },
{ ShortcutAction::IncreaseFontSize, LegacyParseAdjustFontSizeArgs(1) },

{ ShortcutAction::SplitPane, winrt::TerminalApp::implementation::SplitPaneArgs::FromJson },
{ ShortcutAction::SplitVertical, LegacyParseSplitPaneArgs(SplitState::Vertical) },
{ ShortcutAction::SplitHorizontal, LegacyParseSplitPaneArgs(SplitState::Horizontal) },

{ ShortcutAction::Invalid, nullptr },
};

Expand Down
29 changes: 11 additions & 18 deletions src/cascadia/TerminalApp/Pane.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,6 @@ DEFINE_ENUM_FLAG_OPERATORS(Borders);
class Pane : public std::enable_shared_from_this<Pane>
{
public:
enum class SplitState : int
{
None = 0,
Vertical = 1,
Horizontal = 2
};

Pane(const GUID& profile,
const winrt::Microsoft::Terminal::TerminalControl::TermControl& control,
const bool lastFocused = false);
Expand All @@ -64,8 +57,8 @@ class Pane : public std::enable_shared_from_this<Pane>
bool ResizePane(const winrt::TerminalApp::Direction& direction);
bool NavigateFocus(const winrt::TerminalApp::Direction& direction);

bool CanSplit(SplitState splitType);
std::pair<std::shared_ptr<Pane>, std::shared_ptr<Pane>> Split(SplitState splitType,
bool CanSplit(winrt::TerminalApp::SplitState splitType);
std::pair<std::shared_ptr<Pane>, std::shared_ptr<Pane>> Split(winrt::TerminalApp::SplitState splitType,
const GUID& profile,
const winrt::Microsoft::Terminal::TerminalControl::TermControl& control);

Expand All @@ -83,7 +76,7 @@ class Pane : public std::enable_shared_from_this<Pane>

std::shared_ptr<Pane> _firstChild{ nullptr };
std::shared_ptr<Pane> _secondChild{ nullptr };
SplitState _splitState{ SplitState::None };
winrt::TerminalApp::SplitState _splitState{ winrt::TerminalApp::SplitState::None };
std::optional<float> _firstPercent{ std::nullopt };
std::optional<float> _secondPercent{ std::nullopt };

Expand All @@ -103,8 +96,8 @@ class Pane : public std::enable_shared_from_this<Pane>
bool _HasFocusedChild() const noexcept;
void _SetupChildCloseHandlers();

bool _CanSplit(SplitState splitType);
std::pair<std::shared_ptr<Pane>, std::shared_ptr<Pane>> _Split(SplitState splitType,
bool _CanSplit(winrt::TerminalApp::SplitState splitType);
std::pair<std::shared_ptr<Pane>, std::shared_ptr<Pane>> _Split(winrt::TerminalApp::SplitState splitType,
const GUID& profile,
const winrt::Microsoft::Terminal::TerminalControl::TermControl& control);

Expand Down Expand Up @@ -137,23 +130,23 @@ class Pane : public std::enable_shared_from_this<Pane>
// again happens _across_ a separator.
// Arguments:
// - direction: The Direction to compare
// - splitType: The SplitState to compare
// - splitType: The winrt::TerminalApp::SplitState to compare
// Return Value:
// - true iff the direction is perpendicular to the splitType. False for
// SplitState::None.
// winrt::TerminalApp::SplitState::None.
static constexpr bool DirectionMatchesSplit(const winrt::TerminalApp::Direction& direction,
const SplitState& splitType)
const winrt::TerminalApp::SplitState& splitType)
{
if (splitType == SplitState::None)
if (splitType == winrt::TerminalApp::SplitState::None)
{
return false;
}
else if (splitType == SplitState::Horizontal)
else if (splitType == winrt::TerminalApp::SplitState::Horizontal)
{
return direction == winrt::TerminalApp::Direction::Up ||
direction == winrt::TerminalApp::Direction::Down;
}
else if (splitType == SplitState::Vertical)
else if (splitType == winrt::TerminalApp::SplitState::Vertical)
{
return direction == winrt::TerminalApp::Direction::Left ||
direction == winrt::TerminalApp::Direction::Right;
Expand Down
4 changes: 2 additions & 2 deletions src/cascadia/TerminalApp/Tab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ void Tab::Scroll(const int delta)
// - splitType: The type of split we want to create.
// Return Value:
// - True if the focused pane can be split. False otherwise.
bool Tab::CanSplitPane(Pane::SplitState splitType)
bool Tab::CanSplitPane(winrt::TerminalApp::SplitState splitType)
{
return _activePane->CanSplit(splitType);
}
Expand All @@ -217,7 +217,7 @@ bool Tab::CanSplitPane(Pane::SplitState splitType)
// - control: A TermControl to use in the new pane.
// Return Value:
// - <none>
void Tab::SplitPane(Pane::SplitState splitType, const GUID& profile, TermControl& control)
void Tab::SplitPane(winrt::TerminalApp::SplitState splitType, const GUID& profile, TermControl& control)
{
auto [first, second] = _activePane->Split(splitType, profile, control);

Expand Down
4 changes: 2 additions & 2 deletions src/cascadia/TerminalApp/Tab.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class Tab

void Scroll(const int delta);

bool CanSplitPane(Pane::SplitState splitType);
void SplitPane(Pane::SplitState splitType, const GUID& profile, winrt::Microsoft::Terminal::TerminalControl::TermControl& control);
bool CanSplitPane(winrt::TerminalApp::SplitState splitType);
void SplitPane(winrt::TerminalApp::SplitState splitType, const GUID& profile, winrt::Microsoft::Terminal::TerminalControl::TermControl& control);

void UpdateIcon(const winrt::hstring iconPath);

Expand Down
33 changes: 6 additions & 27 deletions src/cascadia/TerminalApp/TerminalPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -597,8 +597,9 @@ namespace winrt::TerminalApp::implementation
bindings.ScrollDown({ this, &TerminalPage::_HandleScrollDown });
bindings.NextTab({ this, &TerminalPage::_HandleNextTab });
bindings.PrevTab({ this, &TerminalPage::_HandlePrevTab });
bindings.SplitVertical({ this, &TerminalPage::_HandleSplitVertical });
bindings.SplitHorizontal({ this, &TerminalPage::_HandleSplitHorizontal });
// bindings.SplitVertical({ this, &TerminalPage::_HandleSplitVertical });
// bindings.SplitHorizontal({ this, &TerminalPage::_HandleSplitHorizontal });
zadjii-msft marked this conversation as resolved.
Show resolved Hide resolved
bindings.SplitPane({ this, &TerminalPage::_HandleSplitPane });
bindings.ScrollUpPage({ this, &TerminalPage::_HandleScrollUpPage });
bindings.ScrollDownPage({ this, &TerminalPage::_HandleScrollDownPage });
bindings.OpenSettings({ this, &TerminalPage::_HandleOpenSettings });
Expand Down Expand Up @@ -900,41 +901,19 @@ namespace winrt::TerminalApp::implementation
_tabs[focusedTabIndex]->Scroll(delta);
}

// Method Description:
// - Vertically split the focused pane, and place the given TermControl into
// the newly created pane.
// Arguments:
// - profile: The profile GUID to associate with the newly created pane. If
// this is nullopt, use the default profile.
void TerminalPage::_SplitVertical(const std::optional<GUID>& profileGuid)
{
_SplitPane(Pane::SplitState::Vertical, profileGuid);
}

// Method Description:
// - Horizontally split the focused pane and place the given TermControl
// into the newly created pane.
// Arguments:
// - profile: The profile GUID to associate with the newly created pane. If
// this is nullopt, use the default profile.
void TerminalPage::_SplitHorizontal(const std::optional<GUID>& profileGuid)
{
_SplitPane(Pane::SplitState::Horizontal, profileGuid);
}

// Method Description:
// - Split the focused pane either horizontally or vertically, and place the
// given TermControl into the newly created pane.
// - If splitType == SplitState::None, this method does nothing.
// Arguments:
// - splitType: one value from the Pane::SplitState enum, indicating how the
// - splitType: one value from the TerminalApp::SplitState enum, indicating how the
// new pane should be split from its parent.
// - profile: The profile GUID to associate with the newly created pane. If
// this is nullopt, use the default profile.
void TerminalPage::_SplitPane(const Pane::SplitState splitType, const std::optional<GUID>& profileGuid)
void TerminalPage::_SplitPane(const TerminalApp::SplitState splitType, const std::optional<GUID>& profileGuid)
{
// Do nothing if we're requesting no split.
if (splitType == Pane::SplitState::None)
if (splitType == TerminalApp::SplitState::None)
{
return;
}
Expand Down
Loading