87 lines
2.6 KiB
C#
87 lines
2.6 KiB
C#
using System;
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using Wino.Core.Domain;
|
|
using Wino.Core.Domain.Entities.Shared;
|
|
using Wino.Core.Domain.Enums;
|
|
|
|
namespace Wino.Core.ViewModels.Data;
|
|
|
|
/// <summary>
|
|
/// ViewModel wrapper for KeyboardShortcut entity.
|
|
/// </summary>
|
|
public partial class KeyboardShortcutViewModel : ObservableObject
|
|
{
|
|
[ObservableProperty]
|
|
private bool isEnabled;
|
|
|
|
public Guid Id { get; }
|
|
public string Key { get; }
|
|
public ModifierKeys ModifierKeys { get; }
|
|
public MailOperation MailOperation { get; }
|
|
public DateTime CreatedAt { get; }
|
|
|
|
public string DisplayName
|
|
{
|
|
get
|
|
{
|
|
var modifierText = string.Empty;
|
|
if (ModifierKeys.HasFlag(ModifierKeys.Control))
|
|
modifierText += "Ctrl+";
|
|
if (ModifierKeys.HasFlag(ModifierKeys.Alt))
|
|
modifierText += "Alt+";
|
|
if (ModifierKeys.HasFlag(ModifierKeys.Shift))
|
|
modifierText += "Shift+";
|
|
if (ModifierKeys.HasFlag(ModifierKeys.Windows))
|
|
modifierText += "Win+";
|
|
|
|
return modifierText + Key;
|
|
}
|
|
}
|
|
|
|
public string MailOperationDisplayName
|
|
{
|
|
get
|
|
{
|
|
return MailOperation switch
|
|
{
|
|
MailOperation.Archive => "Archive",
|
|
MailOperation.UnArchive => "Unarchive",
|
|
MailOperation.SoftDelete => "Delete",
|
|
MailOperation.Move => "Move",
|
|
MailOperation.MoveToJunk => "Move to Junk",
|
|
MailOperation.SetFlag => "Set Flag",
|
|
MailOperation.ClearFlag => "Clear Flag",
|
|
MailOperation.MarkAsRead => "Mark as Read",
|
|
MailOperation.MarkAsUnread => "Mark as Unread",
|
|
MailOperation.Reply => "Reply",
|
|
MailOperation.ReplyAll => "Reply All",
|
|
MailOperation.Forward => "Forward",
|
|
_ => MailOperation.ToString()
|
|
};
|
|
}
|
|
}
|
|
|
|
public KeyboardShortcutViewModel(KeyboardShortcut shortcut)
|
|
{
|
|
Id = shortcut.Id;
|
|
Key = shortcut.Key;
|
|
ModifierKeys = shortcut.ModifierKeys;
|
|
MailOperation = shortcut.MailOperation;
|
|
CreatedAt = shortcut.CreatedAt;
|
|
IsEnabled = shortcut.IsEnabled;
|
|
}
|
|
|
|
public KeyboardShortcut ToEntity()
|
|
{
|
|
return new KeyboardShortcut
|
|
{
|
|
Id = Id,
|
|
Key = Key,
|
|
ModifierKeys = ModifierKeys,
|
|
MailOperation = MailOperation,
|
|
CreatedAt = CreatedAt,
|
|
IsEnabled = IsEnabled
|
|
};
|
|
}
|
|
}
|