Blazor-Diagrams / Blazor.Diagrams

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

Question/Enhancement - How do I prevent or short-circuit node and link Deletion #164

Open schaveyt opened 2 years ago

schaveyt commented 2 years ago

Desired Behavior

Before the user deletes anything from the diagram, i must present a confirmation modal. If the user approved, one continues with deleting from the diagram as well as the application performing additional housekeeping. If the user cancels the deletion, the deletion should be aborted

Current Behavior

The user is able to press the delete key and diagram element is deleted. There is not way for me to intercept this and present the confirmation modal.

For now, I set the DiagramOptions.DeleteKey = "" to prevent diagram deletions entirely.

zHaytam commented 2 years ago

Hi, there is a ShouldDeleteX option for synchronously checking if it's allowed or not. Would this functionality help you? https://github.com/Blazor-Diagrams/Blazor.Diagrams/issues/142

zHaytam commented 2 years ago

I believe you could also do it using a custom behavior, but that's not documented right now.

schaveyt commented 2 years ago

🤔 interesting. Let me research that and get back to u.

snehabihani commented 2 years ago

image I am using Prompt for deleting the nodes but as I am deleting multiple nodes it is prompting that many times. How to avoid this?

zHaytam commented 2 years ago

With that code it doesn't handle multiple deletes?
I'm not sure how would that be handled in the library (multiple deletes at once)

snehabihani commented 2 years ago

It is handling but after cancel I want to reset the flags for next delete, so I handled in keydown event, but keydown event get called after this so no use.

snehabihani commented 2 years ago

Can we change ShouldDeleteNode for every node we create or it will be same for all nodes.?

zHaytam commented 2 years ago

It's the same for everything.

For now, can you try:

diagram.UnregisterBehavior<KeyboardShortcutsBehavior>();
// register your key press event
diagram.RegisterBehavior(new KeyboardShortcutsBehavior(diagram));
snehabihani commented 2 years ago

With that code it doesn't handle multiple deletes? I'm not sure how would that be handled in the library (multiple deletes at once)

If I want to create PR which branch to fork?

zHaytam commented 2 years ago

develop branch. Although what solution are you thinking of?

snehabihani commented 2 years ago

I Am thinking to filter separate lists for all node,link and group and then check for ShouldDelete condition then do the delete so ShouldDelete will get call only once. whether it is multiple or single delete