CommandDeleteAll.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using System.Collections.Generic;
  2. namespace PaintDotNet.Annotation.Command
  3. {
  4. class CommandDeleteAll : Command
  5. {
  6. List<DrawObject> cloneList;
  7. // Create this command BEFORE applying Delete All function.
  8. public CommandDeleteAll(GraphicsList graphicsList)
  9. {
  10. cloneList = new List<DrawObject>();
  11. // Make clone of the whole list.
  12. // Add objects in reverse order because GraphicsList.Add
  13. // insert every object to the beginning.
  14. int n = graphicsList.Count;
  15. for (int i = n - 1; i >= 0; i--)
  16. {
  17. cloneList.Add(graphicsList[i].Clone());
  18. }
  19. }
  20. public override void Undo(GraphicsList list)
  21. {
  22. // Add all objects from clone list to list -
  23. // opposite to DeleteAll
  24. foreach (DrawObject o in cloneList)
  25. {
  26. list.Add(o);
  27. }
  28. }
  29. public override void Redo(GraphicsList list)
  30. {
  31. // Clear list - make DeleteAll again
  32. list.Clear();
  33. }
  34. }
  35. }