Skip to content

Commit

Permalink
This is a prototype for #996, pane zooming. There's some odd edge cas…
Browse files Browse the repository at this point in the history
…es, but it works _pretty_ well
  • Loading branch information
zadjii-msft committed Jul 17, 2020
1 parent 09471c3 commit ec1aa26
Show file tree
Hide file tree
Showing 12 changed files with 149 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/cascadia/TerminalApp/ActionAndArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ static constexpr std::string_view ScrolldownpageKey{ "scrollDownPage" };
static constexpr std::string_view SwitchToTabKey{ "switchToTab" };
static constexpr std::string_view OpenSettingsKey{ "openSettings" }; // TODO GH#2557: Add args for OpenSettings
static constexpr std::string_view SplitPaneKey{ "splitPane" };
static constexpr std::string_view TogglePaneZoomKey{ "togglePaneZoom" };
static constexpr std::string_view ResizePaneKey{ "resizePane" };
static constexpr std::string_view MoveFocusKey{ "moveFocus" };
static constexpr std::string_view FindKey{ "find" };
Expand Down Expand Up @@ -79,6 +80,7 @@ namespace winrt::TerminalApp::implementation
{ ToggleFullscreenKey, ShortcutAction::ToggleFullscreen },
{ ToggleAlwaysOnTopKey, ShortcutAction::ToggleAlwaysOnTop },
{ SplitPaneKey, ShortcutAction::SplitPane },
{ TogglePaneZoomKey, ShortcutAction::TogglePaneZoom },
{ SetTabColorKey, ShortcutAction::SetTabColor },
{ OpenTabColorPickerKey, ShortcutAction::OpenTabColorPicker },
{ UnboundKey, ShortcutAction::Invalid },
Expand Down Expand Up @@ -260,6 +262,7 @@ namespace winrt::TerminalApp::implementation
{ ShortcutAction::ToggleFullscreen, RS_(L"ToggleFullscreenCommandKey") },
{ ShortcutAction::ToggleAlwaysOnTop, RS_(L"ToggleAlwaysOnTopCommandKey") },
{ ShortcutAction::SplitPane, RS_(L"SplitPaneCommandKey") },
{ ShortcutAction::TogglePaneZoom, RS_(L"TogglePaneZoomCommandKey") },
{ ShortcutAction::Invalid, L"" },
{ ShortcutAction::Find, RS_(L"FindCommandKey") },
{ ShortcutAction::SetTabColor, RS_(L"ResetTabColorCommandKey") },
Expand Down
22 changes: 22 additions & 0 deletions src/cascadia/TerminalApp/AppActionHandlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,28 @@ namespace winrt::TerminalApp::implementation
}
}

void TerminalPage::_HandleTogglePaneZoom(const IInspectable& /*sender*/,
const TerminalApp::ActionEventArgs& args)
{
auto activeTab = _GetFocusedTab();
if (activeTab)
{
// First thing's first, remove the current content from the UI
// tree This is important, because we might be leaving zoom, and if
// a pane is zoomed, then it's currently in the UI tree, and should
// be removed before it's re-added in Pane::UnZoom
_tabContent.Children().Clear();

activeTab->ToggleZoom();

// // Update the selected tab, to trigger us to re-add the tab's GetRootElement to the UI tree
// _tabView.SelectedItem(activeTab->GetTabViewItem());

_tabContent.Children().Append(activeTab->GetRootElement());
}
args.Handled(true);
}

void TerminalPage::_HandleScrollUpPage(const IInspectable& /*sender*/,
const TerminalApp::ActionEventArgs& args)
{
Expand Down
45 changes: 45 additions & 0 deletions src/cascadia/TerminalApp/Pane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1076,6 +1076,51 @@ std::pair<std::shared_ptr<Pane>, std::shared_ptr<Pane>> Pane::_Split(SplitState
return { _firstChild, _secondChild };
}

void Pane::Zoom(std::shared_ptr<Pane> zoomedPane)
{
// Do nothing if we're the only pane in the tree.

// TODO: Can we just do nothing if we're a leaf? is that the equivalent of the above?
if (_IsLeaf())
{
return;
}

if (zoomedPane == _firstChild || zoomedPane == _secondChild)
{
// When we're unzooming the pane, we'll need to re-add it to our UI tree where it originally belonged.
// easy way: just re-add both:
_root.Children().Clear();
}
else
{
_firstChild->Zoom(zoomedPane);
_secondChild->Zoom(zoomedPane);
}
}

void Pane::UnZoom(std::shared_ptr<Pane> zoomedPane)
{
if (_IsLeaf())
{
return;
}

if (zoomedPane == _firstChild || zoomedPane == _secondChild)
{
// When we're unzooming the pane, we'll need to re-add it to our UI tree where it originally belonged.
// easy way: just re-add both:
_root.Children().Clear();
_root.Children().Append(_firstChild->GetRootElement());
_root.Children().Append(_secondChild->GetRootElement());
}
else
{
_firstChild->UnZoom(zoomedPane);
_secondChild->UnZoom(zoomedPane);
}
}

// Method Description:
// - Gets the size in pixels of each of our children, given the full size they
// should fill. Since these children own their own separators (borders), this
Expand Down
3 changes: 3 additions & 0 deletions src/cascadia/TerminalApp/Pane.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ class Pane : public std::enable_shared_from_this<Pane>

int GetLeafPaneCount() const noexcept;

void Zoom(std::shared_ptr<Pane> zoomedPane);
void UnZoom(std::shared_ptr<Pane> zoomedPane);

WINRT_CALLBACK(Closed, winrt::Windows::Foundation::EventHandler<winrt::Windows::Foundation::IInspectable>);
DECLARE_EVENT(GotFocus, _GotFocusHandlers, winrt::delegate<std::shared_ptr<Pane>>);

Expand Down
3 changes: 3 additions & 0 deletions src/cascadia/TerminalApp/Resources/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,9 @@
<data name="SplitPaneCommandKey" xml:space="preserve">
<value>Split pane</value>
</data>
<data name="TogglePaneZoomCommandKey" xml:space="preserve">
<value>Toggle pane zoom</value>
</data>
<data name="NewWindowCommandKey" xml:space="preserve">
<value>New window</value>
</data>
Expand Down
6 changes: 6 additions & 0 deletions src/cascadia/TerminalApp/ShortcutActionDispatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ namespace winrt::TerminalApp::implementation
break;
}

case ShortcutAction::TogglePaneZoom:
{
_TogglePaneZoomHandlers(*this, *eventArgs);
break;
}

case ShortcutAction::SwitchToTab:
{
_SwitchToTabHandlers(*this, *eventArgs);
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalApp/ShortcutActionDispatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ namespace winrt::TerminalApp::implementation
TYPED_EVENT(NextTab, TerminalApp::ShortcutActionDispatch, TerminalApp::ActionEventArgs);
TYPED_EVENT(PrevTab, TerminalApp::ShortcutActionDispatch, TerminalApp::ActionEventArgs);
TYPED_EVENT(SplitPane, TerminalApp::ShortcutActionDispatch, TerminalApp::ActionEventArgs);
TYPED_EVENT(TogglePaneZoom, TerminalApp::ShortcutActionDispatch, TerminalApp::ActionEventArgs);
TYPED_EVENT(AdjustFontSize, TerminalApp::ShortcutActionDispatch, TerminalApp::ActionEventArgs);
TYPED_EVENT(ResetFontSize, TerminalApp::ShortcutActionDispatch, TerminalApp::ActionEventArgs);
TYPED_EVENT(ScrollUp, TerminalApp::ShortcutActionDispatch, TerminalApp::ActionEventArgs);
Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/TerminalApp/ShortcutActionDispatch.idl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ namespace TerminalApp
SplitVertical,
SplitHorizontal,
SplitPane,
TogglePaneZoom,
SwitchToTab,
AdjustFontSize,
ResetFontSize,
Expand Down Expand Up @@ -66,6 +67,7 @@ namespace TerminalApp
event Windows.Foundation.TypedEventHandler<ShortcutActionDispatch, ActionEventArgs> NextTab;
event Windows.Foundation.TypedEventHandler<ShortcutActionDispatch, ActionEventArgs> PrevTab;
event Windows.Foundation.TypedEventHandler<ShortcutActionDispatch, ActionEventArgs> SplitPane;
event Windows.Foundation.TypedEventHandler<ShortcutActionDispatch, ActionEventArgs> TogglePaneZoom;
event Windows.Foundation.TypedEventHandler<ShortcutActionDispatch, ActionEventArgs> AdjustFontSize;
event Windows.Foundation.TypedEventHandler<ShortcutActionDispatch, ActionEventArgs> ResetFontSize;
event Windows.Foundation.TypedEventHandler<ShortcutActionDispatch, ActionEventArgs> ScrollUp;
Expand Down
48 changes: 47 additions & 1 deletion src/cascadia/TerminalApp/Tab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,14 @@ namespace winrt::TerminalApp::implementation
// - The UIElement acting as root of the Tab's root pane.
UIElement Tab::GetRootElement()
{
return _rootPane->GetRootElement();
if (_zoomedPane)
{
return _zoomedPane->GetRootElement();
}
else
{
return _rootPane->GetRootElement();
}
}

// Method Description:
Expand Down Expand Up @@ -302,6 +309,10 @@ namespace winrt::TerminalApp::implementation
// - <none>
void Tab::SplitPane(winrt::TerminalApp::SplitState splitType, const GUID& profile, TermControl& control)
{
// TODO: Can we do this safely? Probably not! Because the Page currently
// owns the content, not the tab!
_exitZoom();

auto [first, second] = _activePane->Split(splitType, profile, control);
_activePane = first;
_AttachEventHandlersToControl(control);
Expand Down Expand Up @@ -348,6 +359,10 @@ namespace winrt::TerminalApp::implementation
// - <none>
void Tab::ResizePane(const winrt::TerminalApp::Direction& direction)
{
// TODO: Can we do this safely? Probably not! Because the Page currently
// owns the content, not the tab!
_exitZoom();

// NOTE: This _must_ be called on the root pane, so that it can propagate
// throughout the entire tree.
_rootPane->ResizePane(direction);
Expand All @@ -362,6 +377,10 @@ namespace winrt::TerminalApp::implementation
// - <none>
void Tab::NavigateFocus(const winrt::TerminalApp::Direction& direction)
{
// TODO: Can we do this safely? Probably not! Because the Page currently
// owns the content, not the tab!
_exitZoom();

// NOTE: This _must_ be called on the root pane, so that it can propagate
// throughout the entire tree.
_rootPane->NavigateFocus(direction);
Expand All @@ -384,6 +403,10 @@ namespace winrt::TerminalApp::implementation
// - <none>
void Tab::ClosePane()
{
// TODO: Can we do this safely? Probably not! Because the Page currently
// owns the content, not the tab!
_exitZoom();

_activePane->Close();
}

Expand Down Expand Up @@ -875,6 +898,29 @@ namespace winrt::TerminalApp::implementation
return _rootPane->PreCalculateAutoSplit(_activePane, availableSpace).value_or(SplitState::Vertical);
}

void Tab::ToggleZoom()
{
if (_zoomedPane)
{
_exitZoom();
}
else
{
_enterZoom();
}
}

void Tab::_enterZoom()
{
_zoomedPane = _activePane;
_rootPane->Zoom(_zoomedPane);
}
void Tab::_exitZoom()
{
_rootPane->UnZoom(_zoomedPane);
_zoomedPane = nullptr;
}

DEFINE_EVENT(Tab, ActivePaneChanged, _ActivePaneChangedHandlers, winrt::delegate<>);
DEFINE_EVENT(Tab, ColorSelected, _colorSelected, winrt::delegate<winrt::Windows::UI::Color>);
DEFINE_EVENT(Tab, ColorCleared, _colorCleared, winrt::delegate<>);
Expand Down
6 changes: 6 additions & 0 deletions src/cascadia/TerminalApp/Tab.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ namespace winrt::TerminalApp::implementation
void ResetTabColor();
void ActivateColorPicker();

void ToggleZoom();

WINRT_CALLBACK(Closed, winrt::Windows::Foundation::EventHandler<winrt::Windows::Foundation::IInspectable>);
WINRT_CALLBACK(PropertyChanged, Windows::UI::Xaml::Data::PropertyChangedEventHandler);
DECLARE_EVENT(ActivePaneChanged, _ActivePaneChangedHandlers, winrt::delegate<>);
Expand All @@ -72,6 +74,7 @@ namespace winrt::TerminalApp::implementation
private:
std::shared_ptr<Pane> _rootPane{ nullptr };
std::shared_ptr<Pane> _activePane{ nullptr };
std::shared_ptr<Pane> _zoomedPane{ nullptr };
winrt::hstring _lastIconPath{};
winrt::TerminalApp::ColorPickupFlyout _tabColorPickup{};
std::optional<winrt::Windows::UI::Color> _tabColor{};
Expand Down Expand Up @@ -101,6 +104,9 @@ namespace winrt::TerminalApp::implementation
winrt::fire_and_forget _UpdateTitle();
void _ConstructTabRenameBox(const winrt::hstring& tabText);

void _enterZoom();
void _exitZoom();

friend class ::TerminalAppLocalTests::TabTests;
};
}
10 changes: 10 additions & 0 deletions src/cascadia/TerminalApp/TerminalPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,7 @@ namespace winrt::TerminalApp::implementation
_actionDispatch->NextTab({ this, &TerminalPage::_HandleNextTab });
_actionDispatch->PrevTab({ this, &TerminalPage::_HandlePrevTab });
_actionDispatch->SplitPane({ this, &TerminalPage::_HandleSplitPane });
_actionDispatch->TogglePaneZoom({ this, &TerminalPage::_HandleTogglePaneZoom });
_actionDispatch->ScrollUpPage({ this, &TerminalPage::_HandleScrollUpPage });
_actionDispatch->ScrollDownPage({ this, &TerminalPage::_HandleScrollDownPage });
_actionDispatch->OpenSettings({ this, &TerminalPage::_HandleOpenSettings });
Expand Down Expand Up @@ -1164,7 +1165,9 @@ namespace winrt::TerminalApp::implementation
if (auto index{ _GetFocusedTabIndex() })
{
auto focusedTab{ _GetStrongTabImpl(*index) };
_tabContent.Children().Clear();
focusedTab->NavigateFocus(direction);
_tabContent.Children().Append(focusedTab->GetRootElement());
}
}

Expand Down Expand Up @@ -1254,7 +1257,9 @@ namespace winrt::TerminalApp::implementation
if (auto index{ _GetFocusedTabIndex() })
{
auto focusedTab{ _GetStrongTabImpl(*index) };
_tabContent.Children().Clear();
focusedTab->ClosePane();
_tabContent.Children().Append(focusedTab->GetRootElement());
}
}

Expand Down Expand Up @@ -1384,7 +1389,9 @@ namespace winrt::TerminalApp::implementation
// Hookup our event handlers to the new terminal
_RegisterTerminalEvents(newControl, *focusedTab);

_tabContent.Children().Clear();
focusedTab->SplitPane(realSplitType, realGuid, newControl);
_tabContent.Children().Append(focusedTab->GetRootElement());
}
CATCH_LOG();
}
Expand All @@ -1402,7 +1409,10 @@ namespace winrt::TerminalApp::implementation
if (auto index{ _GetFocusedTabIndex() })
{
auto focusedTab{ _GetStrongTabImpl(*index) };

_tabContent.Children().Clear();
focusedTab->ResizePane(direction);
_tabContent.Children().Append(focusedTab->GetRootElement());
}
}

Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalApp/TerminalPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ namespace winrt::TerminalApp::implementation
void _HandleNextTab(const IInspectable& sender, const TerminalApp::ActionEventArgs& args);
void _HandlePrevTab(const IInspectable& sender, const TerminalApp::ActionEventArgs& args);
void _HandleSplitPane(const IInspectable& sender, const TerminalApp::ActionEventArgs& args);
void _HandleTogglePaneZoom(const IInspectable& sender, const TerminalApp::ActionEventArgs& args);
void _HandleScrollUpPage(const IInspectable& sender, const TerminalApp::ActionEventArgs& args);
void _HandleScrollDownPage(const IInspectable& sender, const TerminalApp::ActionEventArgs& args);
void _HandleOpenSettings(const IInspectable& sender, const TerminalApp::ActionEventArgs& args);
Expand Down

1 comment on commit ec1aa26

@github-actions

This comment was marked as resolved.

Please sign in to comment.