Implemented export to CSV functionality.

This commit is contained in:
alphafetus committed 2023-10-25 08:45:01 -04:00
1 parent a478d4ebb0
commit ddbc745200
4 files changed
+98 -9

No files matched your search

+23 -1
View File
@@ -1,5 +1,8 @@
using System;
using System.IO;
using System.Reactive;
using System.Threading.Tasks;
using Avalonia.Platform.Storage;
using Avalonia.ReactiveUI;
using PcgsInvUi.ViewModels;
using ReactiveUI;
@@ -10,7 +13,8 @@ public partial class MainWindow : ReactiveWindow<MainWindowViewModel> {
public MainWindow() {
InitializeComponent();
this.WhenActivated(d => d(ViewModel!.ShowDeleteWindow.RegisterHandler(ShowDeleteWindowAsync)));
this.WhenActivated(d => d(ViewModel!.ShowFindWindow.RegisterHandler(ShowFindWindowAsync)));
this.WhenActivated(d => d(ViewModel!.ShowExportWindow.RegisterHandler(ShowFilePickerAsync)));
// this.WhenActivated(d => d(ViewModel!.ShowFindWindow.RegisterHandler(ShowFindWindowAsync)));
}
public async Task ShowDeleteWindowAsync(InteractionContext<DeleteWindowViewModel, Boolean> interaction) {
@@ -28,4 +32,22 @@ public partial class MainWindow : ReactiveWindow<MainWindowViewModel> {
var result = await window.ShowDialog<int>(this);
interaction.SetOutput(result);
}
public async Task ShowFilePickerAsync(InteractionContext<Unit, Stream> interationContext) {
var topLevel = GetTopLevel(this);
var file = await topLevel.StorageProvider.SaveFilePickerAsync(new FilePickerSaveOptions {
Title = "Save CSV...",
DefaultExtension = ".csv",
ShowOverwritePrompt = true,
SuggestedFileName = "coins.csv",
SuggestedStartLocation = await StorageProvider.TryGetWellKnownFolderAsync(WellKnownFolder.Documents)
});
Stream stream;
if (file is not null) {
stream = await file.OpenWriteAsync();
interationContext.SetOutput(stream);
}
}
}