Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dismiss any open content dialog when window is moved #11485

Merged
3 commits merged into from
Oct 12, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/cascadia/TerminalApp/AppLogic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,8 @@ namespace winrt::TerminalApp::implementation
co_return ContentDialogResult::None;
}

_dialog = dialog;

// IMPORTANT: This is necessary as documented in the ContentDialog MSDN docs.
// Since we're hosting the dialog in a Xaml island, we need to connect it to the
// xaml tree somehow.
Expand Down Expand Up @@ -412,6 +414,17 @@ namespace winrt::TerminalApp::implementation
// be released so another can be shown
}

// Method Description:
// - Dismiss the (only) visible ContentDialog
void AppLogic::DismissDialog()
{
if (_dialog)
{
auto localDialog = std::exchange(_dialog, nullptr);
localDialog.Hide();
}
}

// Method Description:
// - Displays a dialog for errors found while loading or validating the
// settings. Uses the resources under the provided title and content keys
Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/TerminalApp/AppLogic.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ namespace winrt::TerminalApp::implementation
bool GetShowTitleInTitlebar();

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

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

Expand All @@ -132,6 +133,7 @@ namespace winrt::TerminalApp::implementation
uint64_t _numOpenWindows{ 0 };

std::shared_mutex _dialogLock;
winrt::Windows::UI::Xaml::Controls::ContentDialog _dialog;

::TerminalApp::AppCommandlineArgs _appArgs;
::TerminalApp::AppCommandlineArgs _settingsAppArgs;
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalApp/AppLogic.idl
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ namespace TerminalApp
// See IDialogPresenter and TerminalPage's DialogPresenter for more
// information.
Windows.Foundation.IAsyncOperation<Windows.UI.Xaml.Controls.ContentDialogResult> ShowDialog(Windows.UI.Xaml.Controls.ContentDialog dialog);
void DismissDialog();

event Windows.Foundation.TypedEventHandler<Object, Windows.UI.Xaml.UIElement> SetTitleBarContent;
event Windows.Foundation.TypedEventHandler<Object, String> TitleChanged;
Expand Down
5 changes: 5 additions & 0 deletions src/cascadia/WindowsTerminal/AppHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1316,6 +1316,11 @@ void AppHost::_WindowMoved()
{
if (_logic)
{
// Ensure any open ContentDialog is dismissed.
// Closing the popup in the UI tree as done below is not sufficient because
// it does not terminate the dialog's async operation.
_logic.DismissDialog();

const auto root{ _logic.GetRoot() };

// This is basically DismissAllPopups which is also in
Expand Down