From d018210f0528822454cb0a62241051ad913daae7 Mon Sep 17 00:00:00 2001 From: Raphael Horber Date: Fri, 20 Nov 2020 18:40:33 +0100 Subject: [PATCH] Make CloseWarningDialog async (#8117) The CloseWarningDialog is now "awaitable"/async, as suggested in PR #7871. As opening the dialog is async, the flag can be reset in the same method. This way the flag operations occur in the same method. The event handlers of the buttons became obsolete and are removed. ## Validation Steps Performed Tested manually. --- src/cascadia/TerminalApp/TerminalPage.cpp | 49 ++++++---------------- src/cascadia/TerminalApp/TerminalPage.h | 6 +-- src/cascadia/TerminalApp/TerminalPage.xaml | 4 +- 3 files changed, 16 insertions(+), 43 deletions(-) diff --git a/src/cascadia/TerminalApp/TerminalPage.cpp b/src/cascadia/TerminalApp/TerminalPage.cpp index d0f68ca479ce..4dcb3c048839 100644 --- a/src/cascadia/TerminalApp/TerminalPage.cpp +++ b/src/cascadia/TerminalApp/TerminalPage.cpp @@ -374,12 +374,13 @@ namespace winrt::TerminalApp::implementation // all the tabs and shut down and app. If cancel is clicked, the dialog will close // - Only one dialog can be visible at a time. If another dialog is visible // when this is called, nothing happens. See _ShowDialog for details - void TerminalPage::_ShowCloseWarningDialog() + winrt::Windows::Foundation::IAsyncOperation TerminalPage::_ShowCloseWarningDialog() { if (auto presenter{ _dialogPresenter.get() }) { - presenter.ShowDialog(FindName(L"CloseAllDialog").try_as()); + co_return co_await presenter.ShowDialog(FindName(L"CloseAllDialog").try_as()); } + co_return ContentDialogResult::None; } // Method Description: @@ -1465,17 +1466,21 @@ namespace winrt::TerminalApp::implementation // Method Description: // - Close the terminal app. If there is more // than one tab opened, show a warning dialog. - void TerminalPage::CloseWindow() + fire_and_forget TerminalPage::CloseWindow() { if (_tabs.Size() > 1 && _settings.GlobalSettings().ConfirmCloseAllTabs() && !_displayingCloseDialog) { _displayingCloseDialog = true; - _ShowCloseWarningDialog(); - } - else - { - _CloseAllTabs(); + ContentDialogResult warningResult = co_await _ShowCloseWarningDialog(); + _displayingCloseDialog = false; + + if (warningResult != ContentDialogResult::Primary) + { + co_return; + } } + + _CloseAllTabs(); } // Method Description: @@ -2189,34 +2194,6 @@ namespace winrt::TerminalApp::implementation _RemoveTabViewItem(tabViewItem); } - // Method Description: - // - Called when the primary button of the content dialog is clicked. - // This calls _CloseAllTabs(), which closes all the tabs currently - // opened and then the Terminal app. This method will be called if - // the user confirms to close all the tabs. - // Arguments: - // - sender: unused - // - ContentDialogButtonClickEventArgs: unused - void TerminalPage::_CloseWarningPrimaryButtonOnClick(WUX::Controls::ContentDialog /* sender */, - WUX::Controls::ContentDialogButtonClickEventArgs /* eventArgs*/) - { - _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 87706c97bd9d..0672a5b218ac 100644 --- a/src/cascadia/TerminalApp/TerminalPage.h +++ b/src/cascadia/TerminalApp/TerminalPage.h @@ -56,7 +56,7 @@ namespace winrt::TerminalApp::implementation winrt::hstring ThirdPartyNoticesLink(); - void CloseWindow(); + winrt::fire_and_forget CloseWindow(); void ToggleFocusMode(); void ToggleFullscreen(); @@ -133,7 +133,7 @@ namespace winrt::TerminalApp::implementation winrt::fire_and_forget _ProcessStartupActions(Windows::Foundation::Collections::IVector actions, const bool initial); void _ShowAboutDialog(); - void _ShowCloseWarningDialog(); + winrt::Windows::Foundation::IAsyncOperation _ShowCloseWarningDialog(); winrt::Windows::Foundation::IAsyncOperation _ShowMultiLinePasteWarningDialog(); winrt::Windows::Foundation::IAsyncOperation _ShowLargePasteWarningDialog(); @@ -147,8 +147,6 @@ namespace winrt::TerminalApp::implementation 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 ae5c242a9d41..b3d239493611 100644 --- a/src/cascadia/TerminalApp/TerminalPage.xaml +++ b/src/cascadia/TerminalApp/TerminalPage.xaml @@ -50,9 +50,7 @@ the MIT License. See LICENSE in the project root for license information. --> x:Load="False" x:Name="CloseAllDialog" x:Uid="CloseAllDialog" - DefaultButton="Primary" - PrimaryButtonClick="_CloseWarningPrimaryButtonOnClick" - CloseButtonClick="_CloseWarningCloseButtonOnClick"> + DefaultButton="Primary">