Page 1 of 1

keep the current cursor's position after an Xml insert.

Posted: Mon Jun 18, 2012 10:38 am
by sebastienlavandier
Hi,

In my application, I can add some swing object to an xml document by drag and drop, by using "AuthorDnDListener", and most specially the function "authorDrop" (which is called when dnd is terminated). In this function, I use the function "AuthorDocumentController.insertXMLFragmentSchemaAware(...)" for add my object to the xml document at the current position by using "editorAccess.getCaretOffset()". That works very well !
But after, when I want to save my object in the xml referencement part, I use again the function "AuthorDocumentController.insertXMLFragmentSchemaAware(...)" with the xml referencement part position. That works too ! But the cursor's position is changed to the screen.
How can I do to keep the position's cursor of the first insert ?
Do you have an idea ?
Thanks in advance.

Re: keep the current cursor's position after an Xml insert.

Posted: Mon Jun 18, 2012 12:24 pm
by Radu
Hi,

Probably before making the second insert you could keep the caret position in a variable and then restore it after the insertion like:

Code: Select all

    int caretOffset = authorAccess.getEditorAccess().getCaretOffset();
//Perform second operation and then:
authorAccess.getEditorAccess().setCaretPosition(caretOffset);
Regards,
Radu

Re: keep the current cursor's position after an Xml insert.

Posted: Mon Jun 18, 2012 1:23 pm
by sebastienlavandier
Hi Radu,

I tried this, but after the second insert the value of the caret position become false (because an xml fragment was inserted).

I can't use this solution.
Do you have another ?
Thanks.

Re: keep the current cursor's position after an Xml insert.

Posted: Mon Jun 18, 2012 2:05 pm
by Radu
Hi Sebastien,

Using the Author API you can also create flexible positions (which are updated when the content changes). Something like this:

Code: Select all

Position position = authAccess.getDocumentController().createPositionInContent(authAccess.getEditorAccess().getCaretOffset());
//Perform operation here
authAccess.getEditorAccess().setCaretPosition(position.getOffset());
Maybe such a workaround will give you better flexibility.

Regards,
Radu

Re: keep the current cursor's position after an Xml insert.

Posted: Tue Jun 19, 2012 10:38 am
by sebastienlavandier
Hi Radu,
Thanks for you answer.
Now the cursor is at the good position (first insert), but the scroll screen stay to the 2nd insert.

Do you have another idea ? or a solution for the scroll ?
Thanks in advance.

Re: keep the current cursor's position after an Xml insert.

Posted: Wed Jun 20, 2012 3:30 pm
by Radu
Hi Sebastien,

Sorry for the delay.
We do not have specific API for scrolling (but maybe we could add some).
But you can use this method

Code: Select all

ro.sync.exml.workspace.api.editor.page.author.WSAuthorEditorPageBase.getAuthorComponent()
to obtain the swing JPanel on which the Author page is rendered.
The parent of this panel should be a JScrollPane and theoretically you could use its methods to obtain the scroll bounds before the action is performed and to set the same scroll bounds after the action is performed.

Regards,
Radu

Re: keep the current cursor's position after an Xml insert.

Posted: Fri Jul 13, 2012 11:39 am
by sebastienlavandier
Sorry for the delay
Thank you very much for your help
Bye

Re: keep the current cursor's position after an Xml insert.

Posted: Wed Oct 24, 2012 9:26 am
by mihaela
Hi,

Oxygen 14.1 was release and it contains a new method in the API to make a specific area of the Author mode visible. The method you can use is:

Code: Select all


ro.sync.exml.workspace.api.editor.page.author.WSAuthorEditorPageBase.scrollToRectangle(Rectangle) 
Here is the javadoc for this method:
http://www.oxygenxml.com/InstData/Edito ... Rectangle)

To get the rectangle corresponding to a specific offset you can use the following API:

Code: Select all


ro.sync.exml.workspace.api.editor.page.WSTextBasedEditorPage.modelToViewRectangle(int)
And the javadoc is:
http://www.oxygenxml.com/InstData/Edito ... angle(int)


Best Regards,
Mihaela