/ src / Ryujinx / UI / Windows / DownloadableContentManagerWindow.axaml.cs
DownloadableContentManagerWindow.axaml.cs
  1  using Avalonia.Controls;
  2  using Avalonia.Interactivity;
  3  using Avalonia.Styling;
  4  using FluentAvalonia.UI.Controls;
  5  using Ryujinx.Ava.Common.Locale;
  6  using Ryujinx.Ava.UI.Models;
  7  using Ryujinx.Ava.UI.ViewModels;
  8  using Ryujinx.HLE.FileSystem;
  9  using Ryujinx.UI.App.Common;
 10  using Ryujinx.UI.Common.Helper;
 11  using System.Threading.Tasks;
 12  
 13  namespace Ryujinx.Ava.UI.Windows
 14  {
 15      public partial class DownloadableContentManagerWindow : UserControl
 16      {
 17          public DownloadableContentManagerViewModel ViewModel;
 18  
 19          public DownloadableContentManagerWindow()
 20          {
 21              DataContext = this;
 22  
 23              InitializeComponent();
 24          }
 25  
 26          public DownloadableContentManagerWindow(VirtualFileSystem virtualFileSystem, ApplicationData applicationData)
 27          {
 28              DataContext = ViewModel = new DownloadableContentManagerViewModel(virtualFileSystem, applicationData);
 29  
 30              InitializeComponent();
 31          }
 32  
 33          public static async Task Show(VirtualFileSystem virtualFileSystem, ApplicationData applicationData)
 34          {
 35              ContentDialog contentDialog = new()
 36              {
 37                  PrimaryButtonText = "",
 38                  SecondaryButtonText = "",
 39                  CloseButtonText = "",
 40                  Content = new DownloadableContentManagerWindow(virtualFileSystem, applicationData),
 41                  Title = string.Format(LocaleManager.Instance[LocaleKeys.DlcWindowTitle], applicationData.Name, applicationData.IdBaseString),
 42              };
 43  
 44              Style bottomBorder = new(x => x.OfType<Grid>().Name("DialogSpace").Child().OfType<Border>());
 45              bottomBorder.Setters.Add(new Setter(IsVisibleProperty, false));
 46  
 47              contentDialog.Styles.Add(bottomBorder);
 48  
 49              await contentDialog.ShowAsync();
 50          }
 51  
 52          private void SaveAndClose(object sender, RoutedEventArgs routedEventArgs)
 53          {
 54              ViewModel.Save();
 55              ((ContentDialog)Parent).Hide();
 56          }
 57  
 58          private void Close(object sender, RoutedEventArgs e)
 59          {
 60              ((ContentDialog)Parent).Hide();
 61          }
 62  
 63          private void RemoveDLC(object sender, RoutedEventArgs e)
 64          {
 65              if (sender is Button button)
 66              {
 67                  if (button.DataContext is DownloadableContentModel model)
 68                  {
 69                      ViewModel.Remove(model);
 70                  }
 71              }
 72          }
 73  
 74          private void OpenLocation(object sender, RoutedEventArgs e)
 75          {
 76              if (sender is Button button)
 77              {
 78                  if (button.DataContext is DownloadableContentModel model)
 79                  {
 80                      OpenHelper.LocateFile(model.ContainerPath);
 81                  }
 82              }
 83          }
 84  
 85          private void OnSelectionChanged(object sender, SelectionChangedEventArgs e)
 86          {
 87              foreach (var content in e.AddedItems)
 88              {
 89                  if (content is DownloadableContentModel model)
 90                  {
 91                      var index = ViewModel.DownloadableContents.IndexOf(model);
 92  
 93                      if (index != -1)
 94                      {
 95                          ViewModel.DownloadableContents[index].Enabled = true;
 96                      }
 97                  }
 98              }
 99  
100              foreach (var content in e.RemovedItems)
101              {
102                  if (content is DownloadableContentModel model)
103                  {
104                      var index = ViewModel.DownloadableContents.IndexOf(model);
105  
106                      if (index != -1)
107                      {
108                          ViewModel.DownloadableContents[index].Enabled = false;
109                      }
110                  }
111              }
112          }
113      }
114  }