Hi,
I have a CustomDragSelectingTool.
Now I want that, if I make a boxselect, the selected parts are in a special order based on a property in the node.
Is there a way to do this?
Here’s the definition of DragSelectingTool.SelectInRect:
public virtual void SelectInRect(Rect r) {
Diagram diagram = this.Diagram;
if (diagram == null) return;
// choose the selectable Parts within the rectangle
HashSet<Part> parts = new HashSet<Part>(diagram.Panel.FindPartsIn<Part>(r, SearchFlags.SelectableParts, this.Include, SearchLayers.Parts));
if (IsControlKeyDown()) { // toggle or deselect
if (IsShiftKeyDown()) { // deselect only
foreach (Part p in parts) {
if (p.IsSelected) p.IsSelected = false;
}
} else { // toggle selectedness of parts
foreach (Part p in parts) {
p.IsSelected = !p.IsSelected;
}
}
} else if (IsShiftKeyDown()) { // extend selection only
foreach (Part p in parts) {
if (!p.IsSelected) p.IsSelected = true;
}
} else { // select parts, and unselect all other previously selected parts
// this tries to avoid deselecting and then reselecting any Part
List<Part> tounselect = new List<Part>();
foreach (Part p in diagram.SelectedParts) {
if (!parts.Contains(p)) tounselect.Add(p);
}
foreach (Part p in tounselect) {
p.IsSelected = false;
}
foreach (Part p in parts) {
if (!p.IsSelected) p.IsSelected = true;
}
}
}
What you could do is sort the collection of Parts found by FindPartsIn, before actually selecting any Parts.