When a user pastes I'd like to be able to place the graphical objects relative to the current position of the mouse pointer. The IPasteContext does not contain coordinates for the pointer when the paste operation was invoked, so at the moment I'm limited to whatever information I pass through the clipboard from the original copy operation. That allows me to perform the paste at an offset relative to the original, but that may be meaningless if the paste operation is performed in another diagram.
Is that a feature I should request? Or is there some mechanism for getting the mouse pointer coordinates that I'm missing?
to retrieve the current mouse location. Unfortunately, this introduces a
dependency to gef
in your coding and also an internal usage since DiagramEditorInternal is
obviously internal ;-).
So it is really a hack just to try if you could get things working as
So either we could streamline the API of IDiagramEditor or we could
add the coordinates to the context (which is better from my point of view).
If we add coordinates to the context we should express them
I agree with your opinion that passing the coordinates through the context is better. I haven't seen anywhere else in the Graphiti framework where the user in encouraged to randomly sample the position of the mouse. Though I may temporarily try your suggested hack to make my paste a little nicer.
In terms of passing relative coordinates, I'm not sure what the container is in this case. The Diagram that contains the PictogramElements in the array held by the IPasteContext? That seems fine. It might be nice for the IPasteContext to actually have a reference to the Diagram that contains the PictogramElements in the array.
The example code requires that the Diagram be selected to do a paste, but I didn't like the additional click required to deselect the things I had just selected for copying in order to do the paste. So, my canPaste() and my paste() have some additional complexity for digging the Diagram out of whatever shows up in the PictogramElement array.