Skip to content

Commit 049c043

Browse files
committed
some last cleanups
1 parent a1da6c1 commit 049c043

File tree

3 files changed

+124
-139
lines changed

3 files changed

+124
-139
lines changed

src/cascadia/TerminalApp/Pane.cpp

+121-123
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,11 @@ Pane::Pane(const IPaneContent& content, const bool lastFocused) :
4242
const auto& control{ _content.GetRoot() };
4343
_borderFirst.Child(control);
4444

45-
// _setupControlEvents();
46-
4745
// Register an event with the control to have it inform us when it gains focus.
4846
if (control)
4947
{
50-
_gotFocusRevoker = control.GotFocus(winrt::auto_revoke, { this, &Pane::_ControlGotFocusHandler });
51-
_lostFocusRevoker = control.LostFocus(winrt::auto_revoke, { this, &Pane::_ControlLostFocusHandler });
48+
_gotFocusRevoker = control.GotFocus(winrt::auto_revoke, { this, &Pane::_ContentGotFocusHandler });
49+
_lostFocusRevoker = control.LostFocus(winrt::auto_revoke, { this, &Pane::_ContentLostFocusHandler });
5250
}
5351

5452
// When our border is tapped, make sure to transfer focus to our control.
@@ -974,7 +972,7 @@ Pane::PaneNeighborSearch Pane::_FindPaneAndNeighbor(const std::shared_ptr<Pane>
974972
// - <unused>
975973
// Return Value:
976974
// - <none>
977-
void Pane::_ControlGotFocusHandler(const winrt::Windows::Foundation::IInspectable& sender,
975+
void Pane::_ContentGotFocusHandler(const winrt::Windows::Foundation::IInspectable& sender,
978976
const RoutedEventArgs& /* args */)
979977
{
980978
auto f = FocusState::Programmatic;
@@ -989,7 +987,7 @@ void Pane::_ControlGotFocusHandler(const winrt::Windows::Foundation::IInspectabl
989987
// - Called when our control loses focus. We'll use this to trigger our LostFocus
990988
// callback. The tab that's hosting us should have registered a callback which
991989
// can be used to update its own internal focus state
992-
void Pane::_ControlLostFocusHandler(const winrt::Windows::Foundation::IInspectable& /* sender */,
990+
void Pane::_ContentLostFocusHandler(const winrt::Windows::Foundation::IInspectable& /* sender */,
993991
const RoutedEventArgs& /* args */)
994992
{
995993
_LostFocusHandlers(shared_from_this());
@@ -1458,8 +1456,8 @@ void Pane::_CloseChild(const bool closeFirst, const bool /*isDetaching*/)
14581456
// re-attach our handler for the control's GotFocus event.
14591457
if (control)
14601458
{
1461-
_gotFocusRevoker = control.GotFocus(winrt::auto_revoke, { this, &Pane::_ControlGotFocusHandler });
1462-
_lostFocusRevoker = control.LostFocus(winrt::auto_revoke, { this, &Pane::_ControlLostFocusHandler });
1459+
_gotFocusRevoker = control.GotFocus(winrt::auto_revoke, { this, &Pane::_ContentGotFocusHandler });
1460+
_lostFocusRevoker = control.LostFocus(winrt::auto_revoke, { this, &Pane::_ContentLostFocusHandler });
14631461
}
14641462

14651463
// If we're inheriting the "last active" state from one of our children,
@@ -1589,126 +1587,126 @@ winrt::fire_and_forget Pane::_CloseChildRoutine(const bool closeFirst)
15891587

15901588
if (auto pane{ weakThis.get() })
15911589
{
1592-
//// This will query if animations are enabled via the "Show animations in
1593-
//// Windows" setting in the OS
1594-
//winrt::Windows::UI::ViewManagement::UISettings uiSettings;
1595-
//const auto animationsEnabledInOS = uiSettings.AnimationsEnabled();
1596-
//const auto animationsEnabledInApp = Media::Animation::Timeline::AllowDependentAnimations();
1590+
// This will query if animations are enabled via the "Show animations in
1591+
// Windows" setting in the OS
1592+
winrt::Windows::UI::ViewManagement::UISettings uiSettings;
1593+
const auto animationsEnabledInOS = uiSettings.AnimationsEnabled();
1594+
const auto animationsEnabledInApp = Media::Animation::Timeline::AllowDependentAnimations();
15971595

1598-
//// GH#7252: If either child is zoomed, just skip the animation. It won't work.
1599-
//const auto eitherChildZoomed = pane->_firstChild->_zoomed || pane->_secondChild->_zoomed;
1596+
// GH#7252: If either child is zoomed, just skip the animation. It won't work.
1597+
const auto eitherChildZoomed = pane->_firstChild->_zoomed || pane->_secondChild->_zoomed;
16001598
// If animations are disabled, just skip this and go straight to
16011599
// _CloseChild. Curiously, the pane opening animation doesn't need this,
16021600
// and will skip straight to Completed when animations are disabled, but
16031601
// this one doesn't seem to.
1604-
// if (!animationsEnabledInOS || !animationsEnabledInApp || eitherChildZoomed)
1605-
// {
1606-
pane->_CloseChild(closeFirst, false);
1607-
co_return;
1608-
// }
1609-
1610-
// // Setup the animation
1611-
1612-
// auto removedChild = closeFirst ? _firstChild : _secondChild;
1613-
// auto remainingChild = closeFirst ? _secondChild : _firstChild;
1614-
// const auto splitWidth = _splitState == SplitState::Vertical;
1615-
1616-
// Size removedOriginalSize{
1617-
// ::base::saturated_cast<float>(removedChild->_root.ActualWidth()),
1618-
// ::base::saturated_cast<float>(removedChild->_root.ActualHeight())
1619-
// };
1620-
// Size remainingOriginalSize{
1621-
// ::base::saturated_cast<float>(remainingChild->_root.ActualWidth()),
1622-
// ::base::saturated_cast<float>(remainingChild->_root.ActualHeight())
1623-
// };
1624-
1625-
// // Remove both children from the grid
1626-
// _borderFirst.Child(nullptr);
1627-
// _borderSecond.Child(nullptr);
1628-
1629-
// if (_splitState == SplitState::Vertical)
1630-
// {
1631-
// Controls::Grid::SetColumn(_borderFirst, 0);
1632-
// Controls::Grid::SetColumn(_borderSecond, 1);
1633-
// }
1634-
// else if (_splitState == SplitState::Horizontal)
1635-
// {
1636-
// Controls::Grid::SetRow(_borderFirst, 0);
1637-
// Controls::Grid::SetRow(_borderSecond, 1);
1638-
// }
1639-
1640-
// // Create the dummy grid. This grid will be the one we actually animate,
1641-
// // in the place of the closed pane.
1642-
// Controls::Grid dummyGrid;
1643-
// // GH#603 - we can safely add a BG here, as the control is gone right
1644-
// // away, to fill the space as the rest of the pane expands.
1645-
// dummyGrid.Background(_themeResources.unfocusedBorderBrush);
1646-
// // It should be the size of the closed pane.
1647-
// dummyGrid.Width(removedOriginalSize.Width);
1648-
// dummyGrid.Height(removedOriginalSize.Height);
1649-
1650-
// _borderFirst.Child(closeFirst ? dummyGrid : remainingChild->GetRootElement());
1651-
// _borderSecond.Child(closeFirst ? remainingChild->GetRootElement() : dummyGrid);
1652-
1653-
// // Set up the rows/cols as auto/auto, so they'll only use the size of
1654-
// // the elements in the grid.
1655-
// //
1656-
// // * For the closed pane, we want to make that row/col "auto" sized, so
1657-
// // it takes up as much space as is available.
1658-
// // * For the remaining pane, we'll make that row/col "*" sized, so it
1659-
// // takes all the remaining space. As the dummy grid is resized down,
1660-
// // the remaining pane will expand to take the rest of the space.
1661-
// _root.ColumnDefinitions().Clear();
1662-
// _root.RowDefinitions().Clear();
1663-
// if (_splitState == SplitState::Vertical)
1664-
// {
1665-
// auto firstColDef = Controls::ColumnDefinition();
1666-
// auto secondColDef = Controls::ColumnDefinition();
1667-
// firstColDef.Width(!closeFirst ? GridLengthHelper::FromValueAndType(1, GridUnitType::Star) : GridLengthHelper::Auto());
1668-
// secondColDef.Width(closeFirst ? GridLengthHelper::FromValueAndType(1, GridUnitType::Star) : GridLengthHelper::Auto());
1669-
// _root.ColumnDefinitions().Append(firstColDef);
1670-
// _root.ColumnDefinitions().Append(secondColDef);
1671-
// }
1672-
// else if (_splitState == SplitState::Horizontal)
1673-
// {
1674-
// auto firstRowDef = Controls::RowDefinition();
1675-
// auto secondRowDef = Controls::RowDefinition();
1676-
// firstRowDef.Height(!closeFirst ? GridLengthHelper::FromValueAndType(1, GridUnitType::Star) : GridLengthHelper::Auto());
1677-
// secondRowDef.Height(closeFirst ? GridLengthHelper::FromValueAndType(1, GridUnitType::Star) : GridLengthHelper::Auto());
1678-
// _root.RowDefinitions().Append(firstRowDef);
1679-
// _root.RowDefinitions().Append(secondRowDef);
1680-
// }
1681-
1682-
// // Animate the dummy grid from its current size down to 0
1683-
// Media::Animation::DoubleAnimation animation{};
1684-
// animation.Duration(AnimationDuration);
1685-
// animation.From(splitWidth ? removedOriginalSize.Width : removedOriginalSize.Height);
1686-
// animation.To(0.0);
1687-
// // This easing is the same as the entrance animation.
1688-
// animation.EasingFunction(Media::Animation::QuadraticEase{});
1689-
// animation.EnableDependentAnimation(true);
1690-
1691-
// Media::Animation::Storyboard s;
1692-
// s.Duration(AnimationDuration);
1693-
// s.Children().Append(animation);
1694-
// s.SetTarget(animation, dummyGrid);
1695-
// s.SetTargetProperty(animation, splitWidth ? L"Width" : L"Height");
1696-
1697-
// // Start the animation.
1698-
// s.Begin();
1699-
1700-
// std::weak_ptr<Pane> weakThis{ shared_from_this() };
1701-
1702-
// // When the animation is completed, reparent the child's content up to
1703-
// // us, and remove the child nodes from the tree.
1704-
// animation.Completed([weakThis, closeFirst](auto&&, auto&&) {
1705-
// if (auto pane{ weakThis.lock() })
1706-
// {
1707-
// // We don't need to manually undo any of the above trickiness.
1708-
// // We're going to re-parent the child's content into us anyways
1709-
// pane->_CloseChild(closeFirst, false);
1710-
// }
1711-
// });
1602+
if (!animationsEnabledInOS || !animationsEnabledInApp || eitherChildZoomed)
1603+
{
1604+
pane->_CloseChild(closeFirst, false);
1605+
co_return;
1606+
}
1607+
1608+
// Setup the animation
1609+
1610+
auto removedChild = closeFirst ? _firstChild : _secondChild;
1611+
auto remainingChild = closeFirst ? _secondChild : _firstChild;
1612+
const auto splitWidth = _splitState == SplitState::Vertical;
1613+
1614+
Size removedOriginalSize{
1615+
::base::saturated_cast<float>(removedChild->_root.ActualWidth()),
1616+
::base::saturated_cast<float>(removedChild->_root.ActualHeight())
1617+
};
1618+
Size remainingOriginalSize{
1619+
::base::saturated_cast<float>(remainingChild->_root.ActualWidth()),
1620+
::base::saturated_cast<float>(remainingChild->_root.ActualHeight())
1621+
};
1622+
1623+
// Remove both children from the grid
1624+
_borderFirst.Child(nullptr);
1625+
_borderSecond.Child(nullptr);
1626+
1627+
if (_splitState == SplitState::Vertical)
1628+
{
1629+
Controls::Grid::SetColumn(_borderFirst, 0);
1630+
Controls::Grid::SetColumn(_borderSecond, 1);
1631+
}
1632+
else if (_splitState == SplitState::Horizontal)
1633+
{
1634+
Controls::Grid::SetRow(_borderFirst, 0);
1635+
Controls::Grid::SetRow(_borderSecond, 1);
1636+
}
1637+
1638+
// Create the dummy grid. This grid will be the one we actually animate,
1639+
// in the place of the closed pane.
1640+
Controls::Grid dummyGrid;
1641+
// GH#603 - we can safely add a BG here, as the control is gone right
1642+
// away, to fill the space as the rest of the pane expands.
1643+
dummyGrid.Background(_themeResources.unfocusedBorderBrush);
1644+
// It should be the size of the closed pane.
1645+
dummyGrid.Width(removedOriginalSize.Width);
1646+
dummyGrid.Height(removedOriginalSize.Height);
1647+
1648+
_borderFirst.Child(closeFirst ? dummyGrid : remainingChild->GetRootElement());
1649+
_borderSecond.Child(closeFirst ? remainingChild->GetRootElement() : dummyGrid);
1650+
1651+
// Set up the rows/cols as auto/auto, so they'll only use the size of
1652+
// the elements in the grid.
1653+
//
1654+
// * For the closed pane, we want to make that row/col "auto" sized, so
1655+
// it takes up as much space as is available.
1656+
// * For the remaining pane, we'll make that row/col "*" sized, so it
1657+
// takes all the remaining space. As the dummy grid is resized down,
1658+
// the remaining pane will expand to take the rest of the space.
1659+
_root.ColumnDefinitions().Clear();
1660+
_root.RowDefinitions().Clear();
1661+
if (_splitState == SplitState::Vertical)
1662+
{
1663+
auto firstColDef = Controls::ColumnDefinition();
1664+
auto secondColDef = Controls::ColumnDefinition();
1665+
firstColDef.Width(!closeFirst ? GridLengthHelper::FromValueAndType(1, GridUnitType::Star) : GridLengthHelper::Auto());
1666+
secondColDef.Width(closeFirst ? GridLengthHelper::FromValueAndType(1, GridUnitType::Star) : GridLengthHelper::Auto());
1667+
_root.ColumnDefinitions().Append(firstColDef);
1668+
_root.ColumnDefinitions().Append(secondColDef);
1669+
}
1670+
else if (_splitState == SplitState::Horizontal)
1671+
{
1672+
auto firstRowDef = Controls::RowDefinition();
1673+
auto secondRowDef = Controls::RowDefinition();
1674+
firstRowDef.Height(!closeFirst ? GridLengthHelper::FromValueAndType(1, GridUnitType::Star) : GridLengthHelper::Auto());
1675+
secondRowDef.Height(closeFirst ? GridLengthHelper::FromValueAndType(1, GridUnitType::Star) : GridLengthHelper::Auto());
1676+
_root.RowDefinitions().Append(firstRowDef);
1677+
_root.RowDefinitions().Append(secondRowDef);
1678+
}
1679+
1680+
// Animate the dummy grid from its current size down to 0
1681+
Media::Animation::DoubleAnimation animation{};
1682+
animation.Duration(AnimationDuration);
1683+
animation.From(splitWidth ? removedOriginalSize.Width : removedOriginalSize.Height);
1684+
animation.To(0.0);
1685+
// This easing is the same as the entrance animation.
1686+
animation.EasingFunction(Media::Animation::QuadraticEase{});
1687+
animation.EnableDependentAnimation(true);
1688+
1689+
Media::Animation::Storyboard s;
1690+
s.Duration(AnimationDuration);
1691+
s.Children().Append(animation);
1692+
s.SetTarget(animation, dummyGrid);
1693+
s.SetTargetProperty(animation, splitWidth ? L"Width" : L"Height");
1694+
1695+
// Start the animation.
1696+
s.Begin();
1697+
1698+
std::weak_ptr<Pane> weakThis{ shared_from_this() };
1699+
1700+
// When the animation is completed, reparent the child's content up to
1701+
// us, and remove the child nodes from the tree.
1702+
animation.Completed([weakThis, closeFirst](auto&&, auto&&) {
1703+
if (auto pane{ weakThis.lock() })
1704+
{
1705+
// We don't need to manually undo any of the above trickiness.
1706+
// We're going to re-parent the child's content into us anyways
1707+
pane->_CloseChild(closeFirst, false);
1708+
}
1709+
});
17121710
}
17131711
}
17141712

src/cascadia/TerminalApp/Pane.h

+2-10
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,6 @@ class Pane : public std::enable_shared_from_this<Pane>
217217
WINRT_CALLBACK(LostFocus, winrt::delegate<std::shared_ptr<Pane>>);
218218
WINRT_CALLBACK(PaneRaiseBell, winrt::Windows::Foundation::EventHandler<bool>);
219219
WINRT_CALLBACK(Detached, winrt::delegate<std::shared_ptr<Pane>>);
220-
// WINRT_CALLBACK(RestartTerminalRequested, winrt::delegate<std::shared_ptr<Pane>>);
221220

222221
private:
223222
struct PanePoint;
@@ -294,15 +293,10 @@ class Pane : public std::enable_shared_from_this<Pane>
294293

295294
void _Focus();
296295
void _FocusFirstChild();
297-
// void _ControlConnectionStateChangedHandler(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::Foundation::IInspectable& /*args*/);
298-
// void _ControlWarningBellHandler(const winrt::Windows::Foundation::IInspectable& sender,
299-
// const winrt::Windows::Foundation::IInspectable& e);
300-
void _ControlGotFocusHandler(const winrt::Windows::Foundation::IInspectable& sender,
296+
void _ContentGotFocusHandler(const winrt::Windows::Foundation::IInspectable& sender,
301297
const winrt::Windows::UI::Xaml::RoutedEventArgs& e);
302-
void _ControlLostFocusHandler(const winrt::Windows::Foundation::IInspectable& sender,
298+
void _ContentLostFocusHandler(const winrt::Windows::Foundation::IInspectable& sender,
303299
const winrt::Windows::UI::Xaml::RoutedEventArgs& e);
304-
// void _CloseTerminalRequestedHandler(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::Foundation::IInspectable& /*args*/);
305-
// void _RestartTerminalRequestedHandler(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::Foundation::IInspectable& /*args*/);
306300

307301
std::pair<float, float> _CalcChildrenSizes(const float fullSize) const;
308302
SnapChildrenSizeResult _CalcSnappedChildrenSizes(const bool widthOrHeight, const float fullSize) const;
@@ -314,8 +308,6 @@ class Pane : public std::enable_shared_from_this<Pane>
314308

315309
SplitState _convertAutomaticOrDirectionalSplitState(const winrt::Microsoft::Terminal::Settings::Model::SplitDirection& splitType) const;
316310

317-
// winrt::fire_and_forget _playBellSound(winrt::Windows::Foundation::Uri uri);
318-
319311
// Function Description:
320312
// - Returns true if the given direction can be used with the given split
321313
// type.

src/cascadia/TerminalApp/TerminalPaneContent.h

+1-6
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,7 @@ namespace winrt::TerminalApp::implementation
8686
void _controlReadOnlyChanged(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::Foundation::IInspectable& args);
8787
void _controlFocusFollowMouseRequested(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::Foundation::IInspectable& args);
8888

89-
// void _ControlGotFocusHandler(const winrt::Windows::Foundation::IInspectable& sender,
90-
// const winrt::Windows::UI::Xaml::RoutedEventArgs& e);
91-
// void _ControlLostFocusHandler(const winrt::Windows::Foundation::IInspectable& sender,
92-
// const winrt::Windows::UI::Xaml::RoutedEventArgs& e);
93-
void
94-
_CloseTerminalRequestedHandler(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::Foundation::IInspectable& /*args*/);
89+
void _CloseTerminalRequestedHandler(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::Foundation::IInspectable& /*args*/);
9590
void _RestartTerminalRequestedHandler(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::Foundation::IInspectable& /*args*/);
9691
};
9792
}

0 commit comments

Comments
 (0)