Skip to content

Commit b1a2153

Browse files
mpela81PankajBhojwani
authored andcommitted
Dismiss any open content dialog when window is moved (#11485)
## Summary of the Pull Request When the window moves, hide any visible content dialog (only one can be shown at a time) and ensure its associated async operation is terminated. #10922 dismisses any open popups when the window is moved or any scroll viewer scrolls. However, if you just close a Popup from the UI tree, the async operation associated to a ContentDialog (started with `dialog.ShowAsync`) does not terminate. The dialog lock that prevents opening multiple dialogs at the same time is not released, and no further dialog can be shown. Explicitly dismissing the only visible ContentDialog using its `Hide` method terminates the operation. ## Validation Steps Performed Manual tests, open up dialogs and move the window (like in #11425) References #10922 Closes #11425
1 parent b19f449 commit b1a2153

File tree

4 files changed

+20
-0
lines changed

4 files changed

+20
-0
lines changed

src/cascadia/TerminalApp/AppLogic.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,8 @@ namespace winrt::TerminalApp::implementation
353353
co_return ContentDialogResult::None;
354354
}
355355

356+
_dialog = dialog;
357+
356358
// IMPORTANT: This is necessary as documented in the ContentDialog MSDN docs.
357359
// Since we're hosting the dialog in a Xaml island, we need to connect it to the
358360
// xaml tree somehow.
@@ -390,6 +392,16 @@ namespace winrt::TerminalApp::implementation
390392
// be released so another can be shown
391393
}
392394

395+
// Method Description:
396+
// - Dismiss the (only) visible ContentDialog
397+
void AppLogic::DismissDialog()
398+
{
399+
if (auto localDialog = std::exchange(_dialog, nullptr))
400+
{
401+
localDialog.Hide();
402+
}
403+
}
404+
393405
// Method Description:
394406
// - Displays a dialog for errors found while loading or validating the
395407
// settings. Uses the resources under the provided title and content keys

src/cascadia/TerminalApp/AppLogic.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ namespace winrt::TerminalApp::implementation
9696
bool GetAlwaysShowNotificationIcon();
9797

9898
winrt::Windows::Foundation::IAsyncOperation<winrt::Windows::UI::Xaml::Controls::ContentDialogResult> ShowDialog(winrt::Windows::UI::Xaml::Controls::ContentDialog dialog);
99+
void DismissDialog();
99100

100101
Windows::Foundation::Collections::IMapView<Microsoft::Terminal::Control::KeyChord, Microsoft::Terminal::Settings::Model::Command> GlobalHotkeys();
101102

@@ -120,6 +121,7 @@ namespace winrt::TerminalApp::implementation
120121
bool _loadedInitialSettings = false;
121122

122123
std::shared_mutex _dialogLock;
124+
winrt::Windows::UI::Xaml::Controls::ContentDialog _dialog;
123125

124126
::TerminalApp::AppCommandlineArgs _appArgs;
125127
::TerminalApp::AppCommandlineArgs _settingsAppArgs;

src/cascadia/TerminalApp/AppLogic.idl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ namespace TerminalApp
8080
// See IDialogPresenter and TerminalPage's DialogPresenter for more
8181
// information.
8282
Windows.Foundation.IAsyncOperation<Windows.UI.Xaml.Controls.ContentDialogResult> ShowDialog(Windows.UI.Xaml.Controls.ContentDialog dialog);
83+
void DismissDialog();
8384

8485
event Windows.Foundation.TypedEventHandler<Object, Windows.UI.Xaml.UIElement> SetTitleBarContent;
8586
event Windows.Foundation.TypedEventHandler<Object, String> TitleChanged;

src/cascadia/WindowsTerminal/AppHost.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,6 +1108,11 @@ void AppHost::_WindowMoved()
11081108
{
11091109
if (_logic)
11101110
{
1111+
// Ensure any open ContentDialog is dismissed.
1112+
// Closing the popup in the UI tree as done below is not sufficient because
1113+
// it does not terminate the dialog's async operation.
1114+
_logic.DismissDialog();
1115+
11111116
const auto root{ _logic.GetRoot() };
11121117

11131118
// This is basically DismissAllPopups which is also in

0 commit comments

Comments
 (0)