Standardize on Tab::Close for closing tabs (#19656)

This makes it possible to subscribe to `Close` events.
This commit is contained in:
Leonard Hecker
2025-12-17 17:53:41 +01:00
committed by GitHub
parent a331c42d3c
commit 2f8c51e23d
4 changed files with 12 additions and 5 deletions

View File

@@ -933,6 +933,13 @@ namespace winrt::TerminalApp::implementation
return res;
}
void Tab::Close()
{
ASSERT_UI_THREAD();
Closed.raise(nullptr, nullptr);
}
// Method Description:
// - Prepares this tab for being removed from the UI hierarchy by shutting down all active connections.
void Tab::Shutdown()

View File

@@ -61,6 +61,7 @@ namespace winrt::TerminalApp::implementation
void UpdateSettings(const winrt::Microsoft::Terminal::Settings::Model::CascadiaSettings& settings);
void UpdateTitle();
void Close();
void Shutdown();
void ClosePane();

View File

@@ -22,6 +22,7 @@ namespace TerminalApp
UInt32 TabViewNumTabs;
void Focus(Windows.UI.Xaml.FocusState focusState);
void Close();
void Shutdown();
void SetDispatch(ShortcutActionDispatch dispatch);

View File

@@ -411,13 +411,11 @@ namespace winrt::TerminalApp::implementation
auto actions = t->BuildStartupActions(BuildStartupKind::None);
_AddPreviouslyClosedPaneOrTab(std::move(actions));
_RemoveTab(tab);
tab.Close();
}
// Method Description:
// - Removes the tab (both TerminalControl and XAML)
// Arguments:
// - tab: the tab to remove
// Removes the tab (both TerminalControl and XAML).
// NOTE: Don't call this directly, but rather `tab.Close()`.
void TerminalPage::_RemoveTab(const winrt::TerminalApp::Tab& tab)
{
uint32_t tabIndex{};