Files
BITKit/Src/Core/Hotkey/IHotkeyCollection.cs

62 lines
1.3 KiB
C#
Raw Normal View History

2025-02-24 23:02:43 +08:00
using System;
using System.Collections;
using System.Collections.Generic;
2025-08-05 23:34:10 +08:00
using System.Linq;
2025-02-24 23:02:43 +08:00
namespace BITKit.UX.Hotkey
{
public interface IHotkeyProvider
{
string Name { get; }
string Description { get; }
object Data { get; }
bool Enabled { get; }
Action OnPerform { get; }
float HoldDuration => 0;
}
2025-04-05 09:49:01 +08:00
public interface IUXHotKey
{
void Perform(IHotkeyCollection collection);
}
2025-02-24 23:02:43 +08:00
public struct HotkeyProvider : IHotkeyProvider
{
public string Name { get; set; }
public string Description { get; set; }
public object Data { get; set; }
public bool Enabled { get; set; }
public Action OnPerform { get; set; }
public float HoldDuration { get; set; }
}
public interface IHotkeyCollection
{
IEnumerable<IHotkeyProvider> Hotkeys { get; }
void Register(IHotkeyProvider hotkey);
void UnRegister(IHotkeyProvider hotkey);
}
public class HotkeyCollection:IHotkeyCollection
{
2025-08-05 23:34:10 +08:00
public HotkeyCollection()
{
}
public HotkeyCollection(params IHotkeyProvider[] hotkeyProviders)
{
_hotkeys = hotkeyProviders.ToHashSet();
}
2025-02-24 23:02:43 +08:00
private readonly HashSet<IHotkeyProvider> _hotkeys = new();
public IEnumerable<IHotkeyProvider> Hotkeys => _hotkeys;
public void Register(IHotkeyProvider hotkey)
{
_hotkeys.Add(hotkey);
}
public void UnRegister(IHotkeyProvider hotkey)
{
_hotkeys.Remove(hotkey);
}
}
}