Skip to content

Commit

Permalink
misc: chore: Collapse adding a game/autoload dir into a single reusab…
Browse files Browse the repository at this point in the history
…le method.
  • Loading branch information
GreemDev committed Jan 22, 2025
1 parent 9089c4f commit cd8113d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 46 deletions.
6 changes: 2 additions & 4 deletions src/Ryujinx/UI/Views/Settings/SettingsUIView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@
Grid.Column="1"
MinWidth="90"
Margin="10,0,0,0"
ToolTip.Tip="{ext:Locale AddGameDirTooltip}"
Click="AddGameDirButton_OnClick">
ToolTip.Tip="{ext:Locale AddGameDirTooltip}">
<TextBlock HorizontalAlignment="Center"
Text="{ext:Locale SettingsTabGeneralAdd}" />
</Button>
Expand Down Expand Up @@ -168,8 +167,7 @@
Grid.Column="1"
MinWidth="90"
Margin="10,0,0,0"
ToolTip.Tip="{ext:Locale AddAutoloadDirTooltip}"
Click="AddAutoloadDirButton_OnClick">
ToolTip.Tip="{ext:Locale AddAutoloadDirTooltip}">
<TextBlock HorizontalAlignment="Center"
Text="{ext:Locale SettingsTabGeneralAdd}" />
</Button>
Expand Down
70 changes: 28 additions & 42 deletions src/Ryujinx/UI/Views/Settings/SettingsUIView.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
using Avalonia.Collections;
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Platform.Storage;
using Avalonia.VisualTree;
using Gommon;
using Ryujinx.Ava.UI.Helpers;
using Ryujinx.Ava.UI.ViewModels;
using Ryujinx.Ava.Utilities;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;

namespace Ryujinx.Ava.UI.Views.Settings
{
Expand All @@ -18,31 +23,39 @@ public SettingsUiView()
{
InitializeComponent();
ShowTitleBarBox.IsVisible = OperatingSystem.IsWindows();
AddGameDirButton.Command =
Commands.Create(() => AddDirButton(GameDirPathBox, ViewModel.GameDirectories, true));
AddAutoloadDirButton.Command =
Commands.Create(() => AddDirButton(AutoloadDirPathBox, ViewModel.AutoloadDirectories, false));
}

private async void AddGameDirButton_OnClick(object sender, RoutedEventArgs e)
private async Task AddDirButton(TextBox addDirBox, AvaloniaList<string> directories, bool isGameList)
{
string path = GameDirPathBox.Text;
string path = addDirBox.Text;

if (!string.IsNullOrWhiteSpace(path) && Directory.Exists(path) && !ViewModel.GameDirectories.Contains(path))
if (!string.IsNullOrWhiteSpace(path) && Directory.Exists(path) && !directories.Contains(path))
{
ViewModel.GameDirectories.Add(path);
ViewModel.GameDirectoryChanged = true;
directories.Add(path);

addDirBox.Clear();

if (isGameList)
ViewModel.GameDirectoryChanged = true;
else
ViewModel.AutoloadDirectoryChanged = true;
}
else
{
if (this.GetVisualRoot() is Window window)
{
var result = await window.StorageProvider.OpenFolderPickerAsync(new FolderPickerOpenOptions
{
AllowMultiple = false,
});
Optional<IStorageFolder> folder = await RyujinxApp.MainWindow.ViewModel.StorageProvider.OpenSingleFolderPickerAsync();

if (result.Count > 0)
{
ViewModel.GameDirectories.Add(result[0].Path.LocalPath);
if (folder.HasValue)
{
directories.Add(folder.Value.Path.LocalPath);

if (isGameList)
ViewModel.GameDirectoryChanged = true;
}
else
ViewModel.AutoloadDirectoryChanged = true;
}
}
}
Expand All @@ -63,33 +76,6 @@ private void RemoveGameDirButton_OnClick(object sender, RoutedEventArgs e)
}
}

private async void AddAutoloadDirButton_OnClick(object sender, RoutedEventArgs e)
{
string path = AutoloadDirPathBox.Text;

if (!string.IsNullOrWhiteSpace(path) && Directory.Exists(path) && !ViewModel.AutoloadDirectories.Contains(path))
{
ViewModel.AutoloadDirectories.Add(path);
ViewModel.AutoloadDirectoryChanged = true;
}
else
{
if (this.GetVisualRoot() is Window window)
{
var result = await window.StorageProvider.OpenFolderPickerAsync(new FolderPickerOpenOptions
{
AllowMultiple = false,
});

if (result.Count > 0)
{
ViewModel.AutoloadDirectories.Add(result[0].Path.LocalPath);
ViewModel.AutoloadDirectoryChanged = true;
}
}
}
}

private void RemoveAutoloadDirButton_OnClick(object sender, RoutedEventArgs e)
{
int oldIndex = AutoloadDirsList.SelectedIndex;
Expand Down

0 comments on commit cd8113d

Please sign in to comment.