Move confimration dialogue to SettingsWindow

This commit is contained in:
Isaac Marovitz 2024-04-18 18:42:47 -04:00
parent 1ad9b27ed6
commit 286aebf70f
No known key found for this signature in database
GPG key ID: 97250B2B09A132E1
6 changed files with 32 additions and 52 deletions

View file

@ -490,8 +490,8 @@
"DialogUserProfileUnsavedChangesTitle": "Warning - Unsaved Changes", "DialogUserProfileUnsavedChangesTitle": "Warning - Unsaved Changes",
"DialogUserProfileUnsavedChangesMessage": "You have made changes to this user profile that have not been saved.", "DialogUserProfileUnsavedChangesMessage": "You have made changes to this user profile that have not been saved.",
"DialogUserProfileUnsavedChangesSubMessage": "Do you want to discard your changes?", "DialogUserProfileUnsavedChangesSubMessage": "Do you want to discard your changes?",
"DialogControllerSettingsModifiedConfirmMessage": "The current controller settings has been updated.", "DialogSettingsUnsavedChangesMessage": "You have made changes to settings that have not been saved.",
"DialogControllerSettingsModifiedConfirmSubMessage": "Do you want to save?", "DialogSettingsUnsavedChangesSubMessage": "Do you want to discard your changes?",
"DialogLoadFileErrorMessage": "{0}. Errored File: {1}", "DialogLoadFileErrorMessage": "{0}. Errored File: {1}",
"DialogModAlreadyExistsMessage": "Mod already exists", "DialogModAlreadyExistsMessage": "Mod already exists",
"DialogModInvalidMessage": "The specified directory does not contain a mod!", "DialogModInvalidMessage": "The specified directory does not contain a mod!",

View file

@ -591,10 +591,6 @@ namespace Ryujinx.Ava.UI.ViewModels
_directoryChanged = false; _directoryChanged = false;
} }
private static void RevertIfNotSaved()
{
Program.ReloadConfig();
}
public void ApplyButton() public void ApplyButton()
{ {
@ -606,11 +602,5 @@ namespace Ryujinx.Ava.UI.ViewModels
SaveSettings(); SaveSettings();
CloseWindow?.Invoke(); CloseWindow?.Invoke();
} }
public void CancelButton()
{
RevertIfNotSaved();
CloseWindow?.Invoke();
}
} }
} }

View file

@ -65,7 +65,6 @@
Name="PlayerIndexBox" Name="PlayerIndexBox"
HorizontalAlignment="Stretch" HorizontalAlignment="Stretch"
VerticalAlignment="Center" VerticalAlignment="Center"
SelectionChanged="PlayerIndexBox_OnSelectionChanged"
ItemsSource="{Binding PlayerIndexes}" ItemsSource="{Binding PlayerIndexes}"
SelectedIndex="{Binding PlayerId}"> SelectedIndex="{Binding PlayerId}">
<ComboBox.ItemTemplate> <ComboBox.ItemTemplate>

View file

@ -1,7 +1,4 @@
using Avalonia.Controls; using Avalonia.Controls;
using Ryujinx.Ava.Common.Locale;
using Ryujinx.Ava.UI.Helpers;
using Ryujinx.Ava.UI.Models;
using Ryujinx.Ava.UI.ViewModels; using Ryujinx.Ava.UI.ViewModels;
using Ryujinx.Ava.UI.ViewModels.Input; using Ryujinx.Ava.UI.ViewModels.Input;
@ -9,15 +6,10 @@ namespace Ryujinx.Ava.UI.Views.Settings
{ {
public partial class SettingsInputView : UserControl public partial class SettingsInputView : UserControl
{ {
public SettingsViewModel SettingsViewModel;
private bool _dialogOpen;
private InputViewModel ViewModel { get; set; } private InputViewModel ViewModel { get; set; }
public SettingsInputView(SettingsViewModel viewModel) public SettingsInputView(SettingsViewModel viewModel)
{ {
SettingsViewModel = viewModel;
DataContext = ViewModel = new InputViewModel(this, viewModel); DataContext = ViewModel = new InputViewModel(this, viewModel);
InitializeComponent(); InitializeComponent();
@ -28,36 +20,6 @@ namespace Ryujinx.Ava.UI.Views.Settings
ViewModel.Save(); ViewModel.Save();
} }
private async void PlayerIndexBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (SettingsViewModel.IsModified && !_dialogOpen)
{
_dialogOpen = true;
var result = await ContentDialogHelper.CreateConfirmationDialog(
LocaleManager.Instance[LocaleKeys.DialogControllerSettingsModifiedConfirmMessage],
LocaleManager.Instance[LocaleKeys.DialogControllerSettingsModifiedConfirmSubMessage],
LocaleManager.Instance[LocaleKeys.InputDialogYes],
LocaleManager.Instance[LocaleKeys.InputDialogNo],
LocaleManager.Instance[LocaleKeys.RyujinxConfirm]);
if (result == UserResult.Yes)
{
ViewModel.Save();
}
_dialogOpen = false;
SettingsViewModel.IsModified = false;
if (e.AddedItems.Count > 0)
{
var player = (PlayerModel)e.AddedItems[0];
ViewModel.PlayerId = player.Id;
}
}
}
public void Dispose() public void Dispose()
{ {
ViewModel.Dispose(); ViewModel.Dispose();

View file

@ -110,7 +110,7 @@
<Button <Button
IsCancel="True" IsCancel="True"
Content="{locale:Locale SettingsButtonCancel}" Content="{locale:Locale SettingsButtonCancel}"
Command="{Binding CancelButton}" /> Click="Cancel_OnClick" />
<Button <Button
Name="Apply" Name="Apply"
Content="{locale:Locale SettingsButtonApply}" Content="{locale:Locale SettingsButtonApply}"

View file

@ -1,7 +1,9 @@
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Interactivity;
using FluentAvalonia.Core; using FluentAvalonia.Core;
using FluentAvalonia.UI.Controls; using FluentAvalonia.UI.Controls;
using Ryujinx.Ava.Common.Locale; using Ryujinx.Ava.Common.Locale;
using Ryujinx.Ava.UI.Helpers;
using Ryujinx.Ava.UI.ViewModels; using Ryujinx.Ava.UI.ViewModels;
using Ryujinx.Ava.UI.Views.Settings; using Ryujinx.Ava.UI.Views.Settings;
using Ryujinx.HLE.FileSystem; using Ryujinx.HLE.FileSystem;
@ -137,6 +139,33 @@ namespace Ryujinx.Ava.UI.Windows
} }
} }
private static void RevertIfNotSaved()
{
Program.ReloadConfig();
}
private async void Cancel_OnClick(object sender, RoutedEventArgs e)
{
if (ViewModel.IsModified)
{
var result = await ContentDialogHelper.CreateConfirmationDialog(
LocaleManager.Instance[LocaleKeys.DialogSettingsUnsavedChangesMessage],
LocaleManager.Instance[LocaleKeys.DialogSettingsUnsavedChangesSubMessage],
LocaleManager.Instance[LocaleKeys.InputDialogYes],
LocaleManager.Instance[LocaleKeys.InputDialogNo],
LocaleManager.Instance[LocaleKeys.RyujinxConfirm],
parent: this);
if (result != UserResult.Yes)
{
return;
}
}
RevertIfNotSaved();
Close();
}
protected override void OnClosing(WindowClosingEventArgs e) protected override void OnClosing(WindowClosingEventArgs e)
{ {
HotkeysPage.Dispose(); HotkeysPage.Dispose();