Skip to content

Commit 62b4e82

Browse files
committed
closeTab: show confirmation dialog when tab has multiple panes
1 parent 7c488c7 commit 62b4e82

14 files changed

Lines changed: 54 additions & 67 deletions

File tree

.github/copilot-instructions.md

Lines changed: 0 additions & 24 deletions
This file was deleted.

.github/workflows/ci.yml

Lines changed: 0 additions & 8 deletions
This file was deleted.

.github/workflows/copilot-setup-steps.yml

Lines changed: 0 additions & 13 deletions
This file was deleted.

.github/workflows/static-analysis.yml

Lines changed: 0 additions & 22 deletions
This file was deleted.

doc/cascadia/profiles.schema.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2658,6 +2658,11 @@
26582658
"description": "When set to \"true\" closing a window with multiple tabs open will require confirmation. When set to \"false\", the confirmation dialog will not appear.",
26592659
"type": "boolean"
26602660
},
2661+
"warning.confirmCloseAllPanes": {
2662+
"default": true,
2663+
"description": "When set to \"true\" closing a tab with multiple panes open will require confirmation. When set to \"false\", the confirmation dialog will not appear.",
2664+
"type": "boolean"
2665+
},
26612666
"useTabSwitcher": {
26622667
"description": "[Deprecated] Replaced with the \"tabSwitcherMode\" setting.",
26632668
"default": true,

src/cascadia/TerminalApp/Resources/en-US/Resources.resw

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,18 @@
526526
<data name="CloseReadOnlyDialog.Content" xml:space="preserve">
527527
<value>You are about to close a read-only terminal. Do you wish to continue?</value>
528528
</data>
529+
<data name="CloseTabWarningDialog.CloseButtonText" xml:space="preserve">
530+
<value>Cancel</value>
531+
</data>
532+
<data name="CloseTabWarningDialog.Content" xml:space="preserve">
533+
<value>This tab has multiple panes. Do you want to close all of them?</value>
534+
</data>
535+
<data name="CloseTabWarningDialog.PrimaryButtonText" xml:space="preserve">
536+
<value>Close tab</value>
537+
</data>
538+
<data name="CloseTabWarningDialog.Title" xml:space="preserve">
539+
<value>Warning</value>
540+
</data>
529541
<data name="LargePasteDialog.CloseButtonText" xml:space="preserve">
530542
<value>Cancel</value>
531543
</data>

src/cascadia/TerminalApp/TabManagement.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,21 @@ namespace winrt::TerminalApp::implementation
414414
}
415415

416416
auto t = winrt::get_self<implementation::Tab>(tab);
417+
if (t->GetLeafPaneCount() > 1 && _settings.GlobalSettings().ConfirmCloseAllPanes())
418+
{
419+
const auto weak = get_weak();
420+
421+
auto warningResult = co_await _ShowCloseTabWarningDialog();
422+
423+
strong = weak.get();
424+
425+
// If the user didn't explicitly click on close tab - leave
426+
if (!strong || warningResult != ContentDialogResult::Primary)
427+
{
428+
co_return;
429+
}
430+
}
431+
417432
auto actions = t->BuildStartupActions(BuildStartupKind::None);
418433
_AddPreviouslyClosedPaneOrTab(std::move(actions));
419434

src/cascadia/TerminalApp/TerminalPage.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -913,6 +913,17 @@ namespace winrt::TerminalApp::implementation
913913
return _ShowDialogHelper(L"CloseReadOnlyDialog");
914914
}
915915

916+
// Method Description:
917+
// - Displays a dialog to warn the user that they are about to close a tab with
918+
// multiple panes open. Once the user clicks the "Close tab" button, close the tab.
919+
// If "Cancel" is clicked, the dialog will close.
920+
// - Only one dialog can be visible at a time. If another dialog is visible
921+
// when this is called, nothing happens. See _ShowDialog for details
922+
winrt::Windows::Foundation::IAsyncOperation<ContentDialogResult> TerminalPage::_ShowCloseTabWarningDialog()
923+
{
924+
return _ShowDialogHelper(L"CloseTabWarningDialog");
925+
}
926+
916927
// Method Description:
917928
// - Displays a dialog to warn the user about the fact that the text that
918929
// they are trying to paste contains the "new line" character which can

src/cascadia/TerminalApp/TerminalPage.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ namespace winrt::TerminalApp::implementation
304304
winrt::Windows::Foundation::IAsyncOperation<winrt::Windows::UI::Xaml::Controls::ContentDialogResult> _ShowQuitDialog();
305305
winrt::Windows::Foundation::IAsyncOperation<winrt::Windows::UI::Xaml::Controls::ContentDialogResult> _ShowCloseWarningDialog();
306306
winrt::Windows::Foundation::IAsyncOperation<winrt::Windows::UI::Xaml::Controls::ContentDialogResult> _ShowCloseReadOnlyDialog();
307+
winrt::Windows::Foundation::IAsyncOperation<winrt::Windows::UI::Xaml::Controls::ContentDialogResult> _ShowCloseTabWarningDialog();
307308
winrt::Windows::Foundation::IAsyncOperation<winrt::Windows::UI::Xaml::Controls::ContentDialogResult> _ShowMultiLinePasteWarningDialog();
308309
winrt::Windows::Foundation::IAsyncOperation<winrt::Windows::UI::Xaml::Controls::ContentDialogResult> _ShowLargePasteWarningDialog();
309310

src/cascadia/TerminalApp/TerminalPage.xaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@
104104
x:Load="False"
105105
DefaultButton="Close" />
106106

107+
<ContentDialog x:Name="CloseTabWarningDialog"
108+
x:Uid="CloseTabWarningDialog"
109+
Grid.Row="2"
110+
x:Load="False"
111+
DefaultButton="Primary" />
112+
107113
<ContentDialog x:Name="MultiLinePasteDialog"
108114
x:Uid="MultiLinePasteDialog"
109115
Grid.Row="2"

0 commit comments

Comments
 (0)