private CompositeCommand CreateRemoveShapeCommand(RadDiagramShapeBase shape) { if (shape == null) { return(null); } var compositeRemoveShapeCommand = new CompositeCommand(CommandNames.RemoveShapes); var removeCommand = new UndoableDelegateCommand(CommandNames.RemoveShape, s => this.Diagram.RemoveShape(shape), s => this.Diagram.AddShape(shape)); var parentContainer = shape.ParentContainer; if (parentContainer != null) { var execute = new Action <object>((o) => parentContainer.RemoveItem(shape)); var undo = new Action <object>((o) => { if (!parentContainer.Items.Contains(shape)) { parentContainer.AddItem(shape); } }); compositeRemoveShapeCommand.AddCommand(new UndoableDelegateCommand(CommandNames.RemoveItemFromContainer, execute, undo)); } foreach (var changeSourceCommand in shape.OutgoingLinks.Union(shape.IncomingLinks).ToList().Select(connection => this.CreateRemoveConnectionCommand(connection))) { compositeRemoveShapeCommand.AddCommand(changeSourceCommand); } compositeRemoveShapeCommand.AddCommand(removeCommand); var container = shape as RadDiagramContainerShape; if (container != null) { for (int i = container.Items.Count - 1; i >= 0; i--) { var shapeToRemove = container.Items[i] as RadDiagramShapeBase; if (shapeToRemove != null) { compositeRemoveShapeCommand.AddCommand(this.CreateRemoveShapeCommand(shapeToRemove)); } else { var connection = container.Items[i] as IConnection; if (connection != null && connection.Source == null && connection.Target == null) { compositeRemoveShapeCommand.AddCommand(this.CreateRemoveConnectionCommand(container.Items[i] as IConnection)); } } } } return(compositeRemoveShapeCommand); }
void RemoveShapeConnectors(RadDiagramShapeBase shape) { List <IConnector> cs = new List <IConnector>(); foreach (var connen in shape.Connectors) { if (connen.Name != "Right") { cs.Add(connen); } } foreach (var connen in cs) { shape.Connectors.Remove(connen); } }
void RemoveShapeConnectors(RadDiagramShapeBase shape) { List<IConnector> cs = new List<IConnector>(); foreach (var connen in shape.Connectors) { if (connen.Name != "Right") { cs.Add(connen); } } foreach (var connen in cs) { shape.Connectors.Remove(connen); } }
private CompositeCommand CreateRemoveShapeCommand(RadDiagramShapeBase shape) { if (shape == null) return null; var compositeRemoveShapeCommand = new CompositeCommand(CommandNames.RemoveShapes); var removeCommand = new UndoableDelegateCommand(CommandNames.RemoveShape, s => this.Diagram.RemoveShape(shape), s => this.Diagram.AddShape(shape)); var parentContainer = shape.ParentContainer; if (parentContainer != null) { var execute = new Action<object>((o) => parentContainer.RemoveItem(shape)); var undo = new Action<object>((o) => { if (!parentContainer.Items.Contains(shape)) parentContainer.AddItem(shape); }); compositeRemoveShapeCommand.AddCommand(new UndoableDelegateCommand(CommandNames.RemoveItemFromContainer, execute, undo)); } foreach (var changeSourceCommand in shape.OutgoingLinks.Union(shape.IncomingLinks).ToList().Select(connection => this.CreateRemoveConnectionCommand(connection))) { compositeRemoveShapeCommand.AddCommand(changeSourceCommand); } compositeRemoveShapeCommand.AddCommand(removeCommand); var container = shape as RadDiagramContainerShape; if (container != null) { for (int i = container.Items.Count - 1; i >= 0; i--) { var shapeToRemove = container.Items[i] as RadDiagramShapeBase; if (shapeToRemove != null) compositeRemoveShapeCommand.AddCommand(this.CreateRemoveShapeCommand(shapeToRemove)); else { var connection = container.Items[i] as IConnection; if (connection != null && connection.Source == null && connection.Target == null) compositeRemoveShapeCommand.AddCommand(this.CreateRemoveConnectionCommand(container.Items[i] as IConnection)); } } } return compositeRemoveShapeCommand; }
private void RemoveContainer(MainContainerShapeBase container, RadDiagramShapeBase itemToRemove) { if (container == null || itemToRemove == null) return; CompositeCommand command = new CompositeCommand("Remove horizontal container"); if (container.IsCollapsed) { command.AddCommand(new UndoableDelegateCommand("Update container", new Action<object>((o) => { container.IsCollapsed = false; }), new Action<object>((o) => { container.IsCollapsed = true; }))); } command.AddCommand(this.CreateRemoveShapeCommand(itemToRemove)); if (container.IsCollapsed) { command.AddCommand(new UndoableDelegateCommand("Update container", new Action<object>((o) => { }), new Action<object>((o) => { }))); } this.Diagram.UndoRedoService.ExecuteCommand(command); }