Files
Wino-Mail/Wino.Core.Domain/MenuItems/FolderMenuItem.cs
T

83 lines
3.0 KiB
C#
Raw Normal View History

2024-04-18 01:44:37 +02:00
using System.Collections.Generic;
2025-10-06 17:46:00 +02:00
using System.Collections.ObjectModel;
2024-04-18 01:44:37 +02:00
using System.Linq;
using CommunityToolkit.Mvvm.ComponentModel;
2024-11-10 23:28:25 +01:00
using Wino.Core.Domain.Entities.Shared;
2024-04-18 01:44:37 +02:00
using Wino.Core.Domain.Enums;
using Wino.Core.Domain.Interfaces;
using Wino.Core.Domain.Models.Folders;
2025-02-16 11:54:23 +01:00
namespace Wino.Core.Domain.MenuItems;
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
public partial class FolderMenuItem : MenuItemBase<IMailItemFolder, FolderMenuItem>, IFolderMenuItem
{
[ObservableProperty]
private int unreadItemCount;
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
public bool HasTextColor => !string.IsNullOrEmpty(Parameter.TextColorHex);
public bool IsMoveTarget => HandlingFolders.All(a => a.IsMoveTarget);
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
public SpecialFolderType SpecialFolderType => Parameter.SpecialFolderType;
public bool IsSticky => Parameter.IsSticky;
public bool IsSystemFolder => Parameter.IsSystemFolder;
2024-04-18 01:44:37 +02:00
2025-10-06 17:46:00 +02:00
2025-02-16 11:54:23 +01:00
/// <summary>
/// Display name of the folder. More and Category folders have localized display names.
/// </summary>
public string FolderName
{
get
2025-02-16 11:43:30 +01:00
{
2025-02-16 11:54:23 +01:00
if (Parameter.SpecialFolderType == SpecialFolderType.More)
return Translator.MoreFolderNameOverride;
else if (Parameter.SpecialFolderType == SpecialFolderType.Category)
return Translator.CategoriesFolderNameOverride;
2025-02-23 17:05:46 +01:00
else if (Parameter.SpecialFolderType == SpecialFolderType.Archive && ParentAccount.ProviderType == MailProviderType.Gmail)
return Translator.GmailArchiveFolderNameOverride;
2025-02-16 11:54:23 +01:00
else
return Parameter.FolderName;
2025-02-16 11:43:30 +01:00
}
2025-02-16 11:54:23 +01:00
set => SetProperty(Parameter.FolderName, value, Parameter, (u, n) => u.FolderName = n);
}
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
public bool IsSynchronizationEnabled
{
get => Parameter.IsSynchronizationEnabled;
set => SetProperty(Parameter.IsSynchronizationEnabled, value, Parameter, (u, n) => u.IsSynchronizationEnabled = n);
}
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
public IEnumerable<IMailItemFolder> HandlingFolders => new List<IMailItemFolder>() { Parameter };
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
public MailAccount ParentAccount { get; private set; }
2025-02-16 11:54:23 +01:00
public string AssignedAccountName => ParentAccount?.Name;
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
public bool ShowUnreadCount => Parameter.ShowUnreadCount;
2024-04-18 01:44:37 +02:00
2025-10-06 17:46:00 +02:00
public new ObservableCollection<IMenuItem> SubMenuItems { get; set; } = new ObservableCollection<IMenuItem>();
2024-06-09 02:59:07 +02:00
2025-02-16 11:54:23 +01:00
public FolderMenuItem(IMailItemFolder folderStructure, MailAccount parentAccount, IMenuItem parentMenuItem) : base(folderStructure, folderStructure.Id, parentMenuItem)
{
ParentAccount = parentAccount;
}
2025-02-16 11:35:43 +01:00
2025-02-16 11:54:23 +01:00
public void UpdateFolder(IMailItemFolder folder)
{
Parameter = folder;
2025-02-16 11:35:43 +01:00
2025-02-16 11:54:23 +01:00
OnPropertyChanged(nameof(IsSynchronizationEnabled));
OnPropertyChanged(nameof(ShowUnreadCount));
OnPropertyChanged(nameof(HasTextColor));
OnPropertyChanged(nameof(IsSystemFolder));
OnPropertyChanged(nameof(SpecialFolderType));
OnPropertyChanged(nameof(IsSticky));
OnPropertyChanged(nameof(FolderName));
2025-02-16 11:43:30 +01:00
}
2025-02-16 11:54:23 +01:00
public override string ToString() => FolderName;
public void UpdateParentAccounnt(MailAccount account) => ParentAccount = account;
2024-04-18 01:44:37 +02:00
}