Upcoming view, search/filters, lead reminders, birthdays, folder colors, ICS, sound, undo
- Upcoming: all folders grouped by overdue/today/tomorrow/7 days/later/done - Search (Ctrl+F) + All/Today/Overdue filters + hide done (persisted) - Lead reminder 1/2/3 days or 1 week before; birth year shows age - Several due reminders are combined into one balloon - Folder colors and reordering (drag, context menu) - iCalendar export with RRULE and VALARM - Generated reminder chime (ComfyUI / Stable Audio), can be turned off - Undo snackbar for deleted tasks/folders (Ctrl+Z), Ctrl+N, Del, Esc - 41 tests Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#nullable enable
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Collections.Specialized;
|
||||
using System.ComponentModel;
|
||||
@@ -25,117 +26,159 @@ namespace ReminderOrganizer.ViewModels
|
||||
private readonly ILocalizationService _localizationService;
|
||||
private readonly IAutostartService _autostartService;
|
||||
private readonly DispatcherTimer _reminderTimer;
|
||||
private readonly DispatcherTimer _undoTimer;
|
||||
|
||||
private AppData _appData = new();
|
||||
private Folder? _selectedFolder;
|
||||
private ReminderTask? _selectedTask;
|
||||
private bool _isLoading;
|
||||
private ICollectionView? _selectedFolderTasksView;
|
||||
private bool _isUpcomingMode;
|
||||
private ListCollectionView? _tasksView;
|
||||
private readonly ObservableCollection<ReminderTask> _allTasks = new();
|
||||
private DateTime _lastRefreshDay = DateTime.Today;
|
||||
|
||||
public bool IsLoading
|
||||
{
|
||||
get => _isLoading;
|
||||
set => SetProperty(ref _isLoading, value);
|
||||
}
|
||||
// ---------- texts ----------
|
||||
|
||||
/// <summary>Localized text for XAML: {Binding [Key]}. Refreshed with OnPropertyChanged("").</summary>
|
||||
public string this[string key] => L(key);
|
||||
public string L(string key) => _localizationService.GetString(key);
|
||||
|
||||
public string CopyrightText => $"© {DateTime.Now.Year} Michael Media";
|
||||
public string VersionText => "v" + (typeof(MainViewModel).Assembly.GetName().Version?.ToString(3) ?? "");
|
||||
|
||||
// ---------- state ----------
|
||||
|
||||
public bool IsLoading { get => _isLoading; set => SetProperty(ref _isLoading, value); }
|
||||
|
||||
public ObservableCollection<Folder> Folders => _appData.Folders;
|
||||
public IReadOnlyList<string> FolderColors => Folder.Palette;
|
||||
|
||||
public Folder? SelectedFolder
|
||||
{
|
||||
get => _selectedFolder;
|
||||
set => SelectFolder(value);
|
||||
}
|
||||
|
||||
/// <summary>Folder chosen in the sidebar (always leaves the "Upcoming" view).</summary>
|
||||
public void SelectFolder(Folder? folder)
|
||||
{
|
||||
bool changed = !ReferenceEquals(_selectedFolder, folder) || _isUpcomingMode;
|
||||
_selectedFolder = folder;
|
||||
_isUpcomingMode = false;
|
||||
if (!changed) return;
|
||||
OnPropertyChanged(nameof(SelectedFolder));
|
||||
OnPropertyChanged(nameof(IsUpcomingMode));
|
||||
RebuildView();
|
||||
}
|
||||
|
||||
public bool IsUpcomingMode
|
||||
{
|
||||
get => _isUpcomingMode;
|
||||
set
|
||||
{
|
||||
var old = _selectedFolder;
|
||||
if (SetProperty(ref _selectedFolder, value))
|
||||
{
|
||||
if (old != null) old.Tasks.CollectionChanged -= OnSelectedTasksChanged;
|
||||
if (value != null) value.Tasks.CollectionChanged += OnSelectedTasksChanged;
|
||||
_selectedFolderTasksView = CreateSortedView(value);
|
||||
OnPropertyChanged(nameof(SelectedFolderTasks));
|
||||
OnPropertyChanged(nameof(SelectedFolderTasksView));
|
||||
OnPropertyChanged(nameof(SelectedFolderName));
|
||||
OnPropertyChanged(nameof(TaskCountText));
|
||||
OnPropertyChanged(nameof(HasSelectedFolder));
|
||||
}
|
||||
if (_isUpcomingMode == value) return;
|
||||
_isUpcomingMode = value;
|
||||
OnPropertyChanged();
|
||||
RebuildView();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnSelectedTasksChanged(object? sender, NotifyCollectionChangedEventArgs e)
|
||||
{
|
||||
OnPropertyChanged(nameof(TaskCountText));
|
||||
}
|
||||
public ReminderTask? SelectedTask { get => _selectedTask; set => SetProperty(ref _selectedTask, value); }
|
||||
|
||||
private static ICollectionView? CreateSortedView(Folder? folder)
|
||||
{
|
||||
if (folder == null) return null;
|
||||
var view = new ListCollectionView(folder.Tasks);
|
||||
view.SortDescriptions.Add(new SortDescription(nameof(ReminderTask.IsNotified), ListSortDirection.Ascending));
|
||||
view.SortDescriptions.Add(new SortDescription(nameof(ReminderTask.ReminderDate), ListSortDirection.Ascending));
|
||||
view.IsLiveSorting = true;
|
||||
view.LiveSortingProperties.Add(nameof(ReminderTask.IsNotified));
|
||||
view.LiveSortingProperties.Add(nameof(ReminderTask.ReminderDate));
|
||||
return view;
|
||||
}
|
||||
|
||||
public ReminderTask? SelectedTask
|
||||
{
|
||||
get => _selectedTask;
|
||||
set => SetProperty(ref _selectedTask, value);
|
||||
}
|
||||
|
||||
public ObservableCollection<ReminderTask>? SelectedFolderTasks => SelectedFolder?.Tasks;
|
||||
|
||||
/// <summary>Tasks of the selected folder: open first, then by date.</summary>
|
||||
public ICollectionView? SelectedFolderTasksView => _selectedFolderTasksView;
|
||||
/// <summary>Tasks shown in the list (folder or all, filtered, sorted, grouped in "Upcoming").</summary>
|
||||
public ICollectionView? TasksView => _tasksView;
|
||||
|
||||
public int VisibleCount { get; private set; }
|
||||
public bool HasVisibleTasks => VisibleCount > 0;
|
||||
public bool HasSelectedFolder => SelectedFolder != null;
|
||||
|
||||
public string SelectedFolderName => SelectedFolder?.Name ?? L("Welcome");
|
||||
public string HeaderTitle => IsUpcomingMode ? L("Upcoming") : SelectedFolder?.Name ?? L("Welcome");
|
||||
public string HeaderColor => IsUpcomingMode ? Folder.DefaultColor : SelectedFolder?.Color ?? Folder.DefaultColor;
|
||||
|
||||
public string TaskCountText => $"{SelectedFolder?.Tasks.Count ?? 0} {L("Tasks")}";
|
||||
public string TaskCountText
|
||||
{
|
||||
get
|
||||
{
|
||||
int total = IsUpcomingMode ? _allTasks.Count : SelectedFolder?.Tasks.Count ?? 0;
|
||||
return IsFiltering && VisibleCount != total
|
||||
? string.Format(L("CountOfTotal"), VisibleCount, total)
|
||||
: $"{total} {L("Tasks")}";
|
||||
}
|
||||
}
|
||||
|
||||
public string AddFolderText => L("AddFolder");
|
||||
public string AddTaskText => L("AddTask");
|
||||
public string AutostartText => L("Autostart");
|
||||
public string ExitText => L("Exit");
|
||||
public string FileText => L("File");
|
||||
public string SettingsText => L("Settings");
|
||||
public string LanguageText => L("Language");
|
||||
public string GermanText => L("German");
|
||||
public string EnglishText => L("English");
|
||||
public string DeleteText => L("Delete");
|
||||
public string RenameText => L("Rename");
|
||||
public string ViewText => L("View");
|
||||
public string DarkModeText => L("DarkMode");
|
||||
public string LightModeText => L("LightMode");
|
||||
public string AddTaskToFolderText => L("AddTaskToFolder");
|
||||
public string MinimizeTooltip => L("Minimize");
|
||||
public string MaximizeTooltip => L("Maximize");
|
||||
public string CloseTooltip => L("Close");
|
||||
public string CreateTaskHint => L("CreateTaskHint");
|
||||
public string NoTasks => L("NoTasks");
|
||||
public string FoldersText => L("Folders");
|
||||
public string NameColumnText => L("Name");
|
||||
public string DateColumnText => L("Date");
|
||||
public string EditTaskTooltip => L("EditTaskTooltip");
|
||||
public string DeleteTaskTooltip => L("DeleteTaskTooltip");
|
||||
public string DoneTooltip => L("DoneTooltip");
|
||||
public string InfoText => L("Info");
|
||||
public string DiscordText => L("Discord");
|
||||
public string ImportText => L("Import");
|
||||
public string ExportText => L("Export");
|
||||
public string ImportCsvText => L("ImportCsv");
|
||||
public string ExportCsvText => L("ExportCsv");
|
||||
public string TestNotificationText => L("TestNotification");
|
||||
public string AppTitleText => L("AppTitle");
|
||||
public string RecurringTaskTooltipText => L("RecurringTaskTooltip");
|
||||
public string CopyrightText => $"© {DateTime.Now.Year} Michael Media";
|
||||
public string VersionText => "v" + (typeof(MainViewModel).Assembly.GetName().Version?.ToString(3) ?? "");
|
||||
/// <summary>Badge on "Upcoming": open tasks that are overdue or due within 7 days.</summary>
|
||||
public int UpcomingCount
|
||||
{
|
||||
get
|
||||
{
|
||||
var now = DateTime.Now;
|
||||
return _allTasks.Count(t => TaskQuery.Bucket(t, now) is TaskBucket.Overdue or TaskBucket.Today or TaskBucket.Tomorrow or TaskBucket.ThisWeek);
|
||||
}
|
||||
}
|
||||
|
||||
public string EmptyTitle => IsFiltering ? L("NoMatches") : L("NoTasks");
|
||||
public string EmptyHint => IsFiltering ? L("NoMatchesHint") : L("CreateTaskHint");
|
||||
|
||||
// ---------- search / filter ----------
|
||||
|
||||
private string _searchText = "";
|
||||
public string SearchText
|
||||
{
|
||||
get => _searchText;
|
||||
set { if (SetProperty(ref _searchText, value ?? "")) RefreshView(); }
|
||||
}
|
||||
|
||||
private TaskFilterMode _filterMode = TaskFilterMode.All;
|
||||
public TaskFilterMode FilterMode
|
||||
{
|
||||
get => _filterMode;
|
||||
set
|
||||
{
|
||||
if (!SetProperty(ref _filterMode, value)) return;
|
||||
OnPropertyChanged(nameof(IsFilterAll));
|
||||
OnPropertyChanged(nameof(IsFilterToday));
|
||||
OnPropertyChanged(nameof(IsFilterOverdue));
|
||||
RefreshView();
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsFilterAll { get => FilterMode == TaskFilterMode.All; set { if (value) FilterMode = TaskFilterMode.All; } }
|
||||
public bool IsFilterToday { get => FilterMode == TaskFilterMode.Today; set { if (value) FilterMode = TaskFilterMode.Today; } }
|
||||
public bool IsFilterOverdue { get => FilterMode == TaskFilterMode.Overdue; set { if (value) FilterMode = TaskFilterMode.Overdue; } }
|
||||
|
||||
public bool HideDone
|
||||
{
|
||||
get => _appData.HideDone;
|
||||
set
|
||||
{
|
||||
if (_appData.HideDone == value) return;
|
||||
_appData.HideDone = value;
|
||||
OnPropertyChanged();
|
||||
RefreshView();
|
||||
_ = SaveAsync();
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsFiltering => !string.IsNullOrWhiteSpace(SearchText) || FilterMode != TaskFilterMode.All || HideDone;
|
||||
|
||||
// ---------- settings ----------
|
||||
|
||||
public bool IsGerman => _localizationService.CurrentLanguage == "de";
|
||||
public bool IsEnglish => _localizationService.CurrentLanguage == "en";
|
||||
public bool IsAutostartEnabled => _autostartService.IsAutostartEnabled;
|
||||
|
||||
public bool PlaySound
|
||||
{
|
||||
get => _appData.PlaySound;
|
||||
set
|
||||
{
|
||||
if (_appData.PlaySound == value) return;
|
||||
_appData.PlaySound = value;
|
||||
OnPropertyChanged();
|
||||
_ = SaveAsync();
|
||||
}
|
||||
}
|
||||
|
||||
private bool _isDarkMode = true;
|
||||
public bool IsDarkMode
|
||||
{
|
||||
@@ -151,6 +194,40 @@ namespace ReminderOrganizer.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- undo ----------
|
||||
|
||||
private Action? _undoAction;
|
||||
private string _undoText = "";
|
||||
public string UndoText { get => _undoText; private set => SetProperty(ref _undoText, value); }
|
||||
public bool IsUndoVisible => _undoAction != null;
|
||||
|
||||
private void OfferUndo(string text, Action undo)
|
||||
{
|
||||
_undoAction = undo;
|
||||
UndoText = text;
|
||||
OnPropertyChanged(nameof(IsUndoVisible));
|
||||
_undoTimer.Stop();
|
||||
_undoTimer.Start();
|
||||
}
|
||||
|
||||
private void HideUndo()
|
||||
{
|
||||
_undoTimer.Stop();
|
||||
_undoAction = null;
|
||||
OnPropertyChanged(nameof(IsUndoVisible));
|
||||
}
|
||||
|
||||
private void Undo()
|
||||
{
|
||||
var action = _undoAction;
|
||||
HideUndo();
|
||||
if (action == null) return;
|
||||
action();
|
||||
_ = SaveAsync();
|
||||
}
|
||||
|
||||
// ---------- events / commands ----------
|
||||
|
||||
public event EventHandler<bool>? ThemeChanged;
|
||||
public event EventHandler<ReminderTask?>? EditTaskRequested;
|
||||
|
||||
@@ -164,15 +241,23 @@ namespace ReminderOrganizer.ViewModels
|
||||
public ICommand ExitCommand { get; }
|
||||
public ICommand DeleteFolderCommand { get; }
|
||||
public ICommand RenameFolderCommand { get; }
|
||||
public ICommand MoveFolderUpCommand { get; }
|
||||
public ICommand MoveFolderDownCommand { get; }
|
||||
public ICommand SetFolderColorCommand { get; }
|
||||
public ICommand SaveFolderCommand { get; }
|
||||
public ICommand SetLanguageDeCommand { get; }
|
||||
public ICommand SetLanguageEnCommand { get; }
|
||||
public ICommand ToggleDarkModeCommand { get; }
|
||||
public ICommand TogglePlaySoundCommand { get; }
|
||||
public ICommand MoveTaskToFolderCommand { get; }
|
||||
public ICommand TestNotificationCommand { get; }
|
||||
public ICommand ImportCsvCommand { get; }
|
||||
public ICommand ExportCsvCommand { get; }
|
||||
public ICommand ExportIcsCommand { get; }
|
||||
public ICommand OpenDiscordCommand { get; }
|
||||
public ICommand ShowUpcomingCommand { get; }
|
||||
public ICommand UndoCommand { get; }
|
||||
public ICommand ClearSearchCommand { get; }
|
||||
|
||||
public MainViewModel(
|
||||
IDataService dataService,
|
||||
@@ -185,31 +270,47 @@ namespace ReminderOrganizer.ViewModels
|
||||
_localizationService = localizationService;
|
||||
_autostartService = autostartService;
|
||||
|
||||
ReminderTask.AgeFormatter = age => string.Format(L("TurnsAge"), age);
|
||||
|
||||
// Empty name = refresh every binding (all texts depend on the language).
|
||||
_localizationService.StringsChanged += (s, e) => OnPropertyChanged(string.Empty);
|
||||
_localizationService.StringsChanged += (s, e) =>
|
||||
{
|
||||
OnPropertyChanged(string.Empty);
|
||||
_tasksView?.Refresh(); // group headers + age texts
|
||||
};
|
||||
|
||||
AddFolderCommand = new RelayCommand(AddFolder);
|
||||
AddTaskCommand = new RelayCommand(AddTask, () => SelectedFolder != null);
|
||||
AddTaskCommand = new RelayCommand(AddTask, () => Folders.Count > 0);
|
||||
AddTaskToFolderCommand = new RelayCommand<Folder>(AddTaskToFolder);
|
||||
DeleteTaskCommand = new RelayCommand<ReminderTask>(DeleteTask);
|
||||
EditTaskCommand = new RelayCommand<ReminderTask>(EditTask);
|
||||
ToggleDoneCommand = new RelayCommand<ReminderTask>(t => { _ = SaveAsync(); });
|
||||
DeleteFolderCommand = new RelayCommand(DeleteFolder, () => SelectedFolder != null);
|
||||
RenameFolderCommand = new RelayCommand(RenameFolder, () => SelectedFolder != null);
|
||||
MoveFolderUpCommand = new RelayCommand(() => MoveFolderBy(-1), () => SelectedFolder != null && Folders.IndexOf(SelectedFolder) > 0);
|
||||
MoveFolderDownCommand = new RelayCommand(() => MoveFolderBy(1), () => SelectedFolder != null && Folders.IndexOf(SelectedFolder) < Folders.Count - 1);
|
||||
SetFolderColorCommand = new RelayCommand<string>(SetFolderColor);
|
||||
SaveFolderCommand = new RelayCommand(async () => await SaveAsync());
|
||||
ToggleAutostartCommand = new RelayCommand(ToggleAutostart);
|
||||
SetLanguageDeCommand = new RelayCommand(() => _localizationService.SetLanguage("de"));
|
||||
SetLanguageEnCommand = new RelayCommand(() => _localizationService.SetLanguage("en"));
|
||||
ToggleDarkModeCommand = new RelayCommand(() => IsDarkMode = !IsDarkMode);
|
||||
TogglePlaySoundCommand = new RelayCommand(() => PlaySound = !PlaySound);
|
||||
ExitCommand = new RelayCommand(() => Application.Current.Shutdown());
|
||||
MoveTaskToFolderCommand = new RelayCommand<(ReminderTask, Folder)>(MoveTaskToFolder);
|
||||
TestNotificationCommand = new RelayCommand(TestNotification);
|
||||
ImportCsvCommand = new RelayCommand(ImportCsv);
|
||||
ExportCsvCommand = new RelayCommand(ExportCsv);
|
||||
ExportIcsCommand = new RelayCommand(ExportIcs);
|
||||
OpenDiscordCommand = new RelayCommand(OpenDiscord);
|
||||
ShowUpcomingCommand = new RelayCommand(() => IsUpcomingMode = true);
|
||||
UndoCommand = new RelayCommand(Undo);
|
||||
ClearSearchCommand = new RelayCommand(() => { SearchText = ""; FilterMode = TaskFilterMode.All; });
|
||||
|
||||
_reminderTimer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(30) };
|
||||
_reminderTimer.Tick += (s, e) => CheckReminders();
|
||||
_undoTimer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(7) };
|
||||
_undoTimer.Tick += (s, e) => HideUndo();
|
||||
}
|
||||
|
||||
public async Task InitializeAsync()
|
||||
@@ -226,20 +327,106 @@ namespace ReminderOrganizer.ViewModels
|
||||
await SaveAsync();
|
||||
|
||||
_isDarkMode = _appData.IsDarkMode.Value;
|
||||
OnPropertyChanged(nameof(IsDarkMode));
|
||||
OnPropertyChanged(nameof(Folders));
|
||||
SelectedFolder = _appData.Folders.FirstOrDefault();
|
||||
_appData.Folders.CollectionChanged += (s, e) => { HookFolders(); ReindexTasks(); };
|
||||
HookFolders();
|
||||
ReindexTasks();
|
||||
|
||||
OnPropertyChanged(string.Empty);
|
||||
SelectFolder(_appData.Folders.FirstOrDefault());
|
||||
|
||||
CheckReminders(); // catch up on reminders missed while the app was closed
|
||||
_reminderTimer.Start();
|
||||
IsLoading = false;
|
||||
}
|
||||
|
||||
public string L(string key) => _localizationService.GetString(key);
|
||||
// ---------- task index / view ----------
|
||||
|
||||
private bool Confirm(string message) =>
|
||||
MessageBox.Show(Application.Current.MainWindow, message, L("AppTitle"),
|
||||
MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes;
|
||||
private readonly HashSet<Folder> _hooked = new();
|
||||
|
||||
private void HookFolders()
|
||||
{
|
||||
foreach (var f in _appData.Folders)
|
||||
{
|
||||
if (!_hooked.Add(f)) continue;
|
||||
f.Tasks.CollectionChanged += OnFolderTasksChanged;
|
||||
f.PropertyChanged += OnFolderPropertyChanged;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnFolderTasksChanged(object? sender, NotifyCollectionChangedEventArgs e) => ReindexTasks();
|
||||
|
||||
private void OnFolderPropertyChanged(object? sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName is nameof(Folder.Name) or nameof(Folder.Color))
|
||||
{
|
||||
ReindexTasks();
|
||||
OnPropertyChanged(nameof(HeaderTitle));
|
||||
OnPropertyChanged(nameof(HeaderColor));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Keeps the flat list for "Upcoming" and each task's folder name/color in sync.</summary>
|
||||
private void ReindexTasks()
|
||||
{
|
||||
_allTasks.Clear();
|
||||
foreach (var f in _appData.Folders)
|
||||
{
|
||||
if (!_appData.Folders.Contains(f)) continue;
|
||||
foreach (var t in f.Tasks)
|
||||
{
|
||||
t.FolderName = f.Name;
|
||||
t.FolderColor = f.Color;
|
||||
_allTasks.Add(t);
|
||||
}
|
||||
}
|
||||
UpdateCounts();
|
||||
}
|
||||
|
||||
private void RebuildView()
|
||||
{
|
||||
IEnumerable<ReminderTask>? source = IsUpcomingMode ? _allTasks : SelectedFolder?.Tasks;
|
||||
if (source == null)
|
||||
{
|
||||
_tasksView = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
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)
|
||||
};
|
||||
if (IsUpcomingMode)
|
||||
view.GroupDescriptions.Add(new PropertyGroupDescription(null, new Converters.TaskBucketConverter()));
|
||||
_tasksView = view;
|
||||
}
|
||||
OnPropertyChanged(nameof(TasksView));
|
||||
OnPropertyChanged(nameof(HeaderTitle));
|
||||
OnPropertyChanged(nameof(HeaderColor));
|
||||
OnPropertyChanged(nameof(HasSelectedFolder));
|
||||
UpdateCounts();
|
||||
}
|
||||
|
||||
/// <summary>Re-applies filter, sort and groups (after edits, search, time passing).</summary>
|
||||
public void RefreshView()
|
||||
{
|
||||
_tasksView?.Refresh();
|
||||
_lastRefreshDay = DateTime.Today;
|
||||
UpdateCounts();
|
||||
}
|
||||
|
||||
private void UpdateCounts()
|
||||
{
|
||||
VisibleCount = _tasksView?.Cast<object>().Count() ?? 0;
|
||||
OnPropertyChanged(nameof(VisibleCount));
|
||||
OnPropertyChanged(nameof(HasVisibleTasks));
|
||||
OnPropertyChanged(nameof(TaskCountText));
|
||||
OnPropertyChanged(nameof(UpcomingCount));
|
||||
OnPropertyChanged(nameof(EmptyTitle));
|
||||
OnPropertyChanged(nameof(EmptyHint));
|
||||
}
|
||||
|
||||
// ---------- dialogs ----------
|
||||
|
||||
private string? AskName(string title, string current)
|
||||
{
|
||||
@@ -249,13 +436,15 @@ namespace ReminderOrganizer.ViewModels
|
||||
return string.IsNullOrEmpty(name) ? null : name;
|
||||
}
|
||||
|
||||
// ---------- folders ----------
|
||||
|
||||
private void AddFolder()
|
||||
{
|
||||
var name = AskName(L("NewFolder"), L("NewFolder"));
|
||||
if (name == null) return;
|
||||
var folder = new Folder(name);
|
||||
_appData.Folders.Add(folder);
|
||||
SelectedFolder = folder;
|
||||
SelectFolder(folder);
|
||||
_ = SaveAsync();
|
||||
}
|
||||
|
||||
@@ -265,23 +454,54 @@ namespace ReminderOrganizer.ViewModels
|
||||
var name = AskName(L("RenameFolder"), SelectedFolder.Name);
|
||||
if (name == null) return;
|
||||
SelectedFolder.Name = name;
|
||||
OnPropertyChanged(nameof(SelectedFolderName));
|
||||
_ = SaveAsync();
|
||||
}
|
||||
|
||||
private void DeleteFolder()
|
||||
{
|
||||
if (SelectedFolder == null) return;
|
||||
if (SelectedFolder.Tasks.Count > 0 &&
|
||||
!Confirm(string.Format(L("ConfirmDeleteFolder"), SelectedFolder.Name, SelectedFolder.Tasks.Count)))
|
||||
return;
|
||||
var folder = SelectedFolder;
|
||||
if (folder == null) return;
|
||||
int index = _appData.Folders.IndexOf(folder);
|
||||
_appData.Folders.Remove(folder);
|
||||
_hooked.Remove(folder);
|
||||
folder.Tasks.CollectionChanged -= OnFolderTasksChanged;
|
||||
folder.PropertyChanged -= OnFolderPropertyChanged;
|
||||
SelectFolder(_appData.Folders.ElementAtOrDefault(Math.Max(0, index - 1)));
|
||||
_ = SaveAsync();
|
||||
|
||||
_appData.Folders.Remove(SelectedFolder);
|
||||
SelectedFolder = _appData.Folders.FirstOrDefault();
|
||||
OfferUndo(string.Format(L("DeletedItem"), folder.Name), () =>
|
||||
{
|
||||
_appData.Folders.Insert(Math.Min(index, _appData.Folders.Count), folder);
|
||||
SelectFolder(folder);
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>Moves a folder to a new position (drag & drop or up/down).</summary>
|
||||
public void MoveFolder(Folder folder, int newIndex)
|
||||
{
|
||||
int old = _appData.Folders.IndexOf(folder);
|
||||
newIndex = Math.Clamp(newIndex, 0, _appData.Folders.Count - 1);
|
||||
if (old < 0 || old == newIndex) return;
|
||||
_appData.Folders.Move(old, newIndex);
|
||||
_ = SaveAsync();
|
||||
}
|
||||
|
||||
private void AddTask() => AddTaskInternal(SelectedFolder);
|
||||
private void MoveFolderBy(int delta)
|
||||
{
|
||||
if (SelectedFolder != null)
|
||||
MoveFolder(SelectedFolder, _appData.Folders.IndexOf(SelectedFolder) + delta);
|
||||
}
|
||||
|
||||
private void SetFolderColor(string? color)
|
||||
{
|
||||
if (SelectedFolder == null || string.IsNullOrEmpty(color)) return;
|
||||
SelectedFolder.Color = color;
|
||||
_ = SaveAsync();
|
||||
}
|
||||
|
||||
// ---------- tasks ----------
|
||||
|
||||
private void AddTask() => AddTaskInternal(SelectedFolder ?? Folders.FirstOrDefault());
|
||||
|
||||
private void AddTaskToFolder(Folder? folder) => AddTaskInternal(folder);
|
||||
|
||||
@@ -306,9 +526,15 @@ namespace ReminderOrganizer.ViewModels
|
||||
if (task == null) return;
|
||||
var folder = _appData.Folders.FirstOrDefault(f => f.Tasks.Contains(task));
|
||||
if (folder == null) return;
|
||||
if (!Confirm(string.Format(L("ConfirmDeleteTask"), task.Name))) return;
|
||||
int index = folder.Tasks.IndexOf(task);
|
||||
folder.Tasks.Remove(task);
|
||||
_ = SaveAsync();
|
||||
|
||||
OfferUndo(string.Format(L("DeletedItem"), task.Name), () =>
|
||||
{
|
||||
if (!_appData.Folders.Contains(folder)) return;
|
||||
folder.Tasks.Insert(Math.Min(index, folder.Tasks.Count), task);
|
||||
});
|
||||
}
|
||||
|
||||
private void MoveTaskToFolder((ReminderTask Task, Folder TargetFolder) args)
|
||||
@@ -331,6 +557,8 @@ namespace ReminderOrganizer.ViewModels
|
||||
EditTaskRequested?.Invoke(this, task);
|
||||
}
|
||||
|
||||
// ---------- reminders ----------
|
||||
|
||||
private void ToggleAutostart()
|
||||
{
|
||||
_autostartService.ToggleAutostart();
|
||||
@@ -339,20 +567,56 @@ namespace ReminderOrganizer.ViewModels
|
||||
_autostartService.IsAutostartEnabled ? L("AutostartEnabled") : L("AutostartDisabled"));
|
||||
}
|
||||
|
||||
private string WhenText(DateTime date, DateTime now)
|
||||
{
|
||||
int days = (date.Date - now.Date).Days;
|
||||
return days switch
|
||||
{
|
||||
<= 0 => string.Format(L("TodayAt"), date.ToString("HH:mm")),
|
||||
1 => string.Format(L("TomorrowAt"), date.ToString("HH:mm")),
|
||||
_ => string.Format(L("InDays"), days)
|
||||
};
|
||||
}
|
||||
|
||||
private void CheckReminders()
|
||||
{
|
||||
var due = ReminderTask.ProcessDue(_appData.Folders, DateTime.Now);
|
||||
foreach (var task in due)
|
||||
var now = DateTime.Now;
|
||||
var due = ReminderTask.ProcessDue(_appData.Folders, now);
|
||||
|
||||
if (due.Count == 1)
|
||||
{
|
||||
var body = string.IsNullOrWhiteSpace(task.Description) ? L("Reminder") : task.Description;
|
||||
_notificationService.ShowNotification($"🔔 {task.Name}", body);
|
||||
var d = due[0];
|
||||
var title = d.IsLead ? $"⏰ {d.Task.Name} · {WhenText(d.Date, now)}" : $"🔔 {d.Task.Name}";
|
||||
var parts = new List<string>();
|
||||
if (d.Age is int age) parts.Add(string.Format(L("TurnsAge"), age));
|
||||
if (!string.IsNullOrWhiteSpace(d.Task.Description)) parts.Add(d.Task.Description);
|
||||
if (parts.Count == 0) parts.Add(d.IsLead ? d.Date.ToString("dd.MM.yyyy HH:mm") : L("Reminder"));
|
||||
_notificationService.ShowNotification(title, string.Join(" · ", parts));
|
||||
}
|
||||
else if (due.Count > 1)
|
||||
{
|
||||
// A balloon replaces the previous one – show one summary instead of losing reminders.
|
||||
var lines = due.Take(6).Select(d => (d.IsLead ? "⏰ " : "🔔 ") + d.Task.Name +
|
||||
(d.IsLead ? $" ({WhenText(d.Date, now)})" : ""));
|
||||
var body = string.Join("\n", lines) + (due.Count > 6 ? "\n…" : "");
|
||||
_notificationService.ShowNotification(string.Format(L("RemindersCount"), due.Count), body);
|
||||
}
|
||||
|
||||
if (due.Count > 0)
|
||||
{
|
||||
if (PlaySound) SoundService.PlayReminder();
|
||||
_ = SaveAsync();
|
||||
}
|
||||
else if (_lastRefreshDay != DateTime.Today)
|
||||
{
|
||||
RefreshView(); // "today"/"tomorrow" groups move at midnight
|
||||
}
|
||||
if (due.Count > 0) _ = SaveAsync();
|
||||
}
|
||||
|
||||
private void TestNotification()
|
||||
{
|
||||
_notificationService.ShowNotification(L("TestNotificationTitle"), L("TestNotificationMessage"));
|
||||
if (PlaySound) SoundService.PlayReminder();
|
||||
}
|
||||
|
||||
private void OpenDiscord()
|
||||
@@ -371,6 +635,8 @@ namespace ReminderOrganizer.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- import / export ----------
|
||||
|
||||
private void ImportCsv()
|
||||
{
|
||||
var dialog = new Microsoft.Win32.OpenFileDialog
|
||||
@@ -384,7 +650,6 @@ namespace ReminderOrganizer.ViewModels
|
||||
{
|
||||
var (imported, skipped) = TaskCsv.Import(System.IO.File.ReadAllText(dialog.FileName), _appData);
|
||||
_ = SaveAsync();
|
||||
OnPropertyChanged(nameof(TaskCountText));
|
||||
|
||||
var msg = string.Format(L("ImportSuccess"), imported);
|
||||
if (skipped > 0) msg += " " + string.Format(L("ImportSkipped"), skipped);
|
||||
@@ -396,20 +661,21 @@ namespace ReminderOrganizer.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
private void ExportCsv()
|
||||
private void ExportCsv() =>
|
||||
SaveTextFile("CSV (*.csv)|*.csv", "tasks.csv", L("ExportCsv"), () => TaskCsv.Export(_appData));
|
||||
|
||||
private void ExportIcs() =>
|
||||
SaveTextFile("iCalendar (*.ics)|*.ics", "reminders.ics", L("ExportIcs"), () => IcsExport.Build(_appData, DateTime.UtcNow));
|
||||
|
||||
private void SaveTextFile(string filter, string fileName, string title, Func<string> content)
|
||||
{
|
||||
var dialog = new Microsoft.Win32.SaveFileDialog
|
||||
{
|
||||
Filter = "CSV (*.csv)|*.csv",
|
||||
Title = L("ExportCsv"),
|
||||
FileName = "tasks.csv"
|
||||
};
|
||||
var dialog = new Microsoft.Win32.SaveFileDialog { Filter = filter, Title = title, FileName = fileName };
|
||||
if (dialog.ShowDialog() != true) return;
|
||||
|
||||
try
|
||||
{
|
||||
// UTF-8 with BOM so Excel shows umlauts correctly.
|
||||
System.IO.File.WriteAllText(dialog.FileName, TaskCsv.Export(_appData), new UTF8Encoding(true));
|
||||
// UTF-8 with BOM so Excel shows umlauts correctly (calendars accept it too).
|
||||
System.IO.File.WriteAllText(dialog.FileName, content(), new UTF8Encoding(true));
|
||||
MessageBox.Show(L("ExportSuccess"), L("AppTitle"));
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -418,8 +684,11 @@ namespace ReminderOrganizer.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- persistence ----------
|
||||
|
||||
public async Task SaveAsync()
|
||||
{
|
||||
RefreshView();
|
||||
try
|
||||
{
|
||||
await _dataService.SaveAsync(_appData);
|
||||
|
||||
@@ -70,6 +70,34 @@ namespace ReminderOrganizer.ViewModels
|
||||
}
|
||||
|
||||
public bool IsInPast => !IsRecurring && ReminderDate <= DateTime.Now;
|
||||
|
||||
// lead reminder: index into LeadOptions
|
||||
public static readonly int[] LeadOptions = { 0, 1, 2, 3, 7 };
|
||||
private int _selectedLeadIndex;
|
||||
public int SelectedLeadIndex
|
||||
{
|
||||
get => _selectedLeadIndex;
|
||||
set => SetProperty(ref _selectedLeadIndex, Math.Clamp(value, 0, LeadOptions.Length - 1));
|
||||
}
|
||||
public string LeadLabel => _localizationService.GetString("LeadReminder");
|
||||
public string LeadNone => _localizationService.GetString("LeadNone");
|
||||
public string Lead1 => _localizationService.GetString("LeadOneDay");
|
||||
public string Lead2 => string.Format(_localizationService.GetString("LeadDays"), 2);
|
||||
public string Lead3 => string.Format(_localizationService.GetString("LeadDays"), 3);
|
||||
public string Lead7 => _localizationService.GetString("LeadWeek");
|
||||
|
||||
// birthday
|
||||
private string _birthYearText = "";
|
||||
public string BirthYearText
|
||||
{
|
||||
get => _birthYearText;
|
||||
set { if (SetProperty(ref _birthYearText, value ?? "")) OnPropertyChanged(nameof(BirthYearError)); }
|
||||
}
|
||||
public int? ParsedBirthYear =>
|
||||
int.TryParse(BirthYearText.Trim(), out var y) && y >= 1900 && y <= DateTime.Now.Year ? y : null;
|
||||
public bool BirthYearError => BirthYearText.Trim().Length > 0 && ParsedBirthYear == null;
|
||||
public bool IsYearly => IsRecurring && SelectedRecurrenceIndex == (int)RecurrenceType.Yearly;
|
||||
public string BirthYearLabel => _localizationService.GetString("BirthYear");
|
||||
public string PastDateWarning => _localizationService.GetString("PastDateWarning");
|
||||
public string NextOccurrenceLabel => _localizationService.GetString("NextOccurrence");
|
||||
public string QuickLabel => _localizationService.GetString("Quick");
|
||||
@@ -121,6 +149,7 @@ namespace ReminderOrganizer.ViewModels
|
||||
{
|
||||
// Only copied to the task in Save() – Cancel must not change anything.
|
||||
SetProperty(ref _isRecurring, value);
|
||||
OnPropertyChanged(nameof(IsYearly));
|
||||
OnPropertyChanged(nameof(NextOccurrenceText));
|
||||
OnPropertyChanged(nameof(IsInPast));
|
||||
}
|
||||
@@ -133,6 +162,7 @@ namespace ReminderOrganizer.ViewModels
|
||||
{
|
||||
if (value < 0) return;
|
||||
SetProperty(ref _selectedRecurrenceIndex, value);
|
||||
OnPropertyChanged(nameof(IsYearly));
|
||||
OnPropertyChanged(nameof(IsDailySelected));
|
||||
OnPropertyChanged(nameof(IsWeeklySelected));
|
||||
OnPropertyChanged(nameof(IsMonthlySelected));
|
||||
@@ -224,6 +254,8 @@ namespace ReminderOrganizer.ViewModels
|
||||
_reminderDate = existingTask.ReminderDate;
|
||||
_isRecurring = existingTask.IsRecurring;
|
||||
_selectedRecurrenceIndex = (int)existingTask.RecurrenceType;
|
||||
_selectedLeadIndex = Math.Max(0, Array.IndexOf(LeadOptions, existingTask.LeadDays));
|
||||
_birthYearText = existingTask.BirthYear?.ToString() ?? "";
|
||||
}
|
||||
|
||||
SaveCommand = new RelayCommand(Save, CanSave);
|
||||
@@ -239,7 +271,7 @@ namespace ReminderOrganizer.ViewModels
|
||||
OnPropertyChanged(nameof(SelectedMinuteIndex));
|
||||
}
|
||||
|
||||
private bool CanSave() => !string.IsNullOrWhiteSpace(Name);
|
||||
private bool CanSave() => !string.IsNullOrWhiteSpace(Name) && !BirthYearError;
|
||||
|
||||
private void ValidateInput()
|
||||
{
|
||||
@@ -279,6 +311,12 @@ namespace ReminderOrganizer.ViewModels
|
||||
{
|
||||
if (!CanSave()) return;
|
||||
|
||||
var leadDays = LeadOptions[SelectedLeadIndex];
|
||||
bool timingChanged = _originalTask.ReminderDate != ReminderDate || _originalTask.LeadDays != leadDays;
|
||||
_originalTask.LeadDays = leadDays;
|
||||
_originalTask.BirthYear = IsYearly ? ParsedBirthYear : null;
|
||||
if (timingChanged || _isNewTask) _originalTask.IsPreNotified = false;
|
||||
|
||||
_originalTask.Name = Name.Trim();
|
||||
_originalTask.Description = Description?.Trim() ?? "";
|
||||
_originalTask.IsRecurring = IsRecurring;
|
||||
|
||||
Reference in New Issue
Block a user