Page 1 of 1

Drop objects onto the XML editor.

Posted: Thu Jun 14, 2012 1:40 pm
by SSC
Hello,

We do use the Eclipse version of Oxygen 13.2.

I´d like to drop graphic objects onto the XML editor, so that they are inserted at the location where the drop takes place.

Currently I try to use com.oxygenxml.editor.editors.author.AuthorDnDListener extension to achieve that.

When a drop occurs I want to use one of the insertXMLFragment methods of the ro.sync.ecss.extensions.api.AuthorDocumentController, but I do not know where to get the correct arguments for the method.
Do you have a hint for me, how I can achieve to insert XML fragments via Drag&Drop at the right position where the drop takes place?

Regards,

Simon

Re: Drop objects onto the XML editor.

Posted: Thu Jun 14, 2012 3:36 pm
by Radu
Hi Simon,

Yes, you can get from the drop event the X and Y coordinates and translate them to an offset in the Author page.
But it's not as simple as it should be, we should probably add some API to translate this point which comes in screen coordinates to a certain offset (the correctDropLocation method you see below).

Here's the code which should work:

Code: Select all

      /**
* Correct the drop location taking onto account the scroll offsets.
*
* @param e The drop location in screen coordinates.
* @return The corrected location, depending on the scroll insets.
*/
private org.eclipse.swt.graphics.Point correctDropLocation(DropTargetEvent e) {
org.eclipse.swt.graphics.Point p = new org.eclipse.swt.graphics.Point(e.x, e.y);
// Obtain the control absolute coordinates.
Control control = (Control) authorAccess.getEditorAccess().getAuthorComponent();
p = control.toControl(p);
Scrollable canvas = (Scrollable) authorAccess.getEditorAccess().getAuthorComponent();
ScrollBar vbar = canvas.getVerticalBar();
ScrollBar hbar = canvas.getHorizontalBar();
p.y += vbar.getSelection();
p.x += hbar.getSelection();
return p;
}

@Override
public void authorDrop(DropTargetEvent event) {
Point pt = correctDropLocation(event);
AuthorViewToModelInfo vtm = authorAccess.getEditorAccess().viewToModel(pt.x, pt.y);
authorAccess.getEditorAccess().setCaretPosition(vtm.getOffset());
}
Regards,
Radu

Re: Drop objects onto the XML editor.

Posted: Thu Feb 14, 2013 3:50 pm
by Radu
Hi,

In Oxygen 14.2 we added the method:

ro.sync.exml.workspace.api.editor.page.WSTextBasedEditorPage.getLocationRelativeToEditorFromScreen(int, int)

which can be used for such cases.

Regards,
Radu