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

Manually put our ContentDialogs in the tab content, rather than above #12840

Merged
6 commits merged into from
Apr 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 1 addition & 13 deletions src/cascadia/TerminalApp/AppLogic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,11 +348,7 @@ namespace winrt::TerminalApp::implementation
}

_dialog = dialog;
// GH#12622: After the dialog is displayed, always clear it out. If we
// don't, we won't be able to display another!
const auto cleanup = wil::scope_exit([this]() {
_dialog = nullptr;
});

// 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 @@ -400,14 +396,6 @@ namespace winrt::TerminalApp::implementation
}
}

// Method Description:
// - Returns true if there is no dialog currently being shown (meaning that we can show a dialog)
// - Returns false if there is a dialog currently being shown (meaning that we cannot show another dialog)
bool AppLogic::CanShowDialog()
{
return (_dialog == nullptr);
}

// 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
1 change: 0 additions & 1 deletion src/cascadia/TerminalApp/AppLogic.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ namespace winrt::TerminalApp::implementation
bool GetShowTitleInTitlebar();

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

Windows::Foundation::Collections::IMapView<Microsoft::Terminal::Control::KeyChord, Microsoft::Terminal::Settings::Model::Command> GlobalHotkeys();
Expand Down
5 changes: 5 additions & 0 deletions src/cascadia/TerminalApp/AppLogic.idl
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ namespace TerminalApp

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

// 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;
event Windows.Foundation.TypedEventHandler<Object, LastTabClosedEventArgs> LastTabClosed;
Expand Down
17 changes: 1 addition & 16 deletions src/cascadia/TerminalApp/TerminalPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -705,29 +705,14 @@ namespace winrt::TerminalApp::implementation
ShellExecute(nullptr, nullptr, currentPath.c_str(), nullptr, nullptr, SW_SHOW);
}

// Method description:
// - Called when the user closes a content dialog
// - Tells the presenter to update its knowledge of whether there is a content dialog open
void TerminalPage::_DialogCloseClick(const IInspectable&,
const ContentDialogButtonClickEventArgs&)
{
if (auto presenter{ _dialogPresenter.get() })
{
presenter.DismissDialog();
}
}

// Method Description:
// - Helper to show a content dialog
// - We only open a content dialog if there isn't one open already
winrt::Windows::Foundation::IAsyncOperation<ContentDialogResult> TerminalPage::_ShowDialogHelper(const std::wstring_view& name)
{
if (auto presenter{ _dialogPresenter.get() })
{
if (presenter.CanShowDialog())
{
co_return co_await presenter.ShowDialog(FindName(name).try_as<WUX::Controls::ContentDialog>());
}
co_return co_await presenter.ShowDialog(FindName(name).try_as<WUX::Controls::ContentDialog>());
}
co_return ContentDialogResult::None;
}
Expand Down
1 change: 0 additions & 1 deletion src/cascadia/TerminalApp/TerminalPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ namespace winrt::TerminalApp::implementation
winrt::Windows::Foundation::IAsyncOperation<winrt::Windows::UI::Xaml::Controls::ContentDialogResult> _ShowCloseReadOnlyDialog();
winrt::Windows::Foundation::IAsyncOperation<winrt::Windows::UI::Xaml::Controls::ContentDialogResult> _ShowMultiLinePasteWarningDialog();
winrt::Windows::Foundation::IAsyncOperation<winrt::Windows::UI::Xaml::Controls::ContentDialogResult> _ShowLargePasteWarningDialog();
void _DialogCloseClick(const IInspectable& sender, const Windows::UI::Xaml::Controls::ContentDialogButtonClickEventArgs& eventArgs);

void _CreateNewTabFlyout();
void _OpenNewTabDropdown();
Expand Down
2 changes: 0 additions & 2 deletions src/cascadia/TerminalApp/TerminalPage.idl
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ namespace TerminalApp
interface IDialogPresenter
{
Windows.Foundation.IAsyncOperation<Windows.UI.Xaml.Controls.ContentDialogResult> ShowDialog(Windows.UI.Xaml.Controls.ContentDialog dialog);
Boolean CanShowDialog();
void DismissDialog();
};

[default_interface] runtimeclass TerminalPage : Windows.UI.Xaml.Controls.Page, Windows.UI.Xaml.Data.INotifyPropertyChanged
Expand Down
33 changes: 25 additions & 8 deletions src/cascadia/TerminalApp/TerminalPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,27 @@
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch" />

<!--
GH#12775 et. al: After switching to ControlsV2, it seems that
delay-loading a dialog causes the ContentDialog to be assigned a
Height equal to it's content size. If we DON'T assign the
ContentDialog a Row, I believe it's assigned Row 0 by default. So,
when the dialog gets opened, the dialog seemingly causes a giant
hole to appear in the body of the app.

Assigning all the dialogs to Row 2 (where the rest of the content
is) makes the "hole" appear in the same space as the rest of the
TabContent, fixing the issue.

Note that the actual content in a content dialog gets parented to
the PopupRoot, so it actually always appeared in the correct place, it's
just this weird hole that appeared in Row 0.
-->

<ContentDialog x:Name="AboutDialog"
x:Uid="AboutDialog"
Grid.Row="2"
x:Load="False"
CloseButtonClick="_DialogCloseClick"
DefaultButton="Close">
<StackPanel Orientation="Vertical">
<TextBlock IsTextSelectionEnabled="True">
Expand All @@ -96,26 +113,26 @@

<ContentDialog x:Name="QuitDialog"
x:Uid="QuitDialog"
Grid.Row="2"
x:Load="False"
CloseButtonClick="_DialogCloseClick"
DefaultButton="Primary" />

<ContentDialog x:Name="CloseAllDialog"
x:Uid="CloseAllDialog"
Grid.Row="2"
x:Load="False"
CloseButtonClick="_DialogCloseClick"
DefaultButton="Primary" />

<ContentDialog x:Name="CloseReadOnlyDialog"
x:Uid="CloseReadOnlyDialog"
Grid.Row="2"
x:Load="False"
CloseButtonClick="_DialogCloseClick"
DefaultButton="Close" />

<ContentDialog x:Name="MultiLinePasteDialog"
x:Uid="MultiLinePasteDialog"
Grid.Row="2"
x:Load="False"
CloseButtonClick="_DialogCloseClick"
DefaultButton="Primary">
<StackPanel>
<TextBlock x:Uid="MultiLineWarningText"
Expand All @@ -134,14 +151,14 @@

<ContentDialog x:Name="LargePasteDialog"
x:Uid="LargePasteDialog"
Grid.Row="2"
x:Load="False"
CloseButtonClick="_DialogCloseClick"
DefaultButton="Primary" />

<ContentDialog x:Name="ControlNoticeDialog"
x:Uid="ControlNoticeDialog"
Grid.Row="2"
x:Load="False"
CloseButtonClick="_DialogCloseClick"
DefaultButton="Primary">
<TextBlock IsTextSelectionEnabled="True"
TextWrapping="WrapWholeWords">
Expand All @@ -151,8 +168,8 @@

<ContentDialog x:Name="CouldNotOpenUriDialog"
x:Uid="CouldNotOpenUriDialog"
Grid.Row="2"
x:Load="False"
CloseButtonClick="_DialogCloseClick"
DefaultButton="Primary">
<TextBlock IsTextSelectionEnabled="True"
TextWrapping="WrapWholeWords">
Expand Down