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:
@@ -53,6 +53,7 @@ using Aaru.Devices;
|
||||
using Aaru.Gui.Models;
|
||||
using Aaru.Localization;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Platform.Storage;
|
||||
using Avalonia.Threading;
|
||||
using MsBox.Avalonia;
|
||||
using MsBox.Avalonia.Enums;
|
||||
@@ -2049,29 +2050,29 @@ public sealed class ImageConvertViewModel : 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 || result.Length != 1)
|
||||
if(result is null)
|
||||
{
|
||||
DestinationText = "";
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(string.IsNullOrEmpty(Path.GetExtension(result))) result += SelectedPlugin.Plugin.KnownExtensions.First();
|
||||
DestinationText = result.Path.AbsolutePath;
|
||||
|
||||
DestinationText = result;
|
||||
if(string.IsNullOrEmpty(Path.GetExtension(DestinationText)))
|
||||
DestinationText += SelectedPlugin.Plugin.KnownExtensions.First();
|
||||
}
|
||||
|
||||
void ExecuteCreatorCommand() => CreatorText = _inputFormat.Info.Creator;
|
||||
@@ -2113,37 +2114,29 @@ public sealed class ImageConvertViewModel : ViewModelBase
|
||||
_aaruMetadata = null;
|
||||
MetadataJsonText = "";
|
||||
|
||||
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 = await dlgMetadata.ShowAsync(_view);
|
||||
|
||||
if(result is null || result.Length != 1) return;
|
||||
if(result.Count != 1) return;
|
||||
|
||||
try
|
||||
{
|
||||
var fs = new FileStream(result[0], FileMode.Open);
|
||||
var fs = new FileStream(result[0].Path.AbsolutePath, FileMode.Open);
|
||||
|
||||
_aaruMetadata =
|
||||
(await JsonSerializer.DeserializeAsync(fs, typeof(MetadataJson), MetadataJsonContext.Default) as
|
||||
MetadataJson)?.AaruMetadata;
|
||||
|
||||
fs.Close();
|
||||
MetadataJsonText = result[0];
|
||||
MetadataJsonText = result[0].Path.AbsolutePath;
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -2164,30 +2157,22 @@ public sealed class ImageConvertViewModel : ViewModelBase
|
||||
_dumpHardware = null;
|
||||
ResumeFileText = "";
|
||||
|
||||
var dlgMetadata = new OpenFileDialog
|
||||
{
|
||||
Title = UI.Dialog_Choose_existing_resume_file
|
||||
};
|
||||
IReadOnlyList<IStorageFile> result = _view.StorageProvider.OpenFilePickerAsync(new FilePickerOpenOptions
|
||||
{
|
||||
Title = UI.Dialog_Choose_existing_resume_file,
|
||||
AllowMultiple = false,
|
||||
FileTypeFilter = new List<FilePickerFileType>
|
||||
{
|
||||
FilePickerFileTypes.AaruResumeFile
|
||||
}
|
||||
})
|
||||
.Result;
|
||||
|
||||
dlgMetadata.Filters?.Add(new FileDialogFilter
|
||||
{
|
||||
Name = UI.Dialog_Choose_existing_resume_file,
|
||||
Extensions =
|
||||
[
|
||||
..new[]
|
||||
{
|
||||
".json"
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
string[] result = await dlgMetadata.ShowAsync(_view);
|
||||
|
||||
if(result is null || result.Length != 1) return;
|
||||
if(result.Count != 1) return;
|
||||
|
||||
try
|
||||
{
|
||||
var fs = new FileStream(result[0], FileMode.Open);
|
||||
var fs = new FileStream(result[0].Path.AbsolutePath, FileMode.Open);
|
||||
|
||||
Resume resume =
|
||||
(await JsonSerializer.DeserializeAsync(fs, typeof(ResumeJson), ResumeJsonContext.Default) as ResumeJson)
|
||||
@@ -2198,7 +2183,7 @@ public sealed class ImageConvertViewModel : ViewModelBase
|
||||
if(resume?.Tries?.Any() == false)
|
||||
{
|
||||
_dumpHardware = resume.Tries;
|
||||
ResumeFileText = result[0];
|
||||
ResumeFileText = result[0].Path.AbsolutePath;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
// ****************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
using System.Reactive;
|
||||
@@ -44,6 +45,7 @@ using Aaru.Console;
|
||||
using Aaru.Core;
|
||||
using Aaru.Localization;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Platform.Storage;
|
||||
using Avalonia.Threading;
|
||||
using ReactiveUI;
|
||||
|
||||
@@ -322,25 +324,15 @@ public sealed class ImageSidecarViewModel : ViewModelBase
|
||||
|
||||
async Task ExecuteDestinationCommand()
|
||||
{
|
||||
var dlgDestination = new SaveFileDialog
|
||||
IStorageFile result = await _view.StorageProvider.SaveFilePickerAsync(new FilePickerSaveOptions
|
||||
{
|
||||
Title = UI.Dialog_Choose_destination_file
|
||||
};
|
||||
|
||||
dlgDestination.Filters?.Add(new FileDialogFilter
|
||||
{
|
||||
Name = UI.Dialog_Aaru_Metadata,
|
||||
Extensions =
|
||||
[
|
||||
..new[]
|
||||
{
|
||||
"*.json"
|
||||
}
|
||||
]
|
||||
Title = UI.Dialog_Choose_destination_file,
|
||||
FileTypeChoices = new List<FilePickerFileType>
|
||||
{
|
||||
FilePickerFileTypes.AaruMetadata
|
||||
}
|
||||
});
|
||||
|
||||
string result = await dlgDestination.ShowAsync(_view);
|
||||
|
||||
if(result is null)
|
||||
{
|
||||
DestinationText = "";
|
||||
@@ -348,8 +340,7 @@ public sealed class ImageSidecarViewModel : ViewModelBase
|
||||
return;
|
||||
}
|
||||
|
||||
if(string.IsNullOrEmpty(Path.GetExtension(result))) result += ".json";
|
||||
|
||||
DestinationText = result;
|
||||
DestinationText = result.Path.AbsolutePath;
|
||||
if(string.IsNullOrEmpty(Path.GetExtension(DestinationText))) DestinationText += ".json";
|
||||
}
|
||||
}
|
||||
@@ -59,6 +59,7 @@ using Avalonia.Controls;
|
||||
using Avalonia.Controls.ApplicationLifetimes;
|
||||
using Avalonia.Media.Imaging;
|
||||
using Avalonia.Platform;
|
||||
using Avalonia.Platform.Storage;
|
||||
using JetBrains.Annotations;
|
||||
using MsBox.Avalonia;
|
||||
using MsBox.Avalonia.Enums;
|
||||
@@ -530,17 +531,19 @@ public sealed class MainWindowViewModel : ViewModelBase
|
||||
async Task ExecuteOpenCommand()
|
||||
{
|
||||
// TODO: Extensions
|
||||
var dlgOpenImage = new OpenFileDialog
|
||||
IReadOnlyList<IStorageFile> result = await _view.StorageProvider.OpenFilePickerAsync(new FilePickerOpenOptions
|
||||
{
|
||||
Title = UI.Dialog_Choose_image_to_open,
|
||||
AllowMultiple = false
|
||||
};
|
||||
AllowMultiple = false,
|
||||
FileTypeFilter = new List<FilePickerFileType>
|
||||
{
|
||||
FilePickerFileTypes.All
|
||||
}
|
||||
});
|
||||
|
||||
string[] result = await dlgOpenImage.ShowAsync(_view);
|
||||
if(result.Count != 1) return;
|
||||
|
||||
if(result?.Length != 1) return;
|
||||
|
||||
IFilter inputFilter = PluginRegister.Singleton.GetFilter(result[0]);
|
||||
IFilter inputFilter = PluginRegister.Singleton.GetFilter(result[0].Path.AbsolutePath);
|
||||
|
||||
if(inputFilter == null)
|
||||
{
|
||||
@@ -587,7 +590,7 @@ public sealed class MainWindowViewModel : ViewModelBase
|
||||
|
||||
var imageModel = new ImageModel
|
||||
{
|
||||
Path = result[0],
|
||||
Path = result[0].Path.AbsolutePath,
|
||||
Icon = AssetLoader.Exists(mediaResource)
|
||||
? new Bitmap(AssetLoader.Open(mediaResource))
|
||||
: imageFormat.Info.MetadataMediaType == MetadataMediaType.BlockMedia
|
||||
@@ -595,9 +598,9 @@ public sealed class MainWindowViewModel : ViewModelBase
|
||||
: imageFormat.Info.MetadataMediaType == MetadataMediaType.OpticalDisc
|
||||
? _genericOpticalIcon
|
||||
: _genericFolderIcon,
|
||||
FileName = Path.GetFileName(result[0]),
|
||||
FileName = Path.GetFileName(result[0].Path.AbsolutePath),
|
||||
Image = imageFormat,
|
||||
ViewModel = new ImageInfoViewModel(result[0], inputFilter, imageFormat, _view),
|
||||
ViewModel = new ImageInfoViewModel(result[0].Path.AbsolutePath, inputFilter, imageFormat, _view),
|
||||
Filter = inputFilter
|
||||
};
|
||||
|
||||
|
||||
@@ -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