@@ -13,11 +13,23 @@ class Settings : ChangeNotifier
|
|||||||
{
|
{
|
||||||
private string _lastUsedPath;
|
private string _lastUsedPath;
|
||||||
private bool _useDocnetPDFImageRendering;
|
private bool _useDocnetPDFImageRendering;
|
||||||
|
private bool _saveOutputPdfInWorkingDir;
|
||||||
|
private string _outputPdfDir;
|
||||||
|
|
||||||
public Settings()
|
public Settings()
|
||||||
{
|
{
|
||||||
_lastUsedPath = "";
|
_lastUsedPath = "";
|
||||||
_useDocnetPDFImageRendering = true;
|
_useDocnetPDFImageRendering = true;
|
||||||
|
_saveOutputPdfInWorkingDir = true;
|
||||||
|
_outputPdfDir = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public Settings(Settings other)
|
||||||
|
{
|
||||||
|
_lastUsedPath = other.LastUsedPath;
|
||||||
|
_useDocnetPDFImageRendering = other.UseDocnetPDFImageRendering;
|
||||||
|
_saveOutputPdfInWorkingDir = other.SaveOutputPdfInWorkingDir;
|
||||||
|
_outputPdfDir = other.OutputPdfDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
[JsonInclude]
|
[JsonInclude]
|
||||||
@@ -35,6 +47,20 @@ class Settings : ChangeNotifier
|
|||||||
set { _useDocnetPDFImageRendering = value; NotifyPropertyChanged(); }
|
set { _useDocnetPDFImageRendering = value; NotifyPropertyChanged(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[JsonInclude]
|
||||||
|
public bool SaveOutputPdfInWorkingDir
|
||||||
|
{
|
||||||
|
get => _saveOutputPdfInWorkingDir;
|
||||||
|
set { _saveOutputPdfInWorkingDir = value; NotifyPropertyChanged(); }
|
||||||
|
}
|
||||||
|
|
||||||
|
[JsonInclude]
|
||||||
|
public string OutputPdfDir
|
||||||
|
{
|
||||||
|
get => _outputPdfDir;
|
||||||
|
set { _outputPdfDir = value; NotifyPropertyChanged(); }
|
||||||
|
}
|
||||||
|
|
||||||
public static string GetSettingsFileName()
|
public static string GetSettingsFileName()
|
||||||
{
|
{
|
||||||
return "settings.json";
|
return "settings.json";
|
||||||
|
|||||||
@@ -256,7 +256,7 @@ class MainViewModel : BaseViewModel, IFontResolver, ICanCheckShutdown
|
|||||||
|
|
||||||
public async Task ShowSettings()
|
public async Task ShowSettings()
|
||||||
{
|
{
|
||||||
var updatedSettings = await DialogHost.Show(new SettingsViewModel(_settings));
|
var updatedSettings = await DialogHost.Show(new SettingsViewModel(_settings, TopLevelGrabber));
|
||||||
if (updatedSettings != null)
|
if (updatedSettings != null)
|
||||||
{
|
{
|
||||||
_settings = (Settings)updatedSettings;
|
_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: calculate needed width for images based on page width and margins and all that?
|
||||||
// TODO: resize (non-HEIC) images for smaller size...?
|
// 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;
|
IsCreatingPDF = true;
|
||||||
var pdfDoc = new Document();
|
var pdfDoc = new Document();
|
||||||
var outputFileName = ReportTitle + ".pdf";
|
var outputFileName = ReportTitle + ".pdf";
|
||||||
@@ -828,15 +836,15 @@ class MainViewModel : BaseViewModel, IFontResolver, ICanCheckShutdown
|
|||||||
};
|
};
|
||||||
LogInfo("Rendering document to PDF file...");
|
LogInfo("Rendering document to PDF file...");
|
||||||
pdfRenderer.RenderDocument();
|
pdfRenderer.RenderDocument();
|
||||||
string outputPDFFileName = Path.Join(folderPath, outputFileName);
|
string outputPDFFilePath = Path.Join(outputDir, outputFileName);
|
||||||
LogInfo("Saving PDF document to disk...");
|
LogInfo("Saving PDF document to disk...");
|
||||||
pdfRenderer.PdfDocument.Save(outputPDFFileName);
|
pdfRenderer.PdfDocument.Save(outputPDFFilePath);
|
||||||
LogInfo("Finished saving PDF output to: " + outputPDFFileName);
|
LogInfo("Finished saving PDF output to: " + outputPDFFilePath);
|
||||||
await CreateAndSaveReportObjectAfterReportCreation();
|
await CreateAndSaveReportObjectAfterReportCreation();
|
||||||
// clean up data dir
|
// clean up data dir
|
||||||
Directory.Delete(convertedDir, true);
|
Directory.Delete(convertedDir, true);
|
||||||
// show output folder to user
|
// show output folder to user
|
||||||
OpenFolderForFileInFileViewer(outputPDFFileName);
|
OpenFolderForFileInFileViewer(outputPDFFilePath);
|
||||||
IsCreatingPDF = false;
|
IsCreatingPDF = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,15 +25,15 @@ class SettingsViewModel: ChangeNotifier
|
|||||||
{
|
{
|
||||||
private Settings _previousSettings;
|
private Settings _previousSettings;
|
||||||
private Settings _settings;
|
private Settings _settings;
|
||||||
|
private string _errorMessage;
|
||||||
|
private ITopLevelGrabber? _topLevelGrabber;
|
||||||
|
|
||||||
public SettingsViewModel(Settings settingsToEdit)
|
public SettingsViewModel(Settings settingsToEdit, ITopLevelGrabber? topLevelGrabber)
|
||||||
{
|
{
|
||||||
_previousSettings = settingsToEdit;
|
_previousSettings = settingsToEdit;
|
||||||
_settings = new Settings
|
_settings = new Settings(settingsToEdit); // clone it
|
||||||
{
|
_errorMessage = "";
|
||||||
LastUsedPath = _previousSettings.LastUsedPath,
|
_topLevelGrabber = topLevelGrabber;
|
||||||
UseDocnetPDFImageRendering = _previousSettings.UseDocnetPDFImageRendering
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool UseDocnetPDFImageRendering
|
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()
|
public void Cancel()
|
||||||
{
|
{
|
||||||
DialogHost.Close("DialogHost", null);
|
DialogHost.Close("DialogHost", null);
|
||||||
|
|||||||
@@ -12,13 +12,26 @@
|
|||||||
MaxWidth="350">
|
MaxWidth="350">
|
||||||
<ScrollViewer AllowAutoHide="False">
|
<ScrollViewer AllowAutoHide="False">
|
||||||
<StackPanel Orientation="Vertical"
|
<StackPanel Orientation="Vertical"
|
||||||
Spacing="4"
|
Spacing="8"
|
||||||
Margin="12,4,12,0">
|
Margin="12,4,12,4">
|
||||||
<Label Content="Settings"
|
<Label Content="Settings"
|
||||||
HorizontalAlignment="Center"
|
HorizontalAlignment="Center"
|
||||||
FontSize="16"
|
FontSize="16"
|
||||||
FontWeight="Bold" />
|
FontWeight="Bold" />
|
||||||
<CheckBox IsChecked="{Binding !UseDocnetPDFImageRendering}">Use legacy PDF handling (does not work with macOS annotations)</CheckBox>
|
<CheckBox IsChecked="{Binding !UseDocnetPDFImageRendering}">Use legacy PDF handling (does not work with macOS annotations)</CheckBox>
|
||||||
|
<CheckBox IsChecked="{Binding SaveOutputPdfInWorkingDir}">Always save report PDF in working directory</CheckBox>
|
||||||
|
<Grid ColumnDefinitions="*, *"
|
||||||
|
IsVisible="{Binding !SaveOutputPdfInWorkingDir}">
|
||||||
|
<Button Content="Choose output folder..."
|
||||||
|
Grid.Column="0"
|
||||||
|
Command="{Binding ChooseOutputFolder}"
|
||||||
|
VerticalAlignment="Top"/>
|
||||||
|
<TextBlock Text="{Binding OutputPdfDirPath}"
|
||||||
|
Margin="6,0,0,0"
|
||||||
|
TextWrapping="Wrap"
|
||||||
|
Grid.Column="1"
|
||||||
|
VerticalAlignment="Top"/>
|
||||||
|
</Grid>
|
||||||
<StackPanel Orientation="Horizontal"
|
<StackPanel Orientation="Horizontal"
|
||||||
Spacing="12"
|
Spacing="12"
|
||||||
Margin="0,4,0,0"
|
Margin="0,4,0,0"
|
||||||
|
|||||||
@@ -3,13 +3,12 @@ using Avalonia;
|
|||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using Avalonia.Markup.Xaml;
|
using Avalonia.Markup.Xaml;
|
||||||
|
|
||||||
namespace MayShow.Views
|
namespace MayShow.Views;
|
||||||
|
|
||||||
|
public partial class SettingsView : UserControl
|
||||||
{
|
{
|
||||||
public partial class SettingsView : UserControl
|
public SettingsView()
|
||||||
{
|
{
|
||||||
public SettingsView()
|
this.InitializeComponent();
|
||||||
{
|
|
||||||
this.InitializeComponent();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user