diff --git a/TODO.txt b/TODO.txt index 99cbfc2..5e2f491 100644 --- a/TODO.txt +++ b/TODO.txt @@ -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?) diff --git a/src/MayShow.Shared/Enums/PDFSaveLocation.cs b/src/MayShow.Shared/Enums/PDFSaveLocation.cs new file mode 100644 index 0000000..9185798 --- /dev/null +++ b/src/MayShow.Shared/Enums/PDFSaveLocation.cs @@ -0,0 +1,8 @@ +namespace MayShow.Enums; + +enum PDFSaveLocation : ushort +{ + BaseFolder = 0, + AlwaysAsk = 1, + OtherChosenDir = 2, +} \ No newline at end of file diff --git a/src/MayShow.Shared/Models/ReportPDFCreator.cs b/src/MayShow.Shared/Models/ReportPDFCreator.cs index fc417ed..0a723dd 100644 --- a/src/MayShow.Shared/Models/ReportPDFCreator.cs +++ b/src/MayShow.Shared/Models/ReportPDFCreator.cs @@ -86,7 +86,9 @@ class ReportPDFCreator : ChangeNotifier public async Task CreatePDF(List 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)); diff --git a/src/MayShow.Shared/Models/Settings.cs b/src/MayShow.Shared/Models/Settings.cs index c02c6f9..c2c9909 100644 --- a/src/MayShow.Shared/Models/Settings.cs +++ b/src/MayShow.Shared/Models/Settings.cs @@ -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 _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; } diff --git a/src/MayShow.Shared/ViewModels/SettingsViewModel.cs b/src/MayShow.Shared/ViewModels/SettingsViewModel.cs index 30a6f19..08f90f1 100644 --- a/src/MayShow.Shared/ViewModels/SettingsViewModel.cs +++ b/src/MayShow.Shared/ViewModels/SettingsViewModel.cs @@ -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 diff --git a/src/MayShow.Shared/Views/SettingsView.axaml b/src/MayShow.Shared/Views/SettingsView.axaml index 0fe83d7..35f5f85 100644 --- a/src/MayShow.Shared/Views/SettingsView.axaml +++ b/src/MayShow.Shared/Views/SettingsView.axaml @@ -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"> + + + Use legacy PDF handling (does not work with macOS annotations) - Always save report PDF in working directory + + + + + + -