From f39b643b000430a4dc70f0e627f7e9b856b20110 Mon Sep 17 00:00:00 2001 From: Michael Babienco Date: Wed, 8 Apr 2026 16:09:20 +0900 Subject: [PATCH] Add date format pickers (settings not used yet) --- src/Helpers/Constants.cs | 19 +++++++++++++ src/MayShow.csproj | 2 +- src/Models/DateDisplayFormat.cs | 35 ++++++++++++++++++++++++ src/Models/Settings.cs | 20 ++++++++++++++ src/ViewModels/SettingsViewModel.cs | 42 +++++++++++++++++++++++++++++ src/Views/SettingsView.axaml | 28 ++++++++++++++++++- 6 files changed, 144 insertions(+), 2 deletions(-) create mode 100644 src/Models/DateDisplayFormat.cs diff --git a/src/Helpers/Constants.cs b/src/Helpers/Constants.cs index 11d8f05..d540bc3 100644 --- a/src/Helpers/Constants.cs +++ b/src/Helpers/Constants.cs @@ -1,4 +1,7 @@ +using System.Collections.Generic; +using MayShow.Models; + namespace MayShow.Helpers; class Constants @@ -10,6 +13,22 @@ class Constants public static string ReportSavedDataFileName = "report_data.json"; + public static List GetDateDisplayFormats() + { + return [ + new DateDisplayFormat("Month/Day/Year", "4/5/2026", "M/d/yyyy"), + new DateDisplayFormat("Year-Month-Day", "2026-04-05", "yyyy-dd-MM"), + new DateDisplayFormat("Month Day, Year", "April 5, 2026", "MMMM d, yyyy"), + new DateDisplayFormat("DOW, Month Day, Year", "Sunday, April 5, 2026", "dddd, MMMM d, yyyy"), + new DateDisplayFormat("Abbreviated-Month Day, Year", "Apr 5, 2026", "MMM d, yyyy"), + new DateDisplayFormat("DOW, Abbreviated-Month Day, Year", "Sunday, Apr 5, 2026", "dddd, MMM d, yyyy"), + new DateDisplayFormat("Day Month, Year", "5 April, 2026", "d MMMM, yyyy"), + new DateDisplayFormat("Day Abbreviated-Month, Year", "5 Apr, 2026", "d MMM, yyyy"), + new DateDisplayFormat("Day Month, Year", "05 April 2026", "dd MMMM yyyy"), + new DateDisplayFormat("Day Abbreviated-Month, Year", "05 Apr 2026", "dd MMM yyyy"), + ]; + } + public static string[] GetQuotes() { // sources: diff --git a/src/MayShow.csproj b/src/MayShow.csproj index 2ce8058..20b698f 100644 --- a/src/MayShow.csproj +++ b/src/MayShow.csproj @@ -58,7 +58,7 @@ All - + diff --git a/src/Models/DateDisplayFormat.cs b/src/Models/DateDisplayFormat.cs new file mode 100644 index 0000000..3054949 --- /dev/null +++ b/src/Models/DateDisplayFormat.cs @@ -0,0 +1,35 @@ +using MayShow.Helpers; + +namespace MayShow.Models; + +class DateDisplayFormat : ChangeNotifier +{ + private string _title; + private string _example; + private string _value; + + public DateDisplayFormat(string title, string example, string value) + { + _title = title; + _example = example; + _value = value; + } + + public string Title + { + get => _title; + set { _title = value; NotifyPropertyChanged(); } + } + + public string Example + { + get => _example; + set { _example = value; NotifyPropertyChanged(); } + } + + public string Value + { + get => _value; + set { _value = value; NotifyPropertyChanged(); } + } +} \ No newline at end of file diff --git a/src/Models/Settings.cs b/src/Models/Settings.cs index c1b7002..304612b 100644 --- a/src/Models/Settings.cs +++ b/src/Models/Settings.cs @@ -19,6 +19,8 @@ class Settings : ChangeNotifier private decimal _imageResizeThreshold; private bool _saveReportJsonDataInInternalDir; private Dictionary _workingFolderToInternalFolderName; + public string _dataGridDateFormat; + public string _reportDateFormat; public int _settingsVersion; public Settings() @@ -31,6 +33,8 @@ class Settings : ChangeNotifier _saveReportJsonDataInInternalDir = false; _workingFolderToInternalFolderName = []; _settingsVersion = 1; + _dataGridDateFormat = "yyyy-MM-dd"; + _reportDateFormat = "yyyy-MM-dd"; } public Settings(Settings other) @@ -43,6 +47,8 @@ class Settings : ChangeNotifier _saveReportJsonDataInInternalDir = other.SaveReportJsonDataInInternalDir; _workingFolderToInternalFolderName = other.WorkingFolderToInternalFolderName; _settingsVersion = other.SettingsVersion; + _dataGridDateFormat = "yyyy-MM-dd"; + _reportDateFormat = "yyyy-MM-dd"; } [JsonInclude] @@ -102,6 +108,20 @@ class Settings : ChangeNotifier set { _settingsVersion = value; NotifyPropertyChanged(); } } + [JsonInclude] + public string DataGridDateFormat + { + get => _dataGridDateFormat; + set { _dataGridDateFormat = value; NotifyPropertyChanged(); } + } + + [JsonInclude] + public string ReportDateFormat + { + get => _reportDateFormat; + set { _reportDateFormat = value; NotifyPropertyChanged(); } + } + public static string SettingsFileName = "settings.json"; public static string GetSettingsPath() diff --git a/src/ViewModels/SettingsViewModel.cs b/src/ViewModels/SettingsViewModel.cs index 06663c2..05c5b08 100644 --- a/src/ViewModels/SettingsViewModel.cs +++ b/src/ViewModels/SettingsViewModel.cs @@ -19,6 +19,7 @@ using MayShow.Interfaces; using MayShow.Models; using MayShow.Helpers; using MayShows.Helpers; +using System.Collections.Generic; namespace MayShow.ViewModels; @@ -28,6 +29,9 @@ class SettingsViewModel: ChangeNotifier private Settings _settings; private string _errorMessage; private ITopLevelGrabber? _topLevelGrabber; + private List _dateFormats; + private int _gridDisplayDateFormatSelectedIndex; + private int _reportDisplayDateFormatSelectedIndex; public SettingsViewModel(Settings settingsToEdit, ITopLevelGrabber? topLevelGrabber) { @@ -35,6 +39,17 @@ class SettingsViewModel: ChangeNotifier _settings = new Settings(settingsToEdit); // clone it _errorMessage = ""; _topLevelGrabber = topLevelGrabber; + _dateFormats = Constants.GetDateDisplayFormats(); + _gridDisplayDateFormatSelectedIndex = _dateFormats.FindIndex(x => x.Value == _previousSettings.DataGridDateFormat); + if (_gridDisplayDateFormatSelectedIndex == -1) + { + _gridDisplayDateFormatSelectedIndex = 0; + } + _reportDisplayDateFormatSelectedIndex = _dateFormats.FindIndex(x => x.Value == _previousSettings.ReportDateFormat); + if (_reportDisplayDateFormatSelectedIndex == -1) + { + _reportDisplayDateFormatSelectedIndex = 0; + } } public bool UseDocnetPDFImageRendering @@ -109,6 +124,33 @@ class SettingsViewModel: ChangeNotifier } } + public List DateFormats + { + get => _dateFormats; + } + + public int DataGridDisplayDateFormatSelectedIndex + { + get => _gridDisplayDateFormatSelectedIndex; + set + { + _gridDisplayDateFormatSelectedIndex = value; + _settings.DataGridDateFormat = _dateFormats[value].Value; + NotifyPropertyChanged(); + } + } + + public int ReportDisplayDateFormatSelectedIndex + { + get => _reportDisplayDateFormatSelectedIndex; + set + { + _reportDisplayDateFormatSelectedIndex = value; + _settings.ReportDateFormat = _dateFormats[value].Value; + NotifyPropertyChanged(); + } + } + public async void ChooseOutputFolder() { var topLevel = _topLevelGrabber?.GetTopLevel(); diff --git a/src/Views/SettingsView.axaml b/src/Views/SettingsView.axaml index efa30b9..35dd693 100644 --- a/src/Views/SettingsView.axaml +++ b/src/Views/SettingsView.axaml @@ -46,8 +46,34 @@ HorizontalAlignment="Left" VerticalAlignment="Top"/> +