Save/load settings, Move about window to dialog

This commit is contained in:
2026-02-16 18:13:14 +09:00
parent 016ecf0a30
commit 5910e3812b
10 changed files with 195 additions and 44 deletions
+33
View File
@@ -0,0 +1,33 @@
#nullable enable
using System;
using System.Collections.ObjectModel;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Avalonia.Platform.Storage;
using Avalonia.Themes.Fluent;
using DialogHostAvalonia;
using ImageMagick;
using MigraDoc.DocumentObjectModel;
using MigraDoc.Rendering;
using PdfSharp.Fonts;
using PdfSharp.Pdf.IO;
using PdfSharp.Snippets.Font;
using ReceiptPDFBuilder.Interfaces;
using ReceiptPDFBuilder.Models;
namespace ReceiptPDFBuilder.ViewModels;
class AboutViewModel
{
public AboutViewModel()
{
}
public void Close()
{
DialogHost.Close("DialogHost", null);
}
}
+29 -14
View File
@@ -30,6 +30,8 @@ class MainViewModel : BaseViewModel, IFontResolver
private string _reportTitle;
private ObservableCollection<ReportFile> _reportFiles;
private Settings _settings;
public MainViewModel(IChangeViewModel viewModelChanger) : base(viewModelChanger)
{
_baseDir = Path.GetDirectoryName(Environment.ProcessPath) ?? "";
@@ -39,6 +41,12 @@ class MainViewModel : BaseViewModel, IFontResolver
_reportFiles = new ObservableCollection<ReportFile>();
_reportFiles.CollectionChanged += ( sender, e ) => { NotifyPropertyChanged(nameof(IsCreatePDFButtonEnabled)); };
_reportTitle = "";
_settings = Settings.LoadSettings();
if (!string.IsNullOrWhiteSpace(_settings.LastUsedPath))
{
LogInfo("Loading data at last used path of {0}", _settings.LastUsedPath);
ScanFolder(_settings.LastUsedPath);
}
}
public string ReportTitle
@@ -95,20 +103,27 @@ class MainViewModel : BaseViewModel, IFontResolver
if (folders.Count == 1)
{
var folder = folders[0];
LogInfo("Chosen folder: " + folder.Path.LocalPath);
if (Directory.Exists(folder.Path.LocalPath))
{
_workingFolder = folder.Path.LocalPath;
NotifyPropertyChanged(nameof(IsTitleBoxVisible));
// TODO: Scan folder for saved info from previous reports and reload that first
// Scan folder for files and display in DataGrid
var filePaths = Directory.GetFiles(_workingFolder);
filePaths.Sort();
foreach (var filePath in filePaths)
{
AddFileBasedOnPath(filePath);
}
}
LogInfo("Loading items in folder: " + folder.Path.LocalPath);
ScanFolder(folder.Path.LocalPath);
_settings.LastUsedPath = folder.Path.LocalPath;
await _settings.SaveSettingsAsync();
}
}
}
private void ScanFolder(string path)
{
if (Directory.Exists(path))
{
_workingFolder = path;
NotifyPropertyChanged(nameof(IsTitleBoxVisible));
// TODO: Scan folder for saved info from previous reports and reload that first
// Scan folder for files and display in DataGrid
var filePaths = Directory.GetFiles(_workingFolder);
filePaths.Sort();
foreach (var filePath in filePaths)
{
AddFileBasedOnPath(filePath);
}
}
}