ShortcutController.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Windows.Input;
  5. namespace PixiEditor.Models.Controllers
  6. {
  7. public class ShortcutController
  8. {
  9. public static bool BlockShortcutExecution { get; set; }
  10. public List<Shortcut> Shortcuts { get; set; }
  11. public ShortcutController()
  12. {
  13. Shortcuts = new List<Shortcut>();
  14. }
  15. public void KeyPressed(Key key)
  16. {
  17. if (!BlockShortcutExecution)
  18. {
  19. Shortcut[] shortcuts = Shortcuts.FindAll(x => x.ShortcutKey == key).ToArray();
  20. if (shortcuts.Length < 1) return;
  21. shortcuts = shortcuts.OrderByDescending(x => x.Modifier).ToArray();
  22. for (int i = 0; i < shortcuts.Length; i++)
  23. {
  24. if (Keyboard.Modifiers.HasFlag(shortcuts[i].Modifier))
  25. {
  26. shortcuts[i].Execute();
  27. break;
  28. }
  29. }
  30. }
  31. }
  32. }
  33. }