diff --git a/src/core/Microsoft.PowerToys.Settings.UI.Lib/AppSpecificKeysDataModel.cs b/src/core/Microsoft.PowerToys.Settings.UI.Lib/AppSpecificKeysDataModel.cs new file mode 100644 index 0000000000..1aa1230e58 --- /dev/null +++ b/src/core/Microsoft.PowerToys.Settings.UI.Lib/AppSpecificKeysDataModel.cs @@ -0,0 +1,32 @@ +// Copyright (c) Microsoft Corporation +// The Microsoft Corporation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Collections.Generic; +using System.Linq; +using System.Text.Json.Serialization; +using Microsoft.PowerToys.Settings.UI.Lib.Utilities; + +namespace Microsoft.PowerToys.Settings.UI.Lib +{ + public class AppSpecificKeysDataModel : KeysDataModel + { + [JsonPropertyName("targetApp")] + public string TargetApp { get; set; } + + public new List GetOriginalKeys() + { + return base.GetOriginalKeys(); + } + + public new List GetNewRemapKeys() + { + return base.GetNewRemapKeys(); + } + + public bool Compare(AppSpecificKeysDataModel arg) + { + return OriginalKeys.Equals(arg.OriginalKeys) && NewRemapKeys.Equals(arg.NewRemapKeys) && TargetApp.Equals(arg.TargetApp); + } + } +} diff --git a/src/core/Microsoft.PowerToys.Settings.UI.Lib/KeysDataModel.cs b/src/core/Microsoft.PowerToys.Settings.UI.Lib/KeysDataModel.cs index d9140f7da8..d33a020e15 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI.Lib/KeysDataModel.cs +++ b/src/core/Microsoft.PowerToys.Settings.UI.Lib/KeysDataModel.cs @@ -2,10 +2,10 @@ // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using Microsoft.PowerToys.Settings.UI.Lib.Utilities; using System.Collections.Generic; using System.Linq; using System.Text.Json.Serialization; +using Microsoft.PowerToys.Settings.UI.Lib.Utilities; namespace Microsoft.PowerToys.Settings.UI.Lib { diff --git a/src/core/Microsoft.PowerToys.Settings.UI.Lib/RemapKeysDataModel.cs b/src/core/Microsoft.PowerToys.Settings.UI.Lib/RemapKeysDataModel.cs index 67477c4214..4712721b47 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI.Lib/RemapKeysDataModel.cs +++ b/src/core/Microsoft.PowerToys.Settings.UI.Lib/RemapKeysDataModel.cs @@ -17,4 +17,4 @@ namespace Microsoft.PowerToys.Settings.UI.Lib InProcessRemapKeys = new List(); } } -} \ No newline at end of file +} diff --git a/src/core/Microsoft.PowerToys.Settings.UI.Lib/ShortcutsKeyDataModel.cs b/src/core/Microsoft.PowerToys.Settings.UI.Lib/ShortcutsKeyDataModel.cs index ad245f4808..944904dec4 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI.Lib/ShortcutsKeyDataModel.cs +++ b/src/core/Microsoft.PowerToys.Settings.UI.Lib/ShortcutsKeyDataModel.cs @@ -12,9 +12,13 @@ namespace Microsoft.PowerToys.Settings.UI.Lib [JsonPropertyName("global")] public List GlobalRemapShortcuts { get; set; } + [JsonPropertyName("appSpecific")] + public List AppSpecificRemapShortcuts { get; set; } + public ShortcutsKeyDataModel() { GlobalRemapShortcuts = new List(); + AppSpecificRemapShortcuts = new List(); } } } diff --git a/src/core/Microsoft.PowerToys.Settings.UI/ViewModels/KeyboardManagerViewModel.cs b/src/core/Microsoft.PowerToys.Settings.UI/ViewModels/KeyboardManagerViewModel.cs index 7fe6ab3c77..858d11ebe0 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI/ViewModels/KeyboardManagerViewModel.cs +++ b/src/core/Microsoft.PowerToys.Settings.UI/ViewModels/KeyboardManagerViewModel.cs @@ -74,7 +74,6 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels PowerToyName, settings.Properties.ActiveConfiguration.Value + JsonFileType, OnConfigFileUpdate); - } public bool Enabled @@ -113,17 +112,22 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels } } - public List RemapShortcuts + public static List CombineShortcutLists(List globalShortcutList, List appSpecificShortcutList) + { + return globalShortcutList.ConvertAll(x => new AppSpecificKeysDataModel { OriginalKeys = x.OriginalKeys, NewRemapKeys = x.NewRemapKeys, TargetApp = "All Apps" }).Concat(appSpecificShortcutList).ToList(); + } + + public List RemapShortcuts { get { if (profile != null) { - return profile.RemapShortcuts.GlobalRemapShortcuts; + return CombineShortcutLists(profile.RemapShortcuts.GlobalRemapShortcuts, profile.RemapShortcuts.AppSpecificRemapShortcuts); } else { - return new List(); + return new List(); } } } diff --git a/src/core/Microsoft.PowerToys.Settings.UI/Views/KeyboardManagerPage.xaml b/src/core/Microsoft.PowerToys.Settings.UI/Views/KeyboardManagerPage.xaml index 926b7caa7a..d509eea86f 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI/Views/KeyboardManagerPage.xaml +++ b/src/core/Microsoft.PowerToys.Settings.UI/Views/KeyboardManagerPage.xaml @@ -81,6 +81,95 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -192,7 +281,7 @@