-
Notifications
You must be signed in to change notification settings - Fork 9.2k
Replace confirmCloseAllTabs with confirmOnClose
#20055
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -801,7 +801,7 @@ namespace winrt::TerminalApp::implementation | |
|
|
||
| _RemoveTabs(tabsToRemove); | ||
|
|
||
| actionArgs.Handled(true); | ||
| actionArgs.Handled(!tabsToRemove.empty()); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this just a change on technical correctness or is there a common situation where |
||
| } | ||
| } | ||
|
|
||
|
|
@@ -837,7 +837,7 @@ namespace winrt::TerminalApp::implementation | |
| // tab row, until you mouse over them. Probably has something to do | ||
| // with tabs not resizing down until there's a mouse exit event. | ||
|
|
||
| actionArgs.Handled(true); | ||
| actionArgs.Handled(!tabsToRemove.empty()); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -394,7 +394,9 @@ namespace winrt::TerminalApp::implementation | |
| // - Removes the tab (both TerminalControl and XAML) after prompting for approval | ||
| // Arguments: | ||
| // - tab: the tab to remove | ||
| winrt::Windows::Foundation::IAsyncAction TerminalPage::_HandleCloseTabRequested(winrt::TerminalApp::Tab tab) | ||
| // - skipConfirmClose: if true, skip the confirmOnClose check. Used when | ||
| // an aggregate confirmation has already been shown (i.e. close other tabs) | ||
| winrt::Windows::Foundation::IAsyncAction TerminalPage::_HandleCloseTabRequested(winrt::TerminalApp::Tab tab, bool skipConfirmClose) | ||
| { | ||
| winrt::com_ptr<TerminalPage> strong; | ||
|
|
||
|
|
@@ -413,6 +415,24 @@ namespace winrt::TerminalApp::implementation | |
| } | ||
| } | ||
|
|
||
| // Skip the per-tab confirmOnClose check when the caller has already | ||
| // shown an aggregate confirmation dialog (e.g. _RemoveTabs). | ||
| if (!skipConfirmClose) | ||
| { | ||
| const auto tabImpl = _GetTabImpl(tab); | ||
| if (tabImpl && _ShouldWarnOnCloseTab(tabImpl)) | ||
| { | ||
| const auto weak = get_weak(); | ||
|
|
||
| auto warningResult = co_await _ShowConfirmCloseDialog(ConfirmCloseDialogKind::Tab); | ||
| strong = weak.get(); | ||
| if (!strong || warningResult != ContentDialogResult::Primary) | ||
| { | ||
| co_return; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| auto t = winrt::get_self<implementation::Tab>(tab); | ||
| auto actions = t->BuildStartupActions(BuildStartupKind::None); | ||
| _AddPreviouslyClosedPaneOrTab(std::move(actions)); | ||
|
|
@@ -782,6 +802,22 @@ namespace winrt::TerminalApp::implementation | |
| if (const auto pane{ activeTab->GetActivePane() }) | ||
| { | ||
| const auto weak = get_weak(); | ||
|
|
||
| // Check if we should warn before closing a single pane | ||
| // (only triggers on Always — Automatic doesn't warn for single pane) | ||
| const auto setting = _settings.GlobalSettings().ConfirmOnClose(); | ||
| if (setting == ConfirmOnClose::Always) | ||
| { | ||
| // If this is the last pane, closing it closes the tab, | ||
| // so use the tab dialog text instead. | ||
| const auto kind = activeTab->GetLeafPaneCount() == 1 ? ConfirmCloseDialogKind::Tab : ConfirmCloseDialogKind::Pane; | ||
| auto warningResult = co_await _ShowConfirmCloseDialog(kind); | ||
| if (!weak.get() || warningResult != ContentDialogResult::Primary) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're immediately dropping the strong reference here and you may be the last holder of |
||
| { | ||
| co_return; | ||
| } | ||
| } | ||
|
|
||
| if (co_await _PaneConfirmCloseReadOnly(pane)) | ||
| { | ||
| if (const auto strong = weak.get()) | ||
|
|
@@ -795,10 +831,33 @@ namespace winrt::TerminalApp::implementation | |
|
|
||
| // Method Description: | ||
| // - Close all panes with the given IDs sequentially. | ||
| // - Shows a single aggregate confirmation dialog upfront if the confirmOnClose setting warrants it. | ||
| // Arguments: | ||
| // - weakTab: weak reference to the tab that the pane belongs to. | ||
| // - weakTab: weak reference to the tab that the panes belong to. | ||
| // - paneIds: collection of the IDs of the panes that are marked for removal. | ||
| void TerminalPage::_ClosePanes(weak_ref<Tab> weakTab, std::vector<uint32_t> paneIds) | ||
| safe_void_coroutine TerminalPage::_ClosePanes(weak_ref<Tab> weakTab, std::vector<uint32_t> paneIds) | ||
| { | ||
| // Show a single aggregate confirmation for closing multiple panes. | ||
| if (_settings.GlobalSettings().ConfirmOnClose() != ConfirmOnClose::Never) | ||
| { | ||
| const auto weak = get_weak(); | ||
| auto warningResult = co_await _ShowConfirmCloseDialog(ConfirmCloseDialogKind::MultiplePanes); | ||
| if (!weak.get() || warningResult != ContentDialogResult::Primary) | ||
| { | ||
| co_return; | ||
| } | ||
| } | ||
| _CloseRemainingPanes(weakTab, std::move(paneIds)); | ||
| } | ||
|
|
||
| // Method Description: | ||
| // - Recursively closes panes by ID, chaining each close via the | ||
| // ClosedByParent callback. Called after confirmation has already | ||
| // been handled by _ClosePanes. | ||
| // Arguments: | ||
| // - weakTab: weak reference to the tab that the panes belong to | ||
| // - paneIds: remaining pane IDs to close | ||
| void TerminalPage::_CloseRemainingPanes(weak_ref<Tab> weakTab, std::vector<uint32_t> paneIds) | ||
| { | ||
| if (auto strongTab{ weakTab.get() }) | ||
| { | ||
|
|
@@ -813,10 +872,9 @@ namespace winrt::TerminalApp::implementation | |
| pane->ClosedByParent([ids{ std::move(paneIds) }, weakThis{ get_weak() }, weakTab]() { | ||
| if (auto strongThis{ weakThis.get() }) | ||
| { | ||
| strongThis->_ClosePanes(weakTab, std::move(ids)); | ||
| strongThis->_CloseRemainingPanes(weakTab, std::move(ids)); | ||
| } | ||
| }); | ||
|
|
||
| // Close the pane which will eventually trigger the closed by parent event | ||
| _HandleClosePaneRequested(pane); | ||
| break; | ||
|
|
@@ -841,18 +899,33 @@ namespace winrt::TerminalApp::implementation | |
|
|
||
| // Method Description: | ||
| // - Closes provided tabs one by one | ||
| // - Shows a single aggregate confirmation dialog upfront if the confirmOnClose setting warrants it. | ||
| // Arguments: | ||
| // - tabs - tabs to remove | ||
| safe_void_coroutine TerminalPage::_RemoveTabs(const std::vector<winrt::TerminalApp::Tab> tabs) | ||
| { | ||
| if (tabs.empty()) | ||
| { | ||
| co_return; | ||
| } | ||
|
|
||
| // Show a single aggregate confirmation instead of per-tab dialogs. | ||
| const auto weak = get_weak(); | ||
| if (_settings.GlobalSettings().ConfirmOnClose() != ConfirmOnClose::Never) | ||
| { | ||
| auto warningResult = co_await _ShowConfirmCloseDialog(ConfirmCloseDialogKind::MultipleTabs); | ||
| if (!weak.get() || warningResult != ContentDialogResult::Primary) | ||
| { | ||
| co_return; | ||
| } | ||
| } | ||
|
|
||
| for (auto& tab : tabs) | ||
| { | ||
| winrt::Windows::Foundation::IAsyncAction action{ nullptr }; | ||
| if (const auto strong = weak.get()) | ||
| { | ||
| action = _HandleCloseTabRequested(tab); | ||
| action = _HandleCloseTabRequested(tab, /*skipConfirmClose*/ true); | ||
| } | ||
|
|
||
| if (!action) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add a
"deprecated": true,property here: https://json-schema.org/understanding-json-schema/reference/annotations