Extend ContentDialogHelper to work on multiple windows
This commit is contained in:
parent
eb212aa91b
commit
f195198608
1 changed files with 70 additions and 55 deletions
|
@ -28,7 +28,8 @@ namespace Ryujinx.Ava.UI.Helpers
|
||||||
string closeButton,
|
string closeButton,
|
||||||
UserResult primaryButtonResult = UserResult.Ok,
|
UserResult primaryButtonResult = UserResult.Ok,
|
||||||
ManualResetEvent deferResetEvent = null,
|
ManualResetEvent deferResetEvent = null,
|
||||||
TypedEventHandler<ContentDialog, ContentDialogButtonClickEventArgs> deferCloseAction = null)
|
TypedEventHandler<ContentDialog, ContentDialogButtonClickEventArgs> deferCloseAction = null,
|
||||||
|
Window parent = null)
|
||||||
{
|
{
|
||||||
UserResult result = UserResult.None;
|
UserResult result = UserResult.None;
|
||||||
|
|
||||||
|
@ -62,7 +63,7 @@ namespace Ryujinx.Ava.UI.Helpers
|
||||||
contentDialog.PrimaryButtonClick += deferCloseAction;
|
contentDialog.PrimaryButtonClick += deferCloseAction;
|
||||||
}
|
}
|
||||||
|
|
||||||
await ShowAsync(contentDialog);
|
await ShowAsync(contentDialog, parent);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -77,11 +78,21 @@ namespace Ryujinx.Ava.UI.Helpers
|
||||||
int iconSymbol,
|
int iconSymbol,
|
||||||
UserResult primaryButtonResult = UserResult.Ok,
|
UserResult primaryButtonResult = UserResult.Ok,
|
||||||
ManualResetEvent deferResetEvent = null,
|
ManualResetEvent deferResetEvent = null,
|
||||||
TypedEventHandler<ContentDialog, ContentDialogButtonClickEventArgs> deferCloseAction = null)
|
TypedEventHandler<ContentDialog, ContentDialogButtonClickEventArgs> deferCloseAction = null,
|
||||||
|
Window parent = null)
|
||||||
{
|
{
|
||||||
Grid content = CreateTextDialogContent(primaryText, secondaryText, iconSymbol);
|
Grid content = CreateTextDialogContent(primaryText, secondaryText, iconSymbol);
|
||||||
|
|
||||||
return await ShowContentDialog(title, content, primaryButton, secondaryButton, closeButton, primaryButtonResult, deferResetEvent, deferCloseAction);
|
return await ShowContentDialog(
|
||||||
|
title,
|
||||||
|
content,
|
||||||
|
primaryButton,
|
||||||
|
secondaryButton,
|
||||||
|
closeButton,
|
||||||
|
primaryButtonResult,
|
||||||
|
deferResetEvent,
|
||||||
|
deferCloseAction,
|
||||||
|
parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async static Task<UserResult> ShowDeferredContentDialog(
|
public async static Task<UserResult> ShowDeferredContentDialog(
|
||||||
|
@ -94,7 +105,8 @@ namespace Ryujinx.Ava.UI.Helpers
|
||||||
string closeButton,
|
string closeButton,
|
||||||
int iconSymbol,
|
int iconSymbol,
|
||||||
ManualResetEvent deferResetEvent,
|
ManualResetEvent deferResetEvent,
|
||||||
Func<Window, Task> doWhileDeferred = null)
|
Func<Window, Task> doWhileDeferred = null,
|
||||||
|
Window parent = null)
|
||||||
{
|
{
|
||||||
bool startedDeferring = false;
|
bool startedDeferring = false;
|
||||||
|
|
||||||
|
@ -108,7 +120,8 @@ namespace Ryujinx.Ava.UI.Helpers
|
||||||
iconSymbol,
|
iconSymbol,
|
||||||
primaryButton == LocaleManager.Instance[LocaleKeys.InputDialogYes] ? UserResult.Yes : UserResult.Ok,
|
primaryButton == LocaleManager.Instance[LocaleKeys.InputDialogYes] ? UserResult.Yes : UserResult.Ok,
|
||||||
deferResetEvent,
|
deferResetEvent,
|
||||||
DeferClose);
|
DeferClose,
|
||||||
|
parent);
|
||||||
|
|
||||||
async void DeferClose(ContentDialog sender, ContentDialogButtonClickEventArgs args)
|
async void DeferClose(ContentDialog sender, ContentDialogButtonClickEventArgs args)
|
||||||
{
|
{
|
||||||
|
@ -199,7 +212,8 @@ namespace Ryujinx.Ava.UI.Helpers
|
||||||
string secondaryText,
|
string secondaryText,
|
||||||
string acceptButton,
|
string acceptButton,
|
||||||
string closeButton,
|
string closeButton,
|
||||||
string title)
|
string title,
|
||||||
|
Window parent = null)
|
||||||
{
|
{
|
||||||
return await ShowTextDialog(
|
return await ShowTextDialog(
|
||||||
title,
|
title,
|
||||||
|
@ -208,7 +222,8 @@ namespace Ryujinx.Ava.UI.Helpers
|
||||||
acceptButton,
|
acceptButton,
|
||||||
"",
|
"",
|
||||||
closeButton,
|
closeButton,
|
||||||
(int)Symbol.Important);
|
(int)Symbol.Important,
|
||||||
|
parent: parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static async Task<UserResult> CreateConfirmationDialog(
|
internal static async Task<UserResult> CreateConfirmationDialog(
|
||||||
|
@ -217,7 +232,8 @@ namespace Ryujinx.Ava.UI.Helpers
|
||||||
string acceptButtonText,
|
string acceptButtonText,
|
||||||
string cancelButtonText,
|
string cancelButtonText,
|
||||||
string title,
|
string title,
|
||||||
UserResult primaryButtonResult = UserResult.Yes)
|
UserResult primaryButtonResult = UserResult.Yes,
|
||||||
|
Window parent = null)
|
||||||
{
|
{
|
||||||
return await ShowTextDialog(
|
return await ShowTextDialog(
|
||||||
string.IsNullOrWhiteSpace(title) ? LocaleManager.Instance[LocaleKeys.DialogConfirmationTitle] : title,
|
string.IsNullOrWhiteSpace(title) ? LocaleManager.Instance[LocaleKeys.DialogConfirmationTitle] : title,
|
||||||
|
@ -227,7 +243,8 @@ namespace Ryujinx.Ava.UI.Helpers
|
||||||
"",
|
"",
|
||||||
cancelButtonText,
|
cancelButtonText,
|
||||||
(int)Symbol.Help,
|
(int)Symbol.Help,
|
||||||
primaryButtonResult);
|
primaryButtonResult,
|
||||||
|
parent: parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static async Task CreateUpdaterInfoDialog(string primary, string secondaryText)
|
internal static async Task CreateUpdaterInfoDialog(string primary, string secondaryText)
|
||||||
|
@ -268,7 +285,11 @@ namespace Ryujinx.Ava.UI.Helpers
|
||||||
(int)Symbol.Dismiss);
|
(int)Symbol.Dismiss);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static async Task<bool> CreateChoiceDialog(string title, string primary, string secondaryText)
|
internal static async Task<bool> CreateChoiceDialog(
|
||||||
|
string title,
|
||||||
|
string primary,
|
||||||
|
string secondaryText,
|
||||||
|
Window parent = null)
|
||||||
{
|
{
|
||||||
if (_isChoiceDialogOpen)
|
if (_isChoiceDialogOpen)
|
||||||
{
|
{
|
||||||
|
@ -285,7 +306,8 @@ namespace Ryujinx.Ava.UI.Helpers
|
||||||
"",
|
"",
|
||||||
LocaleManager.Instance[LocaleKeys.InputDialogNo],
|
LocaleManager.Instance[LocaleKeys.InputDialogNo],
|
||||||
(int)Symbol.Help,
|
(int)Symbol.Help,
|
||||||
UserResult.Yes);
|
UserResult.Yes,
|
||||||
|
parent: parent);
|
||||||
|
|
||||||
_isChoiceDialogOpen = false;
|
_isChoiceDialogOpen = false;
|
||||||
|
|
||||||
|
@ -308,20 +330,18 @@ namespace Ryujinx.Ava.UI.Helpers
|
||||||
LocaleManager.Instance[LocaleKeys.DialogExitSubMessage]);
|
LocaleManager.Instance[LocaleKeys.DialogExitSubMessage]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task<ContentDialogResult> ShowAsync(ContentDialog contentDialog)
|
public static async Task<ContentDialogResult> ShowAsync(ContentDialog contentDialog, Window parent = null)
|
||||||
{
|
{
|
||||||
ContentDialogResult result;
|
ContentDialogResult result;
|
||||||
bool isTopDialog = true;
|
bool isTopDialog = true;
|
||||||
|
|
||||||
Window parent = GetMainWindow();
|
parent ??= GetMainWindow();
|
||||||
|
|
||||||
if (_contentDialogOverlayWindow != null)
|
if (_contentDialogOverlayWindow != null)
|
||||||
{
|
{
|
||||||
isTopDialog = false;
|
isTopDialog = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parent is MainWindow window)
|
|
||||||
{
|
|
||||||
parent.Activate();
|
parent.Activate();
|
||||||
|
|
||||||
_contentDialogOverlayWindow = new ContentDialogOverlayWindow
|
_contentDialogOverlayWindow = new ContentDialogOverlayWindow
|
||||||
|
@ -365,11 +385,6 @@ namespace Ryujinx.Ava.UI.Helpers
|
||||||
}
|
}
|
||||||
|
|
||||||
result = await _contentDialogOverlayWindow.ShowDialog<ContentDialogResult>(parent);
|
result = await _contentDialogOverlayWindow.ShowDialog<ContentDialogResult>(parent);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
result = await ShowDialog();
|
|
||||||
}
|
|
||||||
|
|
||||||
async Task<ContentDialogResult> ShowDialog()
|
async Task<ContentDialogResult> ShowDialog()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue