mirror of
https://git.ryujinx.app/kenji-nx/ryujinx.git
synced 2025-12-14 07:37:04 +00:00
UI: Add more NotificationHelper methods
Simplify ID copy logic
This commit is contained in:
parent
c089f90b53
commit
2db7d60cae
4 changed files with 59 additions and 18 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
using Avalonia;
|
using Avalonia;
|
||||||
using Avalonia.Controls.ApplicationLifetimes;
|
using Avalonia.Controls.ApplicationLifetimes;
|
||||||
|
using Avalonia.Input.Platform;
|
||||||
using Avalonia.Markup.Xaml;
|
using Avalonia.Markup.Xaml;
|
||||||
using Avalonia.Platform;
|
using Avalonia.Platform;
|
||||||
using Avalonia.Styling;
|
using Avalonia.Styling;
|
||||||
|
|
@ -24,8 +25,11 @@ namespace Ryujinx.Ava
|
||||||
.ApplicationLifetime.Cast<IClassicDesktopStyleApplicationLifetime>()
|
.ApplicationLifetime.Cast<IClassicDesktopStyleApplicationLifetime>()
|
||||||
.MainWindow.Cast<MainWindow>();
|
.MainWindow.Cast<MainWindow>();
|
||||||
|
|
||||||
public static IClassicDesktopStyleApplicationLifetime DesktopLifetime => Current!
|
public static bool IsClipboardAvailable(out IClipboard clipboard)
|
||||||
.ApplicationLifetime.Cast<IClassicDesktopStyleApplicationLifetime>();
|
{
|
||||||
|
clipboard = MainWindow.Clipboard;
|
||||||
|
return clipboard != null;
|
||||||
|
}
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,6 @@
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using Avalonia.Controls.Notifications;
|
|
||||||
using Avalonia.Input;
|
using Avalonia.Input;
|
||||||
using Avalonia.Interactivity;
|
using Avalonia.Interactivity;
|
||||||
using FluentAvalonia.UI.Controls;
|
|
||||||
using Ryujinx.Ava.UI.Helpers;
|
using Ryujinx.Ava.UI.Helpers;
|
||||||
using Ryujinx.Ava.UI.ViewModels;
|
using Ryujinx.Ava.UI.ViewModels;
|
||||||
using Ryujinx.UI.App.Common;
|
using Ryujinx.UI.App.Common;
|
||||||
|
|
@ -59,16 +57,18 @@ namespace Ryujinx.Ava.UI.Controls
|
||||||
if (sender is not Button { Content: TextBlock idText })
|
if (sender is not Button { Content: TextBlock idText })
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (App.MainWindow.Clipboard is { } clipboard)
|
if (!App.IsClipboardAvailable(out var clipboard))
|
||||||
{
|
return;
|
||||||
|
|
||||||
var appData = mwvm.Applications.FirstOrDefault(it => it.IdString == idText.Text);
|
var appData = mwvm.Applications.FirstOrDefault(it => it.IdString == idText.Text);
|
||||||
if (appData is null)
|
if (appData is null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
await clipboard.SetTextAsync(appData.IdString);
|
await clipboard.SetTextAsync(appData.IdString);
|
||||||
|
|
||||||
NotificationHelper.Show("Copied Title ID", $"{appData.Name} ({appData.IdString})", NotificationType.Information);
|
NotificationHelper.ShowInformation(
|
||||||
}
|
"Copied Title ID",
|
||||||
|
$"{appData.Name} ({appData.IdString})");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -62,9 +62,46 @@ namespace Ryujinx.Ava.UI.Helpers
|
||||||
_notifications.Add(new Notification(title, text, type, delay, onClick, onClose));
|
_notifications.Add(new Notification(title, text, type, delay, onClick, onClose));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ShowError(string message)
|
public static void ShowError(string message) =>
|
||||||
{
|
ShowError(
|
||||||
Show(LocaleManager.Instance[LocaleKeys.DialogErrorTitle], $"{LocaleManager.Instance[LocaleKeys.DialogErrorMessage]}\n\n{message}", NotificationType.Error);
|
LocaleManager.Instance[LocaleKeys.DialogErrorTitle],
|
||||||
}
|
$"{LocaleManager.Instance[LocaleKeys.DialogErrorMessage]}\n\n{message}"
|
||||||
|
);
|
||||||
|
|
||||||
|
public static void ShowInformation(string title, string text, bool waitingExit = false, Action onClick = null, Action onClose = null) =>
|
||||||
|
Show(
|
||||||
|
title,
|
||||||
|
text,
|
||||||
|
NotificationType.Information,
|
||||||
|
waitingExit,
|
||||||
|
onClick,
|
||||||
|
onClose);
|
||||||
|
|
||||||
|
public static void ShowSuccess(string title, string text, bool waitingExit = false, Action onClick = null, Action onClose = null) =>
|
||||||
|
Show(
|
||||||
|
title,
|
||||||
|
text,
|
||||||
|
NotificationType.Success,
|
||||||
|
waitingExit,
|
||||||
|
onClick,
|
||||||
|
onClose);
|
||||||
|
|
||||||
|
public static void ShowWarning(string title, string text, bool waitingExit = false, Action onClick = null, Action onClose = null) =>
|
||||||
|
Show(
|
||||||
|
title,
|
||||||
|
text,
|
||||||
|
NotificationType.Warning,
|
||||||
|
waitingExit,
|
||||||
|
onClick,
|
||||||
|
onClose);
|
||||||
|
|
||||||
|
public static void ShowError(string title, string text, bool waitingExit = false, Action onClick = null, Action onClose = null) =>
|
||||||
|
Show(
|
||||||
|
title,
|
||||||
|
text,
|
||||||
|
NotificationType.Error,
|
||||||
|
waitingExit,
|
||||||
|
onClick,
|
||||||
|
onClose);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue