Trying to do some actions to selected nodes when they are moved. Ideally, just click-and-drag a node should run the code, but MOUSEDOWN doesn’t recognize the node as selected. So it requires the first click to get selection, and then second click and drag to run the code, which doesn’t seem right.
I don’t know if there’s a better way to do it, but now I’m getting selection with MOUSEDOWN (for a single node) and MOUSEUP (for marquee box selection) and run actions with DRAWFOREGROUND.
(also it needs to calculate some stuff at the moment of selection, that’s why its separated from drawforeground)
Not quite. Here’s a little screengrab: if you first select the node and then drag it, the other nodes adjust accordingly (it gets selection and calculates the relation to other nodes on mousedown). But if you just click+drag in one click, it the MOUSEDOWN doesn’t recognize the node as selected and doesn’t run the code:
Ooh, just got what you meant before! Yes, is it possible to subscribe to changes in selection and if nodes are moved? I guess it would be better than mousedown/dragged!
Sorry for not answering earlier. Unfortunately I don’t remember what I had in mind.
But to repeat my question: How do you plan to en/disable this functionality? It seems to me that this should be a tool in the toolbar (next to the select tool).
Hi, thanks for getting back to this!
Yes, I have it as a toolbar tool, but unfortunately it doesn’t make a difference. Or i don’t see how it should.
So basically, it needs some callback for changes in selection, and MOUSEUP / DOWN don’t always work for that: I’d expect that if you click on a node selecting it, you’d immediately get that node as selection from MOUSEDOWN, but it doesn’t get it, if that makes sense.
If you have a tool, you don’t need all that callback and KVO stuff. Just overwrite ´mouseDragged_()and do all your processing there (probably callsuper` first). I’ll try to add that to the templates.
Ohh now it makes sense, thank you!
Is the code from mouseDragged_ of the original selection tool available somewhere? I could probably keep a good part of it, but can’t find it anywhere.
Hi Georg! Is there a way to add those mouse callbacks from a Palette plugin? Using the line above doesn’t seem to do anything. Or is there a better way to run code from Palette plugin whenever the current layer has changed?
I tried using DRAWFOREGROUND and checking glyph.lastChange, but it includes changes in selection, which makes the code override any further user action.