/AvalonEdit/ICSharpCode.AvalonEdit/Document/UndoOperationGroup.cs

http://github.com/icsharpcode/ILSpy · C# · 76 lines · 46 code · 9 blank · 21 comment · 7 complexity · 09bd4ba47e42e4dcb440e38ac8e0eca3 MD5 · raw file

  1. // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
  2. //
  3. // Permission is hereby granted, free of charge, to any person obtaining a copy of this
  4. // software and associated documentation files (the "Software"), to deal in the Software
  5. // without restriction, including without limitation the rights to use, copy, modify, merge,
  6. // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
  7. // to whom the Software is furnished to do so, subject to the following conditions:
  8. //
  9. // The above copyright notice and this permission notice shall be included in all copies or
  10. // substantial portions of the Software.
  11. //
  12. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  13. // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  14. // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
  15. // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  16. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  17. // DEALINGS IN THE SOFTWARE.
  18. using System;
  19. using System.Diagnostics;
  20. using ICSharpCode.AvalonEdit.Utils;
  21. namespace ICSharpCode.AvalonEdit.Document
  22. {
  23. /// <summary>
  24. /// This class stacks the last x operations from the undostack and makes
  25. /// one undo/redo operation from it.
  26. /// </summary>
  27. sealed class UndoOperationGroup : IUndoableOperationWithContext
  28. {
  29. IUndoableOperation[] undolist;
  30. public UndoOperationGroup(Deque<IUndoableOperation> stack, int numops)
  31. {
  32. if (stack == null) {
  33. throw new ArgumentNullException("stack");
  34. }
  35. Debug.Assert(numops > 0 , "UndoOperationGroup : numops should be > 0");
  36. Debug.Assert(numops <= stack.Count);
  37. undolist = new IUndoableOperation[numops];
  38. for (int i = 0; i < numops; ++i) {
  39. undolist[i] = stack.PopBack();
  40. }
  41. }
  42. public void Undo()
  43. {
  44. for (int i = 0; i < undolist.Length; ++i) {
  45. undolist[i].Undo();
  46. }
  47. }
  48. public void Undo(UndoStack stack)
  49. {
  50. for (int i = 0; i < undolist.Length; ++i) {
  51. stack.RunUndo(undolist[i]);
  52. }
  53. }
  54. public void Redo()
  55. {
  56. for (int i = undolist.Length - 1; i >= 0; --i) {
  57. undolist[i].Redo();
  58. }
  59. }
  60. public void Redo(UndoStack stack)
  61. {
  62. for (int i = undolist.Length - 1; i >= 0; --i) {
  63. stack.RunRedo(undolist[i]);
  64. }
  65. }
  66. }
  67. }