SettingsUIView.axaml.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. using Avalonia.Controls;
  2. using Avalonia.Controls.ApplicationLifetimes;
  3. using Avalonia.Interactivity;
  4. using Ryujinx.Ava.Common.Locale;
  5. using Ryujinx.Ava.UI.ViewModels;
  6. using System.Collections.Generic;
  7. using System.IO;
  8. using System.Linq;
  9. namespace Ryujinx.Ava.UI.Views.Settings
  10. {
  11. public partial class SettingsUIView : UserControl
  12. {
  13. public SettingsViewModel ViewModel;
  14. public SettingsUIView()
  15. {
  16. InitializeComponent();
  17. }
  18. private async void AddButton_OnClick(object sender, RoutedEventArgs e)
  19. {
  20. string path = PathBox.Text;
  21. if (!string.IsNullOrWhiteSpace(path) && Directory.Exists(path) && !ViewModel.GameDirectories.Contains(path))
  22. {
  23. ViewModel.GameDirectories.Add(path);
  24. ViewModel.DirectoryChanged = true;
  25. }
  26. else
  27. {
  28. if (Avalonia.Application.Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
  29. {
  30. path = await new OpenFolderDialog().ShowAsync(desktop.MainWindow);
  31. if (!string.IsNullOrWhiteSpace(path))
  32. {
  33. ViewModel.GameDirectories.Add(path);
  34. ViewModel.DirectoryChanged = true;
  35. }
  36. }
  37. }
  38. }
  39. private void RemoveButton_OnClick(object sender, RoutedEventArgs e)
  40. {
  41. int oldIndex = GameList.SelectedIndex;
  42. foreach (string path in new List<string>(GameList.SelectedItems.Cast<string>()))
  43. {
  44. ViewModel.GameDirectories.Remove(path);
  45. ViewModel.DirectoryChanged = true;
  46. }
  47. if (GameList.ItemCount > 0)
  48. {
  49. GameList.SelectedIndex = oldIndex < GameList.ItemCount ? oldIndex : 0;
  50. }
  51. }
  52. public async void BrowseTheme(object sender, RoutedEventArgs e)
  53. {
  54. var dialog = new OpenFileDialog()
  55. {
  56. Title = LocaleManager.Instance[LocaleKeys.SettingsSelectThemeFileDialogTitle],
  57. AllowMultiple = false
  58. };
  59. dialog.Filters.Add(new FileDialogFilter() { Extensions = { "xaml" }, Name = LocaleManager.Instance[LocaleKeys.SettingsXamlThemeFile] });
  60. if (Avalonia.Application.Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
  61. {
  62. var file = await dialog.ShowAsync(desktop.MainWindow);
  63. if (file != null && file.Length > 0)
  64. {
  65. ViewModel.CustomThemePath = file[0];
  66. }
  67. }
  68. }
  69. }
  70. }