From 56992296bf4d27b7a60398c381dfe06adc84b498 Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Thu, 30 Sep 2021 08:25:16 -0500 Subject: [PATCH] Apply suggestions from code review Co-authored-by: Carlos Zamora --- src/cascadia/TerminalApp/Pane.cpp | 21 +++++++-------------- src/cascadia/TerminalApp/TerminalPage.cpp | 3 +-- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/src/cascadia/TerminalApp/Pane.cpp b/src/cascadia/TerminalApp/Pane.cpp index 299c26e0c..616a73cd4 100644 --- a/src/cascadia/TerminalApp/Pane.cpp +++ b/src/cascadia/TerminalApp/Pane.cpp @@ -42,8 +42,7 @@ Pane::Pane(const Profile& profile, const Controls::UserControl& control, const b _root.Children().Append(_border); _border.Child(_control); - const auto& termControl{ _control.try_as() }; - if (termControl) + if (const auto& termControl{ _control.try_as() }) { _connectionStateChangedToken = termControl.ConnectionStateChanged({ this, &Pane::_ControlConnectionStateChangedHandler }); _warningBellToken = termControl.WarningBell({ this, &Pane::_ControlWarningBellHandler }); @@ -726,8 +725,7 @@ winrt::Windows::UI::Xaml::Controls::UserControl Pane::ReplaceControl(const winrt } const auto& oldControl = _control; - const auto& oldTermControl{ _control.try_as() }; - if (oldTermControl) + if (const auto& oldTermControl{ _control.try_as() }) { oldTermControl.ConnectionStateChanged(_connectionStateChangedToken); oldTermControl.WarningBell(_warningBellToken); @@ -735,8 +733,7 @@ winrt::Windows::UI::Xaml::Controls::UserControl Pane::ReplaceControl(const winrt _control = control; _border.Child(_control); - const auto& termControl{ _control.try_as() }; - if (termControl) + if (const auto& termControl{ _control.try_as() }) { _connectionStateChangedToken = termControl.ConnectionStateChanged({ this, &Pane::_ControlConnectionStateChangedHandler }); _warningBellToken = termControl.WarningBell({ this, &Pane::_ControlWarningBellHandler }); @@ -1493,8 +1490,7 @@ void Pane::_CloseChild(const bool closeFirst, const bool isDetaching) // handlers since it is just getting moved. if (!isDetaching) { - const auto& closedControl{ closedChild->_control.try_as() }; - if (closedControl) + if (const auto& closedControl{ closedChild->_control.try_as() }) { closedControl.ConnectionStateChanged(closedChild->_connectionStateChangedToken); closedControl.WarningBell(closedChild->_warningBellToken); @@ -1504,8 +1500,7 @@ void Pane::_CloseChild(const bool closeFirst, const bool isDetaching) closedChild->Closed(closedChildClosedToken); remainingChild->Closed(remainingChildClosedToken); - const auto& remainingControl{ remainingChild->_control.try_as() }; - if (remainingControl) + if (const auto& remainingControl{ remainingChild->_control.try_as() }) { remainingControl.ConnectionStateChanged(remainingChild->_connectionStateChangedToken); remainingControl.WarningBell(remainingChild->_warningBellToken); @@ -1585,8 +1580,7 @@ void Pane::_CloseChild(const bool closeFirst, const bool isDetaching) closedChild->Closed(closedChildClosedToken); if (!isDetaching) { - const auto& closedControl{ closedChild->_control.try_as() }; - if (closedControl) + if (const auto& closedControl{ closedChild->_control.try_as() }) { closedControl.ConnectionStateChanged(closedChild->_connectionStateChangedToken); closedControl.WarningBell(closedChild->_warningBellToken); @@ -2287,8 +2281,7 @@ std::pair, std::shared_ptr> Pane::_Split(SplitDirect // modify our tree std::unique_lock lock{ _createCloseLock }; - const auto& termControl{ _control.try_as() }; - if (termControl) + if (const auto& termControl{ _control.try_as() }) { // revoke our handler - the child will take care of the control now. termControl.ConnectionStateChanged(_connectionStateChangedToken); diff --git a/src/cascadia/TerminalApp/TerminalPage.cpp b/src/cascadia/TerminalApp/TerminalPage.cpp index c96911e2d..c85d5b036 100644 --- a/src/cascadia/TerminalApp/TerminalPage.cpp +++ b/src/cascadia/TerminalApp/TerminalPage.cpp @@ -1838,8 +1838,7 @@ namespace winrt::TerminalApp::implementation WUX::Controls::UserControl controlToAdd{ newControl }; const auto& cmdline{ controlSettings.DefaultSettings().Commandline() }; - const bool doAdminWarning = _shouldPromptForCommandline(cmdline); - if (doAdminWarning) + if (_shouldPromptForCommandline(cmdline)) { auto warningControl{ winrt::make_self(newControl, cmdline) }; warningControl->PrimaryButtonClicked({ get_weak(), &TerminalPage::_adminWarningPrimaryClicked });