mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-04 18:26:39 +02:00
46 lines
1.3 KiB
C#
46 lines
1.3 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 CommunityToolkit.Mvvm.ComponentModel;
|
|||
|
|
using Microsoft.CmdPal.UI.ViewModels.Settings;
|
|||
|
|
|
|||
|
|
namespace Microsoft.CmdPal.UI.ViewModels;
|
|||
|
|
|
|||
|
|
public partial class HotkeyManager : ObservableObject
|
|||
|
|
{
|
|||
|
|
private readonly TopLevelCommandManager _topLevelCommandManager;
|
|||
|
|
private readonly List<TopLevelHotkey> _commandHotkeys;
|
|||
|
|
|
|||
|
|
public HotkeyManager(TopLevelCommandManager tlcManager, SettingsModel settings)
|
|||
|
|
{
|
|||
|
|
_topLevelCommandManager = tlcManager;
|
|||
|
|
_commandHotkeys = settings.CommandHotkeys;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void UpdateHotkey(string commandId, HotkeySettings? hotkey)
|
|||
|
|
{
|
|||
|
|
// If any of the commands were already bound to this hotkey, remove that
|
|||
|
|
foreach (var item in _commandHotkeys)
|
|||
|
|
{
|
|||
|
|
if (item.Hotkey == hotkey)
|
|||
|
|
{
|
|||
|
|
item.Hotkey = null;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
_commandHotkeys.RemoveAll(item => item.Hotkey == null);
|
|||
|
|
|
|||
|
|
foreach (var item in _commandHotkeys)
|
|||
|
|
{
|
|||
|
|
if (item.CommandId == commandId)
|
|||
|
|
{
|
|||
|
|
_commandHotkeys.Remove(item);
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
_commandHotkeys.Add(new(hotkey, commandId));
|
|||
|
|
}
|
|||
|
|
}
|