From 07185c74a04c8c4bed4a08c0295a969c045a75b7 Mon Sep 17 00:00:00 2001 From: cinqmilleans Date: Wed, 29 Mar 2023 17:13:34 +0200 Subject: [PATCH 1/6] enums --- src/Files.App/Actions/Display/GroupAction.cs | 6 +- src/Files.App/Actions/Display/LayoutAction.cs | 23 ++- src/Files.App/Actions/Display/SortAction.cs | 10 +- .../Actions/Open/OpenTerminalAction.cs | 3 +- .../Actions/Open/OpenTerminalAsAdminAction.cs | 3 +- src/Files.App/Commands/{ => HotKey}/HotKey.cs | 7 +- .../Commands/{ => HotKey}/HotKeyHelpers.cs | 0 src/Files.App/Commands/HotKey/KeyModifiers.cs | 25 ++++ src/Files.App/Commands/HotKey/Keys.cs | 139 ++++++++++++++++++ 9 files changed, 191 insertions(+), 25 deletions(-) rename src/Files.App/Commands/{ => HotKey}/HotKey.cs (85%) rename src/Files.App/Commands/{ => HotKey}/HotKeyHelpers.cs (100%) create mode 100644 src/Files.App/Commands/HotKey/KeyModifiers.cs create mode 100644 src/Files.App/Commands/HotKey/Keys.cs diff --git a/src/Files.App/Actions/Display/GroupAction.cs b/src/Files.App/Actions/Display/GroupAction.cs index 7fe8e730ea95..1ae86efb9c39 100644 --- a/src/Files.App/Actions/Display/GroupAction.cs +++ b/src/Files.App/Actions/Display/GroupAction.cs @@ -142,7 +142,7 @@ private void DisplayContext_PropertyChanged(object? sender, PropertyChangedEvent internal class GroupAscendingAction : ObservableObject, IToggleAction { - private IDisplayPageContext context = Ioc.Default.GetRequiredService(); + private readonly IDisplayPageContext context = Ioc.Default.GetRequiredService(); public string Label { get; } = "Ascending".GetLocalizedResource(); @@ -178,7 +178,7 @@ private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e) internal class GroupDescendingAction : ObservableObject, IToggleAction { - private IDisplayPageContext context = Ioc.Default.GetRequiredService(); + private readonly IDisplayPageContext context = Ioc.Default.GetRequiredService(); public string Label { get; } = "Descending".GetLocalizedResource(); @@ -214,7 +214,7 @@ private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e) internal class ToggleGroupDirectionAction : IAction { - private IDisplayPageContext context = Ioc.Default.GetRequiredService(); + private readonly IDisplayPageContext context = Ioc.Default.GetRequiredService(); public string Label { get; } = "ToggleSortDirection".GetLocalizedResource(); diff --git a/src/Files.App/Actions/Display/LayoutAction.cs b/src/Files.App/Actions/Display/LayoutAction.cs index efcdff6de582..2167162ac47a 100644 --- a/src/Files.App/Actions/Display/LayoutAction.cs +++ b/src/Files.App/Actions/Display/LayoutAction.cs @@ -5,7 +5,6 @@ using Files.App.Extensions; using System.ComponentModel; using System.Threading.Tasks; -using Windows.System; namespace Files.App.Actions { @@ -16,7 +15,7 @@ internal class LayoutDetailsAction : ToggleLayoutAction public override string Label { get; } = "Details".GetLocalizedResource(); public override RichGlyph Glyph { get; } = new("\uE179"); - public override HotKey HotKey { get; } = new(VirtualKey.Number1, VirtualKeyModifiers.Control | VirtualKeyModifiers.Shift); + public override HotKey HotKey { get; } = new(Keys.Number1, KeyModifiers.CtrlShift); } internal class LayoutTilesAction : ToggleLayoutAction @@ -26,7 +25,7 @@ internal class LayoutTilesAction : ToggleLayoutAction public override string Label { get; } = "Tiles".GetLocalizedResource(); public override RichGlyph Glyph { get; } = new("\uE15C"); - public override HotKey HotKey { get; } = new(VirtualKey.Number2, VirtualKeyModifiers.Control | VirtualKeyModifiers.Shift); + public override HotKey HotKey { get; } = new(Keys.Number2, KeyModifiers.CtrlShift); } internal class LayoutGridSmallAction : ToggleLayoutAction @@ -36,7 +35,7 @@ internal class LayoutGridSmallAction : ToggleLayoutAction public override string Label { get; } = "SmallIcons".GetLocalizedResource(); public override RichGlyph Glyph { get; } = new("\uE80A"); - public override HotKey HotKey { get; } = new(VirtualKey.Number3, VirtualKeyModifiers.Control | VirtualKeyModifiers.Shift); + public override HotKey HotKey { get; } = new(Keys.Number3, KeyModifiers.CtrlShift); } internal class LayoutGridMediumAction : ToggleLayoutAction @@ -46,7 +45,7 @@ internal class LayoutGridMediumAction : ToggleLayoutAction public override string Label { get; } = "MediumIcons".GetLocalizedResource(); public override RichGlyph Glyph { get; } = new("\uF0E2"); - public override HotKey HotKey { get; } = new(VirtualKey.Number4, VirtualKeyModifiers.Control | VirtualKeyModifiers.Shift); + public override HotKey HotKey { get; } = new(Keys.Number4, KeyModifiers.CtrlShift); } internal class LayoutGridLargeAction : ToggleLayoutAction @@ -56,7 +55,7 @@ internal class LayoutGridLargeAction : ToggleLayoutAction public override string Label { get; } = "LargeIcons".GetLocalizedResource(); public override RichGlyph Glyph { get; } = new("\uE739"); - public override HotKey HotKey { get; } = new(VirtualKey.Number5, VirtualKeyModifiers.Control | VirtualKeyModifiers.Shift); + public override HotKey HotKey { get; } = new(Keys.Number5, KeyModifiers.CtrlShift); } internal class LayoutColumnsAction : ToggleLayoutAction @@ -66,7 +65,7 @@ internal class LayoutColumnsAction : ToggleLayoutAction public override string Label { get; } = "Columns".GetLocalizedResource(); public override RichGlyph Glyph { get; } = new(opacityStyle: "ColorIconColumnsLayout"); - public override HotKey HotKey { get; } = new(VirtualKey.Number6, VirtualKeyModifiers.Control | VirtualKeyModifiers.Shift); + public override HotKey HotKey { get; } = new(Keys.Number6, KeyModifiers.CtrlShift); } internal class LayoutAdaptiveAction : ToggleLayoutAction @@ -78,7 +77,7 @@ internal class LayoutAdaptiveAction : ToggleLayoutAction public override bool IsExecutable => Context.IsLayoutAdaptiveEnabled; public override RichGlyph Glyph { get; } = new("\uF576"); - public override HotKey HotKey { get; } = new(VirtualKey.Number7, VirtualKeyModifiers.Control | VirtualKeyModifiers.Shift); + public override HotKey HotKey { get; } = new(Keys.Number7, KeyModifiers.CtrlShift); protected override void OnContextChanged(string propertyName) { @@ -137,8 +136,8 @@ internal class LayoutDecreaseSizeAction : IAction public string Description => "TODO: Need to be described."; - public HotKey HotKey { get; } = new(VirtualKey.Subtract, VirtualKeyModifiers.Control); - public HotKey MediaHotKey { get; } = new((VirtualKey)189, VirtualKeyModifiers.Control); + public HotKey HotKey { get; } = new(Keys.Subtract, KeyModifiers.Ctrl); + public HotKey MediaHotKey { get; } = new(Keys.OemMinus, KeyModifiers.Ctrl); public Task ExecuteAsync() { @@ -155,8 +154,8 @@ internal class LayoutIncreaseSizeAction : IAction public string Description => "TODO: Need to be described."; - public HotKey HotKey { get; } = new(VirtualKey.Add, VirtualKeyModifiers.Control); - public HotKey MediaHotKey { get; } = new((VirtualKey)187, VirtualKeyModifiers.Control); + public HotKey HotKey { get; } = new(Keys.Add, KeyModifiers.Ctrl); + public HotKey MediaHotKey { get; } = new(Keys.OemPlus, KeyModifiers.Ctrl); public Task ExecuteAsync() { diff --git a/src/Files.App/Actions/Display/SortAction.cs b/src/Files.App/Actions/Display/SortAction.cs index 1bb46846798a..e62a138b43a7 100644 --- a/src/Files.App/Actions/Display/SortAction.cs +++ b/src/Files.App/Actions/Display/SortAction.cs @@ -79,8 +79,8 @@ internal class SortByDateDeletedAction : SortByAction internal abstract class SortByAction : ObservableObject, IToggleAction { - private IContentPageContext contentContext = Ioc.Default.GetRequiredService(); - private IDisplayPageContext displayContext = Ioc.Default.GetRequiredService(); + private readonly IContentPageContext contentContext = Ioc.Default.GetRequiredService(); + private readonly IDisplayPageContext displayContext = Ioc.Default.GetRequiredService(); protected abstract SortOption SortOption { get; } @@ -126,7 +126,7 @@ private void DisplayContext_PropertyChanged(object? sender, PropertyChangedEvent internal class SortAscendingAction : ObservableObject, IToggleAction { - private IDisplayPageContext context = Ioc.Default.GetRequiredService(); + private readonly IDisplayPageContext context = Ioc.Default.GetRequiredService(); public string Label { get; } = "Ascending".GetLocalizedResource(); @@ -154,7 +154,7 @@ private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e) internal class SortDescendingAction : ObservableObject, IToggleAction { - private IDisplayPageContext context = Ioc.Default.GetRequiredService(); + private readonly IDisplayPageContext context = Ioc.Default.GetRequiredService(); public string Label { get; } = "Descending".GetLocalizedResource(); @@ -182,7 +182,7 @@ private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e) internal class ToggleSortDirectionAction : IAction { - private IDisplayPageContext context = Ioc.Default.GetRequiredService(); + private readonly IDisplayPageContext context = Ioc.Default.GetRequiredService(); public string Label { get; } = "ToggleSortDirection".GetLocalizedResource(); diff --git a/src/Files.App/Actions/Open/OpenTerminalAction.cs b/src/Files.App/Actions/Open/OpenTerminalAction.cs index e6792e0eb6b0..8d4888ab2516 100644 --- a/src/Files.App/Actions/Open/OpenTerminalAction.cs +++ b/src/Files.App/Actions/Open/OpenTerminalAction.cs @@ -10,7 +10,6 @@ using System.Text; using System.Threading.Tasks; using Windows.Storage; -using Windows.System; namespace Files.App.Actions { @@ -22,7 +21,7 @@ internal class OpenTerminalAction : ObservableObject, IAction public virtual string Description => "TODO: Need to be described."; - public virtual HotKey HotKey { get; } = new((VirtualKey)192, VirtualKeyModifiers.Control); + public virtual HotKey HotKey { get; } = new(Keys.Oem3, KeyModifiers.Ctrl); public RichGlyph Glyph { get; } = new("\uE756"); diff --git a/src/Files.App/Actions/Open/OpenTerminalAsAdminAction.cs b/src/Files.App/Actions/Open/OpenTerminalAsAdminAction.cs index 43003b812127..4abd46338925 100644 --- a/src/Files.App/Actions/Open/OpenTerminalAsAdminAction.cs +++ b/src/Files.App/Actions/Open/OpenTerminalAsAdminAction.cs @@ -1,7 +1,6 @@ using Files.App.Commands; using Files.App.Extensions; using System.Diagnostics; -using Windows.System; namespace Files.App.Actions { @@ -11,7 +10,7 @@ internal class OpenTerminalAsAdminAction : OpenTerminalAction public override string Description => "TODO: Need to be described."; - public override HotKey HotKey { get; } = new((VirtualKey)192, VirtualKeyModifiers.Control | VirtualKeyModifiers.Shift); + public override HotKey HotKey { get; } = new(Keys.Oem3, KeyModifiers.CtrlShift); protected override ProcessStartInfo? GetProcessStartInfo() { diff --git a/src/Files.App/Commands/HotKey.cs b/src/Files.App/Commands/HotKey/HotKey.cs similarity index 85% rename from src/Files.App/Commands/HotKey.cs rename to src/Files.App/Commands/HotKey/HotKey.cs index bc6cb85412e7..cd9a1b27df38 100644 --- a/src/Files.App/Commands/HotKey.cs +++ b/src/Files.App/Commands/HotKey/HotKey.cs @@ -12,7 +12,10 @@ namespace Files.App.Commands public VirtualKey Key { get; } = VirtualKey.None; public VirtualKeyModifiers Modifiers { get; } = VirtualKeyModifiers.None; - public HotKey(VirtualKey key) : this(key, VirtualKeyModifiers.None) { } + public Keys CommandKey => (Keys)Key; + public KeyModifiers CommandKeyModifiers => (KeyModifiers)Modifiers; + + public HotKey(VirtualKey key) : this(key, VirtualKeyModifiers.None) {} public HotKey(VirtualKey key, VirtualKeyModifiers modifiers) { if (!key.IsValid()) @@ -30,6 +33,8 @@ or VirtualKey.Control or VirtualKey.LeftControl or VirtualKey.RightControl or VirtualKey.Shift or VirtualKey.LeftShift or VirtualKey.RightShift or VirtualKey.LeftWindows or VirtualKey.RightWindows; } + public HotKey(Keys key) : this((VirtualKey)key) {} + public HotKey(Keys key, KeyModifiers modifier) : this((VirtualKey)key, (VirtualKeyModifiers)modifier) {} public void Deconstruct(out VirtualKey key, out VirtualKeyModifiers modifiers) => (key, modifiers) = (Key, Modifiers); diff --git a/src/Files.App/Commands/HotKeyHelpers.cs b/src/Files.App/Commands/HotKey/HotKeyHelpers.cs similarity index 100% rename from src/Files.App/Commands/HotKeyHelpers.cs rename to src/Files.App/Commands/HotKey/HotKeyHelpers.cs diff --git a/src/Files.App/Commands/HotKey/KeyModifiers.cs b/src/Files.App/Commands/HotKey/KeyModifiers.cs new file mode 100644 index 000000000000..f1f6b876c4c5 --- /dev/null +++ b/src/Files.App/Commands/HotKey/KeyModifiers.cs @@ -0,0 +1,25 @@ +using System; + +namespace Files.App.Commands +{ + [Flags] + public enum KeyModifiers : ushort + { + None = 0x0000, + Ctrl = 0x0001, + Menu = 0x0002, + Shift = 0x0004, + Win = 0x0008, + CtrlMenu = Ctrl + Menu, + CtrlShift = Ctrl + Shift, + CtrlWin = Ctrl + Win, + MenuShift = Menu + Shift, + MenuWin = Menu + Win, + ShiftWin = Shift + Win, + CtrlMenuShift = Ctrl + Menu + Shift, + CtrlMenuWin = Ctrl + Menu + Win, + CtrlShiftWin = Ctrl + Shift + Win, + MenuShiftWin = Menu + Shift + Win, + CtrlMenuShiftWin = Ctrl + Menu + Shift + Win, + } +} diff --git a/src/Files.App/Commands/HotKey/Keys.cs b/src/Files.App/Commands/HotKey/Keys.cs new file mode 100644 index 000000000000..2af157b2f39a --- /dev/null +++ b/src/Files.App/Commands/HotKey/Keys.cs @@ -0,0 +1,139 @@ +using Windows.System; + +namespace Files.App.Commands +{ + public enum Keys : ushort + { + None, + Enter = VirtualKey.Enter, + Space = VirtualKey.Space, + Escape = VirtualKey.Escape, + Back = VirtualKey.Back, + Tab = VirtualKey.Tab, + Insert = VirtualKey.Insert, + Delete = VirtualKey.Delete, + Left = VirtualKey.Left, + Right = VirtualKey.Right, + Down = VirtualKey.Down, + Up = VirtualKey.Up, + Home = VirtualKey.Home, + End = VirtualKey.End, + PageDown = VirtualKey.PageDown, + PageUp = VirtualKey.PageUp, + Separator = VirtualKey.Separator, + Pause = VirtualKey.Pause, + Sleep = VirtualKey.Sleep, + Clear = VirtualKey.Clear, + Print = VirtualKey.Print, + Help = VirtualKey.Help, + Mouse4 = VirtualKey.XButton1, + Mouse5 = VirtualKey.XButton2, + F1 = VirtualKey.F1, + F2 = VirtualKey.F2, + F3 = VirtualKey.F3, + F4 = VirtualKey.F4, + F5 = VirtualKey.F5, + F6 = VirtualKey.F6, + F7 = VirtualKey.F7, + F8 = VirtualKey.F8, + F9 = VirtualKey.F9, + F10 = VirtualKey.F10, + F11 = VirtualKey.F11, + F12 = VirtualKey.F12, + F13 = VirtualKey.F13, + F14 = VirtualKey.F14, + F15 = VirtualKey.F15, + F16 = VirtualKey.F16, + F17 = VirtualKey.F17, + F18 = VirtualKey.F18, + F19 = VirtualKey.F19, + F20 = VirtualKey.F20, + F21 = VirtualKey.F21, + F22 = VirtualKey.F22, + F23 = VirtualKey.F23, + F24 = VirtualKey.F24, + Number0 = VirtualKey.Number0, + Number1 = VirtualKey.Number1, + Number2 = VirtualKey.Number2, + Number3 = VirtualKey.Number3, + Number4 = VirtualKey.Number4, + Number5 = VirtualKey.Number5, + Number6 = VirtualKey.Number6, + Number7 = VirtualKey.Number7, + Number8 = VirtualKey.Number8, + Number9 = VirtualKey.Number9, + Pad0 = VirtualKey.NumberPad0, + Pad1 = VirtualKey.NumberPad1, + Pad2 = VirtualKey.NumberPad2, + Pad3 = VirtualKey.NumberPad3, + Pad4 = VirtualKey.NumberPad4, + Pad5 = VirtualKey.NumberPad5, + Pad6 = VirtualKey.NumberPad6, + Pad7 = VirtualKey.NumberPad7, + Pad8 = VirtualKey.NumberPad8, + Pad9 = VirtualKey.NumberPad9, + A = VirtualKey.A, + B = VirtualKey.B, + C = VirtualKey.C, + D = VirtualKey.D, + E = VirtualKey.E, + F = VirtualKey.F, + G = VirtualKey.G, + H = VirtualKey.H, + I = VirtualKey.I, + J = VirtualKey.J, + K = VirtualKey.K, + L = VirtualKey.L, + M = VirtualKey.M, + N = VirtualKey.N, + O = VirtualKey.O, + P = VirtualKey.P, + Q = VirtualKey.Q, + R = VirtualKey.R, + S = VirtualKey.S, + T = VirtualKey.T, + U = VirtualKey.U, + V = VirtualKey.V, + W = VirtualKey.W, + X = VirtualKey.X, + Y = VirtualKey.Y, + Z = VirtualKey.Z, + Add = VirtualKey.Add, + Subtract = VirtualKey.Subtract, + Multiply = VirtualKey.Multiply, + Divide = VirtualKey.Divide, + Oem1 = 186, + Oem2 = 191, + Oem3 = 192, + Oem4 = 219, + Oem5 = 220, + Oem6 = 221, + Oem7 = 222, + Oem8 = 223, + OemPlus = 187, + OemComma = 188, + OemMinus = 189, + OemPeriod = 190, + Oem102 = 226, + OemClear = 254, + Application = VirtualKey.Application, + Application1 = 182, + Application2 = 183, + Mail = 180, + GoHome = VirtualKey.GoHome, + GoBack = VirtualKey.GoBack, + GoForward = VirtualKey.GoForward, + Refresh = VirtualKey.Refresh, + BrowserStop = VirtualKey.Stop, + Search = VirtualKey.Search, + Favorites = VirtualKey.Favorites, + PlayPause = 179, + MediaStop = 178, + PreviousTrack = 177, + NextTrack = 176, + MediaSelect = 181, + Mute = 173, + VolumeDown = 174, + VolumeUp = 175, + } +} From 4aec946f4e509c1c15ef763f0f59c3db209bdad0 Mon Sep 17 00:00:00 2001 From: cinqmilleans Date: Wed, 29 Mar 2023 17:36:17 +0200 Subject: [PATCH 2/6] actions --- .../Actions/Content/Archives/DecompressArchive.cs | 3 +-- .../Content/QuickLook/LaunchQuickLookAction.cs | 3 +-- .../Actions/Content/RefreshItemsAction.cs | 6 ++---- .../Actions/Content/Selection/SelectAllAction.cs | 4 ++-- .../Content/Selection/ToggleSelectAction.cs | 3 +-- src/Files.App/Actions/FileSystem/CopyItemAction.cs | 3 +-- src/Files.App/Actions/FileSystem/CopyPathAction.cs | 3 +-- src/Files.App/Actions/FileSystem/CutItemAction.cs | 3 +-- .../Actions/FileSystem/DeleteItemAction.cs | 3 +-- src/Files.App/Actions/FileSystem/OpenItemAction.cs | 3 +-- .../Actions/FileSystem/PasteItemAction.cs | 3 +-- .../FileSystem/PasteItemToSelectionAction.cs | 3 +-- src/Files.App/Actions/FileSystem/RenameAction.cs | 11 +++++------ .../Actions/Global/EnterCompactOverlayAction.cs | 3 +-- .../Actions/Global/ExitCompactOverlayAction.cs | 3 +-- src/Files.App/Actions/Global/OpenHelpAction.cs | 2 +- src/Files.App/Actions/Global/SearchAction.cs | 6 ++---- .../Actions/Global/ToggleCompactOverlayAction.cs | 3 +-- .../Actions/Global/ToggleFullScreenAction.cs | 3 +-- .../Navigation/DuplicateSelectedTabAction.cs | 3 +-- .../Actions/Navigation/NavigateBackAction.cs | 9 ++++----- .../Actions/Navigation/NavigateForwardAction.cs | 7 +++---- .../Actions/Navigation/NavigateUpAction.cs | 6 ++---- src/Files.App/Actions/Navigation/NewTabAction.cs | 3 +-- .../Actions/Navigation/ReopenClosedTabAction.cs | 3 +-- src/Files.App/Actions/Open/OpenSettingsAction.cs | 3 +-- .../Actions/Show/TogglePreviewPaneAction.cs | 3 +-- .../Actions/Show/ToggleShowHiddenItemsAction.cs | 3 +-- src/Files.App/Commands/HotKey/HotKey.cs | 14 +++++++++++--- src/Files.App/Commands/HotKey/HotKeyHelpers.cs | 10 +++++----- .../Views/LayoutModes/ColumnViewBase.xaml.cs | 2 +- .../Views/LayoutModes/DetailsLayoutBrowser.xaml.cs | 2 +- .../Views/LayoutModes/GridViewBrowser.xaml.cs | 2 +- 33 files changed, 60 insertions(+), 81 deletions(-) diff --git a/src/Files.App/Actions/Content/Archives/DecompressArchive.cs b/src/Files.App/Actions/Content/Archives/DecompressArchive.cs index 41437a50e251..42c2a6bdb6b9 100644 --- a/src/Files.App/Actions/Content/Archives/DecompressArchive.cs +++ b/src/Files.App/Actions/Content/Archives/DecompressArchive.cs @@ -6,7 +6,6 @@ using Files.App.Helpers; using System.ComponentModel; using System.Threading.Tasks; -using Windows.System; namespace Files.App.Actions { @@ -18,7 +17,7 @@ internal class DecompressArchive : ObservableObject, IAction public string Description => "TODO: Need to be described."; - public HotKey HotKey { get; } = new(VirtualKey.E, VirtualKeyModifiers.Control); + public HotKey HotKey { get; } = new(Keys.E, KeyModifiers.Ctrl); public bool IsExecutable => IsContextPageTypeAdaptedToCommand() && ArchiveHelpers.CanDecompress(context.SelectedItems); diff --git a/src/Files.App/Actions/Content/QuickLook/LaunchQuickLookAction.cs b/src/Files.App/Actions/Content/QuickLook/LaunchQuickLookAction.cs index e7a21d649368..eb94ccc70b49 100644 --- a/src/Files.App/Actions/Content/QuickLook/LaunchQuickLookAction.cs +++ b/src/Files.App/Actions/Content/QuickLook/LaunchQuickLookAction.cs @@ -5,7 +5,6 @@ using Files.App.Extensions; using Files.App.Helpers; using System.Threading.Tasks; -using Windows.System; namespace Files.App.Actions { @@ -13,7 +12,7 @@ internal class LaunchQuickLookAction : ObservableObject, IAction { private readonly IContentPageContext context = Ioc.Default.GetRequiredService(); - public HotKey HotKey { get; } = new(VirtualKey.Space); + public HotKey HotKey { get; } = new(Keys.Space); public bool IsExecutable => context.SelectedItems.Count == 1 && (!context.ShellPage?.ToolbarViewModel?.IsEditModeEnabled ?? false) && diff --git a/src/Files.App/Actions/Content/RefreshItemsAction.cs b/src/Files.App/Actions/Content/RefreshItemsAction.cs index 8e68cf3651d4..70ea91f39519 100644 --- a/src/Files.App/Actions/Content/RefreshItemsAction.cs +++ b/src/Files.App/Actions/Content/RefreshItemsAction.cs @@ -5,7 +5,6 @@ using Files.App.Extensions; using System.ComponentModel; using System.Threading.Tasks; -using Windows.System; namespace Files.App.Actions { @@ -18,10 +17,9 @@ internal class RefreshItemsAction : ObservableObject, IAction public RichGlyph Glyph { get; } = new("\uE72C"); - public HotKey HotKey { get; } = new(VirtualKey.R, VirtualKeyModifiers.Control); + public HotKey HotKey { get; } = new(Keys.R, KeyModifiers.Ctrl); + public HotKey SecondHotKey { get; } = new(Keys.F5); - public HotKey SecondHotKey { get; } = new(VirtualKey.F5); - public bool IsExecutable => context.CanRefresh; public RefreshItemsAction() diff --git a/src/Files.App/Actions/Content/Selection/SelectAllAction.cs b/src/Files.App/Actions/Content/Selection/SelectAllAction.cs index 64eb87870494..40354f421b3f 100644 --- a/src/Files.App/Actions/Content/Selection/SelectAllAction.cs +++ b/src/Files.App/Actions/Content/Selection/SelectAllAction.cs @@ -3,7 +3,6 @@ using Files.App.Contexts; using Files.App.Extensions; using System.Threading.Tasks; -using Windows.System; namespace Files.App.Actions { @@ -16,7 +15,8 @@ internal class SelectAllAction : IAction public string Description => "TODO: Need to be described."; public RichGlyph Glyph { get; } = new("\uE8B3"); - public HotKey HotKey { get; } = new(VirtualKey.A, VirtualKeyModifiers.Control); + + public HotKey HotKey { get; } = new(Keys.A, KeyModifiers.Ctrl); public bool IsExecutable { diff --git a/src/Files.App/Actions/Content/Selection/ToggleSelectAction.cs b/src/Files.App/Actions/Content/Selection/ToggleSelectAction.cs index 1a9c95f7fed7..14a4fb008edb 100644 --- a/src/Files.App/Actions/Content/Selection/ToggleSelectAction.cs +++ b/src/Files.App/Actions/Content/Selection/ToggleSelectAction.cs @@ -3,7 +3,6 @@ using Microsoft.UI.Xaml.Controls.Primitives; using Microsoft.UI.Xaml.Input; using System.Threading.Tasks; -using Windows.System; namespace Files.App.Actions { @@ -12,7 +11,7 @@ internal class ToggleSelectAction : IAction public string Label { get; } = "ToggleSelect".GetLocalizedResource(); public string Description => "TODO: Need to be described."; - public HotKey HotKey { get; } = new(VirtualKey.Space, VirtualKeyModifiers.Control); + public HotKey HotKey { get; } = new(Keys.Space, KeyModifiers.Ctrl); public bool IsExecutable => GetFocusedElement() is not null; diff --git a/src/Files.App/Actions/FileSystem/CopyItemAction.cs b/src/Files.App/Actions/FileSystem/CopyItemAction.cs index 7317b2ff9209..d1b9823d3f53 100644 --- a/src/Files.App/Actions/FileSystem/CopyItemAction.cs +++ b/src/Files.App/Actions/FileSystem/CopyItemAction.cs @@ -6,7 +6,6 @@ using Files.App.Helpers; using System.ComponentModel; using System.Threading.Tasks; -using Windows.System; namespace Files.App.Actions { @@ -20,7 +19,7 @@ internal class CopyItemAction : ObservableObject, IAction public RichGlyph Glyph { get; } = new RichGlyph(opacityStyle: "ColorIconCopy"); - public HotKey HotKey { get; } = new(VirtualKey.C, VirtualKeyModifiers.Control); + public HotKey HotKey { get; } = new(Keys.C, KeyModifiers.Ctrl); public bool IsExecutable => context.HasSelection; diff --git a/src/Files.App/Actions/FileSystem/CopyPathAction.cs b/src/Files.App/Actions/FileSystem/CopyPathAction.cs index 2abc2374e221..3c1a5473d92b 100644 --- a/src/Files.App/Actions/FileSystem/CopyPathAction.cs +++ b/src/Files.App/Actions/FileSystem/CopyPathAction.cs @@ -6,7 +6,6 @@ using System; using System.Threading.Tasks; using Windows.ApplicationModel.DataTransfer; -using Windows.System; namespace Files.App.Actions { @@ -20,7 +19,7 @@ internal class CopyPathAction : IAction public RichGlyph Glyph { get; } = new RichGlyph(opacityStyle: "ColorIconCopyLocation"); - public HotKey HotKey { get; } = new(VirtualKey.C, VirtualKeyModifiers.Control | VirtualKeyModifiers.Shift); + public HotKey HotKey { get; } = new(Keys.C, KeyModifiers.CtrlShift); public async Task ExecuteAsync() { diff --git a/src/Files.App/Actions/FileSystem/CutItemAction.cs b/src/Files.App/Actions/FileSystem/CutItemAction.cs index 29cf9981972d..a0878cfe0884 100644 --- a/src/Files.App/Actions/FileSystem/CutItemAction.cs +++ b/src/Files.App/Actions/FileSystem/CutItemAction.cs @@ -6,7 +6,6 @@ using Files.App.Helpers; using System.ComponentModel; using System.Threading.Tasks; -using Windows.System; namespace Files.App.Actions { @@ -20,7 +19,7 @@ internal class CutItemAction : ObservableObject, IAction public RichGlyph Glyph { get; } = new RichGlyph(opacityStyle: "ColorIconCut"); - public HotKey HotKey { get; } = new(VirtualKey.X, VirtualKeyModifiers.Control); + public HotKey HotKey { get; } = new(Keys.X, KeyModifiers.Ctrl); public bool IsExecutable => context.HasSelection; diff --git a/src/Files.App/Actions/FileSystem/DeleteItemAction.cs b/src/Files.App/Actions/FileSystem/DeleteItemAction.cs index 97244a25496e..13872bf4a346 100644 --- a/src/Files.App/Actions/FileSystem/DeleteItemAction.cs +++ b/src/Files.App/Actions/FileSystem/DeleteItemAction.cs @@ -10,7 +10,6 @@ using System.Linq; using System.Threading.Tasks; using Windows.Storage; -using Windows.System; namespace Files.App.Actions { @@ -25,7 +24,7 @@ internal class DeleteItemAction : ObservableObject, IAction public RichGlyph Glyph { get; } = new RichGlyph(opacityStyle: "ColorIconDelete"); - public HotKey HotKey { get; } = new(VirtualKey.Delete); + public HotKey HotKey { get; } = new(Keys.Delete); public bool IsExecutable => context.HasSelection && diff --git a/src/Files.App/Actions/FileSystem/OpenItemAction.cs b/src/Files.App/Actions/FileSystem/OpenItemAction.cs index f211e9d5f575..d9f23beece05 100644 --- a/src/Files.App/Actions/FileSystem/OpenItemAction.cs +++ b/src/Files.App/Actions/FileSystem/OpenItemAction.cs @@ -10,7 +10,6 @@ using System.Linq; using System.Threading.Tasks; using Windows.Storage; -using Windows.System; namespace Files.App.Actions { @@ -24,7 +23,7 @@ internal class OpenItemAction : ObservableObject, IAction public RichGlyph Glyph => new(opacityStyle: "ColorIconOpenFile"); - public HotKey HotKey => new(VirtualKey.Enter); + public HotKey HotKey => new(Keys.Enter); private const int MaxOpenCount = 10; diff --git a/src/Files.App/Actions/FileSystem/PasteItemAction.cs b/src/Files.App/Actions/FileSystem/PasteItemAction.cs index cd1e5b39af27..d8000a885c8f 100644 --- a/src/Files.App/Actions/FileSystem/PasteItemAction.cs +++ b/src/Files.App/Actions/FileSystem/PasteItemAction.cs @@ -7,7 +7,6 @@ using Files.App.Helpers; using System.ComponentModel; using System.Threading.Tasks; -using Windows.System; namespace Files.App.Actions { @@ -21,7 +20,7 @@ internal class PasteItemAction : ObservableObject, IAction public RichGlyph Glyph { get; } = new(opacityStyle: "ColorIconPaste"); - public HotKey HotKey { get; } = new(VirtualKey.V, VirtualKeyModifiers.Control); + public HotKey HotKey { get; } = new(Keys.V, KeyModifiers.Ctrl); private bool isExecutable; public bool IsExecutable => isExecutable; diff --git a/src/Files.App/Actions/FileSystem/PasteItemToSelectionAction.cs b/src/Files.App/Actions/FileSystem/PasteItemToSelectionAction.cs index bba64abbe366..0955ca2ac2c7 100644 --- a/src/Files.App/Actions/FileSystem/PasteItemToSelectionAction.cs +++ b/src/Files.App/Actions/FileSystem/PasteItemToSelectionAction.cs @@ -8,7 +8,6 @@ using Files.App.Helpers; using System.ComponentModel; using System.Threading.Tasks; -using Windows.System; namespace Files.App.Actions { @@ -22,7 +21,7 @@ internal class PasteItemToSelectionAction : ObservableObject, IAction public RichGlyph Glyph { get; } = new(opacityStyle: "ColorIconPaste"); - public HotKey HotKey { get; } = new(VirtualKey.V, VirtualKeyModifiers.Control | VirtualKeyModifiers.Shift); + public HotKey HotKey { get; } = new(Keys.V, KeyModifiers.CtrlShift); private bool isExecutable; public bool IsExecutable => isExecutable; diff --git a/src/Files.App/Actions/FileSystem/RenameAction.cs b/src/Files.App/Actions/FileSystem/RenameAction.cs index 9f75fe93f15b..2ca6ccd854aa 100644 --- a/src/Files.App/Actions/FileSystem/RenameAction.cs +++ b/src/Files.App/Actions/FileSystem/RenameAction.cs @@ -4,7 +4,6 @@ using Files.App.Contexts; using Files.App.Extensions; using System.Threading.Tasks; -using Windows.System; namespace Files.App.Actions { @@ -13,17 +12,17 @@ internal class RenameAction : ObservableObject, IAction private readonly IContentPageContext context = Ioc.Default.GetRequiredService(); public string Label { get; } = "Rename".GetLocalizedResource(); - + public string Description { get; } = "TODO"; - public HotKey HotKey { get; } = new(VirtualKey.F2); + public HotKey HotKey { get; } = new(Keys.F2); public RichGlyph Glyph { get; } = new(opacityStyle: "ColorIconRename"); - public bool IsExecutable => - context.ShellPage is not null && + public bool IsExecutable => + context.ShellPage is not null && IsPageTypeValid() && - context.ShellPage.SlimContentPage is not null && + context.ShellPage.SlimContentPage is not null && IsSelectionValid(); public RenameAction() diff --git a/src/Files.App/Actions/Global/EnterCompactOverlayAction.cs b/src/Files.App/Actions/Global/EnterCompactOverlayAction.cs index 24dcf5b56ee4..8cfe658cc977 100644 --- a/src/Files.App/Actions/Global/EnterCompactOverlayAction.cs +++ b/src/Files.App/Actions/Global/EnterCompactOverlayAction.cs @@ -7,7 +7,6 @@ using System.ComponentModel; using System.Threading.Tasks; using Windows.Graphics; -using Windows.System; namespace Files.App.Actions { @@ -19,7 +18,7 @@ internal class EnterCompactOverlayAction : ObservableObject, IAction public RichGlyph Glyph { get; } = new(opacityStyle: "EnterCompactOverlay"); - public HotKey HotKey { get; } = new(VirtualKey.Up, VirtualKeyModifiers.Menu | VirtualKeyModifiers.Control); + public HotKey HotKey { get; } = new(Keys.Up, KeyModifiers.CtrlMenu); public string Description => "EnterCompactOverlayDescription".GetLocalizedResource(); diff --git a/src/Files.App/Actions/Global/ExitCompactOverlayAction.cs b/src/Files.App/Actions/Global/ExitCompactOverlayAction.cs index 49fc3a188a6b..f8d60a2fb44d 100644 --- a/src/Files.App/Actions/Global/ExitCompactOverlayAction.cs +++ b/src/Files.App/Actions/Global/ExitCompactOverlayAction.cs @@ -6,7 +6,6 @@ using Microsoft.UI.Windowing; using System.ComponentModel; using System.Threading.Tasks; -using Windows.System; namespace Files.App.Actions { @@ -18,7 +17,7 @@ internal class ExitCompactOverlayAction : ObservableObject, IAction public RichGlyph Glyph { get; } = new(opacityStyle: "ExitCompactOverlay"); - public HotKey HotKey { get; } = new(VirtualKey.Down, VirtualKeyModifiers.Menu | VirtualKeyModifiers.Control); + public HotKey HotKey { get; } = new(Keys.Down, KeyModifiers.CtrlMenu); public string Description => "ExitCompactOverlayDescription".GetLocalizedResource(); diff --git a/src/Files.App/Actions/Global/OpenHelpAction.cs b/src/Files.App/Actions/Global/OpenHelpAction.cs index ed8b9a481b8b..5e7a84e4aa6f 100644 --- a/src/Files.App/Actions/Global/OpenHelpAction.cs +++ b/src/Files.App/Actions/Global/OpenHelpAction.cs @@ -12,7 +12,7 @@ internal class OpenHelpAction : IAction public string Description => "TODO: Need to be described."; - public HotKey HotKey { get; } = new(VirtualKey.F1); + public HotKey HotKey { get; } = new(Keys.F1); public async Task ExecuteAsync() { diff --git a/src/Files.App/Actions/Global/SearchAction.cs b/src/Files.App/Actions/Global/SearchAction.cs index 389d4f840675..6885fc69f6f2 100644 --- a/src/Files.App/Actions/Global/SearchAction.cs +++ b/src/Files.App/Actions/Global/SearchAction.cs @@ -5,7 +5,6 @@ using Files.App.Extensions; using System.ComponentModel; using System.Threading.Tasks; -using Windows.System; namespace Files.App.Actions { @@ -17,9 +16,8 @@ internal class SearchAction : ObservableObject, IAction public string Description { get; } = "TODO: Need to be described."; - public HotKey HotKey { get; } = new(VirtualKey.F, VirtualKeyModifiers.Control); - - public HotKey SecondHotKey { get; } = new(VirtualKey.F3); + public HotKey HotKey { get; } = new(Keys.F, KeyModifiers.Ctrl); + public HotKey SecondHotKey { get; } = new(Keys.F3); public RichGlyph Glyph { get; } = new(); diff --git a/src/Files.App/Actions/Global/ToggleCompactOverlayAction.cs b/src/Files.App/Actions/Global/ToggleCompactOverlayAction.cs index 32f8c6c1b582..67d2e476682c 100644 --- a/src/Files.App/Actions/Global/ToggleCompactOverlayAction.cs +++ b/src/Files.App/Actions/Global/ToggleCompactOverlayAction.cs @@ -7,7 +7,6 @@ using System.ComponentModel; using System.Threading.Tasks; using Windows.Graphics; -using Windows.System; namespace Files.App.Actions { @@ -17,7 +16,7 @@ internal class ToggleCompactOverlayAction : ObservableObject, IToggleAction public string Label { get; } = "ToggleCompactOverlay".GetLocalizedResource(); - public HotKey HotKey { get; } = new(VirtualKey.F12); + public HotKey HotKey { get; } = new(Keys.F12); public string Description => "ToggleCompactOverlayDescription".GetLocalizedResource(); diff --git a/src/Files.App/Actions/Global/ToggleFullScreenAction.cs b/src/Files.App/Actions/Global/ToggleFullScreenAction.cs index e522ef2d1dbb..1409f8ae0feb 100644 --- a/src/Files.App/Actions/Global/ToggleFullScreenAction.cs +++ b/src/Files.App/Actions/Global/ToggleFullScreenAction.cs @@ -2,7 +2,6 @@ using Files.App.Extensions; using Microsoft.UI.Windowing; using System.Threading.Tasks; -using Windows.System; namespace Files.App.Actions { @@ -12,7 +11,7 @@ internal class ToggleFullScreenAction : IToggleAction public string Description => "TODO: Need to be described."; - public HotKey HotKey { get; } = new(VirtualKey.F11); + public HotKey HotKey { get; } = new(Keys.F11); public bool IsOn { diff --git a/src/Files.App/Actions/Navigation/DuplicateSelectedTabAction.cs b/src/Files.App/Actions/Navigation/DuplicateSelectedTabAction.cs index 12d4a021b804..566b3f00138a 100644 --- a/src/Files.App/Actions/Navigation/DuplicateSelectedTabAction.cs +++ b/src/Files.App/Actions/Navigation/DuplicateSelectedTabAction.cs @@ -4,7 +4,6 @@ using Files.App.Extensions; using Files.App.Views; using System.Threading.Tasks; -using Windows.System; using static Files.App.ViewModels.MainPageViewModel; namespace Files.App.Actions @@ -16,7 +15,7 @@ internal class DuplicateSelectedTabAction : IAction public string Label { get; } = "DuplicateTab".GetLocalizedResource(); public string Description => "TODO: Need to be described."; - public HotKey HotKey { get; } = new(VirtualKey.K, VirtualKeyModifiers.Control | VirtualKeyModifiers.Shift); + public HotKey HotKey { get; } = new(Keys.K, KeyModifiers.CtrlShift); public async Task ExecuteAsync() { diff --git a/src/Files.App/Actions/Navigation/NavigateBackAction.cs b/src/Files.App/Actions/Navigation/NavigateBackAction.cs index 24ddeec2916b..b2f09bd8a59d 100644 --- a/src/Files.App/Actions/Navigation/NavigateBackAction.cs +++ b/src/Files.App/Actions/Navigation/NavigateBackAction.cs @@ -5,7 +5,6 @@ using Files.App.Extensions; using System.ComponentModel; using System.Threading.Tasks; -using Windows.System; namespace Files.App.Actions { @@ -17,10 +16,10 @@ internal class NavigateBackAction : ObservableObject, IAction public string Description { get; } = "NavigateBack".GetLocalizedResource(); - public HotKey HotKey { get; } = new(VirtualKey.Left, VirtualKeyModifiers.Menu); - public HotKey SecondHotKey { get; } = new(VirtualKey.Back); - public HotKey ThirdHotKey { get; } = new(VirtualKey.XButton1); - public HotKey MediaHotKey { get; } = new(VirtualKey.GoBack); + public HotKey HotKey { get; } = new(Keys.Left, KeyModifiers.Menu); + public HotKey SecondHotKey { get; } = new(Keys.Back); + public HotKey ThirdHotKey { get; } = new(Keys.Mouse4); + public HotKey MediaHotKey { get; } = new(Keys.GoBack); public RichGlyph Glyph { get; } = new("\uE72B"); diff --git a/src/Files.App/Actions/Navigation/NavigateForwardAction.cs b/src/Files.App/Actions/Navigation/NavigateForwardAction.cs index 1651cad21f98..0cbb8e38da99 100644 --- a/src/Files.App/Actions/Navigation/NavigateForwardAction.cs +++ b/src/Files.App/Actions/Navigation/NavigateForwardAction.cs @@ -5,7 +5,6 @@ using Files.App.Extensions; using System.ComponentModel; using System.Threading.Tasks; -using Windows.System; namespace Files.App.Actions { @@ -17,9 +16,9 @@ internal class NavigateForwardAction : ObservableObject, IAction public string Description { get; } = "NavigateForward".GetLocalizedResource(); - public HotKey HotKey { get; } = new(VirtualKey.Right, VirtualKeyModifiers.Menu); - public HotKey SecondHotKey { get; } = new(VirtualKey.XButton2); - public HotKey MediaHotKey { get; } = new(VirtualKey.GoForward); + public HotKey HotKey { get; } = new(Keys.Right, KeyModifiers.Menu); + public HotKey SecondHotKey { get; } = new(Keys.Mouse5); + public HotKey MediaHotKey { get; } = new(Keys.GoForward); public RichGlyph Glyph { get; } = new("\uE72A"); diff --git a/src/Files.App/Actions/Navigation/NavigateUpAction.cs b/src/Files.App/Actions/Navigation/NavigateUpAction.cs index 4ef98e595b8e..80d4bc096a27 100644 --- a/src/Files.App/Actions/Navigation/NavigateUpAction.cs +++ b/src/Files.App/Actions/Navigation/NavigateUpAction.cs @@ -1,12 +1,10 @@ - -using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.DependencyInjection; using Files.App.Commands; using Files.App.Contexts; using Files.App.Extensions; using System.ComponentModel; using System.Threading.Tasks; -using Windows.System; namespace Files.App.Actions { @@ -18,7 +16,7 @@ internal class NavigateUpAction : ObservableObject, IAction public string Description { get; } = "NavigateUp".GetLocalizedResource(); - public HotKey HotKey { get; } = new(VirtualKey.Up, VirtualKeyModifiers.Menu); + public HotKey HotKey { get; } = new(Keys.Up, KeyModifiers.Menu); public RichGlyph Glyph { get; } = new("\uE74A"); diff --git a/src/Files.App/Actions/Navigation/NewTabAction.cs b/src/Files.App/Actions/Navigation/NewTabAction.cs index c01a70f3b888..cd5677d4e284 100644 --- a/src/Files.App/Actions/Navigation/NewTabAction.cs +++ b/src/Files.App/Actions/Navigation/NewTabAction.cs @@ -2,7 +2,6 @@ using Files.App.Extensions; using Files.App.ViewModels; using System.Threading.Tasks; -using Windows.System; namespace Files.App.Actions { @@ -12,7 +11,7 @@ internal class NewTabAction : IAction public string Description => "TODO: Need to be described."; - public HotKey HotKey { get; } = new(VirtualKey.T, VirtualKeyModifiers.Control); + public HotKey HotKey { get; } = new(Keys.T, KeyModifiers.Ctrl); public Task ExecuteAsync() => MainPageViewModel.AddNewTabAsync(); } diff --git a/src/Files.App/Actions/Navigation/ReopenClosedTabAction.cs b/src/Files.App/Actions/Navigation/ReopenClosedTabAction.cs index 01e92ccc7742..01faa922bb84 100644 --- a/src/Files.App/Actions/Navigation/ReopenClosedTabAction.cs +++ b/src/Files.App/Actions/Navigation/ReopenClosedTabAction.cs @@ -6,7 +6,6 @@ using Files.App.UserControls.MultitaskingControl; using System.ComponentModel; using System.Threading.Tasks; -using Windows.System; namespace Files.App.Actions { @@ -18,7 +17,7 @@ internal class ReopenClosedTabAction : ObservableObject, IAction public string Description { get; } = "TODO: Need to be described"; - public HotKey HotKey { get; } = new(VirtualKey.T, VirtualKeyModifiers.Control | VirtualKeyModifiers.Shift); + public HotKey HotKey { get; } = new(Keys.T, KeyModifiers.CtrlShift); public bool IsExecutable => context.Control is not null && diff --git a/src/Files.App/Actions/Open/OpenSettingsAction.cs b/src/Files.App/Actions/Open/OpenSettingsAction.cs index 912df47c168e..9d3ec7b20bef 100644 --- a/src/Files.App/Actions/Open/OpenSettingsAction.cs +++ b/src/Files.App/Actions/Open/OpenSettingsAction.cs @@ -5,7 +5,6 @@ using Files.Backend.Services; using Files.Backend.ViewModels.Dialogs; using System.Threading.Tasks; -using Windows.System; namespace Files.App.Actions { @@ -19,7 +18,7 @@ internal class OpenSettingsAction : IAction public string Description => "Settings".GetLocalizedResource(); - public HotKey HotKey { get; } = new((VirtualKey)188, VirtualKeyModifiers.Control); + public HotKey HotKey { get; } = new(Keys.OemComma, KeyModifiers.Ctrl); public async Task ExecuteAsync() { diff --git a/src/Files.App/Actions/Show/TogglePreviewPaneAction.cs b/src/Files.App/Actions/Show/TogglePreviewPaneAction.cs index 18132930a464..ac6e30c5b599 100644 --- a/src/Files.App/Actions/Show/TogglePreviewPaneAction.cs +++ b/src/Files.App/Actions/Show/TogglePreviewPaneAction.cs @@ -5,7 +5,6 @@ using Files.App.ViewModels; using System.ComponentModel; using System.Threading.Tasks; -using Windows.System; namespace Files.App.Actions { @@ -18,7 +17,7 @@ internal class TogglePreviewPaneAction : ObservableObject, IToggleAction public string Description => "TODO: Need to be described."; public RichGlyph Glyph { get; } = new(opacityStyle: "ColorIconRightPane"); - public HotKey HotKey { get; } = new(VirtualKey.P, VirtualKeyModifiers.Control); + public HotKey HotKey { get; } = new(Keys.P, KeyModifiers.Ctrl); public bool IsOn => viewModel.IsEnabled; diff --git a/src/Files.App/Actions/Show/ToggleShowHiddenItemsAction.cs b/src/Files.App/Actions/Show/ToggleShowHiddenItemsAction.cs index 4148b275760e..5708b7e45e49 100644 --- a/src/Files.App/Actions/Show/ToggleShowHiddenItemsAction.cs +++ b/src/Files.App/Actions/Show/ToggleShowHiddenItemsAction.cs @@ -5,7 +5,6 @@ using Files.Backend.Services.Settings; using System.ComponentModel; using System.Threading.Tasks; -using Windows.System; namespace Files.App.Actions { @@ -17,7 +16,7 @@ internal class ToggleShowHiddenItemsAction : ObservableObject, IToggleAction public string Description => "TODO: Need to be described."; - public HotKey HotKey { get; } = new(VirtualKey.H, VirtualKeyModifiers.Control); + public HotKey HotKey { get; } = new(Keys.H, KeyModifiers.Ctrl); public bool IsOn => settings.ShowHiddenItems; diff --git a/src/Files.App/Commands/HotKey/HotKey.cs b/src/Files.App/Commands/HotKey/HotKey.cs index cd9a1b27df38..050b82bee994 100644 --- a/src/Files.App/Commands/HotKey/HotKey.cs +++ b/src/Files.App/Commands/HotKey/HotKey.cs @@ -5,7 +5,7 @@ namespace Files.App.Commands { public readonly struct HotKey : IEquatable { - public static HotKey None { get; } = new(VirtualKey.None, VirtualKeyModifiers.None); + public static HotKey None { get; } = new(Keys.None, KeyModifiers.None); public bool IsNone => Key is VirtualKey.None; @@ -15,6 +15,16 @@ namespace Files.App.Commands public Keys CommandKey => (Keys)Key; public KeyModifiers CommandKeyModifiers => (KeyModifiers)Modifiers; + public HotKey(Keys key) : this(key, KeyModifiers.None) {} + public HotKey(Keys key, KeyModifiers modifier) + { + if (key is Keys.None) + return; + + Key = (VirtualKey)key; + Modifiers = (VirtualKeyModifiers)modifier; + } + public HotKey(VirtualKey key) : this(key, VirtualKeyModifiers.None) {} public HotKey(VirtualKey key, VirtualKeyModifiers modifiers) { @@ -33,8 +43,6 @@ or VirtualKey.Control or VirtualKey.LeftControl or VirtualKey.RightControl or VirtualKey.Shift or VirtualKey.LeftShift or VirtualKey.RightShift or VirtualKey.LeftWindows or VirtualKey.RightWindows; } - public HotKey(Keys key) : this((VirtualKey)key) {} - public HotKey(Keys key, KeyModifiers modifier) : this((VirtualKey)key, (VirtualKeyModifiers)modifier) {} public void Deconstruct(out VirtualKey key, out VirtualKeyModifiers modifiers) => (key, modifiers) = (Key, Modifiers); diff --git a/src/Files.App/Commands/HotKey/HotKeyHelpers.cs b/src/Files.App/Commands/HotKey/HotKeyHelpers.cs index 74038c60dc01..798d35376be5 100644 --- a/src/Files.App/Commands/HotKey/HotKeyHelpers.cs +++ b/src/Files.App/Commands/HotKey/HotKeyHelpers.cs @@ -194,11 +194,11 @@ internal static class HotKeyHelpers private static readonly ImmutableArray textBoxHotKeys = new List { - new HotKey(VirtualKey.X, VirtualKeyModifiers.Control), // Cut - new HotKey(VirtualKey.C, VirtualKeyModifiers.Control), // Copy - new HotKey(VirtualKey.V, VirtualKeyModifiers.Control), // Paste - new HotKey(VirtualKey.A, VirtualKeyModifiers.Control), // Select all - new HotKey(VirtualKey.Z, VirtualKeyModifiers.Control), // Cancel + new HotKey(Keys.X, KeyModifiers.Ctrl), // Cut + new HotKey(Keys.C, KeyModifiers.Ctrl), // Copy + new HotKey(Keys.V, KeyModifiers.Ctrl), // Paste + new HotKey(Keys.A, KeyModifiers.Ctrl), // Select all + new HotKey(Keys.Z, KeyModifiers.Ctrl), // Cancel }.ToImmutableArray(); public static bool IsValid(this VirtualKeyModifiers modifier) => modifiers.ContainsKey(modifier); diff --git a/src/Files.App/Views/LayoutModes/ColumnViewBase.xaml.cs b/src/Files.App/Views/LayoutModes/ColumnViewBase.xaml.cs index 94ce4812d03b..2c96c466dbba 100644 --- a/src/Files.App/Views/LayoutModes/ColumnViewBase.xaml.cs +++ b/src/Files.App/Views/LayoutModes/ColumnViewBase.xaml.cs @@ -262,7 +262,7 @@ protected override async void FileList_PreviewKeyDown(object sender, KeyRoutedEv e.Handled = true; var commands = Ioc.Default.GetRequiredService(); - var hotKey = new HotKey(VirtualKey.A, VirtualKeyModifiers.Control); + var hotKey = new HotKey(Keys.A, KeyModifiers.Ctrl); await commands[hotKey].ExecuteAsync(); diff --git a/src/Files.App/Views/LayoutModes/DetailsLayoutBrowser.xaml.cs b/src/Files.App/Views/LayoutModes/DetailsLayoutBrowser.xaml.cs index 0e27dc64d318..07baad5b44fb 100644 --- a/src/Files.App/Views/LayoutModes/DetailsLayoutBrowser.xaml.cs +++ b/src/Files.App/Views/LayoutModes/DetailsLayoutBrowser.xaml.cs @@ -323,7 +323,7 @@ protected override async void FileList_PreviewKeyDown(object sender, KeyRoutedEv e.Handled = true; var commands = Ioc.Default.GetRequiredService(); - var hotKey = new HotKey(VirtualKey.A, VirtualKeyModifiers.Control); + var hotKey = new HotKey(Keys.A, KeyModifiers.Ctrl); await commands[hotKey].ExecuteAsync(); diff --git a/src/Files.App/Views/LayoutModes/GridViewBrowser.xaml.cs b/src/Files.App/Views/LayoutModes/GridViewBrowser.xaml.cs index d9cf4ef982c4..7119fdf9940f 100644 --- a/src/Files.App/Views/LayoutModes/GridViewBrowser.xaml.cs +++ b/src/Files.App/Views/LayoutModes/GridViewBrowser.xaml.cs @@ -260,7 +260,7 @@ protected override async void FileList_PreviewKeyDown(object sender, KeyRoutedEv e.Handled = true; var commands = Ioc.Default.GetRequiredService(); - var hotKey = new HotKey(VirtualKey.A, VirtualKeyModifiers.Control); + var hotKey = new HotKey(Keys.A, KeyModifiers.Ctrl); await commands[hotKey].ExecuteAsync(); From f65ea3cfedf9d6660c6772c33fb4c8049b8ede90 Mon Sep 17 00:00:00 2001 From: cinqmilleans Date: Wed, 29 Mar 2023 18:11:38 +0200 Subject: [PATCH 3/6] Helpers --- .../Global/EnterCompactOverlayAction.cs | 2 +- .../Global/ExitCompactOverlayAction.cs | 2 +- src/Files.App/Commands/HotKey/HotKey.cs | 35 +- .../Commands/HotKey/HotKeyHelpers.cs | 389 +++++++++--------- src/Files.App/Commands/HotKey/KeyModifiers.cs | 8 +- src/Files.App/Views/MainPage.xaml.cs | 6 +- 6 files changed, 205 insertions(+), 237 deletions(-) diff --git a/src/Files.App/Actions/Global/EnterCompactOverlayAction.cs b/src/Files.App/Actions/Global/EnterCompactOverlayAction.cs index 8cfe658cc977..2ca3a355b939 100644 --- a/src/Files.App/Actions/Global/EnterCompactOverlayAction.cs +++ b/src/Files.App/Actions/Global/EnterCompactOverlayAction.cs @@ -18,7 +18,7 @@ internal class EnterCompactOverlayAction : ObservableObject, IAction public RichGlyph Glyph { get; } = new(opacityStyle: "EnterCompactOverlay"); - public HotKey HotKey { get; } = new(Keys.Up, KeyModifiers.CtrlMenu); + public HotKey HotKey { get; } = new(Keys.Up, KeyModifiers.MenuCtrl); public string Description => "EnterCompactOverlayDescription".GetLocalizedResource(); diff --git a/src/Files.App/Actions/Global/ExitCompactOverlayAction.cs b/src/Files.App/Actions/Global/ExitCompactOverlayAction.cs index f8d60a2fb44d..e0ad9ca80f23 100644 --- a/src/Files.App/Actions/Global/ExitCompactOverlayAction.cs +++ b/src/Files.App/Actions/Global/ExitCompactOverlayAction.cs @@ -17,7 +17,7 @@ internal class ExitCompactOverlayAction : ObservableObject, IAction public RichGlyph Glyph { get; } = new(opacityStyle: "ExitCompactOverlay"); - public HotKey HotKey { get; } = new(Keys.Down, KeyModifiers.CtrlMenu); + public HotKey HotKey { get; } = new(Keys.Down, KeyModifiers.MenuCtrl); public string Description => "ExitCompactOverlayDescription".GetLocalizedResource(); diff --git a/src/Files.App/Commands/HotKey/HotKey.cs b/src/Files.App/Commands/HotKey/HotKey.cs index 050b82bee994..2baf9ee895f6 100644 --- a/src/Files.App/Commands/HotKey/HotKey.cs +++ b/src/Files.App/Commands/HotKey/HotKey.cs @@ -1,5 +1,4 @@ using System; -using Windows.System; namespace Files.App.Commands { @@ -7,44 +6,22 @@ namespace Files.App.Commands { public static HotKey None { get; } = new(Keys.None, KeyModifiers.None); - public bool IsNone => Key is VirtualKey.None; + public bool IsNone => Key is Keys.None; - public VirtualKey Key { get; } = VirtualKey.None; - public VirtualKeyModifiers Modifiers { get; } = VirtualKeyModifiers.None; - - public Keys CommandKey => (Keys)Key; - public KeyModifiers CommandKeyModifiers => (KeyModifiers)Modifiers; + public Keys Key { get; } + public KeyModifiers Modifiers { get; } public HotKey(Keys key) : this(key, KeyModifiers.None) {} - public HotKey(Keys key, KeyModifiers modifier) - { - if (key is Keys.None) - return; - - Key = (VirtualKey)key; - Modifiers = (VirtualKeyModifiers)modifier; - } - - public HotKey(VirtualKey key) : this(key, VirtualKeyModifiers.None) {} - public HotKey(VirtualKey key, VirtualKeyModifiers modifiers) + public HotKey(Keys key, KeyModifiers modifiers) { - if (!key.IsValid()) + if (key is Keys.None || !Enum.IsDefined(key)) return; - if (IsModifier(key)) - throw new ArgumentException("The key cannot be a modifier.", nameof(key)); - Key = key; Modifiers = modifiers; - - static bool IsModifier(VirtualKey key) - => key is VirtualKey.Menu or VirtualKey.LeftMenu or VirtualKey.RightMenu - or VirtualKey.Control or VirtualKey.LeftControl or VirtualKey.RightControl - or VirtualKey.Shift or VirtualKey.LeftShift or VirtualKey.RightShift - or VirtualKey.LeftWindows or VirtualKey.RightWindows; } - public void Deconstruct(out VirtualKey key, out VirtualKeyModifiers modifiers) + public void Deconstruct(out Keys key, out KeyModifiers modifiers) => (key, modifiers) = (Key, Modifiers); public static implicit operator string(HotKey hotKey) => hotKey.ToString(); diff --git a/src/Files.App/Commands/HotKey/HotKeyHelpers.cs b/src/Files.App/Commands/HotKey/HotKeyHelpers.cs index 798d35376be5..c0e668c5355b 100644 --- a/src/Files.App/Commands/HotKey/HotKeyHelpers.cs +++ b/src/Files.App/Commands/HotKey/HotKeyHelpers.cs @@ -12,184 +12,184 @@ namespace Files.App.Commands { internal static class HotKeyHelpers { - private static readonly IImmutableDictionary modifiers = new Dictionary() + private static readonly IImmutableDictionary modifiers = new Dictionary() { - [VirtualKeyModifiers.Menu] = "Menu".GetString(), - [VirtualKeyModifiers.Control] = "Control".GetString(), - [VirtualKeyModifiers.Shift] = "Shift".GetString(), - [VirtualKeyModifiers.Windows] = "Windows".GetString(), + [KeyModifiers.Menu] = "Menu".GetString(), + [KeyModifiers.Ctrl] = "Control".GetString(), + [KeyModifiers.Shift] = "Shift".GetString(), + [KeyModifiers.Win] = "Windows".GetString(), }.ToImmutableDictionary(); - private static readonly IImmutableDictionary keys = new Dictionary() + private static readonly IImmutableDictionary keys = new Dictionary() { - [VirtualKey.Enter] = "Enter".GetString(), - [VirtualKey.Space] = "Space".GetString(), - [VirtualKey.Escape] = "Escape".GetString(), - [VirtualKey.Back] = "Back".GetString(), - [VirtualKey.Tab] = "Tab".GetString(), - [VirtualKey.Insert] = "Insert".GetString(), - [VirtualKey.Delete] = "Delete".GetString(), - [VirtualKey.Left] = "Left".GetString(), - [VirtualKey.Right] = "Right".GetString(), - [VirtualKey.Down] = "Down".GetString(), - [VirtualKey.Up] = "Up".GetString(), - [VirtualKey.Home] = "Home".GetString(), - [VirtualKey.End] = "End".GetString(), - [VirtualKey.PageDown] = "PageDown".GetString(), - [VirtualKey.PageUp] = "PageUp".GetString(), - [VirtualKey.Separator] = "Separator".GetString(), - [VirtualKey.Pause] = "Pause".GetString(), - [VirtualKey.Sleep] = "Sleep".GetString(), - [VirtualKey.Clear] = "Clear".GetString(), - [VirtualKey.Print] = "Print".GetString(), - [VirtualKey.Help] = "Help".GetString(), - [VirtualKey.XButton1] = "Mouse4".GetString(), - [VirtualKey.XButton2] = "Mouse5".GetString(), - [VirtualKey.F1] = "F1", - [VirtualKey.F2] = "F2", - [VirtualKey.F3] = "F3", - [VirtualKey.F4] = "F4", - [VirtualKey.F5] = "F5", - [VirtualKey.F6] = "F6", - [VirtualKey.F7] = "F7", - [VirtualKey.F8] = "F8", - [VirtualKey.F9] = "F9", - [VirtualKey.F10] = "F10", - [VirtualKey.F11] = "F11", - [VirtualKey.F12] = "F12", - [VirtualKey.F13] = "F13", - [VirtualKey.F14] = "F14", - [VirtualKey.F15] = "F15", - [VirtualKey.F16] = "F16", - [VirtualKey.F17] = "F17", - [VirtualKey.F18] = "F18", - [VirtualKey.F19] = "F19", - [VirtualKey.F20] = "F20", - [VirtualKey.F21] = "F21", - [VirtualKey.F22] = "F22", - [VirtualKey.F23] = "F23", - [VirtualKey.F24] = "F24", - [VirtualKey.Number0] = "0", - [VirtualKey.Number1] = "1", - [VirtualKey.Number2] = "2", - [VirtualKey.Number3] = "3", - [VirtualKey.Number4] = "4", - [VirtualKey.Number5] = "5", - [VirtualKey.Number6] = "6", - [VirtualKey.Number7] = "7", - [VirtualKey.Number8] = "8", - [VirtualKey.Number9] = "9", - [VirtualKey.NumberPad0] = "Pad0".GetString(), - [VirtualKey.NumberPad1] = "Pad1".GetString(), - [VirtualKey.NumberPad2] = "Pad2".GetString(), - [VirtualKey.NumberPad3] = "Pad3".GetString(), - [VirtualKey.NumberPad4] = "Pad4".GetString(), - [VirtualKey.NumberPad5] = "Pad5".GetString(), - [VirtualKey.NumberPad6] = "Pad6".GetString(), - [VirtualKey.NumberPad7] = "Pad7".GetString(), - [VirtualKey.NumberPad8] = "Pad8".GetString(), - [VirtualKey.NumberPad9] = "Pad9".GetString(), - [VirtualKey.A] = "A", - [VirtualKey.B] = "B", - [VirtualKey.C] = "C", - [VirtualKey.D] = "D", - [VirtualKey.E] = "E", - [VirtualKey.F] = "F", - [VirtualKey.G] = "G", - [VirtualKey.H] = "H", - [VirtualKey.I] = "I", - [VirtualKey.J] = "J", - [VirtualKey.K] = "K", - [VirtualKey.L] = "L", - [VirtualKey.M] = "M", - [VirtualKey.N] = "N", - [VirtualKey.O] = "O", - [VirtualKey.P] = "P", - [VirtualKey.Q] = "Q", - [VirtualKey.R] = "R", - [VirtualKey.S] = "S", - [VirtualKey.T] = "T", - [VirtualKey.U] = "U", - [VirtualKey.V] = "V", - [VirtualKey.W] = "W", - [VirtualKey.X] = "X", - [VirtualKey.Y] = "Y", - [VirtualKey.Z] = "Z", - [VirtualKey.Add] = "+", - [VirtualKey.Subtract] = "-", - [VirtualKey.Multiply] = "*", - [VirtualKey.Divide] = "/", - [(VirtualKey)186] = GetCharacter(Forms.Keys.Oem1), - [(VirtualKey)187] = GetCharacter(Forms.Keys.Oemplus), - [(VirtualKey)188] = GetCharacter(Forms.Keys.Oemcomma), - [(VirtualKey)189] = GetCharacter(Forms.Keys.OemMinus), - [(VirtualKey)190] = GetCharacter(Forms.Keys.OemPeriod), - [(VirtualKey)191] = GetCharacter(Forms.Keys.Oem2), - [(VirtualKey)192] = GetCharacter(Forms.Keys.Oem3), - [(VirtualKey)219] = GetCharacter(Forms.Keys.Oem4), - [(VirtualKey)220] = GetCharacter(Forms.Keys.Oem5), - [(VirtualKey)221] = GetCharacter(Forms.Keys.Oem6), - [(VirtualKey)222] = GetCharacter(Forms.Keys.Oem7), - [(VirtualKey)223] = GetCharacter(Forms.Keys.Oem8), - [(VirtualKey)226] = GetCharacter(Forms.Keys.Oem102), - [(VirtualKey)254] = GetCharacter(Forms.Keys.OemClear), - [VirtualKey.Application] = "Application".GetString(), - [(VirtualKey)182] = "Application1".GetString(), - [(VirtualKey)183] = "Application2".GetString(), - [(VirtualKey)180] = "Mail".GetString(), - [VirtualKey.GoHome] = "BrowserGoHome".GetString(), - [VirtualKey.GoBack] = "BrowserGoBack".GetString(), - [VirtualKey.GoForward] = "BrowserGoForward".GetString(), - [VirtualKey.Refresh] = "BrowserRefresh".GetString(), - [VirtualKey.Stop] = "BrowserStop".GetString(), - [VirtualKey.Search] = "BrowserSearch".GetString(), - [VirtualKey.Favorites] = "BrowserFavorites".GetString(), - [(VirtualKey)179] = "MediaPlayPause".GetString(), - [(VirtualKey)178] = "MediaStop".GetString(), - [(VirtualKey)177] = "MediaPreviousTrack".GetString(), - [(VirtualKey)176] = "MediaNextTrack".GetString(), - [(VirtualKey)181] = "MediaSelect".GetString(), - [(VirtualKey)173] = "MediaMute".GetString(), - [(VirtualKey)174] = "MediaVolumeDown".GetString(), - [(VirtualKey)175] = "MediaVolumeUp".GetString(), + [Keys.Enter] = "Enter".GetString(), + [Keys.Space] = "Space".GetString(), + [Keys.Escape] = "Escape".GetString(), + [Keys.Back] = "Back".GetString(), + [Keys.Tab] = "Tab".GetString(), + [Keys.Insert] = "Insert".GetString(), + [Keys.Delete] = "Delete".GetString(), + [Keys.Left] = "Left".GetString(), + [Keys.Right] = "Right".GetString(), + [Keys.Down] = "Down".GetString(), + [Keys.Up] = "Up".GetString(), + [Keys.Home] = "Home".GetString(), + [Keys.End] = "End".GetString(), + [Keys.PageDown] = "PageDown".GetString(), + [Keys.PageUp] = "PageUp".GetString(), + [Keys.Separator] = "Separator".GetString(), + [Keys.Pause] = "Pause".GetString(), + [Keys.Sleep] = "Sleep".GetString(), + [Keys.Clear] = "Clear".GetString(), + [Keys.Print] = "Print".GetString(), + [Keys.Help] = "Help".GetString(), + [Keys.Mouse4] = "Mouse4".GetString(), + [Keys.Mouse5] = "Mouse5".GetString(), + [Keys.F1] = "F1", + [Keys.F2] = "F2", + [Keys.F3] = "F3", + [Keys.F4] = "F4", + [Keys.F5] = "F5", + [Keys.F6] = "F6", + [Keys.F7] = "F7", + [Keys.F8] = "F8", + [Keys.F9] = "F9", + [Keys.F10] = "F10", + [Keys.F11] = "F11", + [Keys.F12] = "F12", + [Keys.F13] = "F13", + [Keys.F14] = "F14", + [Keys.F15] = "F15", + [Keys.F16] = "F16", + [Keys.F17] = "F17", + [Keys.F18] = "F18", + [Keys.F19] = "F19", + [Keys.F20] = "F20", + [Keys.F21] = "F21", + [Keys.F22] = "F22", + [Keys.F23] = "F23", + [Keys.F24] = "F24", + [Keys.Number0] = "0", + [Keys.Number1] = "1", + [Keys.Number2] = "2", + [Keys.Number3] = "3", + [Keys.Number4] = "4", + [Keys.Number5] = "5", + [Keys.Number6] = "6", + [Keys.Number7] = "7", + [Keys.Number8] = "8", + [Keys.Number9] = "9", + [Keys.Pad0] = "Pad0".GetString(), + [Keys.Pad1] = "Pad1".GetString(), + [Keys.Pad2] = "Pad2".GetString(), + [Keys.Pad3] = "Pad3".GetString(), + [Keys.Pad4] = "Pad4".GetString(), + [Keys.Pad5] = "Pad5".GetString(), + [Keys.Pad6] = "Pad6".GetString(), + [Keys.Pad7] = "Pad7".GetString(), + [Keys.Pad8] = "Pad8".GetString(), + [Keys.Pad9] = "Pad9".GetString(), + [Keys.A] = "A", + [Keys.B] = "B", + [Keys.C] = "C", + [Keys.D] = "D", + [Keys.E] = "E", + [Keys.F] = "F", + [Keys.G] = "G", + [Keys.H] = "H", + [Keys.I] = "I", + [Keys.J] = "J", + [Keys.K] = "K", + [Keys.L] = "L", + [Keys.M] = "M", + [Keys.N] = "N", + [Keys.O] = "O", + [Keys.P] = "P", + [Keys.Q] = "Q", + [Keys.R] = "R", + [Keys.S] = "S", + [Keys.T] = "T", + [Keys.U] = "U", + [Keys.V] = "V", + [Keys.W] = "W", + [Keys.X] = "X", + [Keys.Y] = "Y", + [Keys.Z] = "Z", + [Keys.Add] = "+", + [Keys.Subtract] = "-", + [Keys.Multiply] = "*", + [Keys.Divide] = "/", + [Keys.Oem1] = GetCharacter(Forms.Keys.Oem1), + [Keys.Oem2] = GetCharacter(Forms.Keys.Oem2), + [Keys.Oem3] = GetCharacter(Forms.Keys.Oem3), + [Keys.Oem4] = GetCharacter(Forms.Keys.Oem4), + [Keys.Oem5] = GetCharacter(Forms.Keys.Oem5), + [Keys.Oem6] = GetCharacter(Forms.Keys.Oem6), + [Keys.Oem7] = GetCharacter(Forms.Keys.Oem7), + [Keys.Oem8] = GetCharacter(Forms.Keys.Oem8), + [Keys.OemPlus] = GetCharacter(Forms.Keys.Oemplus), + [Keys.OemComma] = GetCharacter(Forms.Keys.Oemcomma), + [Keys.OemMinus] = GetCharacter(Forms.Keys.OemMinus), + [Keys.OemPeriod] = GetCharacter(Forms.Keys.OemPeriod), + [Keys.Oem102] = GetCharacter(Forms.Keys.Oem102), + [Keys.OemClear] = GetCharacter(Forms.Keys.OemClear), + [Keys.Application] = "Application".GetString(), + [Keys.Application1] = "Application1".GetString(), + [Keys.Application2] = "Application2".GetString(), + [Keys.Mail] = "Mail".GetString(), + [Keys.GoHome] = "BrowserGoHome".GetString(), + [Keys.GoBack] = "BrowserGoBack".GetString(), + [Keys.GoForward] = "BrowserGoForward".GetString(), + [Keys.Refresh] = "BrowserRefresh".GetString(), + [Keys.BrowserStop] = "BrowserStop".GetString(), + [Keys.Search] = "BrowserSearch".GetString(), + [Keys.Favorites] = "BrowserFavorites".GetString(), + [Keys.PlayPause] = "MediaPlayPause".GetString(), + [Keys.MediaStop] = "MediaStop".GetString(), + [Keys.PreviousTrack] = "MediaPreviousTrack".GetString(), + [Keys.NextTrack] = "MediaNextTrack".GetString(), + [Keys.MediaSelect] = "MediaSelect".GetString(), + [Keys.Mute] = "MediaMute".GetString(), + [Keys.VolumeDown] = "MediaVolumeDown".GetString(), + [Keys.VolumeUp] = "MediaVolumeUp".GetString(), }.ToImmutableDictionary(); - private static readonly ImmutableArray globalKeys = new List + private static readonly ImmutableArray globalKeys = new List { - VirtualKey.GoHome, - VirtualKey.GoBack, - VirtualKey.GoForward, - VirtualKey.Application, - VirtualKey.Favorites, - VirtualKey.Search, - VirtualKey.Refresh, - VirtualKey.Pause, - VirtualKey.Sleep, - VirtualKey.Print, - VirtualKey.F1, - VirtualKey.F2, - VirtualKey.F3, - VirtualKey.F4, - VirtualKey.F5, - VirtualKey.F6, - VirtualKey.F7, - VirtualKey.F8, - VirtualKey.F9, - VirtualKey.F10, - VirtualKey.F11, - VirtualKey.F12, - VirtualKey.F13, - VirtualKey.F14, - VirtualKey.F15, - VirtualKey.F16, - VirtualKey.F17, - VirtualKey.F18, - VirtualKey.F19, - VirtualKey.F20, - VirtualKey.F21, - VirtualKey.F22, - VirtualKey.F23, - VirtualKey.F24, + Keys.GoHome, + Keys.GoBack, + Keys.GoForward, + Keys.Application, + Keys.Favorites, + Keys.Search, + Keys.Refresh, + Keys.Pause, + Keys.Sleep, + Keys.Print, + Keys.F1, + Keys.F2, + Keys.F3, + Keys.F4, + Keys.F5, + Keys.F6, + Keys.F7, + Keys.F8, + Keys.F9, + Keys.F10, + Keys.F11, + Keys.F12, + Keys.F13, + Keys.F14, + Keys.F15, + Keys.F16, + Keys.F17, + Keys.F18, + Keys.F19, + Keys.F20, + Keys.F21, + Keys.F22, + Keys.F23, + Keys.F24, }.ToImmutableArray(); private static readonly ImmutableArray textBoxHotKeys = new List @@ -201,13 +201,10 @@ internal static class HotKeyHelpers new HotKey(Keys.Z, KeyModifiers.Ctrl), // Cancel }.ToImmutableArray(); - public static bool IsValid(this VirtualKeyModifiers modifier) => modifiers.ContainsKey(modifier); - public static bool IsValid(this VirtualKey key) => keys.ContainsKey(key); - - public static bool IsGlobalKey(this VirtualKey key) => globalKeys.Contains(key); + public static bool IsGlobalKey(this Keys key) => globalKeys.Contains(key); public static bool IsTextBoxHotKey(this HotKey hotKey) => textBoxHotKeys.Contains(hotKey); - public static VirtualKeyModifiers GetCurrentKeyModifiers() + public static KeyModifiers GetCurrentKeyModifiers() { var modifiers = VirtualKeyModifiers.None; @@ -228,7 +225,7 @@ public static VirtualKeyModifiers GetCurrentKeyModifiers() modifiers |= VirtualKeyModifiers.Windows; } - return modifiers; + return (KeyModifiers)modifiers; static bool IsPressed(VirtualKey key) => InputKeyboardSource.GetKeyStateForCurrentThread(key).HasFlag(CoreVirtualKeyStates.Down); @@ -236,28 +233,22 @@ static bool IsPressed(VirtualKey key) public static string ToString(HotKey hotKey) { - return hotKey.Modifiers is VirtualKeyModifiers.None - ? ToString(hotKey.Key) - : $"{ToString(hotKey.Modifiers)}+{ToString(hotKey.Key)}"; - } - public static string ToString(VirtualKeyModifiers modifier) - { - StringBuilder builder = new(); - if (modifier.HasFlag(VirtualKeyModifiers.Menu)) - builder.Append($"+{modifiers[VirtualKeyModifiers.Menu]}"); - if (modifier.HasFlag(VirtualKeyModifiers.Control)) - builder.Append($"+{modifiers[VirtualKeyModifiers.Control]}"); - if (modifier.HasFlag(VirtualKeyModifiers.Shift)) - builder.Append($"+{modifiers[VirtualKeyModifiers.Shift]}"); - if (modifier.HasFlag(VirtualKeyModifiers.Windows)) - builder.Append($"+{modifiers[VirtualKeyModifiers.Windows]}"); - if (modifier is not VirtualKeyModifiers.None) - builder.Remove(0, 1); - return builder.ToString(); - } - public static string ToString(VirtualKey key) - { - return keys.TryGetValue(key, out string? label) ? label : string.Empty; + if (hotKey.Key is Keys.None) + return string.Empty; + if (hotKey.Modifiers is KeyModifiers.None) + return keys[hotKey.Key]; + + StringBuilder modifierBuilder = new(); + if (hotKey.Modifiers.HasFlag(KeyModifiers.Menu)) + modifierBuilder.Append($"{modifiers[KeyModifiers.Menu]}+"); + if (hotKey.Modifiers.HasFlag(KeyModifiers.Ctrl)) + modifierBuilder.Append($"{modifiers[KeyModifiers.Ctrl]}+"); + if (hotKey.Modifiers.HasFlag(KeyModifiers.Shift)) + modifierBuilder.Append($"{modifiers[KeyModifiers.Shift]}+"); + if (hotKey.Modifiers.HasFlag(KeyModifiers.Win)) + modifierBuilder.Append($"{modifiers[KeyModifiers.Win]}+"); + + return $"{modifierBuilder}{keys[hotKey.Key]}"; } private static string GetString(this string key) => $"Key/{key}".GetLocalizedResource(); diff --git a/src/Files.App/Commands/HotKey/KeyModifiers.cs b/src/Files.App/Commands/HotKey/KeyModifiers.cs index f1f6b876c4c5..e94d813f6099 100644 --- a/src/Files.App/Commands/HotKey/KeyModifiers.cs +++ b/src/Files.App/Commands/HotKey/KeyModifiers.cs @@ -10,16 +10,16 @@ public enum KeyModifiers : ushort Menu = 0x0002, Shift = 0x0004, Win = 0x0008, - CtrlMenu = Ctrl + Menu, + MenuCtrl = Ctrl + Menu, CtrlShift = Ctrl + Shift, CtrlWin = Ctrl + Win, MenuShift = Menu + Shift, MenuWin = Menu + Win, ShiftWin = Shift + Win, - CtrlMenuShift = Ctrl + Menu + Shift, - CtrlMenuWin = Ctrl + Menu + Win, + MenuCtrlShift = Ctrl + Menu + Shift, + MenuCtrlWin = Ctrl + Menu + Win, CtrlShiftWin = Ctrl + Shift + Win, MenuShiftWin = Menu + Shift + Win, - CtrlMenuShiftWin = Ctrl + Menu + Shift + Win, + MenuCtrlShiftWin = Ctrl + Menu + Shift + Win, } } diff --git a/src/Files.App/Views/MainPage.xaml.cs b/src/Files.App/Views/MainPage.xaml.cs index 3564e3c69c6c..100ccf50bee3 100644 --- a/src/Files.App/Views/MainPage.xaml.cs +++ b/src/Files.App/Views/MainPage.xaml.cs @@ -224,7 +224,7 @@ protected override async void OnPreviewKeyDown(KeyRoutedEventArgs e) break; default: var currentModifiers = HotKeyHelpers.GetCurrentKeyModifiers(); - HotKey hotKey = new(e.Key, currentModifiers); + HotKey hotKey = new((Keys)e.Key, currentModifiers); // A textbox takes precedence over certain hotkeys. bool isTextBox = e.OriginalSource is DependencyObject source && source.FindAscendantOrSelf() is not null; @@ -234,7 +234,7 @@ protected override async void OnPreviewKeyDown(KeyRoutedEventArgs e) { break; } - if (currentModifiers is VirtualKeyModifiers.None && !e.Key.IsGlobalKey()) + if (currentModifiers is KeyModifiers.None && !hotKey.Key.IsGlobalKey()) { break; } @@ -555,7 +555,7 @@ private void RootGrid_PreviewKeyDown(object sender, KeyRoutedEventArgs e) break; default: var currentModifiers = HotKeyHelpers.GetCurrentKeyModifiers(); - HotKey hotKey = new(e.Key, currentModifiers); + HotKey hotKey = new((Keys)e.Key, currentModifiers); // Prevents the arrow key events from navigating the list instead of switching compact overlay if (Commands[hotKey].Code is CommandCodes.EnterCompactOverlay or CommandCodes.ExitCompactOverlay) From 2860d5fa28eec7a795f26d4daf2ac732d16137c5 Mon Sep 17 00:00:00 2001 From: cinqmilleans Date: Wed, 29 Mar 2023 18:23:10 +0200 Subject: [PATCH 4/6] ToString --- src/Files.App/Commands/HotKey/HotKeyHelpers.cs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Files.App/Commands/HotKey/HotKeyHelpers.cs b/src/Files.App/Commands/HotKey/HotKeyHelpers.cs index c0e668c5355b..21f5d68e385d 100644 --- a/src/Files.App/Commands/HotKey/HotKeyHelpers.cs +++ b/src/Files.App/Commands/HotKey/HotKeyHelpers.cs @@ -238,17 +238,18 @@ public static string ToString(HotKey hotKey) if (hotKey.Modifiers is KeyModifiers.None) return keys[hotKey.Key]; - StringBuilder modifierBuilder = new(); + StringBuilder builder = new(); if (hotKey.Modifiers.HasFlag(KeyModifiers.Menu)) - modifierBuilder.Append($"{modifiers[KeyModifiers.Menu]}+"); + builder.Append($"{modifiers[KeyModifiers.Menu]}+"); if (hotKey.Modifiers.HasFlag(KeyModifiers.Ctrl)) - modifierBuilder.Append($"{modifiers[KeyModifiers.Ctrl]}+"); + builder.Append($"{modifiers[KeyModifiers.Ctrl]}+"); if (hotKey.Modifiers.HasFlag(KeyModifiers.Shift)) - modifierBuilder.Append($"{modifiers[KeyModifiers.Shift]}+"); + builder.Append($"{modifiers[KeyModifiers.Shift]}+"); if (hotKey.Modifiers.HasFlag(KeyModifiers.Win)) - modifierBuilder.Append($"{modifiers[KeyModifiers.Win]}+"); + builder.Append($"{modifiers[KeyModifiers.Win]}+"); + builder.Append(keys[hotKey.Key]); - return $"{modifierBuilder}{keys[hotKey.Key]}"; + return builder.ToString(); } private static string GetString(this string key) => $"Key/{key}".GetLocalizedResource(); From 73f6862f4d91dabc559da2dedf948a7b5700b064 Mon Sep 17 00:00:00 2001 From: cinqmilleans Date: Tue, 4 Apr 2023 14:46:39 +0200 Subject: [PATCH 5/6] merge --- src/Files.App/Views/MainPage.xaml.cs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Files.App/Views/MainPage.xaml.cs b/src/Files.App/Views/MainPage.xaml.cs index 100ccf50bee3..c3cb97ee22d8 100644 --- a/src/Files.App/Views/MainPage.xaml.cs +++ b/src/Files.App/Views/MainPage.xaml.cs @@ -231,13 +231,9 @@ protected override async void OnPreviewKeyDown(KeyRoutedEventArgs e) if (isTextBox) { if (hotKey.IsTextBoxHotKey()) - { break; - } if (currentModifiers is KeyModifiers.None && !hotKey.Key.IsGlobalKey()) - { break; - } } // Execute command for hotkey From c317d0582b57f1132896c24529849d142b729cc1 Mon Sep 17 00:00:00 2001 From: cinqmilleans Date: Tue, 4 Apr 2023 15:30:59 +0200 Subject: [PATCH 6/6] new actions --- .../Actions/Navigation/CloseSelectedTabAction.cs | 9 ++++----- src/Files.App/Actions/Navigation/NextTabAction.cs | 3 +-- src/Files.App/Actions/Navigation/PreviousTabAction.cs | 3 +-- src/Files.App/Actions/Show/ToggleSidebarAction.cs | 3 +-- 4 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/Files.App/Actions/Navigation/CloseSelectedTabAction.cs b/src/Files.App/Actions/Navigation/CloseSelectedTabAction.cs index 6c363dcece24..f1ba9cf2e909 100644 --- a/src/Files.App/Actions/Navigation/CloseSelectedTabAction.cs +++ b/src/Files.App/Actions/Navigation/CloseSelectedTabAction.cs @@ -5,7 +5,6 @@ using Files.App.Extensions; using System.ComponentModel; using System.Threading.Tasks; -using Windows.System; namespace Files.App.Actions { @@ -17,15 +16,15 @@ internal class CloseSelectedTabAction : ObservableObject, IAction public string Description { get; } = "TODO: Need to be described."; - public HotKey HotKey { get; } = new(VirtualKey.W, VirtualKeyModifiers.Control); + public HotKey HotKey { get; } = new(Keys.W, KeyModifiers.Ctrl); - public HotKey SecondHotKey { get; } = new(VirtualKey.F4, VirtualKeyModifiers.Control); + public HotKey SecondHotKey { get; } = new(Keys.F4, KeyModifiers.Ctrl); public RichGlyph Glyph { get; } = new(); public bool IsExecutable => - context.Control is not null && - context.TabCount > 0 && + context.Control is not null && + context.TabCount > 0 && context.CurrentTabItem is not null; public CloseSelectedTabAction() diff --git a/src/Files.App/Actions/Navigation/NextTabAction.cs b/src/Files.App/Actions/Navigation/NextTabAction.cs index f0b771608586..af0641a4ea8f 100644 --- a/src/Files.App/Actions/Navigation/NextTabAction.cs +++ b/src/Files.App/Actions/Navigation/NextTabAction.cs @@ -5,7 +5,6 @@ using Files.App.Extensions; using System.ComponentModel; using System.Threading.Tasks; -using Windows.System; namespace Files.App.Actions { @@ -19,7 +18,7 @@ internal class NextTabAction : ObservableObject, IAction public bool IsExecutable => multitaskingContext.TabCount > 1; - public HotKey HotKey { get; } = new(VirtualKey.Tab, VirtualKeyModifiers.Control); + public HotKey HotKey { get; } = new(Keys.Tab, KeyModifiers.Ctrl); public NextTabAction() { diff --git a/src/Files.App/Actions/Navigation/PreviousTabAction.cs b/src/Files.App/Actions/Navigation/PreviousTabAction.cs index 1ea96583c9bf..fa6b043d4937 100644 --- a/src/Files.App/Actions/Navigation/PreviousTabAction.cs +++ b/src/Files.App/Actions/Navigation/PreviousTabAction.cs @@ -5,7 +5,6 @@ using Files.App.Extensions; using System.ComponentModel; using System.Threading.Tasks; -using Windows.System; namespace Files.App.Actions { @@ -19,7 +18,7 @@ internal class PreviousTabAction : ObservableObject, IAction public bool IsExecutable => multitaskingContext.TabCount > 1; - public HotKey HotKey { get; } = new(VirtualKey.Tab, VirtualKeyModifiers.Control | VirtualKeyModifiers.Shift); + public HotKey HotKey { get; } = new(Keys.Tab, KeyModifiers.CtrlShift); public PreviousTabAction() { diff --git a/src/Files.App/Actions/Show/ToggleSidebarAction.cs b/src/Files.App/Actions/Show/ToggleSidebarAction.cs index 036458243a16..919d2177c1fe 100644 --- a/src/Files.App/Actions/Show/ToggleSidebarAction.cs +++ b/src/Files.App/Actions/Show/ToggleSidebarAction.cs @@ -5,7 +5,6 @@ using Files.App.ViewModels; using System.ComponentModel; using System.Threading.Tasks; -using Windows.System; namespace Files.App.Actions { @@ -17,7 +16,7 @@ internal class ToggleSidebarAction : ObservableObject, IToggleAction public string Description { get; } = "TODO: Need to be described."; - public HotKey HotKey { get; } = new(VirtualKey.B, VirtualKeyModifiers.Control); + public HotKey HotKey { get; } = new(Keys.B, KeyModifiers.Ctrl); public bool IsOn => viewModel.IsSidebarOpen;