SelectionViewModel.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System.Windows.Input;
  2. using PixiEditor.DrawingApi.Core.Numerics;
  3. using PixiEditor.Models.Commands.Attributes.Commands;
  4. namespace PixiEditor.ViewModels.SubViewModels.Main;
  5. [Command.Group("PixiEditor.Selection", "Selection")]
  6. internal class SelectionViewModel : SubViewModel<ViewModelMain>
  7. {
  8. public SelectionViewModel(ViewModelMain owner)
  9. : base(owner)
  10. {
  11. }
  12. [Command.Basic("PixiEditor.Selection.SelectAll", "Select all", "Select everything", CanExecute = "PixiEditor.HasDocument", Key = Key.A, Modifiers = ModifierKeys.Control)]
  13. public void SelectAll()
  14. {
  15. var doc = Owner.DocumentManagerSubViewModel.ActiveDocument;
  16. if (doc is null)
  17. return;
  18. doc.Operations.SelectAll();
  19. }
  20. [Command.Basic("PixiEditor.Selection.Clear", "Clear selection", "Clear selection", CanExecute = "PixiEditor.Selection.IsNotEmpty", Key = Key.D, Modifiers = ModifierKeys.Control)]
  21. public void ClearSelection()
  22. {
  23. var doc = Owner.DocumentManagerSubViewModel.ActiveDocument;
  24. if (doc is null)
  25. return;
  26. doc.Operations.ClearSelection();
  27. }
  28. [Evaluator.CanExecute("PixiEditor.Selection.IsNotEmpty")]
  29. public bool SelectionIsNotEmpty()
  30. {
  31. return !Owner.DocumentManagerSubViewModel.ActiveDocument?.SelectionPathBindable?.IsEmpty ?? false;
  32. }
  33. [Command.Basic("PixiEditor.Selection.TransformArea", "Transform selected area", "Transform selected area", CanExecute = "PixiEditor.Selection.IsNotEmpty", Key = Key.T, Modifiers = ModifierKeys.Control)]
  34. public void TransformSelectedArea()
  35. {
  36. Owner.DocumentManagerSubViewModel.ActiveDocument?.Operations.TransformSelectedArea(false);
  37. }
  38. [Command.Basic("PixiEditor.Selection.NudgeSelectedObjectLeft", "Nudge selected object left", "Nudge selected object left", Key = Key.Left, Parameter = new int[] { -1, 0 }, IconPath = "E76B", IconEvaluator = "PixiEditor.FontIcon")]
  39. [Command.Basic("PixiEditor.Selection.NudgeSelectedObjectRight", "Nudge selected object right", "Nudge selected object right", Key = Key.Right, Parameter = new int[] { 1, 0 }, IconPath = "E76C", IconEvaluator = "PixiEditor.FontIcon")]
  40. [Command.Basic("PixiEditor.Selection.NudgeSelectedObjectUp", "Nudge selected object up", "Nudge selected object up", Key = Key.Up, Parameter = new int[] { 0, -1 }, IconPath = "E70E", IconEvaluator = "PixiEditor.FontIcon")]
  41. [Command.Basic("PixiEditor.Selection.NudgeSelectedObjectDown", "Nudge selected object down", "Nudge selected object down", Key = Key.Down, Parameter = new int[] { 0, 1 }, IconPath = "E70D", IconEvaluator = "PixiEditor.FontIcon")]
  42. public void NudgeSelectedObject(int[] dist)
  43. {
  44. VecI distance = new(dist[0], dist[1]);
  45. Owner.DocumentManagerSubViewModel.ActiveDocument?.Operations.NudgeSelectedObject(distance);
  46. }
  47. }