mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
[GUI] Replace file dialogs with file pickers.
This commit is contained in:
@@ -55,6 +55,7 @@ using Aaru.Devices;
|
||||
using Aaru.Gui.Models;
|
||||
using Aaru.Localization;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Platform.Storage;
|
||||
using Avalonia.Threading;
|
||||
using DynamicData;
|
||||
using JetBrains.Annotations;
|
||||
@@ -505,26 +506,18 @@ public sealed class MediaDumpViewModel : ViewModelBase
|
||||
return;
|
||||
}
|
||||
|
||||
var dlgMetadata = new OpenFileDialog
|
||||
{
|
||||
Title = UI.Dialog_Choose_existing_metadata_sidecar
|
||||
};
|
||||
IReadOnlyList<IStorageFile> result = _view.StorageProvider.OpenFilePickerAsync(new FilePickerOpenOptions
|
||||
{
|
||||
Title = UI.Dialog_Choose_existing_metadata_sidecar,
|
||||
AllowMultiple = false,
|
||||
FileTypeFilter = new List<FilePickerFileType>
|
||||
{
|
||||
FilePickerFileTypes.AaruMetadata
|
||||
}
|
||||
})
|
||||
.Result;
|
||||
|
||||
dlgMetadata.Filters?.Add(new FileDialogFilter
|
||||
{
|
||||
Name = UI.Dialog_Aaru_Metadata,
|
||||
Extensions =
|
||||
[
|
||||
..new[]
|
||||
{
|
||||
".json"
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
string[] result = dlgMetadata.ShowAsync(_view).Result;
|
||||
|
||||
if(result?.Length != 1)
|
||||
if(result.Count != 1)
|
||||
{
|
||||
ExistingMetadata = false;
|
||||
|
||||
@@ -533,7 +526,7 @@ public sealed class MediaDumpViewModel : ViewModelBase
|
||||
|
||||
try
|
||||
{
|
||||
var fs = new FileStream(result[0], FileMode.Open);
|
||||
var fs = new FileStream(result[0].Path.AbsolutePath, FileMode.Open);
|
||||
|
||||
_sidecar =
|
||||
(JsonSerializer.Deserialize(fs, typeof(MetadataJson), MetadataJsonContext.Default) as MetadataJson)
|
||||
@@ -668,19 +661,18 @@ public sealed class MediaDumpViewModel : ViewModelBase
|
||||
{
|
||||
if(SelectedPlugin is null) return;
|
||||
|
||||
var dlgDestination = new SaveFileDialog
|
||||
IStorageFile result = await _view.StorageProvider.SaveFilePickerAsync(new FilePickerSaveOptions
|
||||
{
|
||||
Title = UI.Dialog_Choose_destination_file
|
||||
};
|
||||
|
||||
dlgDestination.Filters?.Add(new FileDialogFilter
|
||||
{
|
||||
Name = SelectedPlugin.Plugin.Name,
|
||||
Extensions = SelectedPlugin.Plugin.KnownExtensions.ToList()
|
||||
Title = UI.Dialog_Choose_destination_file,
|
||||
FileTypeChoices = new List<FilePickerFileType>
|
||||
{
|
||||
new(SelectedPlugin.Plugin.Name)
|
||||
{
|
||||
Patterns = SelectedPlugin.Plugin.KnownExtensions.ToList()
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
string result = await dlgDestination.ShowAsync(_view);
|
||||
|
||||
if(result is null)
|
||||
{
|
||||
Destination = "";
|
||||
@@ -689,11 +681,13 @@ public sealed class MediaDumpViewModel : ViewModelBase
|
||||
return;
|
||||
}
|
||||
|
||||
if(string.IsNullOrEmpty(Path.GetExtension(result))) result += SelectedPlugin.Plugin.KnownExtensions.First();
|
||||
Destination = result.Path.AbsolutePath;
|
||||
|
||||
Destination = result;
|
||||
_outputPrefix = Path.Combine(Path.GetDirectoryName(Destination) ?? "",
|
||||
Path.GetFileNameWithoutExtension(Destination));
|
||||
|
||||
_outputPrefix = Path.Combine(Path.GetDirectoryName(result) ?? "", Path.GetFileNameWithoutExtension(result));
|
||||
if(string.IsNullOrEmpty(Path.GetExtension(Destination)))
|
||||
Destination += SelectedPlugin.Plugin.KnownExtensions.First();
|
||||
|
||||
Resume = true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user