1 | using System.Collections.Generic;
|
---|
2 | namespace Netron.Diagramming.Core {
|
---|
3 | /// <summary>
|
---|
4 | /// Pen style command
|
---|
5 | /// </summary>
|
---|
6 | class PenStyleCommand : Command {
|
---|
7 | #region Fields
|
---|
8 | CollectionBase<IDiagramEntity> bundle;
|
---|
9 | IController controller;
|
---|
10 |
|
---|
11 | IPenStyle newStyle;
|
---|
12 | Dictionary<string, IPenStyle> previousStyles = new Dictionary<string, IPenStyle>();
|
---|
13 | #endregion
|
---|
14 |
|
---|
15 | #region Properties
|
---|
16 |
|
---|
17 |
|
---|
18 |
|
---|
19 |
|
---|
20 | /// <summary>
|
---|
21 | /// Gets the entities.
|
---|
22 | /// </summary>
|
---|
23 | /// <value>The shape.</value>
|
---|
24 | public CollectionBase<IDiagramEntity> Entities {
|
---|
25 | get { return bundle; }
|
---|
26 | }
|
---|
27 |
|
---|
28 | #endregion
|
---|
29 |
|
---|
30 | #region Constructor
|
---|
31 | /// <summary>
|
---|
32 | /// Initializes a new instance of the <see cref="T:PenStyleCommand"/> class.
|
---|
33 | /// </summary>
|
---|
34 | /// <param name="controller">The controller.</param>
|
---|
35 | /// <param name="bundle">The bundle.</param>
|
---|
36 | /// <param name="penStyle">The pen style.</param>
|
---|
37 | public PenStyleCommand(IController controller, CollectionBase<IDiagramEntity> bundle, IPenStyle penStyle)
|
---|
38 | : base(controller) {
|
---|
39 | this.Text = "Fill style";
|
---|
40 | this.controller = controller;
|
---|
41 | this.bundle = bundle;//the bundle should contain only IShape and IConnection entities!
|
---|
42 | this.newStyle = penStyle;
|
---|
43 | }
|
---|
44 | #endregion
|
---|
45 |
|
---|
46 | #region Methods
|
---|
47 |
|
---|
48 | /// <summary>
|
---|
49 | /// Perform redo of this command.
|
---|
50 | /// </summary>
|
---|
51 | public override void Redo() {
|
---|
52 | if (bundle == null || bundle.Count == 0)
|
---|
53 | return;
|
---|
54 | previousStyles.Clear();
|
---|
55 | foreach (IDiagramEntity entity in bundle) {
|
---|
56 | if (entity is IConnection) {
|
---|
57 | previousStyles.Add(entity.Uid.ToString(), entity.PenStyle);
|
---|
58 | (entity as IConnection).PenStyle = newStyle;
|
---|
59 | }
|
---|
60 | }
|
---|
61 | }
|
---|
62 |
|
---|
63 | /// <summary>
|
---|
64 | /// Perform undo of this command.
|
---|
65 | /// </summary>
|
---|
66 | public override void Undo() {
|
---|
67 | if (bundle == null || bundle.Count == 0)
|
---|
68 | return;
|
---|
69 | foreach (IDiagramEntity entity in bundle) {
|
---|
70 | if (entity is IConnection)
|
---|
71 | (entity as IConnection).PenStyle = previousStyles[entity.Uid.ToString()];
|
---|
72 | }
|
---|
73 |
|
---|
74 |
|
---|
75 |
|
---|
76 |
|
---|
77 | }
|
---|
78 |
|
---|
79 |
|
---|
80 | #endregion
|
---|
81 | }
|
---|
82 |
|
---|
83 | } |
---|