Files
Wino-Mail/Wino.Mail.WinUI/Dialogs/SystemFolderConfigurationDialog.xaml.cs
T

71 lines
2.6 KiB
C#
Raw Normal View History

2025-11-15 14:52:01 +01:00
using System;
2025-09-29 11:16:14 +02:00
using System.Collections.Generic;
using System.Linq;
using Microsoft.UI.Xaml.Controls;
using Wino.Core.Domain;
using Wino.Core.Domain.Entities.Mail;
using Wino.Core.Domain.Enums;
using Wino.Core.Domain.Models.Folders;
namespace Wino.Dialogs;
public sealed partial class SystemFolderConfigurationDialog : ContentDialog
{
private bool canDismissDialog = false;
2025-11-14 18:51:48 +01:00
public SystemFolderConfiguration? Configuration { get; set; }
2025-09-29 11:16:14 +02:00
public List<MailItemFolder> AvailableFolders { get; }
2025-11-14 18:51:48 +01:00
public MailItemFolder? Sent { get; set; }
public MailItemFolder? Draft { get; set; }
public MailItemFolder? Archive { get; set; }
public MailItemFolder? Junk { get; set; }
public MailItemFolder? Trash { get; set; }
2025-09-29 11:16:14 +02:00
public SystemFolderConfigurationDialog(List<MailItemFolder> availableFolders)
{
InitializeComponent();
AvailableFolders = availableFolders;
2025-11-14 18:51:48 +01:00
Sent = AvailableFolders.Find(a => a.SpecialFolderType == SpecialFolderType.Sent);
Draft = AvailableFolders.Find(a => a.SpecialFolderType == SpecialFolderType.Draft);
Archive = AvailableFolders.Find(a => a.SpecialFolderType == SpecialFolderType.Archive);
Junk = AvailableFolders.Find(a => a.SpecialFolderType == SpecialFolderType.Junk);
Trash = AvailableFolders.Find(a => a.SpecialFolderType == SpecialFolderType.Deleted);
2025-09-29 11:16:14 +02:00
}
private void DialogClosing(ContentDialog sender, ContentDialogClosingEventArgs args)
{
args.Cancel = !canDismissDialog;
}
private void CancelClicked(ContentDialog sender, ContentDialogButtonClickEventArgs args)
=> canDismissDialog = true;
private void SaveClicked(ContentDialog sender, ContentDialogButtonClickEventArgs args)
{
2025-11-14 18:51:48 +01:00
ValidationErrorTextBlock!.Text = string.Empty;
2025-09-29 11:16:14 +02:00
2025-11-14 18:51:48 +01:00
var allSpecialFolders = new List<MailItemFolder?>()
2025-09-29 11:16:14 +02:00
{
Sent, Draft, Archive, Trash, Junk
};
if (allSpecialFolders.Any(a => a != null && a.SpecialFolderType == SpecialFolderType.Inbox))
2025-11-14 18:51:48 +01:00
ValidationErrorTextBlock!.Text = Translator.SystemFolderConfigDialogValidation_InboxSelected;
2025-09-29 11:16:14 +02:00
2025-11-14 18:51:48 +01:00
if (new HashSet<Guid>(allSpecialFolders.Where(a => a != null).Select(x => x!.Id)).Count != allSpecialFolders.Where(a => a != null).Count())
ValidationErrorTextBlock!.Text = Translator.SystemFolderConfigDialogValidation_DuplicateSystemFolders;
2025-09-29 11:16:14 +02:00
// Check if we can save.
2025-11-14 18:51:48 +01:00
if (string.IsNullOrEmpty(ValidationErrorTextBlock!.Text))
2025-09-29 11:16:14 +02:00
{
var configuration = new SystemFolderConfiguration(Sent, Draft, Archive, Trash, Junk);
canDismissDialog = true;
Configuration = configuration;
}
}
}