Keyboard shortcuts dialog.

This commit is contained in:
Burak Kaan Köse
2025-10-29 16:26:46 +01:00
parent abaab18eb7
commit b44fb5c45a
25 changed files with 1112 additions and 4 deletions
@@ -0,0 +1,60 @@
using System;
using SQLite;
using Wino.Core.Domain.Enums;
namespace Wino.Core.Domain.Entities.Shared;
/// <summary>
/// Represents a user-defined keyboard shortcut for mail operations.
/// </summary>
public class KeyboardShortcut
{
[PrimaryKey]
public Guid Id { get; set; }
/// <summary>
/// The key combination string (e.g., "D", "Delete", "F1").
/// </summary>
public string Key { get; set; }
/// <summary>
/// The modifier keys for this shortcut.
/// </summary>
public ModifierKeys ModifierKeys { get; set; }
/// <summary>
/// The mail operation this shortcut triggers.
/// </summary>
public MailOperation MailOperation { get; set; }
/// <summary>
/// Whether this shortcut is enabled.
/// </summary>
public bool IsEnabled { get; set; } = true;
/// <summary>
/// When this shortcut was created.
/// </summary>
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
/// <summary>
/// User-friendly display name for the shortcut.
/// </summary>
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;
}
}
}
+16
View File
@@ -0,0 +1,16 @@
using System;
namespace Wino.Core.Domain.Enums;
/// <summary>
/// Defines keyboard modifier keys that can be used in keyboard shortcuts.
/// </summary>
[Flags]
public enum ModifierKeys
{
None = 0,
Control = 1,
Alt = 2,
Shift = 4,
Windows = 8
}
+1
View File
@@ -26,6 +26,7 @@ public enum WinoPage
SettingOptionsPage,
AliasManagementPage,
EditAccountDetailsPage,
KeyboardShortcutsPage,
// Calendar
CalendarPage,
CalendarSettingsPage,
@@ -0,0 +1,65 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Wino.Core.Domain.Entities.Shared;
using Wino.Core.Domain.Enums;
namespace Wino.Core.Domain.Interfaces;
/// <summary>
/// Service for managing keyboard shortcuts for mail operations.
/// </summary>
public interface IKeyboardShortcutService
{
/// <summary>
/// Gets all available keyboard shortcuts.
/// </summary>
/// <returns>Collection of keyboard shortcuts.</returns>
Task<IEnumerable<KeyboardShortcut>> GetKeyboardShortcutsAsync();
/// <summary>
/// Gets enabled keyboard shortcuts only.
/// </summary>
/// <returns>Collection of enabled keyboard shortcuts.</returns>
Task<IEnumerable<KeyboardShortcut>> GetEnabledKeyboardShortcutsAsync();
/// <summary>
/// Creates or updates a keyboard shortcut.
/// </summary>
/// <param name="shortcut">The keyboard shortcut to save.</param>
/// <returns>The saved keyboard shortcut.</returns>
Task<KeyboardShortcut> SaveKeyboardShortcutAsync(KeyboardShortcut shortcut);
/// <summary>
/// Deletes a keyboard shortcut.
/// </summary>
/// <param name="shortcutId">The ID of the shortcut to delete.</param>
Task DeleteKeyboardShortcutAsync(Guid shortcutId);
/// <summary>
/// Gets the mail operation for the given key combination.
/// </summary>
/// <param name="key">The pressed key.</param>
/// <param name="modifierKeys">The modifier keys pressed.</param>
/// <returns>The mail operation if found, otherwise null.</returns>
Task<MailOperation?> GetMailOperationForKeyAsync(string key, ModifierKeys modifierKeys);
/// <summary>
/// Checks if a key combination is already assigned to another shortcut.
/// </summary>
/// <param name="key">The key to check.</param>
/// <param name="modifierKeys">The modifier keys to check.</param>
/// <param name="excludeShortcutId">Optional ID to exclude from the check (for updates).</param>
/// <returns>True if the combination is already used, false otherwise.</returns>
Task<bool> IsKeyCombinationInUseAsync(string key, ModifierKeys modifierKeys, Guid? excludeShortcutId = null);
/// <summary>
/// Creates default keyboard shortcuts for common mail operations.
/// </summary>
Task CreateDefaultShortcutsAsync();
/// <summary>
/// Resets all shortcuts to defaults.
/// </summary>
Task ResetToDefaultShortcutsAsync();
}
@@ -5,6 +5,7 @@ using System.Threading.Tasks;
using Wino.Core.Domain.Entities.Mail;
using Wino.Core.Domain.Entities.Shared;
using Wino.Core.Domain.Enums;
using Wino.Core.Domain.Models;
using Wino.Core.Domain.Models.Folders;
namespace Wino.Core.Domain.Interfaces;
@@ -49,4 +50,13 @@ public interface IMailDialogService : IDialogServiceBase
/// Presents a dialog to the user to show email source.
/// </summary>
Task ShowMessageSourceDialogAsync(string messageSource);
/// <summary>
/// Presents a dialog to the user for keyboard shortcut creation/modification.
/// </summary>
/// <param name="existingShortcut">Existing shortcut to edit, or null for new shortcut.</param>
/// <returns>Dialog result with shortcut information.</returns>
#pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type.
Task<KeyboardShortcutDialogResult> ShowKeyboardShortcutDialogAsync(KeyboardShortcut existingShortcut = null);
#pragma warning restore CS8625
}
@@ -0,0 +1,54 @@
using Wino.Core.Domain.Enums;
namespace Wino.Core.Domain.Models;
/// <summary>
/// Result returned from keyboard shortcut dialog.
/// </summary>
public class KeyboardShortcutDialogResult
{
/// <summary>
/// Whether the dialog was completed successfully.
/// </summary>
public bool IsSuccess { get; set; }
/// <summary>
/// The key combination entered by the user.
/// </summary>
public string Key { get; set; } = string.Empty;
/// <summary>
/// The modifier keys selected by the user.
/// </summary>
public ModifierKeys ModifierKeys { get; set; }
/// <summary>
/// The mail operation selected by the user.
/// </summary>
public MailOperation MailOperation { get; set; }
/// <summary>
/// Creates a successful result.
/// </summary>
public static KeyboardShortcutDialogResult Success(string key, ModifierKeys modifierKeys, MailOperation mailOperation)
{
return new KeyboardShortcutDialogResult
{
IsSuccess = true,
Key = key,
ModifierKeys = modifierKeys,
MailOperation = mailOperation
};
}
/// <summary>
/// Creates a canceled result.
/// </summary>
public static KeyboardShortcutDialogResult Canceled()
{
return new KeyboardShortcutDialogResult
{
IsSuccess = false
};
}
}
@@ -229,6 +229,22 @@
"HoverActionOption_MoveJunk": "Move to Junk",
"HoverActionOption_ToggleFlag": "Flag / Unflag",
"HoverActionOption_ToggleRead": "Read / Unread",
"KeyboardShortcuts_FailedToReset": "Failed to reset keyboard shortcuts.",
"KeyboardShortcuts_FailedToUpdate": "Failed to update keyboard shortcuts",
"KeyboardShortcuts_MailoperationAction": "Action",
"KeyboardShortcuts_FailedToLoad": "Failed to load keyboard shortcuts.",
"KeyboardShortcuts_EnterKeyForShortcut": "Please enter a key for the shortcut.",
"KeyboardShortcuts_SelectOperationForShortcut": "Please an action to perform for the shortcut.",
"KeyboardShortcuts_ShortcutInUse": "This shortcut is already in use by another s hortcut.",
"KeyboardShortcuts_FailedToSave": "Failed to save the shortcut.",
"KeyboardShortcuts_FailedToDelete": "Failed to delete the shortcut.",
"KeyboardShortcuts_PageDescription": "Set up keyboard shortcuts for quick mail operations. Press keys while focused on the key input field to capture shortcuts.",
"KeyboardShortcuts_Add": "Add shortcut",
"KeyboardShortcuts_ResetToDefaults": "Reset to Defaults",
"KeyboardShortcuts_PressKeysHere": "Press keys here...",
"KeyboardShortcuts_KeyCombination": "Key Combination",
"KeyboardShortcuts_FocusArea": "Focus the field above and press the desired key combination",
"KeyboardShortcuts_Modifiers": "Modifier Keys",
"ImageRenderingDisabled": "Image rendering is disabled for this message.",
"ImapAdvancedSetupDialog_AuthenticationMethod": "Authentication method",
"ImapAdvancedSetupDialog_ConnectionSecurity": "Connection security",
@@ -465,6 +481,8 @@
"SearchBarPlaceholder": "Search",
"SearchingIn": "Searching in",
"SearchPivotName": "Results",
"Settings_KeyboardShortcuts_Title": "Keyboard Shortcuts",
"Settings_KeyboardShortcuts_Description": "Manage keyboard shortcuts for quick actions on the mails.",
"SettingConfigureSpecialFolders_Button": "Configure",
"SettingsEditAccountDetails_IMAPConfiguration_Title": "IMAP/SMTP Configuration",
"SettingsEditAccountDetails_IMAPConfiguration_Description": "Change your incoming/outgoing server settings.",