"Properties" context menu item logic

Feb 7, 2013 at 5:28 AM
Edited Feb 7, 2013 at 5:29 AM
Hi,

I think that "Properties" context menu item does not work as expected in case several shapes are selected. While PropertyPresenter displays [in the "primary" PropertyGrid] properties common to all selected shapes, "Properties" menu item click handler is designed to show properties of only one shape - see Display.CreatePropertiesMenuItemDef() method, it contains the following code:
return new DelegateMenuItemDef("Properties", Properties.Resources.DiagramPropertiesBtn3,
    description, isFeasible, Permission.Data, shapes,
    , p) => PropertyController.SetObject(0, obj));
I think that this code must be executed only if one shape is currently selected, and if several shapes are selected - PropertyController.SetObjects(int, IEnumerable) method should be used.

Steps to reproduce the issue:
  • Add two shapes to the diagram.
  • Select both shapes - Primary PropertyGrid will show properties common for both shapes.
  • Still with both shapes selected, right-click on one of the shapes - Primary PropertyGrid will show properties of this shape only (the one under mouse cursor). I'm not sure that this is the expected behavior. However, I may be wrong :)
Coordinator
Feb 7, 2013 at 7:58 AM
Edited Feb 7, 2013 at 8:08 AM
Thanks for the feedback. We will correct this issue.

[Edit] Corrected version:
private MenuItemDef CreatePropertiesMenuItemDef(Diagram diagram, IShapeCollection shapes, Point position) {
    bool isFeasible = (Diagram != null && PropertyController != null);
    string description;
    object obj = null;
    if (!isFeasible) description = "Properties are not available.";
    else {
        string descriptionFormat = "Show properties of {0} {2}{1}{2}";
        Shape s = shapes.FindShape(position.X, position.Y, ControlPointCapabilities.None, 0, null);
        if (s != null) {
            if (shapes.Count == 1)
                description = string.Format(descriptionFormat, "Shape", s.Type.Name, "'");
            else description = string.Format(descriptionFormat, shapes.Count, "Shapes", "");
            obj = s;
        } else {
            description = string.Format(descriptionFormat, typeof(Diagram).Name, Diagram.Title, "'");
            obj = diagram;
        }
    }

    return new DelegateMenuItemDef("Properties", Properties.Resources.DiagramPropertiesBtn3,
        description, isFeasible, Permission.Data, shapes,
        (a, p) => PropertyController.SetObjects(0, shapes));
}