using System.Collections.Generic;
namespace Netron.Diagramming.Core {
///
/// Pen style command
///
class PenStyleCommand : Command {
#region Fields
CollectionBase bundle;
IController controller;
IPenStyle newStyle;
Dictionary previousStyles = new Dictionary();
#endregion
#region Properties
///
/// Gets the entities.
///
/// The shape.
public CollectionBase Entities {
get { return bundle; }
}
#endregion
#region Constructor
///
/// Initializes a new instance of the class.
///
/// The controller.
/// The bundle.
/// The pen style.
public PenStyleCommand(IController controller, CollectionBase bundle, IPenStyle penStyle)
: base(controller) {
this.Text = "Fill style";
this.controller = controller;
this.bundle = bundle;//the bundle should contain only IShape and IConnection entities!
this.newStyle = penStyle;
}
#endregion
#region Methods
///
/// Perform redo of this command.
///
public override void Redo() {
if (bundle == null || bundle.Count == 0)
return;
previousStyles.Clear();
foreach (IDiagramEntity entity in bundle) {
if (entity is IConnection) {
previousStyles.Add(entity.Uid.ToString(), entity.PenStyle);
(entity as IConnection).PenStyle = newStyle;
}
}
}
///
/// Perform undo of this command.
///
public override void Undo() {
if (bundle == null || bundle.Count == 0)
return;
foreach (IDiagramEntity entity in bundle) {
if (entity is IConnection)
(entity as IConnection).PenStyle = previousStyles[entity.Uid.ToString()];
}
}
#endregion
}
}