From 2b6f4d4e08e695b75216553b002a9c61a52f0634 Mon Sep 17 00:00:00 2001 From: XanatosX <10531466+XanatosX@users.noreply.github.com> Date: Tue, 31 Jan 2023 21:09:05 +0100 Subject: [PATCH 1/8] Remove test error --- src/ModularToolManager/App.axaml.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/ModularToolManager/App.axaml.cs b/src/ModularToolManager/App.axaml.cs index 9986806..92b5352 100644 --- a/src/ModularToolManager/App.axaml.cs +++ b/src/ModularToolManager/App.axaml.cs @@ -81,8 +81,6 @@ private Serilog.ILogger CreateLoggerConfig(IServiceCollection collection) public override void OnFrameworkInitializationCompleted() { var provider = BuildServiceCollection().BuildServiceProvider(); - Microsoft.Extensions.Logging.ILogger testing = provider.GetRequiredService>(); - testing.LogError("test"); WeakReferenceMessenger.Default.Register(this, (_, e) => { if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) From ba1bfcf8f40b53573bada7591d2ce0e62fe7348e Mon Sep 17 00:00:00 2001 From: XanatosX <10531466+XanatosX@users.noreply.github.com> Date: Tue, 31 Jan 2023 21:09:10 +0100 Subject: [PATCH 2/8] Add first hotkey --- src/ModularToolManager/Resources/Hotkeys.json | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 src/ModularToolManager/Resources/Hotkeys.json diff --git a/src/ModularToolManager/Resources/Hotkeys.json b/src/ModularToolManager/Resources/Hotkeys.json new file mode 100644 index 0000000..f393e1a --- /dev/null +++ b/src/ModularToolManager/Resources/Hotkeys.json @@ -0,0 +1,8 @@ +[ + { + "Name": "AbortHotkey", + "Description": "AbortHotkeyDescription", + "WorkingOn": "AbortHotkeyWorkingOn", + "Keys": "AbortHotkeyKeys" + } +] From b4d8a7490a6b9f6bb5d99c3ad33f3915554a1f1b Mon Sep 17 00:00:00 2001 From: XanatosX <10531466+XanatosX@users.noreply.github.com> Date: Tue, 31 Jan 2023 22:03:02 +0100 Subject: [PATCH 3/8] Add code to display hotkey Add some hotkeys --- src/ModularToolManager/Models/HotkeyModel.cs | 33 +++++ .../ModularToolManager.csproj | 5 + .../Properties/Properties.Designer.cs | 9 ++ .../Properties/Properties.resx | 3 + .../Properties/Resources.Designer.cs | 126 ++++++++++++++++++ .../Properties/Resources.resx | 42 ++++++ src/ModularToolManager/Resources/Hotkeys.json | 53 +++++++- src/ModularToolManager/Resources/Icons.axaml | 1 + .../IO/GetApplicationInformationService.cs | 32 +++++ .../ViewModels/HotkeysViewModel.cs | 18 +++ .../ViewModels/KeyboardKeyViewModel.cs | 32 +++++ .../ViewModels/MainWindowViewModel.cs | 10 ++ .../ViewModels/SingleHotkeyViewModel.cs | 35 +++++ .../Views/HotkeysView.axaml | 8 ++ .../Views/HotkeysView.axaml.cs | 16 +++ .../Views/KeyboardKeyView.axaml | 12 ++ .../Views/KeyboardKeyView.axaml.cs | 15 +++ src/ModularToolManager/Views/MainWindow.axaml | 2 +- .../Views/SingleHotkeyView.axaml | 18 +++ .../Views/SingleHotkeyView.axaml.cs | 16 +++ 20 files changed, 481 insertions(+), 5 deletions(-) create mode 100644 src/ModularToolManager/Models/HotkeyModel.cs create mode 100644 src/ModularToolManager/ViewModels/HotkeysViewModel.cs create mode 100644 src/ModularToolManager/ViewModels/KeyboardKeyViewModel.cs create mode 100644 src/ModularToolManager/ViewModels/SingleHotkeyViewModel.cs create mode 100644 src/ModularToolManager/Views/HotkeysView.axaml create mode 100644 src/ModularToolManager/Views/HotkeysView.axaml.cs create mode 100644 src/ModularToolManager/Views/KeyboardKeyView.axaml create mode 100644 src/ModularToolManager/Views/KeyboardKeyView.axaml.cs create mode 100644 src/ModularToolManager/Views/SingleHotkeyView.axaml create mode 100644 src/ModularToolManager/Views/SingleHotkeyView.axaml.cs diff --git a/src/ModularToolManager/Models/HotkeyModel.cs b/src/ModularToolManager/Models/HotkeyModel.cs new file mode 100644 index 0000000..db75a94 --- /dev/null +++ b/src/ModularToolManager/Models/HotkeyModel.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ModularToolManager.Models; + +/// +/// Model representing a single hotkey +/// +internal class HotkeyModel +{ + /// + /// The name of the hotkey + /// + public string? Name { get; init; } + + /// + /// The description of the hotkey + /// + public string? Description { get; init; } + + /// + /// Where does the hotkey work + /// + public string? WorkingOn { get; init; } + + /// + /// The keys to press to trigger the hotkey + /// + public List? Keys { get; init; } +} diff --git a/src/ModularToolManager/ModularToolManager.csproj b/src/ModularToolManager/ModularToolManager.csproj index aa7a877..3522263 100644 --- a/src/ModularToolManager/ModularToolManager.csproj +++ b/src/ModularToolManager/ModularToolManager.csproj @@ -8,10 +8,12 @@ + + @@ -43,6 +45,9 @@ AllPluginsView.axaml + + HotkeysView.axaml + diff --git a/src/ModularToolManager/Properties/Properties.Designer.cs b/src/ModularToolManager/Properties/Properties.Designer.cs index f265d20..5cfcbd8 100644 --- a/src/ModularToolManager/Properties/Properties.Designer.cs +++ b/src/ModularToolManager/Properties/Properties.Designer.cs @@ -132,6 +132,15 @@ internal static string Icon_hide { } } + /// + /// Looks up a localized string similar to keyboard_regular. + /// + internal static string Icon_Keyboard { + get { + return ResourceManager.GetString("Icon_Keyboard", resourceCulture); + } + } + /// /// Looks up a localized string similar to flag_regular. /// diff --git a/src/ModularToolManager/Properties/Properties.resx b/src/ModularToolManager/Properties/Properties.resx index 45ba094..a1ff3c2 100644 --- a/src/ModularToolManager/Properties/Properties.resx +++ b/src/ModularToolManager/Properties/Properties.resx @@ -141,6 +141,9 @@ eye_hide_regular + + keyboard_regular + flag_regular diff --git a/src/ModularToolManager/Properties/Resources.Designer.cs b/src/ModularToolManager/Properties/Resources.Designer.cs index 395b28b..f0a79bf 100644 --- a/src/ModularToolManager/Properties/Resources.Designer.cs +++ b/src/ModularToolManager/Properties/Resources.Designer.cs @@ -222,6 +222,132 @@ public static string FunctionSelection_SearchForFunction { } } + /// + /// Looks up a localized string similar to Abort the current action or close the current modal. + /// + public static string Hotkey_Abort_Description { + get { + return ResourceManager.GetString("Hotkey_Abort_Description", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Abort. + /// + public static string Hotkey_Abort_Name { + get { + return ResourceManager.GetString("Hotkey_Abort_Name", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Change Language, Add/Edit Function, Settings. + /// + public static string Hotkey_Abort_WorkingOn { + get { + return ResourceManager.GetString("Hotkey_Abort_WorkingOn", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Working at the following places: . + /// + public static string Hotkey_Abort_WorkingOn_Prefix_Colon { + get { + return ResourceManager.GetString("Hotkey_Abort_WorkingOn_Prefix_Colon", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Main Window. + /// + public static string Hotkey_Language_WorkingOn { + get { + return ResourceManager.GetString("Hotkey_Language_WorkingOn", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to New Function. + /// + public static string Hotkey_New { + get { + return ResourceManager.GetString("Hotkey_New", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Create a new function. + /// + public static string Hotkey_New_Description { + get { + return ResourceManager.GetString("Hotkey_New_Description", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to ctrl. + /// + public static string Key_Ctrl { + get { + return ResourceManager.GetString("Key_Ctrl", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Esc. + /// + public static string Key_Esc { + get { + return ResourceManager.GetString("Key_Esc", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to F1. + /// + public static string Key_F1 { + get { + return ResourceManager.GetString("Key_F1", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to F12. + /// + public static string Key_F12 { + get { + return ResourceManager.GetString("Key_F12", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to h. + /// + public static string Key_H { + get { + return ResourceManager.GetString("Key_H", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to l. + /// + public static string Key_L { + get { + return ResourceManager.GetString("Key_L", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to n. + /// + public static string Key_N { + get { + return ResourceManager.GetString("Key_N", resourceCulture); + } + } + /// /// Looks up a localized string similar to File. /// diff --git a/src/ModularToolManager/Properties/Resources.resx b/src/ModularToolManager/Properties/Resources.resx index 4c5a1ec..9a00e39 100644 --- a/src/ModularToolManager/Properties/Resources.resx +++ b/src/ModularToolManager/Properties/Resources.resx @@ -171,6 +171,48 @@ Search for function + + Abort the current action or close the current modal + + + Abort + + + Change Language, Add/Edit Function, Settings + + + Working at the following places: + + + Main Window + + + New Function + + + Create a new function + + + ctrl + + + Esc + + + F1 + + + F12 + + + h + + + l + + + n + File diff --git a/src/ModularToolManager/Resources/Hotkeys.json b/src/ModularToolManager/Resources/Hotkeys.json index f393e1a..e503096 100644 --- a/src/ModularToolManager/Resources/Hotkeys.json +++ b/src/ModularToolManager/Resources/Hotkeys.json @@ -1,8 +1,53 @@ [ { - "Name": "AbortHotkey", - "Description": "AbortHotkeyDescription", - "WorkingOn": "AbortHotkeyWorkingOn", - "Keys": "AbortHotkeyKeys" + "Name": "Hotkey_Abort_Name", + "Description": "Hotkey_Abort_Description", + "WorkingOn": "Hotkey_Abort_WorkingOn", + "Keys": [ + "Key_Esc" + ] + }, + { + "Name": "Hotkey_New", + "Description": "Hotkey_New_Description", + "WorkingOn": "Hotkey_Language_WorkingOn", + "Keys": [ + "Key_Ctrl", + "Key_N" + ] + }, + { + "Name": "Hotkey_Language", + "Description": "Hotkey_Language_Description", + "WorkingOn": "Hotkey_Language_WorkingOn", + "Keys": [ + "Key_Ctrl", + "Key_L" + ] + }, + { + "Name": "Hotkey_Hide", + "Description": "Hotkey_Hide_Description", + "WorkingOn": "Hotkey_Hide_WorkingOn", + "Keys": [ + "Key_Ctrl", + "Key_H" + ] + }, + { + "Name": "Hotkey_About", + "Description": "Hotkey_About_Description", + "WorkingOn": "Hotkey_About_WorkingOn", + "Keys": [ + "Key_F1" + ] + }, + { + "Name": "Hotkey_Report_Bug", + "Description": "Hotkey_Report_Bug_Description", + "WorkingOn": "Hotkey_Report_Bug_WorkingOn", + "Keys": [ + "Key_F12" + ] } ] diff --git a/src/ModularToolManager/Resources/Icons.axaml b/src/ModularToolManager/Resources/Icons.axaml index 1f57e14..4200ae0 100644 --- a/src/ModularToolManager/Resources/Icons.axaml +++ b/src/ModularToolManager/Resources/Icons.axaml @@ -18,6 +18,7 @@ M27.3138 4.68622C28.8759 6.24832 28.8759 8.78098 27.3138 10.3431L12.5409 25.116C11.9001 25.7568 11.0972 26.2114 10.218 26.4312L5.63602 27.5767C4.90364 27.7598 4.24025 27.0964 4.42335 26.364L5.56885 21.782C5.78864 20.9028 6.24323 20.0999 6.88402 19.4591L21.6569 4.68622C23.219 3.12412 25.7517 3.12412 27.3138 4.68622ZM20.2426 8.92865L8.29824 20.8734C7.91376 21.2578 7.641 21.7396 7.50913 22.2671L6.76786 25.2322L9.73295 24.4909C10.2604 24.359 10.7422 24.0863 11.1267 23.7018L23.0706 11.7566L20.2426 8.92865ZM23.0712 6.10043L21.6566 7.51465L24.4846 10.3426L25.8996 8.92886C26.6806 8.14781 26.6806 6.88148 25.8996 6.10043C25.1185 5.31939 23.8522 5.31939 23.0712 6.10043Z M24,7.25 C27.1017853,7.25 29.629937,9.70601719 29.7458479,12.7794443 L29.75,13 L37,13 C37.6903559,13 38.25,13.5596441 38.25,14.25 C38.25,14.8972087 37.7581253,15.4295339 37.1278052,15.4935464 L37,15.5 L35.909,15.5 L34.2058308,38.0698451 C34.0385226,40.2866784 32.1910211,42 29.9678833,42 L18.0321167,42 C15.8089789,42 13.9614774,40.2866784 13.7941692,38.0698451 L12.09,15.5 L11,15.5 C10.3527913,15.5 9.8204661,15.0081253 9.75645361,14.3778052 L9.75,14.25 C9.75,13.6027913 10.2418747,13.0704661 10.8721948,13.0064536 L11,13 L18.25,13 C18.25,9.82436269 20.8243627,7.25 24,7.25 Z M33.4021054,15.5 L14.5978946,15.5 L16.2870795,37.8817009 C16.3559711,38.7945146 17.116707,39.5 18.0321167,39.5 L29.9678833,39.5 C30.883293,39.5 31.6440289,38.7945146 31.7129205,37.8817009 L33.4021054,15.5 Z M27.25,20.75 C27.8972087,20.75 28.4295339,21.2418747 28.4935464,21.8721948 L28.5,22 L28.5,33 C28.5,33.6903559 27.9403559,34.25 27.25,34.25 C26.6027913,34.25 26.0704661,33.7581253 26.0064536,33.1278052 L26,33 L26,22 C26,21.3096441 26.5596441,20.75 27.25,20.75 Z M20.75,20.75 C21.3972087,20.75 21.9295339,21.2418747 21.9935464,21.8721948 L22,22 L22,33 C22,33.6903559 21.4403559,34.25 20.75,34.25 C20.1027913,34.25 19.5704661,33.7581253 19.5064536,33.1278052 L19.5,33 L19.5,22 C19.5,21.3096441 20.0596441,20.75 20.75,20.75 Z M24,9.75 C22.2669685,9.75 20.8507541,11.1064548 20.7551448,12.8155761 L20.75,13 L27.25,13 C27.25,11.2050746 25.7949254,9.75 24,9.75 Z M24 4C35.0457 4 44 12.9543 44 24C44 35.0457 35.0457 44 24 44C12.9543 44 4 35.0457 4 24C4 12.9543 12.9543 4 24 4ZM24 6.5C14.335 6.5 6.5 14.335 6.5 24C6.5 33.665 14.335 41.5 24 41.5C33.665 41.5 41.5 33.665 41.5 24C41.5 14.335 33.665 6.5 24 6.5ZM24.25 32C25.0784 32 25.75 32.6716 25.75 33.5C25.75 34.3284 25.0784 35 24.25 35C23.4216 35 22.75 34.3284 22.75 33.5C22.75 32.6716 23.4216 32 24.25 32ZM24.25 13C27.6147 13 30.5 15.8821 30.5 19.2488C30.502 21.3691 29.7314 22.7192 27.8216 24.7772L26.8066 25.8638C25.7842 27.0028 25.3794 27.7252 25.3409 28.5793L25.3379 28.7411L25.3323 28.8689L25.3143 28.9932C25.2018 29.5636 24.7009 29.9957 24.0968 30.0001C23.4065 30.0049 22.8428 29.4493 22.8379 28.7589C22.8251 26.9703 23.5147 25.7467 25.1461 23.9739L26.1734 22.8762C27.5312 21.3837 28.0012 20.503 28 19.25C28 17.2634 26.2346 15.5 24.25 15.5C22.3307 15.5 20.6142 17.1536 20.5055 19.0587L20.4935 19.3778C20.4295 20.0081 19.8972 20.5 19.25 20.5C18.5596 20.5 18 19.9404 18 19.25C18 15.8846 20.8864 13 24.25 13Z + M19.7453641,5 C20.9880048,5 21.9953641,6.00735931 21.9953641,7.25 L21.9953641,16.754591 C21.9953641,17.9972317 20.9880048,19.004591 19.7453641,19.004591 L4.25,19.004591 C3.00735931,19.004591 2,17.9972317 2,16.754591 L2,7.25 C2,6.00735931 3.00735931,5 4.25,5 L19.7453641,5 Z M19.7453641,6.5 L4.25,6.5 C3.83578644,6.5 3.5,6.83578644 3.5,7.25 L3.5,16.754591 C3.5,17.1688046 3.83578644,17.504591 4.25,17.504591 L19.7453641,17.504591 C20.1595777,17.504591 20.4953641,17.1688046 20.4953641,16.754591 L20.4953641,7.25 C20.4953641,6.83578644 20.1595777,6.5 19.7453641,6.5 Z M6.75,14.5 L17.25,14.5 C17.6642136,14.5 18,14.8357864 18,15.25 C18,15.6296958 17.7178461,15.943491 17.3517706,15.9931534 L17.25,16 L6.75,16 C6.33578644,16 6,15.6642136 6,15.25 C6,14.8703042 6.28215388,14.556509 6.64822944,14.5068466 L6.75,14.5 L17.25,14.5 L6.75,14.5 Z M16.5,11 C17.0522847,11 17.5,11.4477153 17.5,12 C17.5,12.5522847 17.0522847,13 16.5,13 C15.9477153,13 15.5,12.5522847 15.5,12 C15.5,11.4477153 15.9477153,11 16.5,11 Z M10.5048752,11 C11.05716,11 11.5048752,11.4477153 11.5048752,12 C11.5048752,12.5522847 11.05716,13 10.5048752,13 C9.95259045,13 9.5048752,12.5522847 9.5048752,12 C9.5048752,11.4477153 9.95259045,11 10.5048752,11 Z M7.5048752,11 C8.05715995,11 8.5048752,11.4477153 8.5048752,12 C8.5048752,12.5522847 8.05715995,13 7.5048752,13 C6.95259045,13 6.5048752,12.5522847 6.5048752,12 C6.5048752,11.4477153 6.95259045,11 7.5048752,11 Z M13.5048752,11 C14.05716,11 14.5048752,11.4477153 14.5048752,12 C14.5048752,12.5522847 14.05716,13 13.5048752,13 C12.9525905,13 12.5048752,12.5522847 12.5048752,12 C12.5048752,11.4477153 12.9525905,11 13.5048752,11 Z M6,8 C6.55228475,8 7,8.44771525 7,9 C7,9.55228475 6.55228475,10 6,10 C5.44771525,10 5,9.55228475 5,9 C5,8.44771525 5.44771525,8 6,8 Z M8.9951248,8 C9.54740955,8 9.9951248,8.44771525 9.9951248,9 C9.9951248,9.55228475 9.54740955,10 8.9951248,10 C8.44284005,10 7.9951248,9.55228475 7.9951248,9 C7.9951248,8.44771525 8.44284005,8 8.9951248,8 Z M11.9951248,8 C12.5474095,8 12.9951248,8.44771525 12.9951248,9 C12.9951248,9.55228475 12.5474095,10 11.9951248,10 C11.44284,10 10.9951248,9.55228475 10.9951248,9 C10.9951248,8.44771525 11.44284,8 11.9951248,8 Z M14.9951248,8 C15.5474095,8 15.9951248,8.44771525 15.9951248,9 C15.9951248,9.55228475 15.5474095,10 14.9951248,10 C14.44284,10 13.9951248,9.55228475 13.9951248,9 C13.9951248,8.44771525 14.44284,8 14.9951248,8 Z M17.9951248,8 C18.5474095,8 18.9951248,8.44771525 18.9951248,9 C18.9951248,9.55228475 18.5474095,10 17.9951248,10 C17.44284,10 16.9951248,9.55228475 16.9951248,9 C16.9951248,8.44771525 17.44284,8 17.9951248,8 Z diff --git a/src/ModularToolManager/Services/IO/GetApplicationInformationService.cs b/src/ModularToolManager/Services/IO/GetApplicationInformationService.cs index 97720b6..05b18e1 100644 --- a/src/ModularToolManager/Services/IO/GetApplicationInformationService.cs +++ b/src/ModularToolManager/Services/IO/GetApplicationInformationService.cs @@ -6,6 +6,7 @@ using System.IO; using System.Linq; using System.Reflection; +using System.Security.Cryptography; using System.Text.Json; namespace ModularToolManager.Services.IO; @@ -100,4 +101,35 @@ public IEnumerable GetDependencies() /// /// The link to the github repository public string GetGithubUrl() => Properties.Properties.GitHubUrl; + + /// + /// Get all the hotkeys for the application + /// + /// A list with all the hotkeys + public IEnumerable GetHotkeys() + { + IEnumerable loadedHotkeys = Enumerable.Empty(); + using (Stream? stream = readerService.GetResourceStream("hotkeys.json")) + { + if (stream is not null && stream != Stream.Null) + { + loadedHotkeys = JsonSerializer.Deserialize>(stream) ?? loadedHotkeys; + } + } + List returnHotkeys = new(); + foreach (var hotkey in loadedHotkeys) + { + returnHotkeys.Add(new HotkeyModel + { + Name = Properties.Resources.ResourceManager.GetString(hotkey.Name ?? string.Empty), + Description = Properties.Resources.ResourceManager.GetString(hotkey.Description ?? string.Empty), + WorkingOn = Properties.Resources.ResourceManager.GetString(hotkey.WorkingOn ?? string.Empty), + Keys = hotkey.Keys?.Select(key => Properties.Resources.ResourceManager.GetString(key ?? string.Empty)) + .OfType() + .ToList() ?? new(), + }); + } + + return returnHotkeys; + } } diff --git a/src/ModularToolManager/ViewModels/HotkeysViewModel.cs b/src/ModularToolManager/ViewModels/HotkeysViewModel.cs new file mode 100644 index 0000000..deeaa1a --- /dev/null +++ b/src/ModularToolManager/ViewModels/HotkeysViewModel.cs @@ -0,0 +1,18 @@ +using CommunityToolkit.Mvvm.ComponentModel; +using ModularToolManager.Services.IO; +using System.Collections.Generic; +using System.Linq; + +namespace ModularToolManager.ViewModels; +internal partial class HotkeysViewModel : ObservableObject +{ + [ObservableProperty] + private List? hotkeys; + + public HotkeysViewModel(GetApplicationInformationService applicationInformationService) + { + Hotkeys = applicationInformationService.GetHotkeys() + .Select(hotkey => new SingleHotkeyViewModel(hotkey)) + .ToList(); + } +} diff --git a/src/ModularToolManager/ViewModels/KeyboardKeyViewModel.cs b/src/ModularToolManager/ViewModels/KeyboardKeyViewModel.cs new file mode 100644 index 0000000..33a4a41 --- /dev/null +++ b/src/ModularToolManager/ViewModels/KeyboardKeyViewModel.cs @@ -0,0 +1,32 @@ +using CommunityToolkit.Mvvm.ComponentModel; + +namespace ModularToolManager.ViewModels; +internal partial class KeyboardKeyViewModel : ObservableObject +{ + [ObservableProperty] + private string? buttonText; + + + [ObservableProperty] + [NotifyPropertyChangedFor(nameof(PrefixSet))] + private string? prefixText; + + public bool PrefixSet => !string.IsNullOrWhiteSpace(PrefixText); + + [ObservableProperty] + [NotifyPropertyChangedFor(nameof(PostfixSet))] + private string? postfixText; + + public bool PostfixSet => !string.IsNullOrWhiteSpace(PostfixText); + + public KeyboardKeyViewModel(string buttonText) : this(buttonText, string.Empty, string.Empty) + { + } + + public KeyboardKeyViewModel(string buttonText, string prefixText, string postfixText) + { + ButtonText = buttonText; + PrefixText = prefixText; + PostfixText = postfixText; + } +} diff --git a/src/ModularToolManager/ViewModels/MainWindowViewModel.cs b/src/ModularToolManager/ViewModels/MainWindowViewModel.cs index 1d7d95b..10144ca 100644 --- a/src/ModularToolManager/ViewModels/MainWindowViewModel.cs +++ b/src/ModularToolManager/ViewModels/MainWindowViewModel.cs @@ -176,6 +176,16 @@ private async Task OpenAbout() await OpenModalWindow(Properties.Resources.SubMenu_About, Properties.Properties.Icon_About, nameof(AboutViewModel)); } + /// + /// Open the hotkey window + /// + /// A awaitable task + [RelayCommand] + private async Task OpenHotkey() + { + await OpenModalWindow(Properties.Resources.SubMenu_Hotkeys, Properties.Properties.Icon_Keyboard, nameof(HotkeysViewModel)); + } + /// /// Method to open a modal window /// diff --git a/src/ModularToolManager/ViewModels/SingleHotkeyViewModel.cs b/src/ModularToolManager/ViewModels/SingleHotkeyViewModel.cs new file mode 100644 index 0000000..b0a6d55 --- /dev/null +++ b/src/ModularToolManager/ViewModels/SingleHotkeyViewModel.cs @@ -0,0 +1,35 @@ +using CommunityToolkit.Mvvm.ComponentModel; +using ModularToolManager.Models; +using System.Collections.Generic; +using System.Linq; + +namespace ModularToolManager.ViewModels; +internal partial class SingleHotkeyViewModel : ObservableObject +{ + [ObservableProperty] + [NotifyPropertyChangedFor(nameof(Name))] + [NotifyPropertyChangedFor(nameof(Description))] + [NotifyPropertyChangedFor(nameof(WorkingOn))] + [NotifyPropertyChangedFor(nameof(Keys))] + [NotifyPropertyChangedFor(nameof(ToolTipShowDelay))] + [NotifyPropertyChangedFor(nameof(WorkingOnComplete))] + private HotkeyModel hotkey; + + public string? Name => hotkey?.Name; + + public string? Description => hotkey?.Description; + + public string? WorkingOn => hotkey?.WorkingOn; + + public string? WorkingOnComplete => Properties.Resources.Hotkey_Abort_WorkingOn_Prefix_Colon + hotkey?.WorkingOn; + + public int ToolTipShowDelay => string.IsNullOrWhiteSpace(WorkingOn) ? int.MaxValue : 500; + + public List? Keys => hotkey?.Keys?.Select((button, index) => new KeyboardKeyViewModel(button, index != 0 ? "+" : string.Empty, string.Empty)) + .ToList(); + + public SingleHotkeyViewModel(HotkeyModel hotkey) + { + Hotkey = hotkey; + } +} diff --git a/src/ModularToolManager/Views/HotkeysView.axaml b/src/ModularToolManager/Views/HotkeysView.axaml new file mode 100644 index 0000000..0ffe814 --- /dev/null +++ b/src/ModularToolManager/Views/HotkeysView.axaml @@ -0,0 +1,8 @@ + + + diff --git a/src/ModularToolManager/Views/HotkeysView.axaml.cs b/src/ModularToolManager/Views/HotkeysView.axaml.cs new file mode 100644 index 0000000..58e586d --- /dev/null +++ b/src/ModularToolManager/Views/HotkeysView.axaml.cs @@ -0,0 +1,16 @@ +using Avalonia.Controls; +using Avalonia.Markup.Xaml; + +namespace ModularToolManager.Views; +public partial class HotkeysView : UserControl +{ + public HotkeysView() + { + InitializeComponent(); + } + + private void InitializeComponent() + { + AvaloniaXamlLoader.Load(this); + } +} diff --git a/src/ModularToolManager/Views/KeyboardKeyView.axaml b/src/ModularToolManager/Views/KeyboardKeyView.axaml new file mode 100644 index 0000000..7412c98 --- /dev/null +++ b/src/ModularToolManager/Views/KeyboardKeyView.axaml @@ -0,0 +1,12 @@ + + + +