mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-03 17:56:44 +02:00
## Running the Project **Option 1: Test via runner** 1. Check out branch `niels9001/kbm-ux-consolidation` 2. Build PowerToys project 3. Manually build `Modules/KeyboardManagerEditorUI` project separately 4. Run `runner` project 5. Ensure experimental features are enabled in general settings (should be on by default) 6. Launch keyboard manager via settings app **Option 2: Test via installer** 1. Install PowerToys via installer on azure pipeline 1. Launch keyboard manager ## Validation For each page (Text, Remappings, Programs, URLs): * Create shortcuts with variable options and ensure they run as expected * Delete shortcuts and ensure they no longer execute * Try to create invalid shortcuts to check for proper validation * Ensure created shortcuts appear in Power Toys Settings Keyboard manager page * Try toggling shortcuts * Try deleting shortcuts while toggled off ### UI * Any feedback on UI design appreciated as well <img width="1071" height="671" alt="image" src="https://github.com/user-attachments/assets/d2e81de0-6d92-4189-9a33-32e94cce74f7" /> <img width="2142" height="1341" alt="image" src="https://github.com/user-attachments/assets/0e4e5685-fdf1-4dfd-ba52-a2e5bc9a66db" /> Closes: #15870 Closes: #31902 Closes: #45302 Closes: #36227 Closes: #16093 Closes: #13409 Closes: #9919 Closes: #9482 Closes: #8798 Closes: #7054 Closes: #2733 Closes: #2027 Closes: #30167 --------- Co-authored-by: Hao Liu <liuhao3418@gmail.com> Co-authored-by: chenmy77 <162882040+chenmy77@users.noreply.github.com> Co-authored-by: Niels Laute <niels.laute@live.nl> Co-authored-by: Jay <65828559+Jay-o-Way@users.noreply.github.com> Co-authored-by: Jaylyn Barbee <51131738+Jaylyn-Barbee@users.noreply.github.com> Co-authored-by: Dustin L. Howett <duhowett@microsoft.com>
101 lines
4.2 KiB
C#
101 lines
4.2 KiB
C#
// 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.Globalization;
|
|
using System.IO.Abstractions;
|
|
|
|
using Microsoft.PowerToys.Settings.UI.Helpers;
|
|
using Microsoft.PowerToys.Settings.UI.Library;
|
|
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
|
|
using Microsoft.PowerToys.Settings.UI.ViewModels;
|
|
using Microsoft.UI.Xaml.Controls;
|
|
using Windows.System;
|
|
|
|
namespace Microsoft.PowerToys.Settings.UI.Views
|
|
{
|
|
/// <summary>
|
|
/// An empty page that can be used on its own or navigated to within a Frame.
|
|
/// </summary>
|
|
public sealed partial class KeyboardManagerPage : NavigablePage, IRefreshablePage
|
|
{
|
|
private const string PowerToyName = "Keyboard Manager";
|
|
|
|
private readonly IFileSystemWatcher watcher;
|
|
|
|
public KeyboardManagerViewModel ViewModel { get; }
|
|
|
|
public KeyboardManagerPage()
|
|
{
|
|
var settingsUtils = SettingsUtils.Default;
|
|
ViewModel = new KeyboardManagerViewModel(settingsUtils, SettingsRepository<GeneralSettings>.GetInstance(settingsUtils), ShellPage.SendDefaultIPCMessage, FilterRemapKeysList);
|
|
|
|
watcher = Helper.GetFileWatcher(
|
|
PowerToyName,
|
|
ViewModel.Settings.Properties.ActiveConfiguration.Value + ".json",
|
|
OnConfigFileUpdate);
|
|
|
|
InitializeComponent();
|
|
DataContext = ViewModel;
|
|
}
|
|
|
|
private void OnConfigFileUpdate()
|
|
{
|
|
// Note: FileSystemWatcher raise notification multiple times for single update operation.
|
|
// Todo: Handle duplicate events either by somehow suppress them or re-read the configuration every time since we will be updating the UI only if something is changed.
|
|
if (ViewModel.LoadProfile())
|
|
{
|
|
this.DispatcherQueue.TryEnqueue(() =>
|
|
{
|
|
ViewModel.NotifyFileChanged();
|
|
});
|
|
}
|
|
}
|
|
|
|
private static void CombineRemappings(List<KeysDataModel> remapKeysList, uint leftKey, uint rightKey, uint combinedKey)
|
|
{
|
|
// Using InvariantCulture for keys as they are internally represented as numerical values
|
|
KeysDataModel firstRemap = remapKeysList.Find(x => uint.Parse(x.OriginalKeys, CultureInfo.InvariantCulture) == leftKey);
|
|
KeysDataModel secondRemap = remapKeysList.Find(x => uint.Parse(x.OriginalKeys, CultureInfo.InvariantCulture) == rightKey);
|
|
if (firstRemap != null && secondRemap != null)
|
|
{
|
|
if (firstRemap.NewRemapKeys == secondRemap.NewRemapKeys)
|
|
{
|
|
KeysDataModel combinedRemap = new KeysDataModel
|
|
{
|
|
OriginalKeys = combinedKey.ToString(CultureInfo.InvariantCulture),
|
|
NewRemapKeys = firstRemap.NewRemapKeys,
|
|
};
|
|
remapKeysList.Insert(remapKeysList.IndexOf(firstRemap), combinedRemap);
|
|
remapKeysList.Remove(firstRemap);
|
|
remapKeysList.Remove(secondRemap);
|
|
}
|
|
}
|
|
}
|
|
|
|
public static int FilterRemapKeysList(List<KeysDataModel> remapKeysList)
|
|
{
|
|
if (remapKeysList != null)
|
|
{
|
|
CombineRemappings(remapKeysList, (uint)VirtualKey.LeftControl, (uint)VirtualKey.RightControl, (uint)VirtualKey.Control);
|
|
CombineRemappings(remapKeysList, (uint)VirtualKey.LeftMenu, (uint)VirtualKey.RightMenu, (uint)VirtualKey.Menu);
|
|
CombineRemappings(remapKeysList, (uint)VirtualKey.LeftShift, (uint)VirtualKey.RightShift, (uint)VirtualKey.Shift);
|
|
CombineRemappings(remapKeysList, (uint)VirtualKey.LeftWindows, (uint)VirtualKey.RightWindows, Helper.VirtualKeyWindows);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
public void RefreshEnabledState()
|
|
{
|
|
ViewModel.RefreshEnabledState();
|
|
}
|
|
|
|
private void GoBackClassic_Click(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
|
|
{
|
|
ViewModel.UseNewEditor = false;
|
|
}
|
|
}
|
|
}
|