Changeset 4068 for trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.Netron/3.0.2672.12446/Netron.Diagramming.Core-3.0.2672.12446/UndoRedo/Commands/UngroupCommand.cs
- Timestamp:
- 07/22/10 00:44:01 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.Netron/3.0.2672.12446/Netron.Diagramming.Core-3.0.2672.12446/UndoRedo/Commands/UngroupCommand.cs
r2868 r4068 1 using System; 2 using System.Collections.Generic; 3 using System.Text; 4 using System.Drawing; 5 namespace Netron.Diagramming.Core 6 { 1 namespace Netron.Diagramming.Core { 2 /// <summary> 3 /// Ungroup command 4 /// </summary> 5 class UngroupCommand : Command { 6 #region Fields 7 IBundle bundle; 8 IController controller; 9 IGroup mGroup; 10 #endregion 11 12 #region Properties 7 13 /// <summary> 8 /// Ungroup command14 /// Gets the newly created group after <see cref="Redo"/> was called 9 15 /// </summary> 10 class UngroupCommand : Command 11 { 12 #region Fields 13 IBundle bundle; 14 IController controller; 15 IGroup mGroup; 16 #endregion 16 public IGroup Group { 17 get { return mGroup; } 18 } 17 19 18 #region Properties 19 /// <summary> 20 /// Gets the newly created group after <see cref="Redo"/> was called 21 /// </summary> 22 public IGroup Group 23 { 24 get { return mGroup; } 25 } 20 /// <summary> 21 /// Gets the entities. 22 /// </summary> 23 /// <value>The shape.</value> 24 public CollectionBase<IDiagramEntity> Entities { 25 get { return bundle.Entities; } 26 } 26 27 27 /// <summary> 28 /// Gets the entities. 29 /// </summary> 30 /// <value>The shape.</value> 31 public CollectionBase<IDiagramEntity> Entities 32 { 33 get { return bundle.Entities; } 34 } 28 #endregion 35 29 36 #endregion 30 #region Constructor 31 /// <summary> 32 /// Initializes a new instance of the <see cref="T:UngroupCommand"/> class. 33 /// </summary> 34 /// <param name="controller">The controller.</param> 35 /// <param name="group">The group.</param> 36 public UngroupCommand(IController controller, IGroup group) 37 : base(controller) { 38 this.Text = "Ungroup"; 39 this.controller = controller; 40 this.mGroup = group; 41 bundle = new Bundle(); 42 } 43 #endregion 37 44 38 #region Constructor 39 /// <summary> 40 /// Initializes a new instance of the <see cref="T:UngroupCommand"/> class. 41 /// </summary> 42 /// <param name="controller">The controller.</param> 43 /// <param name="group">The group.</param> 44 public UngroupCommand(IController controller, IGroup group) 45 : base(controller) 46 { 47 this.Text = "Ungroup"; 48 this.controller = controller; 49 this.mGroup = group; 50 bundle = new Bundle(); 51 } 52 #endregion 45 #region Methods 53 46 54 #region Methods 47 /// <summary> 48 /// Perform redo of this command. 49 /// </summary> 50 public override void Redo() { 51 //remove the group from the layer 52 this.Controller.Model.DefaultPage.DefaultLayer.Entities.Remove(mGroup); 53 //detach the entities from the group 54 foreach (IDiagramEntity entity in mGroup.Entities) { 55 //this will be recursive if an entity is itself an IGroup 56 entity.Group = null; 57 bundle.Entities.Add(entity); 58 //mGroup.Entities.Remove(entity); 59 Controller.Model.AddEntity(entity); 60 } 61 //change the visuals such that the entities in the group are selected 55 62 56 /// <summary> 57 /// Perform redo of this command. 58 /// </summary> 59 public override void Redo() 60 { 61 //remove the group from the layer 62 this.Controller.Model.DefaultPage.DefaultLayer.Entities.Remove(mGroup); 63 //detach the entities from the group 64 foreach (IDiagramEntity entity in mGroup.Entities) 65 { 66 //this will be recursive if an entity is itself an IGroup 67 entity.Group = null; 68 bundle.Entities.Add(entity); 69 //mGroup.Entities.Remove(entity); 70 Controller.Model.AddEntity(entity); 71 } 72 //change the visuals such that the entities in the group are selected 63 CollectionBase<IDiagramEntity> col = new CollectionBase<IDiagramEntity>(); 64 col.AddRange(mGroup.Entities); 73 65 74 CollectionBase<IDiagramEntity> col = new CollectionBase<IDiagramEntity>(); 75 col.AddRange(mGroup.Entities); 66 this.Controller.Model.Selection.SelectedItems = col; 76 67 77 this.Controller.Model.Selection.SelectedItems = col; 68 mGroup.Invalidate(); 69 mGroup = null; 78 70 79 mGroup.Invalidate(); 80 mGroup = null; 81 82 //note that the entities have never been disconnected from the layer 83 //so they don't have to be re-attached to the anything. 84 //The insertion of the Group simply got pushed in the scene-graph. 71 //note that the entities have never been disconnected from the layer 72 //so they don't have to be re-attached to the anything. 73 //The insertion of the Group simply got pushed in the scene-graph. 85 74 86 75 87 76 } 88 77 89 /// <summary> 90 /// Perform undo of this command. 91 /// </summary> 92 public override void Undo() 93 { 78 /// <summary> 79 /// Perform undo of this command. 80 /// </summary> 81 public override void Undo() { 94 82 95 96 97 98 83 //create a new group 84 GroupShape group = new GroupShape(this.Controller.Model); 85 //asign the entities to the group 86 group.Entities = bundle.Entities; 99 87 100 foreach (IDiagramEntity entity in group.Entities) 101 { 102 //this will be recursive if an entity is itself an IGroup 103 entity.Group = group; 104 } 105 //add the new group to the layer 106 this.Controller.Model.DefaultPage.DefaultLayer.Entities.Add(group); 88 foreach (IDiagramEntity entity in group.Entities) { 89 //this will be recursive if an entity is itself an IGroup 90 entity.Group = group; 91 } 92 //add the new group to the layer 93 this.Controller.Model.DefaultPage.DefaultLayer.Entities.Add(group); 107 94 108 95 mGroup = group; 109 96 110 //select the newly created group 111 CollectionBase<IDiagramEntity> col = new CollectionBase<IDiagramEntity>(); 112 col.Add(mGroup); 113 this.Controller.Model.Selection.SelectedItems = col; 114 mGroup.Invalidate(); 115 116 117 } 97 //select the newly created group 98 CollectionBase<IDiagramEntity> col = new CollectionBase<IDiagramEntity>(); 99 col.Add(mGroup); 100 this.Controller.Model.Selection.SelectedItems = col; 101 mGroup.Invalidate(); 118 102 119 103 120 #endregion121 104 } 122 105 106 107 #endregion 108 } 109 123 110 }
Note: See TracChangeset
for help on using the changeset viewer.