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.
This commit is contained in:
Raphael Horber 2020-11-20 18:40:33 +01:00 committed by GitHub
parent 14fe993516
commit 67dfbd21a6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 43 deletions

View file

@ -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<ContentDialogResult> TerminalPage::_ShowCloseWarningDialog()
{
if (auto presenter{ _dialogPresenter.get() })
{
presenter.ShowDialog(FindName(L"CloseAllDialog").try_as<WUX::Controls::ContentDialog>());
co_return co_await presenter.ShowDialog(FindName(L"CloseAllDialog").try_as<WUX::Controls::ContentDialog>());
}
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

View file

@ -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<Microsoft::Terminal::Settings::Model::ActionAndArgs> actions, const bool initial);
void _ShowAboutDialog();
void _ShowCloseWarningDialog();
winrt::Windows::Foundation::IAsyncOperation<winrt::Windows::UI::Xaml::Controls::ContentDialogResult> _ShowCloseWarningDialog();
winrt::Windows::Foundation::IAsyncOperation<winrt::Windows::UI::Xaml::Controls::ContentDialogResult> _ShowMultiLinePasteWarningDialog();
winrt::Windows::Foundation::IAsyncOperation<winrt::Windows::UI::Xaml::Controls::ContentDialogResult> _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;

View file

@ -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">
</ContentDialog>
<ContentDialog