Skip to content

Commit 52970ef

Browse files
committed
RegisterBigTimeEncapsulationViolatingTerminalPaneContentEvents
1 parent 826fc08 commit 52970ef

File tree

4 files changed

+17
-18
lines changed

4 files changed

+17
-18
lines changed

src/cascadia/TerminalApp/TerminalPage.cpp

+1-16
Original file line numberDiff line numberDiff line change
@@ -1731,11 +1731,8 @@ namespace winrt::TerminalApp::implementation
17311731
// Add an event handler for when the terminal or tab wants to set a
17321732
// progress indicator on the taskbar
17331733
hostingTab.TaskbarProgressChanged({ get_weak(), &TerminalPage::_SetTaskbarProgressHandler });
1734-
}
17351734

1736-
void TerminalPage::_RegisterPaneEvents(const TerminalApp::TerminalPaneContent& paneContent)
1737-
{
1738-
paneContent.RestartTerminalRequested({ get_weak(), &TerminalPage::_restartPaneConnection });
1735+
hostingTab.RestartTerminalRequested({ get_weak(), &TerminalPage::_restartPaneConnection });
17391736
}
17401737

17411738
// Method Description:
@@ -2384,16 +2381,6 @@ namespace winrt::TerminalApp::implementation
23842381
_UnZoomIfNeeded();
23852382
auto [original, _] = activeTab->SplitPane(*realSplitType, splitSize, newPane);
23862383

2387-
// When we split the pane, the Pane itself will create a _new_ Pane
2388-
// instance for the original content. We need to make sure we also
2389-
// re-add our event handler to that newly created pane.
2390-
//
2391-
// _MakePane will already call this for the newly created pane.
2392-
if (const auto& paneContent{ original->GetContent().try_as<TerminalPaneContent>() })
2393-
{
2394-
_RegisterPaneEvents(*paneContent);
2395-
}
2396-
23972384
// After GH#6586, the control will no longer focus itself
23982385
// automatically when it's finished being laid out. Manually focus
23992386
// the control here instead.
@@ -3204,8 +3191,6 @@ namespace winrt::TerminalApp::implementation
32043191
original->SetActive();
32053192
}
32063193

3207-
_RegisterPaneEvents(paneContent);
3208-
32093194
return resultPane;
32103195
}
32113196

src/cascadia/TerminalApp/TerminalPage.h

-1
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,6 @@ namespace winrt::TerminalApp::implementation
345345
void _InitializeTab(winrt::com_ptr<TerminalTab> newTabImpl, uint32_t insertPosition = -1);
346346
void _RegisterTerminalEvents(Microsoft::Terminal::Control::TermControl term);
347347
void _RegisterTabEvents(TerminalTab& hostingTab);
348-
void _RegisterPaneEvents(const TerminalApp::TerminalPaneContent& paneContent);
349348

350349
void _DismissTabContextMenus();
351350
void _FocusCurrentTab(const bool focusAlways);

src/cascadia/TerminalApp/TerminalTab.cpp

+10-1
Original file line numberDiff line numberDiff line change
@@ -904,7 +904,6 @@ namespace winrt::TerminalApp::implementation
904904
if (it != _contentEvents.end())
905905
{
906906
// revoke the event handlers by resetting the event struct
907-
it->second = {};
908907
// and remove it from the map
909908
_contentEvents.erase(paneId);
910909
}
@@ -1060,6 +1059,11 @@ namespace winrt::TerminalApp::implementation
10601059
}
10611060
});
10621061

1062+
if (const auto& terminal{ content.try_as<TerminalApp::TerminalPaneContent>() })
1063+
{
1064+
events.RestartTerminalRequested = terminal.RestartTerminalRequested(winrt::auto_revoke, { get_weak(), &TerminalTab::_bubbleRestartTerminalRequested });
1065+
}
1066+
10631067
if (_tabStatus.IsInputBroadcastActive())
10641068
{
10651069
if (const auto& termContent{ content.try_as<TerminalApp::TerminalPaneContent>() })
@@ -1998,4 +2002,9 @@ namespace winrt::TerminalApp::implementation
19982002
ActionAndArgs actionAndArgs{ ShortcutAction::Find, nullptr };
19992003
_dispatch.DoAction(*this, actionAndArgs);
20002004
}
2005+
void TerminalTab::_bubbleRestartTerminalRequested(TerminalApp::TerminalPaneContent sender,
2006+
const winrt::Windows::Foundation::IInspectable& args)
2007+
{
2008+
RestartTerminalRequested.raise(sender, args);
2009+
}
20012010
}

src/cascadia/TerminalApp/TerminalTab.h

+6
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ namespace winrt::TerminalApp::implementation
9797
return _tabStatus;
9898
}
9999

100+
til::typed_event<TerminalApp::TerminalPaneContent> RestartTerminalRequested;
101+
100102
WINRT_CALLBACK(ActivePaneChanged, winrt::delegate<>);
101103
WINRT_CALLBACK(TabRaiseVisualBell, winrt::delegate<>);
102104
TYPED_EVENT(TaskbarProgressChanged, IInspectable, IInspectable);
@@ -138,6 +140,8 @@ namespace winrt::TerminalApp::implementation
138140
winrt::Microsoft::Terminal::Control::TermControl::KeySent_revoker KeySent;
139141
winrt::Microsoft::Terminal::Control::TermControl::CharSent_revoker CharSent;
140142
winrt::Microsoft::Terminal::Control::TermControl::StringSent_revoker StringSent;
143+
144+
winrt::TerminalApp::TerminalPaneContent::RestartTerminalRequested_revoker RestartTerminalRequested;
141145
};
142146
std::unordered_map<uint32_t, ContentEventTokens> _contentEvents;
143147

@@ -196,6 +200,8 @@ namespace winrt::TerminalApp::implementation
196200
void _moveTabToNewWindowClicked(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::UI::Xaml::RoutedEventArgs& e);
197201
void _findClicked(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::UI::Xaml::RoutedEventArgs& e);
198202

203+
void _bubbleRestartTerminalRequested(TerminalApp::TerminalPaneContent sender, const winrt::Windows::Foundation::IInspectable& args);
204+
199205
friend class ::TerminalAppLocalTests::TabTests;
200206
};
201207
}

0 commit comments

Comments
 (0)