SelectionViewModel.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System;
  2. using System.Collections.Generic;
  3. using PixiEditor.Helpers;
  4. using PixiEditor.Models.DataHolders;
  5. using PixiEditor.Models.Enums;
  6. using PixiEditor.Models.Position;
  7. using PixiEditor.Models.Tools;
  8. using PixiEditor.Models.Tools.Tools;
  9. namespace PixiEditor.ViewModels.SubViewModels.Main
  10. {
  11. public class SelectionViewModel : SubViewModel<ViewModelMain>
  12. {
  13. public RelayCommand DeselectCommand { get; set; }
  14. public RelayCommand SelectAllCommand { get; set; }
  15. private readonly SelectTool selectTool;
  16. public SelectionViewModel(ViewModelMain owner)
  17. : base(owner)
  18. {
  19. DeselectCommand = new RelayCommand(Deselect, SelectionIsNotEmpty);
  20. SelectAllCommand = new RelayCommand(SelectAll, CanSelectAll);
  21. selectTool = new SelectTool(Owner.BitmapManager);
  22. }
  23. public void SelectAll(object parameter)
  24. {
  25. var oldSelection = new List<Coordinates>(Owner.BitmapManager.ActiveDocument.ActiveSelection.SelectedPoints);
  26. Owner.BitmapManager.ActiveDocument.ActiveSelection.SetSelection(selectTool.GetAllSelection(), SelectionType.New);
  27. SelectionHelpers.AddSelectionUndoStep(Owner.BitmapManager.ActiveDocument, oldSelection, SelectionType.New);
  28. }
  29. public void Deselect(object parameter)
  30. {
  31. var oldSelection = new List<Coordinates>(Owner.BitmapManager.ActiveDocument.ActiveSelection.SelectedPoints);
  32. Owner.BitmapManager.ActiveDocument.ActiveSelection?.Clear();
  33. SelectionHelpers.AddSelectionUndoStep(Owner.BitmapManager.ActiveDocument, oldSelection, SelectionType.New);
  34. }
  35. public bool SelectionIsNotEmpty(object property)
  36. {
  37. var selectedPoints = Owner.BitmapManager.ActiveDocument?.ActiveSelection.SelectedPoints;
  38. return selectedPoints != null && selectedPoints.Count > 0;
  39. }
  40. private bool CanSelectAll(object property)
  41. {
  42. return Owner.BitmapManager.ActiveDocument != null && Owner.BitmapManager.ActiveDocument.Layers.Count > 0;
  43. }
  44. }
  45. }