make sure event handlers get replaced, too

This commit is contained in:
Mike Griese 2021-11-09 11:57:46 -06:00
parent fdc574929b
commit 5253c114ae
4 changed files with 29 additions and 9 deletions

View file

@ -847,14 +847,17 @@ bool Pane::SwapPanes(std::shared_ptr<Pane> first, std::shared_ptr<Pane> second)
return false; return false;
} }
winrt::Windows::UI::Xaml::Controls::UserControl Pane::ReplaceControl(const winrt::Windows::UI::Xaml::Controls::UserControl& control) Controls::UserControl Pane::ReplaceControl(const Controls::UserControl& control)
{ {
if (!_IsLeaf()) if (!_IsLeaf())
{ {
return nullptr; return nullptr;
} }
// Remove old control's event handlers
const auto& oldControl = _control; const auto& oldControl = _control;
_gotFocusRevoker.revoke();
_lostFocusRevoker.revoke();
if (const auto& oldTermControl{ _control.try_as<TermControl>() }) if (const auto& oldTermControl{ _control.try_as<TermControl>() })
{ {
oldTermControl.ConnectionStateChanged(_connectionStateChangedToken); oldTermControl.ConnectionStateChanged(_connectionStateChangedToken);
@ -862,7 +865,13 @@ winrt::Windows::UI::Xaml::Controls::UserControl Pane::ReplaceControl(const winrt
} }
_control = control; _control = control;
_borderFirst.Child(_control); _borderFirst.Child(_control);
// Register an event with the control to have it inform us when it gains focus.
_gotFocusRevoker = _control.GotFocus(winrt::auto_revoke, { this, &Pane::_ControlGotFocusHandler });
_lostFocusRevoker = _control.LostFocus(winrt::auto_revoke, { this, &Pane::_ControlLostFocusHandler });
if (const auto& termControl{ _control.try_as<TermControl>() }) if (const auto& termControl{ _control.try_as<TermControl>() })
{ {
_connectionStateChangedToken = termControl.ConnectionStateChanged({ this, &Pane::_ControlConnectionStateChangedHandler }); _connectionStateChangedToken = termControl.ConnectionStateChanged({ this, &Pane::_ControlConnectionStateChangedHandler });

View file

@ -1612,7 +1612,7 @@ namespace winrt::TerminalApp::implementation
{ {
// NOTE: For debugging purposes, changing this to `true || IsElevated()` // NOTE: For debugging purposes, changing this to `true || IsElevated()`
// is a handy way of forcing the elevation logic, even when unelevated. // is a handy way of forcing the elevation logic, even when unelevated.
if (IsElevated()) if (true || IsElevated())
{ {
// If the cmdline is EXACTLY an executable in // If the cmdline is EXACTLY an executable in
// `C:\WINDOWS\System32`, then ignore this check. // `C:\WINDOWS\System32`, then ignore this check.
@ -1662,11 +1662,7 @@ namespace winrt::TerminalApp::implementation
{ {
// Go ahead and allow them. Swap the control into // Go ahead and allow them. Swap the control into
// the pane, which will initialize and start it. // the pane, which will initialize and start it.
pane->ReplaceControl(otherWarning->Control()); tabImpl->ReplaceControl(pane, otherWarning->Control());
// Update the title, because replacing the control like
// this is a little weird, and doesn't actually trigger
// a TitleChanged by itself.
tabImpl->UpdateTitle();
} }
// Don't return true here. We want to make sure to check // Don't return true here. We want to make sure to check
// all the panes for the same commandline we just // all the panes for the same commandline we just

View file

@ -516,10 +516,9 @@ namespace winrt::TerminalApp::implementation
p->Id(_nextPaneId); p->Id(_nextPaneId);
if (auto termControl{ p->_control.try_as<TermControl>() }) if (auto termControl{ p->_control.try_as<TermControl>() })
{ {
// TODO! make sure that the event handlers are still wired up for splitting a pane that creates an unapproved commandline, I don't think they are.
_AttachEventHandlersToControl(p->Id().value(), termControl); _AttachEventHandlersToControl(p->Id().value(), termControl);
} }
_nextPaneId++; _nextPaneId++;
} }
return false; return false;
@ -1756,6 +1755,19 @@ namespace winrt::TerminalApp::implementation
return Title(); return Title();
} }
void TerminalTab::ReplaceControl(std::shared_ptr<Pane> pane, const Controls::UserControl& control)
{
pane->ReplaceControl(control);
if (auto termControl{ pane->_control.try_as<TermControl>() })
{
_AttachEventHandlersToControl(pane->Id().value(), termControl);
}
// Update the title manually.
UpdateTitle();
}
DEFINE_EVENT(TerminalTab, ActivePaneChanged, _ActivePaneChangedHandlers, winrt::delegate<>); DEFINE_EVENT(TerminalTab, ActivePaneChanged, _ActivePaneChangedHandlers, winrt::delegate<>);
DEFINE_EVENT(TerminalTab, ColorSelected, _colorSelected, winrt::delegate<winrt::Windows::UI::Color>); DEFINE_EVENT(TerminalTab, ColorSelected, _colorSelected, winrt::delegate<winrt::Windows::UI::Color>);
DEFINE_EVENT(TerminalTab, ColorCleared, _colorCleared, winrt::delegate<>); DEFINE_EVENT(TerminalTab, ColorCleared, _colorCleared, winrt::delegate<>);

View file

@ -93,6 +93,9 @@ namespace winrt::TerminalApp::implementation
std::shared_ptr<Pane> GetRootPane() const { return _rootPane; } std::shared_ptr<Pane> GetRootPane() const { return _rootPane; }
void ReplaceControl(std::shared_ptr<Pane> pane,
const winrt::Windows::UI::Xaml::Controls::UserControl& control);
winrt::TerminalApp::TerminalTabStatus TabStatus() winrt::TerminalApp::TerminalTabStatus TabStatus()
{ {
return _tabStatus; return _tabStatus;