Replace tab.ActivePaneChanged handler with a method (#17331)

I noticed this while working on #17330. We're constructing a whole
lambda just to do this wacky weak_ref logic, and that feels... gross. We
should just make this a bound method and a typed event, so we can just
use the one event handler regardless
This commit is contained in:
Mike Griese 2024-05-31 12:00:32 -07:00 committed by GitHub
parent ecb5631476
commit 01e4df152e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 28 additions and 22 deletions

View File

@ -136,26 +136,7 @@ namespace winrt::TerminalApp::implementation
// When the tab's active pane changes, we'll want to lookup a new icon
// for it. The Title change will be propagated upwards through the tab's
// PropertyChanged event handler.
newTabImpl->ActivePaneChanged([weakTab, weakThis{ get_weak() }]() {
auto page{ weakThis.get() };
auto tab{ weakTab.get() };
if (page && tab)
{
// Possibly update the icon of the tab.
page->_UpdateTabIcon(*tab);
page->_updateThemeColors();
// Update the taskbar progress as well. We'll raise our own
// SetTaskbarProgress event here, to get tell the hosting
// application to re-query this value from us.
page->SetTaskbarProgress.raise(*page, nullptr);
auto profile = tab->GetFocusedProfile();
page->_UpdateBackground(profile);
}
});
newTabImpl->ActivePaneChanged({ get_weak(), &TerminalPage::_activePaneChanged });
// The RaiseVisualBell event has been bubbled up to here from the pane,
// the next part of the chain is bubbling up to app logic, which will

View File

@ -2237,6 +2237,29 @@ namespace winrt::TerminalApp::implementation
return true;
}
// When the tab's active pane changes, we'll want to lookup a new icon
// for it. The Title change will be propagated upwards through the tab's
// PropertyChanged event handler.
void TerminalPage::_activePaneChanged(winrt::TerminalApp::TerminalTab sender,
Windows::Foundation::IInspectable args)
{
if (const auto tab{ _GetTerminalTabImpl(sender) })
{
// Possibly update the icon of the tab.
_UpdateTabIcon(*tab);
_updateThemeColors();
// Update the taskbar progress as well. We'll raise our own
// SetTaskbarProgress event here, to get tell the hosting
// application to re-query this value from us.
SetTaskbarProgress.raise(*this, nullptr);
auto profile = tab->GetFocusedProfile();
_UpdateBackground(profile);
}
}
uint32_t TerminalPage::NumberOfTabs() const
{
return _tabs.Size();

View File

@ -542,6 +542,8 @@ namespace winrt::TerminalApp::implementation
winrt::Microsoft::Terminal::Control::TermControl _senderOrActiveControl(const winrt::Windows::Foundation::IInspectable& sender);
winrt::com_ptr<TerminalTab> _senderOrFocusedTab(const IInspectable& sender);
void _activePaneChanged(winrt::TerminalApp::TerminalTab tab, Windows::Foundation::IInspectable args);
#pragma region ActionHandlers
// These are all defined in AppActionHandlers.cpp
#define ON_ALL_ACTIONS(action) DECLARE_ACTION_HANDLER(action);

View File

@ -1242,7 +1242,7 @@ namespace winrt::TerminalApp::implementation
_RecalculateAndApplyReadOnly();
// Raise our own ActivePaneChanged event.
ActivePaneChanged.raise();
ActivePaneChanged.raise(*this, nullptr);
}
// Method Description:

View File

@ -99,7 +99,7 @@ namespace winrt::TerminalApp::implementation
til::typed_event<TerminalApp::TerminalPaneContent> RestartTerminalRequested;
til::event<winrt::delegate<>> ActivePaneChanged;
til::typed_event<TerminalApp::TerminalTab, IInspectable> ActivePaneChanged;
til::event<winrt::delegate<>> TabRaiseVisualBell;
til::typed_event<IInspectable, IInspectable> TaskbarProgressChanged;