I’m trying to have a unique name for my nodes when they are copied and pasted. So I add a _1 to the name property in the copyNodeDataFunction like this:
But this function is called twice: once on ctrl-c and once on ctrl-v and the final node comes out with double _1_1 appended to the name. What am I doing wrong?
I’ll be honest with you, I have zero idea what you’re talking about. The diagram.model is exactly the same as the model passed into this function. Same number of nodes and same data.
After the paste is done and this function is run only then I have the new node added.
Sorry, I was confusing this with another similar situation.
The problem is that the node-data-copying-functionality doesn’t by itself know why the copy is being made. I’ll continue to assume you only want to add that name suffix when a paste happens, not when a copy happens.
One way to provide that information is to override CommandHandler.pasteFromClipboard so as to pass the information that that method is being called to your copyNodeDataFunction. For example you could set a global variable.
Alternatively you could look to see whether there is a transaction ongoing. If there isn’t, it’s most likely a copy (i.e. CommandHandler.copySelection). Something like: