Skip to content

Commit

Permalink
Support SplitState::Automatic
Browse files Browse the repository at this point in the history
  • Loading branch information
mcpiroman committed Jan 11, 2020
1 parent b5a04b1 commit f9aaed6
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/cascadia/TerminalApp/ActionArgs.idl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ namespace TerminalApp
enum SplitState
{
Vertical,
Horizontal
Horizontal,
Automatic
};

[default_interface] runtimeclass NewTerminalArgs {
Expand Down
27 changes: 27 additions & 0 deletions src/cascadia/TerminalApp/LeafPane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ GUID LeafPane::GetProfile() const noexcept
// - True if the pane can be split. False otherwise.
bool LeafPane::CanSplit(SplitState splitType)
{
splitType = _ConvertAutomaticSplitState(splitType);
const Size actualSize{ gsl::narrow_cast<float>(_root.ActualWidth()),
gsl::narrow_cast<float>(_root.ActualHeight()) };

Expand Down Expand Up @@ -189,6 +190,7 @@ std::shared_ptr<LeafPane> LeafPane::Split(winrt::TerminalApp::SplitState splitTy
const GUID& profile,
const winrt::Microsoft::Terminal::TerminalControl::TermControl& control)
{
splitType = _ConvertAutomaticSplitState(splitType);
const auto newNeighbour = std::make_shared<LeafPane>(profile, control);

// Update the border of this pane and set appropriate border for the new leaf pane.
Expand Down Expand Up @@ -228,6 +230,31 @@ std::shared_ptr<LeafPane> LeafPane::Split(winrt::TerminalApp::SplitState splitTy
return newNeighbour;
}

// Method Description:
// - Converts an "automatic" split type into either Vertical or Horizontal,
// based upon the current dimensions of the Pane.
// - If any of the other SplitState values are passed in, they're returned
// unmodified.
// Arguments:
// - splitType: The SplitState to attempt to convert
// Return Value:
// - One of Horizontal or Vertical
SplitState LeafPane::_ConvertAutomaticSplitState(const SplitState& splitType) const
{
// Careful here! If the pane doesn't yet have a size, these dimensions will
// be 0, and we'll always return Vertical.

if (splitType == SplitState::Automatic)
{
// If the requested split type was "auto", determine which direction to
// split based on our current dimensions
const Size actualSize{ gsl::narrow_cast<float>(_root.ActualWidth()),
gsl::narrow_cast<float>(_root.ActualHeight()) };
return actualSize.Width >= actualSize.Height ? SplitState::Vertical : SplitState::Horizontal;
}
return splitType;
}

// Method Description:
// - Sets the "Active" state on this pane. Only one pane in a tree of panes
// should be "active".
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalApp/LeafPane.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class LeafPane : public Pane, public std::enable_shared_from_this<LeafPane>
std::shared_ptr<LeafPane> _FindFirstLeaf() override;
void _UpdateBorders();
void _UpdateVisuals();
winrt::TerminalApp::SplitState _ConvertAutomaticSplitState(const winrt::TerminalApp::SplitState& splitType) const;
SnapSizeResult _CalcSnappedDimension(const bool widthOrHeight, const float dimension) const override;
void _AdvanceSnappedDimension(const bool widthOrHeight, LayoutSizeNode& sizeNode) const override;
winrt::Windows::Foundation::Size _GetMinSize() const override;
Expand Down
15 changes: 12 additions & 3 deletions src/cascadia/TerminalApp/TerminalPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@ namespace winrt::TerminalApp::implementation

// Add the new tab to the list of our tabs.
auto newTab = _tabs.emplace_back(std::make_shared<Tab>(profileGuid, term));
newTab->BindEventHandlers();

// Hookup our event handlers to the new terminal
_RegisterTerminalEvents(term, newTab);
Expand All @@ -474,6 +475,17 @@ namespace winrt::TerminalApp::implementation
}
});

newTab->RootPaneChanged([weakTabPtr, weakThis{ get_weak() }]() {
auto page{ weakThis.get() };
auto tab{ weakTabPtr.lock() };

if (page && tab)
{
page->_tabContent.Children().Clear();
page->_tabContent.Children().Append(tab->GetRootElement());
}
});

auto tabViewItem = newTab->GetTabViewItem();
_tabView.TabItems().Append(tabViewItem);

Expand Down Expand Up @@ -798,9 +810,6 @@ namespace winrt::TerminalApp::implementation
// Add an event handler when the terminal wants to paste data from the Clipboard.
term.PasteFromClipboard({ this, &TerminalPage::_PasteFromClipboardHandler });

// Bind Tab events to the TermControl and the Tab's Pane
hostingTab->BindEventHandlers(term);

// Don't capture a strong ref to the tab. If the tab is removed as this
// is called, we don't really care anymore about handling the event.
std::weak_ptr<Tab> weakTabPtr = hostingTab;
Expand Down

0 comments on commit f9aaed6

Please sign in to comment.