Add new enum for where PDF output file is saved

This commit is contained in:
2026-04-23 11:24:04 +09:00
parent 71ca0c6459
commit e813504453
6 changed files with 70 additions and 11 deletions
+2 -1
View File
@@ -8,11 +8,12 @@
-no more option to save data internally -> ALWAYS save report_data.json internally -no more option to save data internally -> ALWAYS save report_data.json internally
*-update project title -> should update recently used data *-update project title -> should update recently used data
-this sort of works, something is wrong with the upgrade process where the UUID is not brought over properly; need to test and fix (maybe fixed already and my dataset is wrong?) -this sort of works, something is wrong with the upgrade process where the UUID is not brought over properly; need to test and fix (maybe fixed already and my dataset is wrong?)
*-add dropdown to Add Items button to have add items from folder and remove choose working folder option (data always saved internally)
-not going to do this; they can always select multiple items from the current picker
-Now that the BaseFolder is always internal...update options for PDF output location -Now that the BaseFolder is always internal...update options for PDF output location
-output in internal dir (default) -output in internal dir (default)
-always ask me every time (opens save file picker after generating PDF to ask user where they want it) -always ask me every time (opens save file picker after generating PDF to ask user where they want it)
-always put in X folder (uses existing option) -always put in X folder (uses existing option)
-add dropdown to Add Items button to have add items from folder and remove choose working folder option (data always saved internally)
-add option to backup added files to internal data directory (always on for iOS) -add option to backup added files to internal data directory (always on for iOS)
-make backup of last generated PDF somewhere -make backup of last generated PDF somewhere
-iOS-specific (MAUI essentials?) -iOS-specific (MAUI essentials?)
@@ -0,0 +1,8 @@
namespace MayShow.Enums;
enum PDFSaveLocation : ushort
{
BaseFolder = 0,
AlwaysAsk = 1,
OtherChosenDir = 2,
}
@@ -86,7 +86,9 @@ class ReportPDFCreator : ChangeNotifier
public async Task<string?> CreatePDF(List<ReportFile> reportFiles, string reportTitle, string outputFolderPath, PDFFontResolver fontResolver, Settings appSettings) public async Task<string?> CreatePDF(List<ReportFile> reportFiles, string reportTitle, string outputFolderPath, PDFFontResolver fontResolver, Settings appSettings)
{ {
// safety checks // safety checks
var outputDir = appSettings.SaveOutputPdfInWorkingDir ? outputFolderPath : appSettings.OutputPdfDir; var outputDir = appSettings.PDFOutputSaveLocation == Enums.PDFSaveLocation.BaseFolder
? outputFolderPath
: appSettings.OutputPdfDir; // TODO: adjust for new logic
if (!Directory.Exists(outputDir)) if (!Directory.Exists(outputDir))
{ {
await DialogHost.Show(new WarningViewModel("Output directory not found! Please adjust your application Settings before continuing. Output directory: " + outputDir)); await DialogHost.Show(new WarningViewModel("Output directory not found! Please adjust your application Settings before continuing. Output directory: " + outputDir));
+22 -2
View File
@@ -6,6 +6,7 @@ using System.Text;
using System.Text.Json; using System.Text.Json;
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
using System.Threading.Tasks; using System.Threading.Tasks;
using MayShow.Enums;
using MayShow.Helpers; using MayShow.Helpers;
namespace MayShow.Models; namespace MayShow.Models;
@@ -14,7 +15,7 @@ class Settings : ChangeNotifier
{ {
private string _lastUsedPath; private string _lastUsedPath;
private bool _useDocnetPDFImageRendering; private bool _useDocnetPDFImageRendering;
private bool _saveOutputPdfInWorkingDir; private bool _saveOutputPdfInWorkingDir; // obsolete
private string _outputPdfDir; private string _outputPdfDir;
private decimal _imageResizeThreshold; private decimal _imageResizeThreshold;
private Dictionary<string, string> _workingFolderToInternalFolderName; // obsolete private Dictionary<string, string> _workingFolderToInternalFolderName; // obsolete
@@ -22,6 +23,7 @@ class Settings : ChangeNotifier
public string _dataGridDateFormat; public string _dataGridDateFormat;
public string _reportDateFormat; public string _reportDateFormat;
public int _settingsVersion; public int _settingsVersion;
private PDFSaveLocation _pdfOutputSaveLocation;
public Settings() : base() public Settings() : base()
{ {
@@ -32,9 +34,10 @@ class Settings : ChangeNotifier
_imageResizeThreshold = 1.5m; _imageResizeThreshold = 1.5m;
_workingFolderToInternalFolderName = []; _workingFolderToInternalFolderName = [];
_allReportInfo = []; _allReportInfo = [];
_settingsVersion = 2; _settingsVersion = 3;
_dataGridDateFormat = "dd/MM/yyyy"; _dataGridDateFormat = "dd/MM/yyyy";
_reportDateFormat = "yyyy-MM-dd"; _reportDateFormat = "yyyy-MM-dd";
_pdfOutputSaveLocation = PDFSaveLocation.BaseFolder;
} }
public Settings(Settings other) public Settings(Settings other)
@@ -49,6 +52,7 @@ class Settings : ChangeNotifier
_allReportInfo = other.AllReportInfo; _allReportInfo = other.AllReportInfo;
_dataGridDateFormat = other.DataGridDateFormat; _dataGridDateFormat = other.DataGridDateFormat;
_reportDateFormat = other.ReportDateFormat; _reportDateFormat = other.ReportDateFormat;
_pdfOutputSaveLocation = other.PDFOutputSaveLocation;
} }
[JsonInclude] [JsonInclude]
@@ -73,6 +77,13 @@ class Settings : ChangeNotifier
set { _saveOutputPdfInWorkingDir = value; NotifyPropertyChanged(); } set { _saveOutputPdfInWorkingDir = value; NotifyPropertyChanged(); }
} }
[JsonInclude]
public PDFSaveLocation PDFOutputSaveLocation
{
get => _pdfOutputSaveLocation;
set { _pdfOutputSaveLocation = value; NotifyPropertyChanged(); }
}
[JsonInclude] [JsonInclude]
public string OutputPdfDir public string OutputPdfDir
{ {
@@ -273,6 +284,15 @@ class Settings : ChangeNotifier
settings.SettingsVersion = 2; settings.SettingsVersion = 2;
settings.SaveSettingsNotAsync(); // saves all data; UUIDs should be in sync if user has toggled settings settings.SaveSettingsNotAsync(); // saves all data; UUIDs should be in sync if user has toggled settings
} }
if (settings.SettingsVersion == 2)
{
if (!settings.SaveOutputPdfInWorkingDir)
{
settings.PDFOutputSaveLocation = PDFSaveLocation.OtherChosenDir;
}
settings.SettingsVersion = 3;
settings.SaveSettingsNotAsync();
}
return settings; return settings;
} }
@@ -8,6 +8,7 @@ using MayShow.Interfaces;
using MayShow.Models; using MayShow.Models;
using MayShow.Helpers; using MayShow.Helpers;
using System.Collections.Generic; using System.Collections.Generic;
using MayShow.Enums;
namespace MayShow.ViewModels; namespace MayShow.ViewModels;
@@ -50,13 +51,19 @@ class SettingsViewModel: ChangeNotifier
} }
} }
public bool SaveOutputPdfInWorkingDir public bool SaveOutputPdfInChosenDir
{ {
get => _settings.SaveOutputPdfInWorkingDir; get => PDFOutputSaveLocation == PDFSaveLocation.OtherChosenDir;
}
public PDFSaveLocation PDFOutputSaveLocation
{
get => _settings.PDFOutputSaveLocation;
set set
{ {
_settings.SaveOutputPdfInWorkingDir = value; _settings.PDFOutputSaveLocation = value;
NotifyPropertyChanged(); NotifyPropertyChanged();
NotifyPropertyChanged(nameof(SaveOutputPdfInChosenDir));
} }
} }
@@ -73,7 +80,7 @@ class SettingsViewModel: ChangeNotifier
public bool IsOutputPdfDirValid public bool IsOutputPdfDirValid
{ {
get => SaveOutputPdfInWorkingDir || (!SaveOutputPdfInWorkingDir && Directory.Exists(OutputPdfDirPath)); get => !SaveOutputPdfInChosenDir || (SaveOutputPdfInChosenDir && Directory.Exists(OutputPdfDirPath));
} }
public bool HasErrorMessage public bool HasErrorMessage
+24 -3
View File
@@ -7,9 +7,14 @@
d:DesignHeight="450" d:DesignHeight="450"
x:Class="MayShow.Views.SettingsView" x:Class="MayShow.Views.SettingsView"
xmlns:models="clr-namespace:MayShow.Models" xmlns:models="clr-namespace:MayShow.Models"
xmlns:enums="clr-namespace:MayShow.Enums"
xmlns:vm="clr-namespace:MayShow.ViewModels" xmlns:vm="clr-namespace:MayShow.ViewModels"
xmlns:converters="using:Avalonia.Controls.Converters"
x:DataType="vm:SettingsViewModel" x:DataType="vm:SettingsViewModel"
MaxWidth="450"> MaxWidth="450">
<UserControl.Resources>
<converters:EnumToBoolConverter x:Key="EnumToBoolConverter" />
</UserControl.Resources>
<ScrollViewer AllowAutoHide="False"> <ScrollViewer AllowAutoHide="False">
<StackPanel Orientation="Vertical" <StackPanel Orientation="Vertical"
Spacing="8" Spacing="8"
@@ -32,10 +37,26 @@
HorizontalAlignment="Left" HorizontalAlignment="Left"
Margin="0,0,0,4" /> Margin="0,0,0,4" />
<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> <StackPanel Spacing="0">
<Label HorizontalAlignment="Left">
Save created PDF Report in the following location:
</Label>
<RadioButton Content="MayShow application directory"
IsChecked="{Binding PDFOutputSaveLocation,
Converter={StaticResource EnumToBoolConverter},
ConverterParameter={x:Static enums:PDFSaveLocation.BaseFolder}}" />
<RadioButton Content="Ask me where to save the PDF file every time"
IsChecked="{Binding PDFOutputSaveLocation,
Converter={StaticResource EnumToBoolConverter},
ConverterParameter={x:Static enums:PDFSaveLocation.AlwaysAsk}}" />
<RadioButton Content="Always save PDF file in the same folder of my choice"
IsChecked="{Binding PDFOutputSaveLocation,
Converter={StaticResource EnumToBoolConverter},
ConverterParameter={x:Static enums:PDFSaveLocation.OtherChosenDir}}" />
</StackPanel>
<Grid ColumnDefinitions="Auto, *" <Grid ColumnDefinitions="Auto, *"
IsVisible="{Binding !SaveOutputPdfInWorkingDir}"> IsVisible="{Binding SaveOutputPdfInChosenDir}">
<Button Content="Choose report output folder..." <Button Content="Choose PDF report output folder..."
Grid.Column="0" Grid.Column="0"
Command="{Binding ChooseOutputFolder}" Command="{Binding ChooseOutputFolder}"
VerticalAlignment="Top"/> VerticalAlignment="Top"/>