@@ -256,7 +256,7 @@ class MainViewModel : BaseViewModel, IFontResolver, ICanCheckShutdown
|
||||
|
||||
public async Task ShowSettings()
|
||||
{
|
||||
var updatedSettings = await DialogHost.Show(new SettingsViewModel(_settings));
|
||||
var updatedSettings = await DialogHost.Show(new SettingsViewModel(_settings, TopLevelGrabber));
|
||||
if (updatedSettings != null)
|
||||
{
|
||||
_settings = (Settings)updatedSettings;
|
||||
@@ -575,6 +575,14 @@ class MainViewModel : BaseViewModel, IFontResolver, ICanCheckShutdown
|
||||
{
|
||||
// TODO: calculate needed width for images based on page width and margins and all that?
|
||||
// TODO: resize (non-HEIC) images for smaller size...?
|
||||
// safety checks
|
||||
var outputDir = _settings.SaveOutputPdfInWorkingDir ? folderPath : _settings.OutputPdfDir;
|
||||
if (!Directory.Exists(outputDir))
|
||||
{
|
||||
await DialogHost.Show(new WarningViewModel("Output directory not found! Please adjust your application Settings before continuing. Output directory: " + outputDir));
|
||||
return;
|
||||
}
|
||||
// start making PDF!
|
||||
IsCreatingPDF = true;
|
||||
var pdfDoc = new Document();
|
||||
var outputFileName = ReportTitle + ".pdf";
|
||||
@@ -828,15 +836,15 @@ class MainViewModel : BaseViewModel, IFontResolver, ICanCheckShutdown
|
||||
};
|
||||
LogInfo("Rendering document to PDF file...");
|
||||
pdfRenderer.RenderDocument();
|
||||
string outputPDFFileName = Path.Join(folderPath, outputFileName);
|
||||
string outputPDFFilePath = Path.Join(outputDir, outputFileName);
|
||||
LogInfo("Saving PDF document to disk...");
|
||||
pdfRenderer.PdfDocument.Save(outputPDFFileName);
|
||||
LogInfo("Finished saving PDF output to: " + outputPDFFileName);
|
||||
pdfRenderer.PdfDocument.Save(outputPDFFilePath);
|
||||
LogInfo("Finished saving PDF output to: " + outputPDFFilePath);
|
||||
await CreateAndSaveReportObjectAfterReportCreation();
|
||||
// clean up data dir
|
||||
Directory.Delete(convertedDir, true);
|
||||
// show output folder to user
|
||||
OpenFolderForFileInFileViewer(outputPDFFileName);
|
||||
OpenFolderForFileInFileViewer(outputPDFFilePath);
|
||||
IsCreatingPDF = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user