diff --git a/CLAUDE.md b/CLAUDE.md index 221ed9f..b9e257c 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -9,6 +9,9 @@ services through `ServiceLocator` (Microsoft.Extensions.DependencyInjection). - `Services/`: `DataService` (JSON in %APPDATA%, atomic + serialized), `LocalizationService` (Locales are **EmbeddedResource** `Locales..json`), `TaskCsv` + `Core/Csv` (import/export), `AutostartService` (HKCU Run, `"exe" --minimized`), `NotificationService` (tray balloon). +- Anniversaries: `ReminderTask.IsAnniversary` (stored as JSON `"IsBirthday"` for older files) + `CategoryId` + → `Models/Category.cs` (presets birthday/wedding/jubilee/memorial + own ones, text with `{0}`/`{o}`). + Filter/sort/group rules are in `Core/TaskQuery.cs` (pure, tested). - `Core/Theme.cs`: the only light/dark palette, used by MainWindow and the dialogs (`Theme.Apply(Resources, dark)`). - `MainWindow.xaml`: custom chrome (WindowStyle=None). Icons are Segoe MDL2 glyphs or Path geometry, **no emojis** (they don't follow the theme). diff --git a/CategoryWindow.xaml b/CategoryWindow.xaml new file mode 100644 index 0000000..28f00bd --- /dev/null +++ b/CategoryWindow.xaml @@ -0,0 +1,168 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - @@ -1020,7 +1081,7 @@ - + + + + + + + + + + + + + + + + + + + @@ -1141,17 +1222,46 @@ + - - - - - - - - + + + diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs index 4d316b2..3482981 100644 --- a/MainWindow.xaml.cs +++ b/MainWindow.xaml.cs @@ -105,7 +105,7 @@ namespace ReminderOrganizer private void UpcomingEntry_Click(object sender, MouseButtonEventArgs e) { - _viewModel.IsUpcomingMode = true; + _viewModel.ShowUpcomingCommand.Execute(null); } private void Window_PreviewKeyDown(object sender, KeyEventArgs e) @@ -145,7 +145,7 @@ namespace ReminderOrganizer { if (task == null) return; - var taskWindow = new TaskWindow(task, _viewModel.IsDarkMode) { Owner = this }; + var taskWindow = new TaskWindow(task, _viewModel.IsDarkMode, _viewModel.Categories) { Owner = this }; if (taskWindow.ShowDialog() == true) { _ = _viewModel.SaveAsync(); diff --git a/Models/Category.cs b/Models/Category.cs new file mode 100644 index 0000000..42e73bd --- /dev/null +++ b/Models/Category.cs @@ -0,0 +1,113 @@ +#nullable enable +using System; +using System.Collections.Generic; +using System.Globalization; +using ReminderOrganizer.Core; + +namespace ReminderOrganizer.Models +{ + /// Sidebar entry for a category (count = open anniversaries). + public record CategoryNavItem(string Id, string Name, string Glyph, string Color, int Count, bool IsActive); + + /// + /// Kind of anniversary (birthday, wedding, jubilee …). Text uses {0} = years, {o} = ordinal ("10." / "10th"). + /// + public class Category : ViewModelBase + { + public const string BirthdayId = "birthday"; + public const string WeddingId = "wedding"; + public const string JubileeId = "jubilee"; + public const string MemorialId = "memorial"; + + /// Segoe MDL2 glyphs offered in the editor (theme-colored, no emojis). + public static readonly string[] Glyphs = + { + "", // balloon + "", // heart + "", // star + "", // people + "", // message + "", // home + "", // flag + "", // history + "", // calendar + "", // music + "", // pet (dog/paw-like) + "", // light bulb + }; + + private string _id = Guid.NewGuid().ToString("N"); + private string _name = ""; + private string _glyph = Glyphs[0]; + private string _color = Folder.DefaultColor; + private string _format = "{0}"; + private bool _isWedding; + + public string Id { get => _id; set => SetProperty(ref _id, value); } + public string Name { get => _name; set => SetProperty(ref _name, value); } + public string Glyph { get => _glyph; set => SetProperty(ref _glyph, value); } + public string Color { get => _color; set => SetProperty(ref _color, value); } + /// e.g. "turns {0}", "{o} anniversary", "{0} years ago". + public string Format { get => _format; set => SetProperty(ref _format, value); } + /// Adds the traditional wedding name (Silver, Gold …). + public bool IsWedding { get => _isWedding; set => SetProperty(ref _isWedding, value); } + + public bool IsPreset => Id is BirthdayId or WeddingId or JubileeId or MemorialId; + + public Category Clone() => new() + { + Id = Id, Name = Name, Glyph = Glyph, Color = Color, Format = Format, IsWedding = IsWedding + }; + + /// Default categories in the given language. + public static List Defaults(Func L) => new() + { + new() { Id = BirthdayId, Name = L("CatBirthday"), Glyph = "", Color = "#EC4899", Format = L("CatBirthdayFormat") }, + new() { Id = WeddingId, Name = L("CatWedding"), Glyph = "", Color = "#F59E0B", Format = L("CatWeddingFormat"), IsWedding = true }, + new() { Id = JubileeId, Name = L("CatJubilee"), Glyph = "", Color = "#3B82F6", Format = L("CatJubileeFormat") }, + new() { Id = MemorialId, Name = L("CatMemorial"), Glyph = "", Color = "#64748B", Format = L("CatMemorialFormat") }, + }; + + /// + /// Presets that still carry a default text of some language get the texts of the new language + /// (user-edited names/formats stay untouched). + /// + public static void RelocalizePresets(IEnumerable categories, Func L, + IEnumerable> allLanguages) + { + var langs = new List>(allLanguages); + foreach (var c in categories) + { + if (!c.IsPreset) continue; + var key = c.Id switch { BirthdayId => "CatBirthday", WeddingId => "CatWedding", JubileeId => "CatJubilee", _ => "CatMemorial" }; + if (langs.Exists(d => d.TryGetValue(key, out var n) && n == c.Name)) c.Name = L(key); + if (langs.Exists(d => d.TryGetValue(key + "Format", out var f) && f == c.Format)) c.Format = L(key + "Format"); + } + } + + /// Years for which a wedding anniversary has a traditional name (key "Wedding{n}"). + public static readonly int[] WeddingYears = { 1, 5, 10, 15, 20, 25, 30, 40, 50, 60, 65, 70 }; + + /// "10th" (en) / "10." (de). + public static string Ordinal(int n, CultureInfo culture) + { + if (culture.TwoLetterISOLanguageName != "en") return n + "."; + var suffix = (n % 100) is 11 or 12 or 13 ? "th" : (n % 10) switch { 1 => "st", 2 => "nd", 3 => "rd", _ => "th" }; + return n + suffix; + } + + /// Applies the format; for weddings appends the traditional name if known. + public string FormatYears(int years, CultureInfo culture, Func L) + { + var text = (Format ?? "{0}") + .Replace("{o}", Ordinal(years, culture)) + .Replace("{0}", years.ToString(culture)); + if (IsWedding && Array.IndexOf(WeddingYears, years) >= 0) + { + var name = L("Wedding" + years); + if (!string.IsNullOrEmpty(name) && name != "Wedding" + years) text += " · " + name; + } + return text; + } + } +} diff --git a/Models/ReminderModels.cs b/Models/ReminderModels.cs index 128705e..0365607 100644 --- a/Models/ReminderModels.cs +++ b/Models/ReminderModels.cs @@ -2,6 +2,7 @@ using System; using System.Collections.ObjectModel; using System.Globalization; +using System.Linq; using ReminderOrganizer.Core; namespace ReminderOrganizer.Models @@ -88,18 +89,48 @@ namespace ReminderOrganizer.Models BirthYear is int y && IsRecurring && RecurrenceType == RecurrenceType.Yearly && ReminderDate.Year > y ? ReminderDate.Year - y : null; - /// Set once by the app (localized "turns {0}"). - public static Func? AgeFormatter { get; set; } + /// Set once by the app: (task, years) → "turns 40" / "10th anniversary · Tin" … + public static Func? AgeFormatter { get; set; } [System.Text.Json.Serialization.JsonIgnore] - public string? AgeText => UpcomingAge is int a ? (AgeFormatter?.Invoke(a) ?? a.ToString()) : null; + public string? AgeText => UpcomingAge is int a ? (AgeFormatter?.Invoke(this, a) ?? a.ToString()) : null; - private bool _isBirthday; - /// Birthday: yearly, date only (no time shown), reminded at . - public bool IsBirthday + private bool _isAnniversary; + /// Anniversary (birthday, wedding …): yearly, date only, reminded at . + /// Stored as "IsBirthday" for compatibility with older files. + [System.Text.Json.Serialization.JsonPropertyName("IsBirthday")] + public bool IsAnniversary { - get => _isBirthday; - set { if (SetProperty(ref _isBirthday, value)) RaiseDisplay(); } + get => _isAnniversary; + set { if (SetProperty(ref _isAnniversary, value)) RaiseDisplay(); } + } + + private string? _categoryId; + /// Anniversary category (see ); null = birthday. + public string? CategoryId + { + get => _categoryId; + set { if (SetProperty(ref _categoryId, value)) RaiseDisplay(); } + } + + /// Set once by the app: id → category. + public static Func? CategoryLookup { get; set; } + + [System.Text.Json.Serialization.JsonIgnore] + public Category? Category => IsAnniversary ? CategoryLookup?.Invoke(CategoryId ?? Category.BirthdayId) : null; + + /// Accent color: category for anniversaries, otherwise folder. + [System.Text.Json.Serialization.JsonIgnore] + public string AccentColor => Category?.Color ?? FolderColor; + + [System.Text.Json.Serialization.JsonIgnore] + public string? CategoryGlyph => Category?.Glyph; + + /// Call after categories were edited. + public void RefreshCategory() + { + OnPropertyChanged(nameof(Category)); + RaiseDisplay(); } public const int BirthdayHour = 9; @@ -110,7 +141,7 @@ namespace ReminderOrganizer.Models /// "19. März" for birthdays, otherwise "19.03.2027 09:00". [System.Text.Json.Serialization.JsonIgnore] - public string DisplayDate => IsBirthday + public string DisplayDate => IsAnniversary ? ReminderDate.ToString(DayMonthPattern(DisplayCulture?.Invoke() ?? CultureInfo.CurrentCulture), DisplayCulture?.Invoke() ?? CultureInfo.CurrentCulture) : ReminderDate.ToString("dd.MM.yyyy HH:mm", CultureInfo.InvariantCulture); @@ -137,6 +168,8 @@ namespace ReminderOrganizer.Models OnPropertyChanged(nameof(DayText)); OnPropertyChanged(nameof(MonthText)); OnPropertyChanged(nameof(AgeText)); + OnPropertyChanged(nameof(AccentColor)); + OnPropertyChanged(nameof(CategoryGlyph)); } /// Next birthday on/after at BirthdayHour (29 Feb → 28 Feb in other years). @@ -154,7 +187,7 @@ namespace ReminderOrganizer.Models private string _folderColor = Folder.DefaultColor; [System.Text.Json.Serialization.JsonIgnore] - public string FolderColor { get => _folderColor; set => SetProperty(ref _folderColor, value); } + public string FolderColor { get => _folderColor; set { if (SetProperty(ref _folderColor, value)) OnPropertyChanged(nameof(AccentColor)); } } public DateTime GetNextOccurrence() => GetNextOccurrence(DateTime.Now); @@ -298,6 +331,24 @@ namespace ReminderOrganizer.Models public bool HideDone { get; set; } /// "list", "compact" or "cards". public string ViewMode { get; set; } = "list"; + /// Group the list by month (collapsible). + public bool GroupByMonth { get; set; } + /// Anniversary categories (birthday, wedding, … and own ones). Filled with defaults on first start. + public ObservableCollection Categories { get; set; } = new(); + + /// Adds missing default categories (keeps user edits of existing ones). + public bool EnsureDefaultCategories(Func L) + { + bool changed = false; + int insertAt = 0; + foreach (var def in Category.Defaults(L)) + { + if (Categories.Any(c => c.Id == def.Id)) { insertAt++; continue; } + Categories.Insert(Math.Min(insertAt++, Categories.Count), def); + changed = true; + } + return changed; + } /// Folders and yearly tasks were checked for birthdays once. public bool BirthdaysMigrated { get; set; } @@ -308,16 +359,43 @@ namespace ReminderOrganizer.Models /// Yearly tasks in a "Geburtstage"/"Birthdays" folder become birthday entries (one-time). public int MigrateBirthdays() { - if (BirthdaysMigrated) return 0; - BirthdaysMigrated = true; + int n = 0; + if (!BirthdaysMigrated) + { + BirthdaysMigrated = true; + n += MarkYearly(LooksLikeBirthdayFolder, Category.BirthdayId); + } + if (!WeddingsMigrated) + { + WeddingsMigrated = true; + n += MarkYearly(LooksLikeWeddingFolder, Category.WeddingId); + } + return n; + } + + public bool WeddingsMigrated { get; set; } + + public static bool LooksLikeWeddingFolder(string? name) => + name != null && (name.Contains("hochzeit", StringComparison.OrdinalIgnoreCase) || + name.Contains("wedding", StringComparison.OrdinalIgnoreCase) || + name.Contains("jahrestag", StringComparison.OrdinalIgnoreCase) || + name.Contains("anniversar", StringComparison.OrdinalIgnoreCase)); + + /// Category a new anniversary in this folder should get (null = no hint). + public static string? CategoryHintForFolder(string? name) => + LooksLikeBirthdayFolder(name) ? Category.BirthdayId : LooksLikeWeddingFolder(name) ? Category.WeddingId : null; + + private int MarkYearly(Func folderMatches, string categoryId) + { int n = 0; foreach (var f in Folders) { - if (!LooksLikeBirthdayFolder(f.Name)) continue; + if (!folderMatches(f.Name)) continue; foreach (var t in f.Tasks) { - if (t.IsBirthday || !t.IsRecurring || t.RecurrenceType != RecurrenceType.Yearly) continue; - t.IsBirthday = true; + if (t.IsAnniversary || !t.IsRecurring || t.RecurrenceType != RecurrenceType.Yearly) continue; + t.IsAnniversary = true; + t.CategoryId = categoryId; n++; } } diff --git a/README.md b/README.md index bbbbfb7..32c10f0 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,11 @@ It runs in the system tray (notification area). - **Upcoming** view: every folder in one list, grouped by Overdue, Today, Tomorrow, Next 7 days, Later - **Search** (Ctrl+F), filters All/Today/Overdue, "Hide done" - One-off or recurring reminders (daily, weekly, monthly, yearly) -- **Remind in advance** (1, 2 or 3 days, or 1 week before); **birthdays** with year of birth show "turns 40" +- **Remind in advance** (1, 2 or 3 days, or 1 week before) +- **Anniversaries** without a time: enter "19.03." or "19.03.1986". Categories Birthday ("turns 40"), Wedding anniversary + ("25th anniversary · Silver"), Jubilee, Memorial day, plus your own (Settings → Categories: icon, color, text) +- Sidebar **Categories** shows every birthday / wedding … across all folders +- Views **list / compact / cards**; **group by month** (click a month to fold it) - Reminders missed while the app was closed are shown at the next start, with a reminder sound (can be turned off) - **Folder colors** and order (drag or context menu); drag a task onto a folder to move it - **Undo** after deleting (Ctrl+Z), shortcuts Ctrl+N (new task), Del, Esc diff --git a/Services/IcsExport.cs b/Services/IcsExport.cs index 9e3223c..ec665d9 100644 --- a/Services/IcsExport.cs +++ b/Services/IcsExport.cs @@ -1,4 +1,4 @@ -#nullable enable +#nullable enable using System; using System.Globalization; using System.Text; @@ -28,7 +28,7 @@ namespace ReminderOrganizer.Services Line("BEGIN:VEVENT"); Line($"UID:{t.Id}@reminder-organizer"); Line($"DTSTAMP:{stamp}"); - if (t.IsBirthday) + if (t.IsAnniversary) { // all-day event Line($"DTSTART;VALUE=DATE:{t.ReminderDate.ToString("yyyyMMdd", CultureInfo.InvariantCulture)}"); @@ -58,7 +58,7 @@ namespace ReminderOrganizer.Services Line("ACTION:DISPLAY"); Line($"DESCRIPTION:{Escape(t.Name)}"); // all-day events start at midnight: remind at 09:00 (same day or lead days before) - Line(t.IsBirthday + Line(t.IsAnniversary ? (t.LeadDays > 0 ? $"TRIGGER:-P{t.LeadDays - 1}DT15H" : "TRIGGER:PT9H") : (t.LeadDays > 0 ? $"TRIGGER:-P{t.LeadDays}D" : "TRIGGER:PT0M")); Line("END:VALARM"); diff --git a/TaskWindow.xaml b/TaskWindow.xaml index 520f4fd..6ffa2d9 100644 --- a/TaskWindow.xaml +++ b/TaskWindow.xaml @@ -143,7 +143,7 @@ - + @@ -157,7 +157,19 @@ Visibility="{Binding HasError, Converter={StaticResource BoolToVisibility}}"/> - + + + + + + + + + + + + diff --git a/TaskWindow.xaml.cs b/TaskWindow.xaml.cs index dc98509..9bc2659 100644 --- a/TaskWindow.xaml.cs +++ b/TaskWindow.xaml.cs @@ -14,13 +14,15 @@ namespace ReminderOrganizer public ReminderTask TaskResult => _viewModel.TaskResult; - public TaskWindow(ReminderTask? existingTask, bool darkMode, bool defaultBirthday = false) + /// Opens a new entry as anniversary of this category (null = appointment). + public TaskWindow(ReminderTask? existingTask, bool darkMode, + System.Collections.Generic.IEnumerable categories, string? defaultCategory = null) { InitializeComponent(); Theme.Apply(Resources, darkMode); var localizationService = (ILocalizationService)ServiceLocator.Services.GetService(typeof(ILocalizationService))!; - _viewModel = new TaskViewModel(localizationService, existingTask, defaultBirthday); + _viewModel = new TaskViewModel(localizationService, existingTask, defaultCategory, categories); _viewModel.RequestClose += OnRequestClose; DataContext = _viewModel; diff --git a/Tests/BirthdayTests.cs b/Tests/BirthdayTests.cs index 346ac77..9d40e31 100644 --- a/Tests/BirthdayTests.cs +++ b/Tests/BirthdayTests.cs @@ -1,4 +1,4 @@ -using System; +using System; using ReminderOrganizer.Core; using ReminderOrganizer.Models; using ReminderOrganizer.Services; @@ -64,9 +64,9 @@ namespace ReminderOrganizer.Tests data.Folders.Add(work); Assert.Equal(1, data.MigrateBirthdays()); - Assert.True(bday.Tasks[0].IsBirthday); - Assert.False(bday.Tasks[1].IsBirthday); - Assert.False(work.Tasks[0].IsBirthday); + Assert.True(bday.Tasks[0].IsAnniversary); + Assert.False(bday.Tasks[1].IsAnniversary); + Assert.False(work.Tasks[0].IsAnniversary); Assert.Equal(0, data.MigrateBirthdays()); } @@ -74,10 +74,10 @@ namespace ReminderOrganizer.Tests public void Birthday_display_has_no_time() { ReminderTask.DisplayCulture = () => new System.Globalization.CultureInfo("de-DE"); - var t = new ReminderTask("x", "", new DateTime(2027, 3, 19, 9, 0, 0)) { IsBirthday = true }; + var t = new ReminderTask("x", "", new DateTime(2027, 3, 19, 9, 0, 0)) { IsAnniversary = true }; Assert.Equal("19. März", t.DisplayDate); Assert.Equal("MÄR", t.MonthText); - t.IsBirthday = false; + t.IsAnniversary = false; Assert.Equal("19.03.2027 09:00", t.DisplayDate); } @@ -87,7 +87,7 @@ namespace ReminderOrganizer.Tests var data = new AppData(); var f = new Folder("Geburtstage"); f.Tasks.Add(new ReminderTask("Oma", "", new DateTime(2027, 1, 27, 9, 0, 0)) - { IsBirthday = true, IsRecurring = true, RecurrenceType = RecurrenceType.Yearly, LeadDays = 1 }); + { IsAnniversary = true, IsRecurring = true, RecurrenceType = RecurrenceType.Yearly, LeadDays = 1 }); data.Folders.Add(f); var ics = IcsExport.Build(data, DateTime.UtcNow); Assert.Contains("DTSTART;VALUE=DATE:20270127", ics); diff --git a/Tests/CategoryTests.cs b/Tests/CategoryTests.cs new file mode 100644 index 0000000..9596a62 --- /dev/null +++ b/Tests/CategoryTests.cs @@ -0,0 +1,129 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text.Json; +using ReminderOrganizer.Core; +using ReminderOrganizer.Models; +using ReminderOrganizer.Services; +using Xunit; + +namespace ReminderOrganizer.Tests +{ + public class CategoryTests + { + private static readonly CultureInfo De = new("de-DE"); + private static readonly CultureInfo En = new("en-US"); + private static readonly Dictionary DeStrings = LocalizationService.LoadStrings("de"); + private static readonly Dictionary EnStrings = LocalizationService.LoadStrings("en"); + private static string LDe(string k) => DeStrings.TryGetValue(k, out var v) ? v : k; + private static string LEn(string k) => EnStrings.TryGetValue(k, out var v) ? v : k; + + [Fact] + public void Wedding_text_with_traditional_name() + { + var wedding = Category.Defaults(LDe).Single(c => c.Id == Category.WeddingId); + Assert.Equal("25. Hochzeitstag · Silberhochzeit", wedding.FormatYears(25, De, LDe)); + Assert.Equal("7. Hochzeitstag", wedding.FormatYears(7, De, LDe)); + + var weddingEn = Category.Defaults(LEn).Single(c => c.Id == Category.WeddingId); + Assert.Equal("50th anniversary · Golden", weddingEn.FormatYears(50, En, LEn)); + } + + [Theory] + [InlineData(1, "1st")] + [InlineData(2, "2nd")] + [InlineData(3, "3rd")] + [InlineData(11, "11th")] + [InlineData(12, "12th")] + [InlineData(22, "22nd")] + [InlineData(101, "101st")] + public void English_ordinals(int n, string expected) => Assert.Equal(expected, Category.Ordinal(n, En)); + + [Fact] + public void Other_presets_format() + { + var defs = Category.Defaults(LDe).ToDictionary(c => c.Id); + Assert.Equal("wird 40", defs[Category.BirthdayId].FormatYears(40, De, LDe)); + Assert.Equal("15 Jahre", defs[Category.JubileeId].FormatYears(15, De, LDe)); + Assert.Equal("vor 12 Jahren", defs[Category.MemorialId].FormatYears(12, De, LDe)); + } + + [Fact] + public void Defaults_are_added_once_and_keep_user_edits() + { + var data = new AppData(); + Assert.True(data.EnsureDefaultCategories(LDe)); + Assert.Equal(4, data.Categories.Count); + data.Categories[0].Name = "Geburtstage Familie"; + data.Categories.Add(new Category { Name = "Hund" }); + Assert.False(data.EnsureDefaultCategories(LDe)); + Assert.Equal("Geburtstage Familie", data.Categories[0].Name); + Assert.Equal(5, data.Categories.Count); + } + + [Fact] + public void Presets_follow_language_unless_renamed() + { + var data = new AppData(); + data.EnsureDefaultCategories(LDe); + data.Categories.Single(c => c.Id == Category.JubileeId).Name = "Firma"; + Category.RelocalizePresets(data.Categories, LEn, new[] { EnStrings, DeStrings }); + Assert.Equal("Birthday", data.Categories.Single(c => c.Id == Category.BirthdayId).Name); + Assert.Equal("turns {0}", data.Categories.Single(c => c.Id == Category.BirthdayId).Format); + Assert.Equal("Firma", data.Categories.Single(c => c.Id == Category.JubileeId).Name); + } + + [Fact] + public void Old_files_map_IsBirthday_to_anniversary() + { + var t = JsonSerializer.Deserialize("{\"Name\":\"Oma\",\"IsBirthday\":true}")!; + Assert.True(t.IsAnniversary); + Assert.Null(t.CategoryId); + Assert.Contains("\"IsBirthday\":true", JsonSerializer.Serialize(t)); + } + + [Fact] + public void Wedding_folders_are_migrated_to_wedding_category() + { + var data = new AppData { BirthdaysMigrated = true }; + var f = new Folder("Hochzeitstage"); + f.Tasks.Add(new ReminderTask("Anna & Tom", "", new DateTime(2027, 6, 1)) { IsRecurring = true, RecurrenceType = RecurrenceType.Yearly }); + data.Folders.Add(f); + Assert.Equal(1, data.MigrateBirthdays()); + Assert.True(f.Tasks[0].IsAnniversary); + Assert.Equal(Category.WeddingId, f.Tasks[0].CategoryId); + Assert.Equal(Category.WeddingId, AppData.CategoryHintForFolder("Hochzeiten")); + Assert.Equal(Category.BirthdayId, AppData.CategoryHintForFolder("Geburtstage")); + Assert.Null(AppData.CategoryHintForFolder("Arbeit")); + } + + [Fact] + public void Category_filter() + { + var bday = new ReminderTask("a", "", DateTime.Now) { IsAnniversary = true }; // null id = birthday + var wedding = new ReminderTask("b", "", DateTime.Now) { IsAnniversary = true, CategoryId = Category.WeddingId }; + var appt = new ReminderTask("c", "", DateTime.Now); + + Assert.True(TaskQuery.MatchesCategory(bday, Category.BirthdayId)); + Assert.False(TaskQuery.MatchesCategory(wedding, Category.BirthdayId)); + Assert.True(TaskQuery.MatchesCategory(wedding, Category.WeddingId)); + Assert.True(TaskQuery.MatchesCategory(appt, TaskQuery.AppointmentsFilter)); + Assert.False(TaskQuery.MatchesCategory(bday, TaskQuery.AppointmentsFilter)); + Assert.True(TaskQuery.MatchesCategory(appt, null)); + } + + [Fact] + public void Month_grouping_is_chronological() + { + var now = new DateTime(2026, 11, 29, 12, 0, 0); + var dec = new ReminderTask("dec", "", new DateTime(2026, 12, 14, 9, 0, 0)); + var doneNov = new ReminderTask("doneNov", "", new DateTime(2026, 11, 2)) { IsNotified = true }; + var jan = new ReminderTask("jan", "", new DateTime(2027, 1, 12, 9, 0, 0)); + var list = new List { jan, dec, doneNov }; + list.Sort((a, b) => new TaskQuery.Comparer(() => now, chronological: true).Compare(a, b)); + Assert.Equal(new[] { "doneNov", "dec", "jan" }, list.Select(t => t.Name)); + Assert.Equal(new DateTime(2026, 12, 1), TaskQuery.MonthKey(dec)); + } + } +} diff --git a/ViewModels/MainViewModel.cs b/ViewModels/MainViewModel.cs index 955cecf..6aa2d5c 100644 --- a/ViewModels/MainViewModel.cs +++ b/ViewModels/MainViewModel.cs @@ -65,9 +65,12 @@ namespace ReminderOrganizer.ViewModels bool changed = !ReferenceEquals(_selectedFolder, folder) || _isUpcomingMode; _selectedFolder = folder; _isUpcomingMode = false; + _categoryFilter = null; if (!changed) return; OnPropertyChanged(nameof(SelectedFolder)); OnPropertyChanged(nameof(IsUpcomingMode)); + OnPropertyChanged(nameof(CategoryFilter)); + OnPropertyChanged(nameof(IsAllUpcoming)); RebuildView(); } @@ -79,6 +82,7 @@ namespace ReminderOrganizer.ViewModels if (_isUpcomingMode == value) return; _isUpcomingMode = value; OnPropertyChanged(); + OnPropertyChanged(nameof(IsAllUpcoming)); RebuildView(); } } @@ -92,8 +96,8 @@ namespace ReminderOrganizer.ViewModels public bool HasVisibleTasks => VisibleCount > 0; public bool HasSelectedFolder => SelectedFolder != null; - public string HeaderTitle => IsUpcomingMode ? L("Upcoming") : SelectedFolder?.Name ?? L("Welcome"); - public string HeaderColor => IsUpcomingMode ? Folder.DefaultColor : SelectedFolder?.Color ?? Folder.DefaultColor; + public string HeaderTitle => ActiveCategory?.Name ?? (IsUpcomingMode ? L("Upcoming") : SelectedFolder?.Name ?? L("Welcome")); + public string HeaderColor => ActiveCategory?.Color ?? (IsUpcomingMode ? Folder.DefaultColor : SelectedFolder?.Color ?? Folder.DefaultColor); public string TaskCountText { @@ -159,7 +163,7 @@ namespace ReminderOrganizer.ViewModels } } - private bool IsFiltering => !string.IsNullOrWhiteSpace(SearchText) || FilterMode != TaskFilterMode.All || HideDone; + private bool IsFiltering => !string.IsNullOrWhiteSpace(SearchText) || FilterMode != TaskFilterMode.All || HideDone || CategoryFilter != null; // ---------- settings ---------- @@ -194,6 +198,92 @@ namespace ReminderOrganizer.ViewModels } } + // ---------- categories ---------- + + public ObservableCollection Categories => _appData.Categories; + + /// Sidebar entries: every category that has entries, with count; active one highlighted. + public IReadOnlyList CategoryNav => + _appData.Categories + .Select(c => new CategoryNavItem(c.Id, c.Name, c.Glyph, c.Color, + _allTasks.Count(t => t.IsAnniversary && !t.IsNotified && (t.CategoryId ?? Category.BirthdayId) == c.Id), + IsUpcomingMode && CategoryFilter == c.Id)) + .Where(n => n.Count > 0) + .ToList(); + + public bool HasCategoryNav => CategoryNav.Count > 0; + + private string? _categoryFilter; + /// Category shown in the "Upcoming" view (null = all). + public string? CategoryFilter + { + get => _categoryFilter; + set + { + if (!SetProperty(ref _categoryFilter, value)) return; + OnPropertyChanged(nameof(HeaderTitle)); + OnPropertyChanged(nameof(HeaderColor)); + OnPropertyChanged(nameof(HeaderGlyph)); + OnPropertyChanged(nameof(IsAllUpcoming)); + RefreshView(); + } + } + + private Category? ActiveCategory => IsUpcomingMode && CategoryFilter != null + ? _appData.Categories.FirstOrDefault(c => c.Id == CategoryFilter) : null; + + /// "Upcoming" without a category filter (for the sidebar highlight). + public bool IsAllUpcoming => IsUpcomingMode && CategoryFilter == null; + + /// Icon in the header: category glyph, calendar for "Upcoming", null = folder outline. + public string? HeaderGlyph => ActiveCategory?.Glyph ?? (IsUpcomingMode ? "" : null); + + private void ShowCategory(string? id) + { + _categoryFilter = id; + OnPropertyChanged(nameof(CategoryFilter)); + OnPropertyChanged(nameof(IsAllUpcoming)); + if (!IsUpcomingMode) IsUpcomingMode = true; // rebuilds the view + else RebuildView(); + } + + private void EditCategories() + { + var dialog = new CategoryWindow(_appData.Categories, IsDarkMode, + id => _allTasks.Count(t => t.IsAnniversary && (t.CategoryId ?? Category.BirthdayId) == id)) + { Owner = Application.Current.MainWindow }; + if (dialog.ShowDialog() != true) return; + + var result = dialog.Result; + var removed = _appData.Categories.Where(c => result.All(r => r.Id != c.Id)).Select(c => c.Id).ToHashSet(); + _appData.Categories.Clear(); + foreach (var c in result) _appData.Categories.Add(c); + foreach (var t in _allTasks) + { + if (t.CategoryId != null && removed.Contains(t.CategoryId)) t.CategoryId = null; // back to birthday + t.RefreshCategory(); + } + if (CategoryFilter != null && removed.Contains(CategoryFilter)) CategoryFilter = null; + UpdateCounts(); + OnPropertyChanged(nameof(HeaderTitle)); + _ = SaveAsync(); + } + + // ---------- month grouping ---------- + + public bool GroupByMonth + { + get => _appData.GroupByMonth; + set + { + if (_appData.GroupByMonth == value) return; + _appData.GroupByMonth = value; + OnPropertyChanged(); + RebuildView(); + _ = SaveAsync(); + } + } + // ---------- view mode ---------- public string ViewMode @@ -292,6 +382,8 @@ namespace ReminderOrganizer.ViewModels public ICommand ShowUpcomingCommand { get; } public ICommand UndoCommand { get; } public ICommand ClearSearchCommand { get; } + public ICommand EditCategoriesCommand { get; } + public ICommand ShowCategoryCommand { get; } public MainViewModel( IDataService dataService, @@ -304,13 +396,19 @@ namespace ReminderOrganizer.ViewModels _localizationService = localizationService; _autostartService = autostartService; - ReminderTask.AgeFormatter = age => string.Format(L("TurnsAge"), age); + ReminderTask.AgeFormatter = (task, years) => + task.Category?.FormatYears(years, ReminderTask.DisplayCulture!(), L) ?? string.Format(L("TurnsAge"), years); + ReminderTask.CategoryLookup = id => + _appData.Categories.FirstOrDefault(c => c.Id == id) ?? _appData.Categories.FirstOrDefault(); ReminderTask.DisplayCulture = () => new System.Globalization.CultureInfo(_localizationService.CurrentLanguage == "de" ? "de-DE" : "en-US"); ReminderTask.RelativeFormatter = RelativeText; // Empty name = refresh every binding (all texts depend on the language). _localizationService.StringsChanged += (s, e) => { + Category.RelocalizePresets(_appData.Categories, L, + new[] { LocalizationService.LoadStrings("en"), LocalizationService.LoadStrings("de") }); + foreach (var t in _allTasks) t.RefreshCategory(); OnPropertyChanged(string.Empty); _tasksView?.Refresh(); // group headers + age texts }; @@ -339,9 +437,11 @@ namespace ReminderOrganizer.ViewModels ExportCsvCommand = new RelayCommand(ExportCsv); ExportIcsCommand = new RelayCommand(ExportIcs); OpenDiscordCommand = new RelayCommand(OpenDiscord); - ShowUpcomingCommand = new RelayCommand(() => IsUpcomingMode = true); + ShowUpcomingCommand = new RelayCommand(() => ShowCategory(null)); + ShowCategoryCommand = new RelayCommand(ShowCategory); UndoCommand = new RelayCommand(Undo); - ClearSearchCommand = new RelayCommand(() => { SearchText = ""; FilterMode = TaskFilterMode.All; }); + ClearSearchCommand = new RelayCommand(() => { SearchText = ""; FilterMode = TaskFilterMode.All; CategoryFilter = null; }); + EditCategoriesCommand = new RelayCommand(EditCategories); _reminderTimer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(30) }; _reminderTimer.Tick += (s, e) => CheckReminders(); @@ -362,7 +462,9 @@ namespace ReminderOrganizer.ViewModels if (firstRun) await SaveAsync(); - if (_appData.MigrateBirthdays() > 0) await SaveAsync(); + bool changed = _appData.EnsureDefaultCategories(L); + changed |= _appData.MigrateBirthdays() > 0; + if (changed) await SaveAsync(); _isDarkMode = _appData.IsDarkMode.Value; _appData.Folders.CollectionChanged += (s, e) => { HookFolders(); ReindexTasks(); }; HookFolders(); @@ -430,16 +532,19 @@ namespace ReminderOrganizer.ViewModels { var view = new ListCollectionView((System.Collections.IList)source) { - CustomSort = new TaskQuery.Comparer(), - Filter = o => o is ReminderTask t && TaskQuery.Matches(t, SearchText, FilterMode, HideDone, DateTime.Now) + CustomSort = new TaskQuery.Comparer(chronological: GroupByMonth), + Filter = o => o is ReminderTask t && TaskQuery.Matches(t, SearchText, FilterMode, HideDone, DateTime.Now, CategoryFilter) }; - if (IsUpcomingMode) + if (GroupByMonth) + view.GroupDescriptions.Add(new PropertyGroupDescription(null, new Converters.MonthKeyConverter())); + else if (IsUpcomingMode) view.GroupDescriptions.Add(new PropertyGroupDescription(null, new Converters.TaskBucketConverter())); _tasksView = view; } OnPropertyChanged(nameof(TasksView)); OnPropertyChanged(nameof(HeaderTitle)); OnPropertyChanged(nameof(HeaderColor)); + OnPropertyChanged(nameof(HeaderGlyph)); OnPropertyChanged(nameof(HasSelectedFolder)); UpdateCounts(); } @@ -461,6 +566,8 @@ namespace ReminderOrganizer.ViewModels OnPropertyChanged(nameof(UpcomingCount)); OnPropertyChanged(nameof(EmptyTitle)); OnPropertyChanged(nameof(EmptyHint)); + OnPropertyChanged(nameof(CategoryNav)); + OnPropertyChanged(nameof(HasCategoryNav)); } // ---------- dialogs ---------- @@ -551,9 +658,15 @@ namespace ReminderOrganizer.ViewModels } // Birthday folders (by name or because they mostly hold birthdays) open the birthday form. - bool birthday = AppData.LooksLikeBirthdayFolder(folder.Name) || - (folder.Tasks.Count > 0 && folder.Tasks.Count(t => t.IsBirthday) * 2 > folder.Tasks.Count); - var taskWindow = new TaskWindow(null, IsDarkMode, birthday) { Owner = Application.Current.MainWindow }; + // Anniversary folders (by name or because they mostly hold anniversaries) open the anniversary form + // with the folder's usual category preselected. + string? category = AppData.CategoryHintForFolder(folder.Name); + var anniversaries = folder.Tasks.Where(t => t.IsAnniversary).ToList(); + if (category == null && anniversaries.Count * 2 > folder.Tasks.Count && anniversaries.Count > 0) + category = anniversaries.GroupBy(t => t.CategoryId ?? Category.BirthdayId).OrderByDescending(g => g.Count()).First().Key; + if (category == null && CategoryFilter is { } cf && cf != TaskQuery.AppointmentsFilter) + category = cf; + var taskWindow = new TaskWindow(null, IsDarkMode, Categories, category) { Owner = Application.Current.MainWindow }; if (taskWindow.ShowDialog() == true) { folder.Tasks.Add(taskWindow.TaskResult); diff --git a/ViewModels/TaskViewModel.cs b/ViewModels/TaskViewModel.cs index 415f96b..02efde8 100644 --- a/ViewModels/TaskViewModel.cs +++ b/ViewModels/TaskViewModel.cs @@ -1,5 +1,7 @@ -#nullable enable +#nullable enable using System; +using System.Collections.Generic; +using System.Linq; using System.Windows.Input; using ReminderOrganizer.Core; using ReminderOrganizer.Models; @@ -69,7 +71,7 @@ namespace ReminderOrganizer.ViewModels } } - public bool IsInPast => !IsBirthday && !IsRecurring && ReminderDate <= DateTime.Now; + public bool IsInPast => !IsAnniversary && !IsRecurring && ReminderDate <= DateTime.Now; // lead reminder: index into LeadOptions public static readonly int[] LeadOptions = { 0, 1, 2, 3, 7 }; @@ -211,8 +213,10 @@ namespace ReminderOrganizer.ViewModels } } - public string WindowTitle => _localizationService.GetString( - IsBirthday ? (_isNewTask ? "NewBirthday" : "EditBirthday") : (_isNewTask ? "NewTask" : "EditTask")); + /// "New birthday", "Edit wedding anniversary", "New task" … + public string WindowTitle => IsAnniversary && SelectedCategory != null + ? string.Format(_localizationService.GetString(_isNewTask ? "NewAnniversaryOf" : "EditAnniversaryOf"), SelectedCategory.Name) + : _localizationService.GetString(_isNewTask ? "NewTask" : "EditTask"); public string NameLabel => _localizationService.GetString("Name"); public string DescriptionLabel => _localizationService.GetString("Description"); @@ -238,7 +242,7 @@ namespace ReminderOrganizer.ViewModels // ---------- birthday mode ---------- private bool _isBirthday; - public bool IsBirthday + public bool IsAnniversary { get => _isBirthday; set @@ -251,7 +255,7 @@ namespace ReminderOrganizer.ViewModels if (value && _isNewTask && SelectedLeadIndex == 0) SelectedLeadIndex = 1; // birthdays: 1 day before by default } } - public bool IsAppointment { get => !IsBirthday; set => IsBirthday = !value; } + public bool IsAppointment { get => !IsAnniversary; set => IsAnniversary = !value; } private string _birthdayText = ""; public string BirthdayText @@ -285,7 +289,9 @@ namespace ReminderOrganizer.ViewModels return _localizationService.GetString(BirthdayInvalid ? "BirthdayInvalid" : "BirthdayHint"); var culture = ReminderTask.DisplayCulture?.Invoke() ?? System.Globalization.CultureInfo.CurrentCulture; var text = next.ToString("ddd, " + ReminderTask.DayMonthPattern(culture) + " yyyy", culture); - if (year is int y) text += " · " + string.Format(_localizationService.GetString("TurnsAge"), next.Year - y); + if (year is int y && next.Year > y) + text += " · " + (SelectedCategory?.FormatYears(next.Year - y, culture, _localizationService.GetString) + ?? string.Format(_localizationService.GetString("TurnsAge"), next.Year - y)); var rel = ReminderTask.RelativeFormatter?.Invoke(next, DateTime.Now); if (!string.IsNullOrEmpty(rel)) text += " · " + rel; return text; @@ -293,23 +299,44 @@ namespace ReminderOrganizer.ViewModels } public string AppointmentText => _localizationService.GetString("TypeAppointment"); - public string BirthdayTypeText => _localizationService.GetString("TypeBirthday"); - public string BirthdayLabel => _localizationService.GetString("BirthdayDate"); + public string BirthdayTypeText => _localizationService.GetString("TypeAnniversary"); + public string BirthdayLabel => _localizationService.GetString("AnniversaryDate"); + public string CategoryLabel => _localizationService.GetString("Category"); public string NoteLabel => _localizationService.GetString("Note"); - public TaskViewModel(ILocalizationService localizationService, ReminderTask? existingTask = null, bool defaultBirthday = false) + // ---------- category ---------- + + public IReadOnlyList Categories { get; } + + private Category? _selectedCategory; + public Category? SelectedCategory + { + get => _selectedCategory; + set + { + if (!SetProperty(ref _selectedCategory, value)) return; + OnPropertyChanged(nameof(BirthdayPreview)); + OnPropertyChanged(nameof(WindowTitle)); + } + } + + public TaskViewModel(ILocalizationService localizationService, ReminderTask? existingTask = null, + string? defaultCategory = null, IEnumerable? categories = null) { _localizationService = localizationService; _isNewTask = existingTask == null; + Categories = (categories ?? Category.Defaults(localizationService.GetString)).ToList(); + var wantedCategory = existingTask?.IsAnniversary == true ? existingTask.CategoryId ?? Category.BirthdayId : defaultCategory; + _selectedCategory = Categories.FirstOrDefault(c => c.Id == wantedCategory) ?? Categories.FirstOrDefault(); if (_isNewTask) { _originalTask = new ReminderTask(); _reminderDate = DateTime.Now.AddHours(1); - _isBirthday = defaultBirthday; - if (defaultBirthday) _selectedLeadIndex = 1; + _isBirthday = defaultCategory != null; + if (_isBirthday) _selectedLeadIndex = 1; } - else if (existingTask!.IsBirthday) + else if (existingTask!.IsAnniversary) { _originalTask = existingTask; _isBirthday = true; @@ -348,7 +375,7 @@ namespace ReminderOrganizer.ViewModels } private bool CanSave() => !string.IsNullOrWhiteSpace(Name) && - (IsBirthday ? TryBirthday(out _, out _) : !BirthYearError); + (IsAnniversary ? TryBirthday(out _, out _) : !BirthYearError); private void ValidateInput() { @@ -388,7 +415,7 @@ namespace ReminderOrganizer.ViewModels { if (!CanSave()) return; - if (IsBirthday && TryBirthday(out var nextBirthday, out var birthYear)) + if (IsAnniversary && TryBirthday(out var nextBirthday, out var birthYear)) { var lead = LeadOptions[SelectedLeadIndex]; // Editing on the birthday itself after it was already reminded: keep next year's date. @@ -396,7 +423,8 @@ namespace ReminderOrganizer.ViewModels nextBirthday = nextBirthday.AddYears(1); if (_isNewTask || _originalTask.ReminderDate != nextBirthday || _originalTask.LeadDays != lead) _originalTask.IsPreNotified = false; - _originalTask.IsBirthday = true; + _originalTask.IsAnniversary = true; + _originalTask.CategoryId = SelectedCategory?.Id ?? Category.BirthdayId; _originalTask.Name = Name.Trim(); _originalTask.Description = Description?.Trim() ?? ""; _originalTask.IsRecurring = true; @@ -408,7 +436,7 @@ namespace ReminderOrganizer.ViewModels RequestClose?.Invoke(this, true); return; } - _originalTask.IsBirthday = false; + _originalTask.IsAnniversary = false; var leadDays = LeadOptions[SelectedLeadIndex]; bool timingChanged = _originalTask.ReminderDate != ReminderDate || _originalTask.LeadDays != leadDays; diff --git a/docs/screenshots/anniversary-dialog.png b/docs/screenshots/anniversary-dialog.png new file mode 100644 index 0000000..5179b95 Binary files /dev/null and b/docs/screenshots/anniversary-dialog.png differ diff --git a/docs/screenshots/categories-months.png b/docs/screenshots/categories-months.png new file mode 100644 index 0000000..c1aea28 Binary files /dev/null and b/docs/screenshots/categories-months.png differ diff --git a/docs/screenshots/category-editor.png b/docs/screenshots/category-editor.png new file mode 100644 index 0000000..3cf750b Binary files /dev/null and b/docs/screenshots/category-editor.png differ