diff --git a/src/Consolonia.Core/Controls/FileSavePicker.axaml.cs b/src/Consolonia.Core/Controls/FileSavePicker.axaml.cs index a3786ef..e527918 100644 --- a/src/Consolonia.Core/Controls/FileSavePicker.axaml.cs +++ b/src/Consolonia.Core/Controls/FileSavePicker.axaml.cs @@ -63,23 +63,26 @@ private async void OnOK(object sender, RoutedEventArgs e) ArgumentNullException.ThrowIfNull(lifetime.MainWindow); ArgumentNullException.ThrowIfNull(lifetime.MainWindow.StorageProvider); - var savePath = ViewModel.SavePath; + string savePath = ViewModel.SavePath; if (!Path.IsPathFullyQualified(ViewModel.SavePath)) - { savePath = Path.GetFullPath(Path.Combine(ViewModel.CurrentFolder.Path.LocalPath, ViewModel.SavePath)); - } - var file = await lifetime.MainWindow.StorageProvider.TryGetFileFromPathAsync(new Uri($"file://{savePath}")); + IStorageFile file = + await lifetime.MainWindow.StorageProvider.TryGetFileFromPathAsync(new Uri($"file://{savePath}")); if (file == null) { - var folder = await lifetime.MainWindow.StorageProvider.TryGetFolderFromPathAsync(new Uri($"file://{Path.GetDirectoryName(savePath)}")); + IStorageFolder folder = + await lifetime.MainWindow.StorageProvider.TryGetFolderFromPathAsync( + new Uri($"file://{Path.GetDirectoryName(savePath)}")); if (folder == null) { CloseDialog(); return; } - file = await folder.CreateFileAsync(Path.GetFileName(savePath)); + + file = await folder.CreateFileAsync(Path.GetFileName(savePath)); } + CloseDialog(file); } diff --git a/src/Consolonia.Core/Controls/FileSavePickerViewModel.cs b/src/Consolonia.Core/Controls/FileSavePickerViewModel.cs index b8b42e9..0c501b1 100644 --- a/src/Consolonia.Core/Controls/FileSavePickerViewModel.cs +++ b/src/Consolonia.Core/Controls/FileSavePickerViewModel.cs @@ -1,4 +1,5 @@ using System; +using System.ComponentModel; using Avalonia.Platform.Storage; using CommunityToolkit.Mvvm.ComponentModel; @@ -6,7 +7,7 @@ namespace Consolonia.Core.Controls { public partial class FileSavePickerViewModel : PickerViewModelBase { - [ObservableProperty] private string _savePath=string.Empty; + [ObservableProperty] private string _savePath = string.Empty; [ObservableProperty] [NotifyPropertyChangedFor(nameof(SelectedFile))] private IStorageItem _selectedItem; @@ -15,19 +16,16 @@ public FileSavePickerViewModel(FilePickerSaveOptions options) : base(options) { ArgumentNullException.ThrowIfNull(options, nameof(options)); - this.PropertyChanged += FileSavePickerViewModel_PropertyChanged; + PropertyChanged += FileSavePickerViewModel_PropertyChanged; } - private void FileSavePickerViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) + public IStorageFile SelectedFile => SelectedItem as IStorageFile; + + private void FileSavePickerViewModel_PropertyChanged(object sender, PropertyChangedEventArgs e) { - if (e.PropertyName == nameof(SelectedFile)) - { - SavePath = SelectedFile.Path.LocalPath; - } + if (e.PropertyName == nameof(SelectedFile)) SavePath = SelectedFile.Path.LocalPath; } - public IStorageFile SelectedFile => SelectedItem as IStorageFile; - protected override bool FilterItem(IStorageItem item) { return true;