This project has moved and is read-only. For the latest updates, please go here.

Problem with Display.ShapesRemoved event

Oct 30, 2012 at 4:33 PM
Edited Oct 30, 2012 at 4:49 PM

Hi,

While Display.ShapesInserted event provides proper collection in e.Shapes (where e is its 2nd argument of type "DiagramPresenterShapesEventArgs"), Display.ShapesRemoved - doesn't: e.Shapes is always empty! Debugging the following method of the Display component

private void PerformDelete(Diagram diagram, IEnumerable<Shape> shapes, bool withModelObjects)
{
  diagramSetController.DeleteShapes(diagram, shapes, withModelObjects);

  OnShapesRemoved(new DiagramPresenterShapesEventArgs(shapes));
  UnselectShapes(shapes);
}

demonstrates that before call to diagramSetController.DeleteShapes we have e.Shapes.Count > 0, and after it - e.Shapes.Count = 0.

As a result, handling the Display.ShapesRemoved event doesn't make it clear which shapes were removed. This makes the life difficult :)

Is this a bug?

[UPDATE] Seems I found a workaround, although I'm not sure that it is reliable. If I maintain some list of shapes (List<Shape>) in the code of my form, filling it in Display.ShapesInserted event handler, then in Display.ShapesRemoved event handler I can scan this list for shapes having their Diagram property set to null: such shapes are the deleted ones - so I must also delete them from my list.

Oct 31, 2012 at 9:23 AM
Edited Oct 31, 2012 at 9:29 AM

Yes, this is a bug. We will correct it with the next release.
Replace the method with this version:

private void PerformDelete(Diagram diagram, IEnumerable<Shape> shapes, bool withModelObjects)
{ 
    DiagramPresenterShapesEventArgs e = new DiagramPresenterShapesEventArgs(shapes);
           
    UnselectShapes(e.Shapes);
    diagramSetController.DeleteShapes(diagram, e.Shapes, withModelObjects);

    OnShapesRemoved(e);
}
Feb 22, 2013 at 9:26 AM
Edited Feb 22, 2013 at 9:27 AM
Hi,

In release 2.0.3 this bug is said to be fixed. And it's true for situation when shape(s) are deleted ; but when shape(s) are cut (and this also brings up the Display.ShapesRemoved event) - it's not fixed: collection e.Shapes is still empty!

Hope you will fix it soon.
Mar 1, 2013 at 8:02 AM
Fixed:
private void PerformCut(Diagram diagram, IEnumerable<Shape> shapes, bool withModelObjects, Point position) {
    DiagramPresenterShapesEventArgs e = new DiagramPresenterShapesEventArgs(shapes);

    UnselectShapes(shapes);
    if (Geometry.IsValid(position))
        diagramSetController.Cut(diagram, e.Shapes, withModelObjects, position);
    else diagramSetController.Cut(diagram, e.Shapes, withModelObjects);

    OnShapesRemoved(e);
}