Repository: microsoft/terminal
File: src/cascadia/TerminalApp/Pane.cpp (C++)

Code before:
        // DON'T use Transparent here - if it's "Transparent", then it won't
        // be able to hittest for clicks, and then clicking on the border
        // will eat focus.
        s_unfocusedBorderBrush = SolidColorBrush{ Colors::Black() };
    }
}

int Pane::GetLeafPaneCount() const noexcept
{
    return _IsLeaf() ? 1 : (_firstChild->GetLeafPaneCount() + _secondChild->GetLeafPaneCount());
}

// Method Description:
// - Should be called when this pane is created via a default terminal handoff
// - Finalizes our configuration given the information that we have been
//   created via default handoff
void Pane::FinalizeConfigurationGivenDefault()
{
    if (_IsLeaf() && _profile && _profile.CloseOnExit() == CloseOnExitMode::Automatic)
    {
        {
            // We only want to close 'gracefully' if we were launched by Terminal
            // Since we were launched via defterm, override this (i.e. it will
            // be treated as 'always', see _ControlConnectionStateChangedHandler
            // for where this boolean is used, and see GH #13325 for discussion)
            _isDefTermSession = true;
        }
    }
}

// Method Description:
// - Returns true if the pane or one of its descendants is read-only
bool Pane::ContainsReadOnly() const
{
    return _IsLeaf() ? _control.ReadOnly() : (_firstChild->ContainsReadOnly() || _secondChild->ContainsReadOnly());
}

// Method Description:
// - If we're a parent, place the taskbar state for all our leaves into the
//   provided vector.
// - If we're a leaf, place our own state into the vector.
// Arguments:
// - states: a vector that will receive all the states of all leaves in the tree
// Return Value:
// - <none>
void Pane::CollectTaskbarStates(std::vector<winrt::TerminalApp::TaskbarState>& states)
{
    if (_IsLeaf())
    {
        auto tbState{ winrt::make<winrt::TerminalApp::implementation::TaskbarState>(_control.TaskbarState(),
                                                                                    _control.TaskbarProgress()) };

Review comment (refactor):
I feel like the name of this member is a bit confusing. It doesn't just store whether this is a "def term session" right? It stores whether "is leaf pane && automatic close on exit". If that's correct, I'd give this member a different, more fitting name.

You could also write:
```cpp
_isDefTermSession = _IsLeaf() && _profile && _profile.CloseOnExit() == CloseOnExitMode::Automatic;
```
...which is IMO more robust against future changes. For instance imagine `_profile` isn't immutable and `CloseOnExit()` might return different values on each invocation. If a direct assignment is used, calling `FinalizeConfigurationGivenDefault()` (or rather `UpdateIsDefTermSession()` in that case) again would correctly update the value.

But can't we move this entire check to line 1020 (`if (_isDefTermSession)`) and get rid of the member entirely?

Code after:
    {
        // DON'T use Transparent here - if it's "Transparent", then it won't
        // be able to hittest for clicks, and then clicking on the border
        // will eat focus.
        s_unfocusedBorderBrush = SolidColorBrush{ Colors::Black() };
    }
}

int Pane::GetLeafPaneCount() const noexcept
{
    return _IsLeaf() ? 1 : (_firstChild->GetLeafPaneCount() + _secondChild->GetLeafPaneCount());
}

// Method Description:
// - Should be called when this pane is created via a default terminal handoff
// - Finalizes our configuration given the information that we have been
//   created via default handoff
void Pane::FinalizeConfigurationGivenDefault()
{
    _isDefTermSession = true;
}

// Method Description:
// - Returns true if the pane or one of its descendants is read-only
bool Pane::ContainsReadOnly() const
{
    return _IsLeaf() ? _control.ReadOnly() : (_firstChild->ContainsReadOnly() || _secondChild->ContainsReadOnly());
}

// Method Description:
// - If we're a parent, place the taskbar state for all our leaves into the
//   provided vector.
// - If we're a leaf, place our own state into the vector.
// Arguments:
// - states: a vector that will receive all the states of all leaves in the tree
// Return Value:
// - <none>
void Pane::CollectTaskbarStates(std::vector<winrt::TerminalApp::TaskbarState>& states)
{
    if (_IsLeaf())
    {
        auto tbState{ winrt::make<winrt::TerminalApp::implementation::TaskbarState>(_control.TaskbarState(),
                                                                                    _control.TaskbarProgress()) };
        states.push_back(tbState);
    }
    else
    {
        _firstChild->CollectTaskbarStates(states);
        _secondChild->CollectTaskbarStates(states);
    }
}