Add new enum for where PDF output file is saved
This commit is contained in:
@@ -8,11 +8,12 @@
|
||||
-no more option to save data internally -> ALWAYS save report_data.json internally
|
||||
*-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?)
|
||||
*-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
|
||||
-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 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)
|
||||
-make backup of last generated PDF somewhere
|
||||
-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)
|
||||
{
|
||||
// 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))
|
||||
{
|
||||
await DialogHost.Show(new WarningViewModel("Output directory not found! Please adjust your application Settings before continuing. Output directory: " + outputDir));
|
||||
|
||||
@@ -6,6 +6,7 @@ using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Threading.Tasks;
|
||||
using MayShow.Enums;
|
||||
using MayShow.Helpers;
|
||||
|
||||
namespace MayShow.Models;
|
||||
@@ -14,7 +15,7 @@ class Settings : ChangeNotifier
|
||||
{
|
||||
private string _lastUsedPath;
|
||||
private bool _useDocnetPDFImageRendering;
|
||||
private bool _saveOutputPdfInWorkingDir;
|
||||
private bool _saveOutputPdfInWorkingDir; // obsolete
|
||||
private string _outputPdfDir;
|
||||
private decimal _imageResizeThreshold;
|
||||
private Dictionary<string, string> _workingFolderToInternalFolderName; // obsolete
|
||||
@@ -22,6 +23,7 @@ class Settings : ChangeNotifier
|
||||
public string _dataGridDateFormat;
|
||||
public string _reportDateFormat;
|
||||
public int _settingsVersion;
|
||||
private PDFSaveLocation _pdfOutputSaveLocation;
|
||||
|
||||
public Settings() : base()
|
||||
{
|
||||
@@ -32,9 +34,10 @@ class Settings : ChangeNotifier
|
||||
_imageResizeThreshold = 1.5m;
|
||||
_workingFolderToInternalFolderName = [];
|
||||
_allReportInfo = [];
|
||||
_settingsVersion = 2;
|
||||
_settingsVersion = 3;
|
||||
_dataGridDateFormat = "dd/MM/yyyy";
|
||||
_reportDateFormat = "yyyy-MM-dd";
|
||||
_pdfOutputSaveLocation = PDFSaveLocation.BaseFolder;
|
||||
}
|
||||
|
||||
public Settings(Settings other)
|
||||
@@ -49,6 +52,7 @@ class Settings : ChangeNotifier
|
||||
_allReportInfo = other.AllReportInfo;
|
||||
_dataGridDateFormat = other.DataGridDateFormat;
|
||||
_reportDateFormat = other.ReportDateFormat;
|
||||
_pdfOutputSaveLocation = other.PDFOutputSaveLocation;
|
||||
}
|
||||
|
||||
[JsonInclude]
|
||||
@@ -73,6 +77,13 @@ class Settings : ChangeNotifier
|
||||
set { _saveOutputPdfInWorkingDir = value; NotifyPropertyChanged(); }
|
||||
}
|
||||
|
||||
[JsonInclude]
|
||||
public PDFSaveLocation PDFOutputSaveLocation
|
||||
{
|
||||
get => _pdfOutputSaveLocation;
|
||||
set { _pdfOutputSaveLocation = value; NotifyPropertyChanged(); }
|
||||
}
|
||||
|
||||
[JsonInclude]
|
||||
public string OutputPdfDir
|
||||
{
|
||||
@@ -273,6 +284,15 @@ class Settings : ChangeNotifier
|
||||
settings.SettingsVersion = 2;
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ using MayShow.Interfaces;
|
||||
using MayShow.Models;
|
||||
using MayShow.Helpers;
|
||||
using System.Collections.Generic;
|
||||
using MayShow.Enums;
|
||||
|
||||
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
|
||||
{
|
||||
_settings.SaveOutputPdfInWorkingDir = value;
|
||||
_settings.PDFOutputSaveLocation = value;
|
||||
NotifyPropertyChanged();
|
||||
NotifyPropertyChanged(nameof(SaveOutputPdfInChosenDir));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,7 +80,7 @@ class SettingsViewModel: ChangeNotifier
|
||||
|
||||
public bool IsOutputPdfDirValid
|
||||
{
|
||||
get => SaveOutputPdfInWorkingDir || (!SaveOutputPdfInWorkingDir && Directory.Exists(OutputPdfDirPath));
|
||||
get => !SaveOutputPdfInChosenDir || (SaveOutputPdfInChosenDir && Directory.Exists(OutputPdfDirPath));
|
||||
}
|
||||
|
||||
public bool HasErrorMessage
|
||||
|
||||
@@ -7,9 +7,14 @@
|
||||
d:DesignHeight="450"
|
||||
x:Class="MayShow.Views.SettingsView"
|
||||
xmlns:models="clr-namespace:MayShow.Models"
|
||||
xmlns:enums="clr-namespace:MayShow.Enums"
|
||||
xmlns:vm="clr-namespace:MayShow.ViewModels"
|
||||
xmlns:converters="using:Avalonia.Controls.Converters"
|
||||
x:DataType="vm:SettingsViewModel"
|
||||
MaxWidth="450">
|
||||
<UserControl.Resources>
|
||||
<converters:EnumToBoolConverter x:Key="EnumToBoolConverter" />
|
||||
</UserControl.Resources>
|
||||
<ScrollViewer AllowAutoHide="False">
|
||||
<StackPanel Orientation="Vertical"
|
||||
Spacing="8"
|
||||
@@ -32,10 +37,26 @@
|
||||
HorizontalAlignment="Left"
|
||||
Margin="0,0,0,4" />
|
||||
<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, *"
|
||||
IsVisible="{Binding !SaveOutputPdfInWorkingDir}">
|
||||
<Button Content="Choose report output folder..."
|
||||
IsVisible="{Binding SaveOutputPdfInChosenDir}">
|
||||
<Button Content="Choose PDF report output folder..."
|
||||
Grid.Column="0"
|
||||
Command="{Binding ChooseOutputFolder}"
|
||||
VerticalAlignment="Top"/>
|
||||
|
||||
Reference in New Issue
Block a user