Allow changing output directory

Closes #5
This commit is contained in:
2026-03-03 09:28:03 +09:00
parent 193f57df02
commit 03da58277e
5 changed files with 124 additions and 19 deletions
+65 -6
View File
@@ -25,15 +25,15 @@ class SettingsViewModel: ChangeNotifier
{
private Settings _previousSettings;
private Settings _settings;
private string _errorMessage;
private ITopLevelGrabber? _topLevelGrabber;
public SettingsViewModel(Settings settingsToEdit)
public SettingsViewModel(Settings settingsToEdit, ITopLevelGrabber? topLevelGrabber)
{
_previousSettings = settingsToEdit;
_settings = new Settings
{
LastUsedPath = _previousSettings.LastUsedPath,
UseDocnetPDFImageRendering = _previousSettings.UseDocnetPDFImageRendering
};
_settings = new Settings(settingsToEdit); // clone it
_errorMessage = "";
_topLevelGrabber = topLevelGrabber;
}
public bool UseDocnetPDFImageRendering
@@ -46,6 +46,65 @@ class SettingsViewModel: ChangeNotifier
}
}
public bool SaveOutputPdfInWorkingDir
{
get => _settings.SaveOutputPdfInWorkingDir;
set
{
_settings.SaveOutputPdfInWorkingDir = value;
NotifyPropertyChanged();
}
}
public string OutputPdfDirPath
{
get => _settings.OutputPdfDir;
set
{
_settings.OutputPdfDir = value;
NotifyPropertyChanged();
}
}
public bool IsOutputPdfDirValid
{
get => SaveOutputPdfInWorkingDir || (!SaveOutputPdfInWorkingDir && Directory.Exists(OutputPdfDirPath));
}
public bool HasErrorMessage
{
get => !string.IsNullOrWhiteSpace(_errorMessage);
}
public string ErrorMessage
{
get => _errorMessage;
set
{
_errorMessage = value;
NotifyPropertyChanged();
NotifyPropertyChanged(nameof(HasErrorMessage));
}
}
public async void ChooseOutputFolder()
{
var topLevel = _topLevelGrabber?.GetTopLevel();
if (topLevel != null)
{
var folders = await topLevel.StorageProvider.OpenFolderPickerAsync(new FolderPickerOpenOptions()
{
Title = "Choose where to save your report file...",
AllowMultiple = false,
});
if (folders.Count == 1)
{
var folder = folders[0];
OutputPdfDirPath = folder.Path.LocalPath;
}
}
}
public void Cancel()
{
DialogHost.Close("DialogHost", null);