CraftSynth.ImageEditor – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | using System.Collections.Generic; |
2 | |||
3 | namespace CraftSynth.ImageEditor |
||
4 | { |
||
5 | /// <summary> |
||
6 | /// Delete All command |
||
7 | /// </summary> |
||
8 | internal class CommandDeleteAll : Command |
||
9 | { |
||
10 | private List<DrawObject> cloneList; |
||
11 | |||
12 | // Create this command BEFORE applying Delete All function. |
||
13 | public CommandDeleteAll(Layers list) |
||
14 | { |
||
15 | cloneList = new List<DrawObject>(); |
||
16 | |||
17 | // Make clone of the whole list. |
||
18 | // Add objects in reverse order because GraphicsList.Add |
||
19 | // insert every object to the beginning. |
||
20 | int n = list[list.ActiveLayerIndex].Graphics.Count; |
||
21 | |||
22 | for (int i = n - 1; i >= 0; i--) |
||
23 | { |
||
24 | cloneList.Add(list[list.ActiveLayerIndex].Graphics[i].Clone()); |
||
25 | } |
||
26 | } |
||
27 | |||
28 | public override void Undo(Layers list) |
||
29 | { |
||
30 | // Add all objects from clone list to list - |
||
31 | // opposite to DeleteAll |
||
32 | foreach (DrawObject o in cloneList) |
||
33 | { |
||
34 | list[list.ActiveLayerIndex].Graphics.Add(o); |
||
35 | } |
||
36 | } |
||
37 | |||
38 | public override void Redo(Layers list) |
||
39 | { |
||
40 | // Clear list - make DeleteAll again |
||
41 | list[list.ActiveLayerIndex].Graphics.Clear(); |
||
42 | } |
||
43 | |||
44 | #region Destruction |
||
45 | // Flag: Has Dispose already been called? |
||
46 | bool _disposed = false; |
||
47 | |||
48 | // Protected implementation of Dispose pattern. |
||
49 | public override void Dispose(bool disposing) |
||
50 | { |
||
51 | if (!this._disposed) |
||
52 | { |
||
53 | |||
54 | if (disposing) |
||
55 | { |
||
56 | // Free any managed objects here. |
||
57 | // |
||
58 | if (this.cloneList != null) |
||
59 | { |
||
60 | foreach (DrawObject drawObject in cloneList) |
||
61 | { |
||
62 | if (drawObject != null) |
||
63 | { |
||
64 | drawObject.Dispose(); |
||
65 | } |
||
66 | } |
||
67 | } |
||
68 | } |
||
69 | |||
70 | // Free any unmanaged objects here. |
||
71 | // |
||
72 | |||
73 | this._disposed = true; |
||
74 | } |
||
75 | } |
||
76 | |||
77 | ~CommandDeleteAll() |
||
78 | { |
||
79 | this.Dispose(false); |
||
80 | } |
||
81 | #endregion |
||
82 | } |
||
83 | } |