CommandDeleteAll.cs 1.2 KB

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