SelectionHelpers.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System.Collections.Generic;
  2. using PixiEditor.Models.DataHolders;
  3. using PixiEditor.Models.Enums;
  4. using PixiEditor.Models.Position;
  5. using PixiEditor.Models.Undo;
  6. namespace PixiEditor.Helpers
  7. {
  8. public class SelectionHelpers
  9. {
  10. public static void UndoSelect(object[] arguments)
  11. {
  12. Document document = (Document)arguments[0];
  13. document.ActiveSelection.SetSelection((IEnumerable<Coordinates>)arguments[1], SelectionType.New);
  14. }
  15. public static void RedoSelect(object[] arguments)
  16. {
  17. Document document = (Document)arguments[0];
  18. document.ActiveSelection.SetSelection((IEnumerable<Coordinates>)arguments[1], SelectionType.New);
  19. }
  20. public static void AddSelectionUndoStep(Document document, IEnumerable<Coordinates> oldPoints, SelectionType mode)
  21. {
  22. if (mode == SelectionType.New && document.ActiveSelection.SelectedPoints.Count != 0)
  23. {
  24. // Add empty selection as the old one get's fully deleted first
  25. document.UndoManager.AddUndoChange(
  26. new Change(UndoSelect, new object[] { document, new List<Coordinates>(oldPoints) }, RedoSelect, new object[] { document, new List<Coordinates>() }));
  27. document.UndoManager.AddUndoChange(
  28. new Change(UndoSelect, new object[] { document, new List<Coordinates>() }, RedoSelect, new object[] { document, new List<Coordinates>(document.ActiveSelection.SelectedPoints) }));
  29. }
  30. else
  31. {
  32. document.UndoManager.AddUndoChange(
  33. new Change(UndoSelect, new object[] { document, new List<Coordinates>(oldPoints) }, RedoSelect, new object[] { document, new List<Coordinates>(document.ActiveSelection.SelectedPoints) }));
  34. }
  35. }
  36. }
  37. }