Add native menu for mac and refactor MainWindow
This commit is contained in:
parent
10a1b56b3c
commit
4a65d6bbd3
37 changed files with 1056 additions and 1084 deletions
74
Source/LibationAvalonia/ViewModels/MainVM.Export.cs
Normal file
74
Source/LibationAvalonia/ViewModels/MainVM.Export.cs
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
using ApplicationServices;
|
||||
using Avalonia.Platform.Storage;
|
||||
using FileManager;
|
||||
using LibationFileManager;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace LibationAvalonia.ViewModels
|
||||
{
|
||||
partial class MainVM
|
||||
{
|
||||
private void Configure_Export() { }
|
||||
|
||||
public async Task ExportLibraryAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
var options = new FilePickerSaveOptions
|
||||
{
|
||||
Title = "Where to export Library",
|
||||
SuggestedStartLocation = await MainWindow.StorageProvider.TryGetFolderFromPathAsync(Configuration.Instance.Books.PathWithoutPrefix),
|
||||
SuggestedFileName = $"Libation Library Export {DateTime.Now:yyyy-MM-dd}",
|
||||
DefaultExtension = "xlsx",
|
||||
ShowOverwritePrompt = true,
|
||||
FileTypeChoices = new FilePickerFileType[]
|
||||
{
|
||||
new("Excel Workbook (*.xlsx)")
|
||||
{
|
||||
Patterns = new[] { "*.xlsx" },
|
||||
//https://gist.github.com/RhetTbull/7221ef3cfd9d746f34b2550d4419a8c2
|
||||
AppleUniformTypeIdentifiers = new[] { "org.openxmlformats.spreadsheetml.sheet" }
|
||||
},
|
||||
new("CSV files (*.csv)")
|
||||
{
|
||||
Patterns = new[] { "*.csv" },
|
||||
AppleUniformTypeIdentifiers = new[] { "public.comma-separated-values-text" }
|
||||
},
|
||||
new("JSON files (*.json)")
|
||||
{
|
||||
Patterns = new[] { "*.json" },
|
||||
AppleUniformTypeIdentifiers = new[] { "public.json" }
|
||||
},
|
||||
new("All files (*.*)") { Patterns = new[] { "*" } }
|
||||
}
|
||||
};
|
||||
|
||||
var selectedFile = (await MainWindow.StorageProvider.SaveFilePickerAsync(options))?.TryGetLocalPath();
|
||||
|
||||
if (selectedFile is null) return;
|
||||
|
||||
var ext = FileUtility.GetStandardizedExtension(System.IO.Path.GetExtension(selectedFile));
|
||||
switch (ext)
|
||||
{
|
||||
case ".xlsx": // xlsx
|
||||
default:
|
||||
LibraryExporter.ToXlsx(selectedFile);
|
||||
break;
|
||||
case ".csv": // csv
|
||||
LibraryExporter.ToCsv(selectedFile);
|
||||
break;
|
||||
case ".json": // json
|
||||
LibraryExporter.ToJson(selectedFile);
|
||||
break;
|
||||
}
|
||||
|
||||
await MessageBox.Show("Library exported to:\r\n" + selectedFile, "Library Exported");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await MessageBox.ShowAdminAlert(MainWindow, "Error attempting to export your library.", "Error exporting", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue