Blazor-Diagrams / Blazor.Diagrams

A fully customizable and extensible all-purpose diagrams library for Blazor
https://blazor-diagrams.zhaytam.com
MIT License
919 stars 176 forks source link

Prevent deletion of a node without preventing it from being moved #309

Closed Zapwasd closed 1 year ago

Zapwasd commented 1 year ago

I would like to have the possibility to delete links but disable the possibility to delete nodes. Nodes should mantain the possibility to be moved. Is it possible?

Thanks in advance.

Zapwasd commented 1 year ago

I have found the solution to my problem.

diagram.SelectionChanged += Diagram_SelectionChanged;

private void Diagram_SelectionChanged(SelectableModel element) { int selectedLinksCount = diagram.Links.Count(x => x.Selected); int selectedNodesCount = diagram.Nodes.Count(x => x.Selected); int selectedGroupsCount = diagram.Groups.Count(x => x.Selected);

if (selectedLinksCount == 1 && selectedNodesCount + selectedGroupsCount == 0)
{
    diagram.Options.DeleteKey = "Delete";
}
else
{
    diagram.Options.DeleteKey = "";
}

}

zHaytam commented 1 year ago

Hello,

Did you try using Options.Constraints? There is ShouldDeleteNode option, which returns true by default, you can change it to _ => false;

Zapwasd commented 1 year ago

Hello,

Did you try using Options.Constraints? There is ShouldDeleteNode option, which returns true by default, you can change it to _ => false;

Thank you zHaytam for your suggestion. It works fine.