1 | using System.Drawing;
|
---|
2 | namespace Netron.Diagramming.Core {
|
---|
3 | /// <summary>
|
---|
4 | /// Delete command.
|
---|
5 | /// </summary>
|
---|
6 | public class DeleteCommand : Command {
|
---|
7 | #region Fields
|
---|
8 | CollectionBase<IDiagramEntity> bundle;
|
---|
9 | IController controller;
|
---|
10 |
|
---|
11 | #endregion
|
---|
12 |
|
---|
13 | #region Properties
|
---|
14 |
|
---|
15 |
|
---|
16 | /// <summary>
|
---|
17 | /// Gets the entities.
|
---|
18 | /// </summary>
|
---|
19 | /// <value>The shape.</value>
|
---|
20 | public CollectionBase<IDiagramEntity> Entities {
|
---|
21 | get { return bundle; }
|
---|
22 | }
|
---|
23 |
|
---|
24 | #endregion
|
---|
25 |
|
---|
26 | #region Constructor
|
---|
27 | /// <summary>
|
---|
28 | /// Initializes a new instance of the <see cref="T:DeleteCommand"/> class.
|
---|
29 | /// </summary>
|
---|
30 | /// <param name="controller">The controller.</param>
|
---|
31 | /// <param name="bundle">The bundle.</param>
|
---|
32 | public DeleteCommand(
|
---|
33 | IController controller,
|
---|
34 | CollectionBase<IDiagramEntity> bundle)
|
---|
35 | : base(controller) {
|
---|
36 | this.Text = "Delete";
|
---|
37 | this.controller = controller;
|
---|
38 | this.bundle = bundle;
|
---|
39 |
|
---|
40 | }
|
---|
41 | #endregion
|
---|
42 |
|
---|
43 | #region Methods
|
---|
44 |
|
---|
45 | /// <summary>
|
---|
46 | /// Perform redo of this command.
|
---|
47 | /// </summary>
|
---|
48 | public override void Redo() {
|
---|
49 | if (bundle.Count == 0) return;
|
---|
50 |
|
---|
51 | foreach (IDiagramEntity entity in bundle) {
|
---|
52 | //this.Controller.Model.DefaultPage.DefaultLayer.Entities.Remove(entity);
|
---|
53 | Controller.Model.Remove(entity);
|
---|
54 | }
|
---|
55 | this.Controller.View.HideTracker();
|
---|
56 | Rectangle rec = Utils.BoundingRectangle(bundle);
|
---|
57 | rec.Inflate(30, 30);
|
---|
58 | this.Controller.View.Invalidate(rec);
|
---|
59 | }
|
---|
60 |
|
---|
61 | /// <summary>
|
---|
62 | /// Perform undo of this command.
|
---|
63 | /// </summary>
|
---|
64 | public override void Undo() {
|
---|
65 |
|
---|
66 | if (bundle.Count == 0) return;
|
---|
67 |
|
---|
68 | foreach (IDiagramEntity entity in bundle) {
|
---|
69 | //this.Controller.Model.DefaultPage.DefaultLayer.Entities.Add(entity);
|
---|
70 | Controller.Model.AddEntity(entity);
|
---|
71 | }
|
---|
72 | this.Controller.View.HideTracker();
|
---|
73 |
|
---|
74 | Rectangle rec = Utils.BoundingRectangle(bundle);
|
---|
75 | rec.Inflate(30, 30);
|
---|
76 | this.Controller.View.Invalidate(rec);
|
---|
77 |
|
---|
78 |
|
---|
79 |
|
---|
80 | }
|
---|
81 |
|
---|
82 |
|
---|
83 | #endregion
|
---|
84 | }
|
---|
85 |
|
---|
86 | } |
---|