diff --git a/src/cascadia/TerminalApp/TerminalPage.cpp b/src/cascadia/TerminalApp/TerminalPage.cpp index fad50d69455..254a198e1dc 100644 --- a/src/cascadia/TerminalApp/TerminalPage.cpp +++ b/src/cascadia/TerminalApp/TerminalPage.cpp @@ -1359,8 +1359,9 @@ namespace winrt::TerminalApp::implementation // than one tab opened, show a warning dialog. void TerminalPage::CloseWindow() { - if (_tabs.Size() > 1 && _settings.GlobalSettings().ConfirmCloseAllTabs()) + if (_tabs.Size() > 1 && _settings.GlobalSettings().ConfirmCloseAllTabs() && !_displayingCloseDialog) { + _displayingCloseDialog = true; _ShowCloseWarningDialog(); } else @@ -2030,6 +2031,20 @@ namespace winrt::TerminalApp::implementation _CloseAllTabs(); } + // Method Description: + // - Called when the close button of the content dialog is clicked. + // This resets the flag _displayingCloseDialog, which was set before + // opening the dialog. Otherwise, the Terminal app would be closed + // on the next close request without showing the warning dialog. + // Arguments: + // - sender: unused + // - ContentDialogButtonClickEventArgs: unused + void TerminalPage::_CloseWarningCloseButtonOnClick(WUX::Controls::ContentDialog /* sender */, + WUX::Controls::ContentDialogButtonClickEventArgs /* eventArgs*/) + { + _displayingCloseDialog = false; + } + // Method Description: // - Hook up keybindings, and refresh the UI of the terminal. // This includes update the settings of all the tabs according diff --git a/src/cascadia/TerminalApp/TerminalPage.h b/src/cascadia/TerminalApp/TerminalPage.h index 8b28ab12397..ac773366a00 100644 --- a/src/cascadia/TerminalApp/TerminalPage.h +++ b/src/cascadia/TerminalApp/TerminalPage.h @@ -124,10 +124,12 @@ namespace winrt::TerminalApp::implementation void _CreateNewTabFromSettings(GUID profileGuid, TerminalApp::TerminalSettings settings); winrt::Microsoft::Terminal::TerminalConnection::ITerminalConnection _CreateConnectionFromSettings(GUID profileGuid, TerminalApp::TerminalSettings settings); + bool _displayingCloseDialog{ false }; void _SettingsButtonOnClick(const IInspectable& sender, const Windows::UI::Xaml::RoutedEventArgs& eventArgs); void _FeedbackButtonOnClick(const IInspectable& sender, const Windows::UI::Xaml::RoutedEventArgs& eventArgs); void _AboutButtonOnClick(const IInspectable& sender, const Windows::UI::Xaml::RoutedEventArgs& eventArgs); void _CloseWarningPrimaryButtonOnClick(Windows::UI::Xaml::Controls::ContentDialog sender, Windows::UI::Xaml::Controls::ContentDialogButtonClickEventArgs eventArgs); + void _CloseWarningCloseButtonOnClick(Windows::UI::Xaml::Controls::ContentDialog sender, Windows::UI::Xaml::Controls::ContentDialogButtonClickEventArgs eventArgs); void _ThirdPartyNoticesOnClick(const IInspectable& sender, const Windows::UI::Xaml::RoutedEventArgs& eventArgs); void _HookupKeyBindings(const Microsoft::Terminal::Settings::Model::KeyMapping& keymap) noexcept; diff --git a/src/cascadia/TerminalApp/TerminalPage.xaml b/src/cascadia/TerminalApp/TerminalPage.xaml index b2901440bf4..e43a0c8672f 100644 --- a/src/cascadia/TerminalApp/TerminalPage.xaml +++ b/src/cascadia/TerminalApp/TerminalPage.xaml @@ -51,7 +51,8 @@ the MIT License. See LICENSE in the project root for license information. --> x:Name="CloseAllDialog" x:Uid="CloseAllDialog" DefaultButton="Primary" - PrimaryButtonClick="_CloseWarningPrimaryButtonOnClick"> + PrimaryButtonClick="_CloseWarningPrimaryButtonOnClick" + CloseButtonClick="_CloseWarningCloseButtonOnClick">