Skip to content

Commit 01e4df1

Browse files
authored
Replace tab.ActivePaneChanged handler with a method (microsoft#17331)
I noticed this while working on microsoft#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
1 parent ecb5631 commit 01e4df1

File tree

5 files changed

+28
-22
lines changed

5 files changed

+28
-22
lines changed

src/cascadia/TerminalApp/TabManagement.cpp

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -136,26 +136,7 @@ namespace winrt::TerminalApp::implementation
136136
// When the tab's active pane changes, we'll want to lookup a new icon
137137
// for it. The Title change will be propagated upwards through the tab's
138138
// PropertyChanged event handler.
139-
newTabImpl->ActivePaneChanged([weakTab, weakThis{ get_weak() }]() {
140-
auto page{ weakThis.get() };
141-
auto tab{ weakTab.get() };
142-
143-
if (page && tab)
144-
{
145-
// Possibly update the icon of the tab.
146-
page->_UpdateTabIcon(*tab);
147-
148-
page->_updateThemeColors();
149-
150-
// Update the taskbar progress as well. We'll raise our own
151-
// SetTaskbarProgress event here, to get tell the hosting
152-
// application to re-query this value from us.
153-
page->SetTaskbarProgress.raise(*page, nullptr);
154-
155-
auto profile = tab->GetFocusedProfile();
156-
page->_UpdateBackground(profile);
157-
}
158-
});
139+
newTabImpl->ActivePaneChanged({ get_weak(), &TerminalPage::_activePaneChanged });
159140

160141
// The RaiseVisualBell event has been bubbled up to here from the pane,
161142
// the next part of the chain is bubbling up to app logic, which will

src/cascadia/TerminalApp/TerminalPage.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2237,6 +2237,29 @@ namespace winrt::TerminalApp::implementation
22372237
return true;
22382238
}
22392239

2240+
// When the tab's active pane changes, we'll want to lookup a new icon
2241+
// for it. The Title change will be propagated upwards through the tab's
2242+
// PropertyChanged event handler.
2243+
void TerminalPage::_activePaneChanged(winrt::TerminalApp::TerminalTab sender,
2244+
Windows::Foundation::IInspectable args)
2245+
{
2246+
if (const auto tab{ _GetTerminalTabImpl(sender) })
2247+
{
2248+
// Possibly update the icon of the tab.
2249+
_UpdateTabIcon(*tab);
2250+
2251+
_updateThemeColors();
2252+
2253+
// Update the taskbar progress as well. We'll raise our own
2254+
// SetTaskbarProgress event here, to get tell the hosting
2255+
// application to re-query this value from us.
2256+
SetTaskbarProgress.raise(*this, nullptr);
2257+
2258+
auto profile = tab->GetFocusedProfile();
2259+
_UpdateBackground(profile);
2260+
}
2261+
}
2262+
22402263
uint32_t TerminalPage::NumberOfTabs() const
22412264
{
22422265
return _tabs.Size();

src/cascadia/TerminalApp/TerminalPage.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,8 @@ namespace winrt::TerminalApp::implementation
542542
winrt::Microsoft::Terminal::Control::TermControl _senderOrActiveControl(const winrt::Windows::Foundation::IInspectable& sender);
543543
winrt::com_ptr<TerminalTab> _senderOrFocusedTab(const IInspectable& sender);
544544

545+
void _activePaneChanged(winrt::TerminalApp::TerminalTab tab, Windows::Foundation::IInspectable args);
546+
545547
#pragma region ActionHandlers
546548
// These are all defined in AppActionHandlers.cpp
547549
#define ON_ALL_ACTIONS(action) DECLARE_ACTION_HANDLER(action);

src/cascadia/TerminalApp/TerminalTab.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1242,7 +1242,7 @@ namespace winrt::TerminalApp::implementation
12421242
_RecalculateAndApplyReadOnly();
12431243

12441244
// Raise our own ActivePaneChanged event.
1245-
ActivePaneChanged.raise();
1245+
ActivePaneChanged.raise(*this, nullptr);
12461246
}
12471247

12481248
// Method Description:

src/cascadia/TerminalApp/TerminalTab.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ namespace winrt::TerminalApp::implementation
9999

100100
til::typed_event<TerminalApp::TerminalPaneContent> RestartTerminalRequested;
101101

102-
til::event<winrt::delegate<>> ActivePaneChanged;
102+
til::typed_event<TerminalApp::TerminalTab, IInspectable> ActivePaneChanged;
103103
til::event<winrt::delegate<>> TabRaiseVisualBell;
104104
til::typed_event<IInspectable, IInspectable> TaskbarProgressChanged;
105105

0 commit comments

Comments
 (0)