terminal/src/cascadia/TerminalApp/Pane.h

148 lines
5.5 KiB
C
Raw Normal View History

// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
//
// Module Name:
// - Pane.h
//
// Abstract:
// - Panes are an abstraction by which the terminal can dislay multiple terminal
// instances simultaneously in a single terminal window. While tabs allow for
// a single terminal window to have many terminal sessions running
// simultaneously within a single window, only one tab can be visible at a
// time. Panes, on the other hand, allow a user to have many different
// terminal sessions visible to the user within the context of a single window
// at the same time. This can enable greater productivity from the user, as
// they can see the output of one terminal window while working in another.
// - See doc/cascadia/Panes.md for a detailed description.
//
// Author:
// - Mike Griese (zadjii-msft) 16-May-2019
#pragma once
#include <winrt/Microsoft.Terminal.TerminalControl.h>
#include <winrt/TerminalApp.h>
#include "../../cascadia/inc/cppwinrt_utils.h"
Indicate which pane is focused with the Accent color on the pan… (#3060) ## Summary of the Pull Request Adds a small border with the accent color to indicate a pane is focused <img src="https://user-images.githubusercontent.com/18356694/66218711-560e4b80-e68f-11e9-85b0-1f387d35bb92.png" width="480"> <img src="https://user-images.githubusercontent.com/18356694/66218757-6f16fc80-e68f-11e9-8d39-db9ab748c4de.png" width="480"> <img src="https://user-images.githubusercontent.com/18356694/66219194-55c28000-e690-11e9-9835-8b5212e70e8a.png" width="480"> ## PR Checklist * [x] Closes #994 * [x] I work here * [😢] Tests added/passed * [n/a] Requires documentation to be updated ## Detailed Description of the Pull Request / Additional comments I've removed the simple Grid we were using as the pane separator, and replaced it with a Border that might appear on any side of a pane. When we add a split, we'll create each child with one of the `Border` flags set (each child with one of a pair of flags). E.g. creating a horizontal split creates one child with the `Top` border, and another with the `Bottom`. Then, if one of those panes is split, it will pass it's border flag to is new children, with the additional flag set. So adding another Vertical split to the above scenario would create a set of panes with either (`Top|Left`, `Top|Right`) or (`Bottom|Left`, `Bottom|Right`) borders set, depending on which pane was split. <hr> * start work on this by tracking border state * Colorize the border * Use the accent color for highlighting * Cleanup the accent color code * Don't buy any rural real estate when closing a pane * Closing panes works well now too * Cleanup for review * Update src/cascadia/TerminalApp/Pane.cpp * try some things that don't work to fix the resizing crash * Revert "try some things that don't work to fix the resizing crash" This reverts commit 3fc14da1130318add37a98d8de8d7ff440bbed59. * this _does_ work, but I think it's not semantically correct * This doesn't seem to work either. I tried adding the pane seperators to the Pane::_GetMinWidth calculation. That works for prevent the crash, but the resizing is wonky now. If you add a Vertical split, then a second, then resize the middle pane really small, you'll see that the _last_ resize doesn't work properly. The text seems to overhand into the border. Additionally, there's really weird behavior resizing panes to be small. They don't always seem to be resizable to the smallest size. * Revert "This doesn't seem to work either." This reverts commit 2fd8323e7ba84527963f051a4e70751e846be87a. * Merge the changes from the "this is the one" branch Again, no idea what I really did that worked, but it does * Cleanup from my mess of a commit This makes so much more sense now * Other PR feedback from @carlos-zamora * Fix a typo
2019-11-01 21:06:11 +01:00
enum class Borders : int
{
None = 0x0,
Top = 0x1,
Bottom = 0x2,
Left = 0x4,
Right = 0x8
};
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);
std::shared_ptr<Pane> GetFocusedPane();
winrt::Microsoft::Terminal::TerminalControl::TermControl GetFocusedTerminalControl();
std::optional<GUID> GetFocusedProfile();
winrt::Windows::UI::Xaml::Controls::Grid GetRootElement();
bool WasLastFocused() const noexcept;
void UpdateFocus();
void UpdateSettings(const winrt::Microsoft::Terminal::Settings::TerminalSettings& settings, const GUID& profile);
void ResizeContent(const winrt::Windows::Foundation::Size& newSize);
bool ResizePane(const winrt::TerminalApp::Direction& direction);
bool NavigateFocus(const winrt::TerminalApp::Direction& direction);
bool CanSplit(SplitState splitType);
void Split(SplitState splitType, const GUID& profile, const winrt::Microsoft::Terminal::TerminalControl::TermControl& control);
void Close();
DECLARE_EVENT(Closed, _closedHandlers, winrt::Microsoft::Terminal::TerminalControl::ConnectionClosedEventArgs);
private:
winrt::Windows::UI::Xaml::Controls::Grid _root{};
Indicate which pane is focused with the Accent color on the pan… (#3060) ## Summary of the Pull Request Adds a small border with the accent color to indicate a pane is focused <img src="https://user-images.githubusercontent.com/18356694/66218711-560e4b80-e68f-11e9-85b0-1f387d35bb92.png" width="480"> <img src="https://user-images.githubusercontent.com/18356694/66218757-6f16fc80-e68f-11e9-8d39-db9ab748c4de.png" width="480"> <img src="https://user-images.githubusercontent.com/18356694/66219194-55c28000-e690-11e9-9835-8b5212e70e8a.png" width="480"> ## PR Checklist * [x] Closes #994 * [x] I work here * [😢] Tests added/passed * [n/a] Requires documentation to be updated ## Detailed Description of the Pull Request / Additional comments I've removed the simple Grid we were using as the pane separator, and replaced it with a Border that might appear on any side of a pane. When we add a split, we'll create each child with one of the `Border` flags set (each child with one of a pair of flags). E.g. creating a horizontal split creates one child with the `Top` border, and another with the `Bottom`. Then, if one of those panes is split, it will pass it's border flag to is new children, with the additional flag set. So adding another Vertical split to the above scenario would create a set of panes with either (`Top|Left`, `Top|Right`) or (`Bottom|Left`, `Bottom|Right`) borders set, depending on which pane was split. <hr> * start work on this by tracking border state * Colorize the border * Use the accent color for highlighting * Cleanup the accent color code * Don't buy any rural real estate when closing a pane * Closing panes works well now too * Cleanup for review * Update src/cascadia/TerminalApp/Pane.cpp * try some things that don't work to fix the resizing crash * Revert "try some things that don't work to fix the resizing crash" This reverts commit 3fc14da1130318add37a98d8de8d7ff440bbed59. * this _does_ work, but I think it's not semantically correct * This doesn't seem to work either. I tried adding the pane seperators to the Pane::_GetMinWidth calculation. That works for prevent the crash, but the resizing is wonky now. If you add a Vertical split, then a second, then resize the middle pane really small, you'll see that the _last_ resize doesn't work properly. The text seems to overhand into the border. Additionally, there's really weird behavior resizing panes to be small. They don't always seem to be resizable to the smallest size. * Revert "This doesn't seem to work either." This reverts commit 2fd8323e7ba84527963f051a4e70751e846be87a. * Merge the changes from the "this is the one" branch Again, no idea what I really did that worked, but it does * Cleanup from my mess of a commit This makes so much more sense now * Other PR feedback from @carlos-zamora * Fix a typo
2019-11-01 21:06:11 +01:00
winrt::Windows::UI::Xaml::Controls::Border _border{};
winrt::Microsoft::Terminal::TerminalControl::TermControl _control{ nullptr };
Indicate which pane is focused with the Accent color on the pan… (#3060) ## Summary of the Pull Request Adds a small border with the accent color to indicate a pane is focused <img src="https://user-images.githubusercontent.com/18356694/66218711-560e4b80-e68f-11e9-85b0-1f387d35bb92.png" width="480"> <img src="https://user-images.githubusercontent.com/18356694/66218757-6f16fc80-e68f-11e9-8d39-db9ab748c4de.png" width="480"> <img src="https://user-images.githubusercontent.com/18356694/66219194-55c28000-e690-11e9-9835-8b5212e70e8a.png" width="480"> ## PR Checklist * [x] Closes #994 * [x] I work here * [😢] Tests added/passed * [n/a] Requires documentation to be updated ## Detailed Description of the Pull Request / Additional comments I've removed the simple Grid we were using as the pane separator, and replaced it with a Border that might appear on any side of a pane. When we add a split, we'll create each child with one of the `Border` flags set (each child with one of a pair of flags). E.g. creating a horizontal split creates one child with the `Top` border, and another with the `Bottom`. Then, if one of those panes is split, it will pass it's border flag to is new children, with the additional flag set. So adding another Vertical split to the above scenario would create a set of panes with either (`Top|Left`, `Top|Right`) or (`Bottom|Left`, `Bottom|Right`) borders set, depending on which pane was split. <hr> * start work on this by tracking border state * Colorize the border * Use the accent color for highlighting * Cleanup the accent color code * Don't buy any rural real estate when closing a pane * Closing panes works well now too * Cleanup for review * Update src/cascadia/TerminalApp/Pane.cpp * try some things that don't work to fix the resizing crash * Revert "try some things that don't work to fix the resizing crash" This reverts commit 3fc14da1130318add37a98d8de8d7ff440bbed59. * this _does_ work, but I think it's not semantically correct * This doesn't seem to work either. I tried adding the pane seperators to the Pane::_GetMinWidth calculation. That works for prevent the crash, but the resizing is wonky now. If you add a Vertical split, then a second, then resize the middle pane really small, you'll see that the _last_ resize doesn't work properly. The text seems to overhand into the border. Additionally, there's really weird behavior resizing panes to be small. They don't always seem to be resizable to the smallest size. * Revert "This doesn't seem to work either." This reverts commit 2fd8323e7ba84527963f051a4e70751e846be87a. * Merge the changes from the "this is the one" branch Again, no idea what I really did that worked, but it does * Cleanup from my mess of a commit This makes so much more sense now * Other PR feedback from @carlos-zamora * Fix a typo
2019-11-01 21:06:11 +01:00
static winrt::Windows::UI::Xaml::Media::SolidColorBrush s_focusedBorderBrush;
std::shared_ptr<Pane> _firstChild{ nullptr };
std::shared_ptr<Pane> _secondChild{ nullptr };
SplitState _splitState{ SplitState::None };
std::optional<float> _firstPercent{ std::nullopt };
std::optional<float> _secondPercent{ std::nullopt };
bool _lastFocused{ false };
std::optional<GUID> _profile{ std::nullopt };
winrt::event_token _connectionClosedToken{ 0 };
winrt::event_token _firstClosedToken{ 0 };
winrt::event_token _secondClosedToken{ 0 };
std::shared_mutex _createCloseLock{};
Indicate which pane is focused with the Accent color on the pan… (#3060) ## Summary of the Pull Request Adds a small border with the accent color to indicate a pane is focused <img src="https://user-images.githubusercontent.com/18356694/66218711-560e4b80-e68f-11e9-85b0-1f387d35bb92.png" width="480"> <img src="https://user-images.githubusercontent.com/18356694/66218757-6f16fc80-e68f-11e9-8d39-db9ab748c4de.png" width="480"> <img src="https://user-images.githubusercontent.com/18356694/66219194-55c28000-e690-11e9-9835-8b5212e70e8a.png" width="480"> ## PR Checklist * [x] Closes #994 * [x] I work here * [😢] Tests added/passed * [n/a] Requires documentation to be updated ## Detailed Description of the Pull Request / Additional comments I've removed the simple Grid we were using as the pane separator, and replaced it with a Border that might appear on any side of a pane. When we add a split, we'll create each child with one of the `Border` flags set (each child with one of a pair of flags). E.g. creating a horizontal split creates one child with the `Top` border, and another with the `Bottom`. Then, if one of those panes is split, it will pass it's border flag to is new children, with the additional flag set. So adding another Vertical split to the above scenario would create a set of panes with either (`Top|Left`, `Top|Right`) or (`Bottom|Left`, `Bottom|Right`) borders set, depending on which pane was split. <hr> * start work on this by tracking border state * Colorize the border * Use the accent color for highlighting * Cleanup the accent color code * Don't buy any rural real estate when closing a pane * Closing panes works well now too * Cleanup for review * Update src/cascadia/TerminalApp/Pane.cpp * try some things that don't work to fix the resizing crash * Revert "try some things that don't work to fix the resizing crash" This reverts commit 3fc14da1130318add37a98d8de8d7ff440bbed59. * this _does_ work, but I think it's not semantically correct * This doesn't seem to work either. I tried adding the pane seperators to the Pane::_GetMinWidth calculation. That works for prevent the crash, but the resizing is wonky now. If you add a Vertical split, then a second, then resize the middle pane really small, you'll see that the _last_ resize doesn't work properly. The text seems to overhand into the border. Additionally, there's really weird behavior resizing panes to be small. They don't always seem to be resizable to the smallest size. * Revert "This doesn't seem to work either." This reverts commit 2fd8323e7ba84527963f051a4e70751e846be87a. * Merge the changes from the "this is the one" branch Again, no idea what I really did that worked, but it does * Cleanup from my mess of a commit This makes so much more sense now * Other PR feedback from @carlos-zamora * Fix a typo
2019-11-01 21:06:11 +01:00
Borders _borders{ Borders::None };
bool _IsLeaf() const noexcept;
bool _HasFocusedChild() const noexcept;
void _SetupChildCloseHandlers();
bool _CanSplit(SplitState splitType);
void _Split(SplitState splitType, const GUID& profile, const winrt::Microsoft::Terminal::TerminalControl::TermControl& control);
void _CreateRowColDefinitions(const winrt::Windows::Foundation::Size& rootSize);
void _CreateSplitContent();
void _ApplySplitDefinitions();
Indicate which pane is focused with the Accent color on the pan… (#3060) ## Summary of the Pull Request Adds a small border with the accent color to indicate a pane is focused <img src="https://user-images.githubusercontent.com/18356694/66218711-560e4b80-e68f-11e9-85b0-1f387d35bb92.png" width="480"> <img src="https://user-images.githubusercontent.com/18356694/66218757-6f16fc80-e68f-11e9-8d39-db9ab748c4de.png" width="480"> <img src="https://user-images.githubusercontent.com/18356694/66219194-55c28000-e690-11e9-9835-8b5212e70e8a.png" width="480"> ## PR Checklist * [x] Closes #994 * [x] I work here * [😢] Tests added/passed * [n/a] Requires documentation to be updated ## Detailed Description of the Pull Request / Additional comments I've removed the simple Grid we were using as the pane separator, and replaced it with a Border that might appear on any side of a pane. When we add a split, we'll create each child with one of the `Border` flags set (each child with one of a pair of flags). E.g. creating a horizontal split creates one child with the `Top` border, and another with the `Bottom`. Then, if one of those panes is split, it will pass it's border flag to is new children, with the additional flag set. So adding another Vertical split to the above scenario would create a set of panes with either (`Top|Left`, `Top|Right`) or (`Bottom|Left`, `Bottom|Right`) borders set, depending on which pane was split. <hr> * start work on this by tracking border state * Colorize the border * Use the accent color for highlighting * Cleanup the accent color code * Don't buy any rural real estate when closing a pane * Closing panes works well now too * Cleanup for review * Update src/cascadia/TerminalApp/Pane.cpp * try some things that don't work to fix the resizing crash * Revert "try some things that don't work to fix the resizing crash" This reverts commit 3fc14da1130318add37a98d8de8d7ff440bbed59. * this _does_ work, but I think it's not semantically correct * This doesn't seem to work either. I tried adding the pane seperators to the Pane::_GetMinWidth calculation. That works for prevent the crash, but the resizing is wonky now. If you add a Vertical split, then a second, then resize the middle pane really small, you'll see that the _last_ resize doesn't work properly. The text seems to overhand into the border. Additionally, there's really weird behavior resizing panes to be small. They don't always seem to be resizable to the smallest size. * Revert "This doesn't seem to work either." This reverts commit 2fd8323e7ba84527963f051a4e70751e846be87a. * Merge the changes from the "this is the one" branch Again, no idea what I really did that worked, but it does * Cleanup from my mess of a commit This makes so much more sense now * Other PR feedback from @carlos-zamora * Fix a typo
2019-11-01 21:06:11 +01:00
void _UpdateBorders();
bool _Resize(const winrt::TerminalApp::Direction& direction);
bool _NavigateFocus(const winrt::TerminalApp::Direction& direction);
void _CloseChild(const bool closeFirst);
void _FocusFirstChild();
void _ControlClosedHandler();
std::pair<float, float> _GetPaneSizes(const float& fullSize);
winrt::Windows::Foundation::Size _GetMinSize() const;
// Function Description:
// - Returns true if the given direction can be used with the given split
// type.
// - This is used for pane resizing (which will need a pane separator
// that's perpendicular to the direction to be able to move the separator
// in that direction).
// - Additionally, it will be used for moving focus between panes, which
// again happens _across_ a separator.
// Arguments:
// - direction: The Direction to compare
// - splitType: The SplitState to compare
// Return Value:
// - true iff the direction is perpendicular to the splitType. False for
// SplitState::None.
static constexpr bool DirectionMatchesSplit(const winrt::TerminalApp::Direction& direction,
const SplitState& splitType)
{
if (splitType == SplitState::None)
{
return false;
}
else if (splitType == SplitState::Horizontal)
{
return direction == winrt::TerminalApp::Direction::Up ||
direction == winrt::TerminalApp::Direction::Down;
}
else if (splitType == SplitState::Vertical)
{
return direction == winrt::TerminalApp::Direction::Left ||
direction == winrt::TerminalApp::Direction::Right;
}
return false;
}
};