using System.Collections.Generic; namespace Netron.Diagramming.Core { /// /// Fill style command /// class FillStyleCommand : Command { #region Fields CollectionBase bundle; IController controller; IPaintStyle 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 paint style. public FillStyleCommand(IController controller, CollectionBase bundle, IPaintStyle paintStyle) : base(controller) { this.Text = "Fill style"; this.controller = controller; this.bundle = bundle;//the bundle should contain only IShape and IConnection entities! this.newStyle = paintStyle; } #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 IShape) { previousStyles.Add(entity.Uid.ToString(), entity.PaintStyle); (entity as IShape).PaintStyle = 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 IShape) (entity as IShape).PaintStyle = previousStyles[entity.Uid.ToString()]; } } #endregion } }