Skip to content

Commit

Permalink
Refactor isConnectionClose
Browse files Browse the repository at this point in the history
  • Loading branch information
mpela81 committed Jul 24, 2023
1 parent 3d23b1a commit 3cf4e75
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
10 changes: 5 additions & 5 deletions src/cascadia/TerminalApp/Pane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1381,15 +1381,15 @@ Profile Pane::GetFocusedProfile()
}

// Method Description:
// - Gets the connection state of this pane. If this Pane is not a leaf this will
// return NotConnected.
// - Returns true if the connection state of this pane is closed. If this Pane is not a leaf this will
// return false.
// Arguments:
// - <none>
// Return Value:
// - The connection state of this Pane.
winrt::Microsoft::Terminal::TerminalConnection::ConnectionState Pane::GetConnectionState() const
// - true if the connection state of this Pane is closed.
bool Pane::IsConnectionClosed() const
{
return _connectionState;
return _connectionState >= ConnectionState::Closed;
}

// Method Description:
Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/TerminalApp/Pane.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class Pane : public std::enable_shared_from_this<Pane>
winrt::Microsoft::Terminal::Control::TermControl GetLastFocusedTerminalControl();
winrt::Microsoft::Terminal::Control::TermControl GetTerminalControl();
winrt::Microsoft::Terminal::Settings::Model::Profile GetFocusedProfile();
winrt::Microsoft::Terminal::TerminalConnection::ConnectionState GetConnectionState() const;
bool IsConnectionClosed() const;

// Method Description:
// - If this is a leaf pane, return its profile.
Expand Down
7 changes: 5 additions & 2 deletions src/cascadia/TerminalApp/TerminalPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4648,9 +4648,12 @@ namespace winrt::TerminalApp::implementation
makeItem(RS_(L"PaneClose"), L"\xE89F", ActionAndArgs{ ShortcutAction::ClosePane, nullptr });
}

if (const auto& control{ _GetActiveControl() }; control.ConnectionState() >= ConnectionState::Closed)
if (const auto pane{ _GetFocusedTabImpl()->GetActivePane() })
{
makeItem(RS_(L"RestartConnectionText"), L"\xE72C", ActionAndArgs{ ShortcutAction::RestartConnection, nullptr });
if (pane->IsConnectionClosed())
{
makeItem(RS_(L"RestartConnectionText"), L"\xE72C", ActionAndArgs{ ShortcutAction::RestartConnection, nullptr });
}
}

if (withSelection)
Expand Down
7 changes: 4 additions & 3 deletions src/cascadia/TerminalApp/TerminalTab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1067,16 +1067,17 @@ namespace winrt::TerminalApp::implementation
if (_rootPane)
{
const bool isClosed = _rootPane->WalkTree([&](const auto& p) {
return p->GetConnectionState() >= ConnectionState::Closed;
return p->IsConnectionClosed();
});

_tabStatus.IsConnectionClosed(isClosed);
}

if (_activePane)
{
const bool isClosed = _activePane->GetConnectionState() >= ConnectionState::Closed;
_restartConnectionMenuItem.Visibility(isClosed ? WUX::Visibility::Visible : WUX::Visibility::Collapsed);
_restartConnectionMenuItem.Visibility(_activePane->IsConnectionClosed() ?
WUX::Visibility::Visible :
WUX::Visibility::Collapsed);
}
}

Expand Down

0 comments on commit 3cf4e75

Please sign in to comment.