oXygene Editor Events
-
- Posts: 4141
- Joined: Fri Mar 28, 2003 2:12 pm
Re: oXygene Editor Events
Post by sorin_ristache »
Do you need to know the current node in Author editing mode and run a custom Author action on the node? The Author API which you can find in the Author SDK (on the Developer page) defines the method AuthorOperation.doOperation() for custom user actions. It receives an AuthorAccess parameter which helps you to find and process the current node of the Author document.
If this is not what you want please give more details about what you need to do.
Regards,
Sorin
-
- Posts: 55
- Joined: Tue Jun 09, 2009 4:47 pm
Re: oXygene Editor Events
Thanx for a quick response. Basically we need to perform different actions but for now the problem is to create handlers to specifick Click and KeyPress events.
As a sample imagine a task to display a cliked word in a separate dialog?
To do this we need to handle the Click event, then identify the clicked node and get it's text content.
Please help.
-
- Posts: 4141
- Joined: Fri Mar 28, 2003 2:12 pm
Re: oXygene Editor Events
Post by sorin_ristache »
We will add in the next version (10.3) the possibility to register a mouse listener for receiving mouse events (that includes mouse click events) on the current Author document. The Author API which enables registering the listener allows you to find and process the current node of the document. Version 10.3 will be released in a couple of weeks.
Regards,
Sorin
-
- Posts: 4141
- Joined: Fri Mar 28, 2003 2:12 pm
Re: oXygene Editor Events
Post by sorin_ristache »
On what platform do you use Oxygen? I can send you the download URL for a Windows kit or for an All Platforms kit.
Regards,
Sorin
-
- Posts: 4141
- Joined: Fri Mar 28, 2003 2:12 pm
Re: oXygene Editor Events
Post by sorin_ristache »
Thank you,
Sorin
-
- Posts: 4141
- Joined: Fri Mar 28, 2003 2:12 pm
-
- Posts: 55
- Joined: Tue Jun 09, 2009 4:47 pm
Re: oXygene Editor Events
AuthorViewToModelInfo modelInfo = m_Context.viewToModel(event.X,event.Y);
AuthorNode m_Anode = modelInfo.getAuthorNode();
int m_ClickOffset = modelInfo.getOffset();
for further development we need to enumerate the child elements of that node.
apparently only the element interface allsows us to enumerate children
aList = aElem.getContentNodes();
how do we cast the node interface to the element one?
-
- Posts: 4141
- Joined: Fri Mar 28, 2003 2:12 pm
Re: oXygene Editor Events
Post by sorin_ristache »
Regards,
Sorin
-
- Posts: 4141
- Joined: Fri Mar 28, 2003 2:12 pm
Re: oXygene Editor Events
Post by sorin_ristache »
Regards,
Sorin
-
- Posts: 55
- Joined: Tue Jun 09, 2009 4:47 pm
Re: oXygene Editor Events
We are using the following set of functions to insert new tags into the document
createDocumentFragment
insertFragment
insertXMLFragment
insertMultipleElements
insertText
Unfortunately we cannot achive the desired result.
In brief: instead of text BEFORE, we nee to get the text AFTER.
BEFORE=======================
<section><title>XML</title>
<para>Firsrt Line. In this section of the book <b>shall</b> I will explain different XML applications.</para>
<para>Second Line. In this section of the book <b>shall</b> I will explain different XML applications.</para>
</section>
==============================
AFTER=========================
<section><title>XML</title>
<para>Firsrt Line. In this <MyTag1>section</MyTag1> of the book <MyTag2><b>shall</b><MyTag2> I will explain different XML applications.</para>
<para>Second Line. In this <MyTag3>section</MyTag3> of the book <MyTag4><b>shall</b> I will</MyTag4> <MyTag5>explain</MyTag5> different <MyTag6>XML</MyTag6> applications.</para>
</section>
==============================
Please advise how can we achieve the desired behaviour using those funstions (or any other)?
Regards,
Max
-
- Posts: 4141
- Joined: Fri Mar 28, 2003 2:12 pm
Re: oXygene Editor Events
Post by sorin_ristache »
You should find the offset of the insert location and call AuthorDocumentController.insertXMLFragment(). For finding the offset (relative to the start of the edited document) for example if you have an AuthorNode reference just call AuthorNode.getStartOffset() or AuthorNode.getEndOffset().
How did you try to insert the new AuthorElement / AuthorNode objects in the Author document?
Regards,
Sorin
-
- Posts: 55
- Joined: Tue Jun 09, 2009 4:47 pm
Re: oXygene Editor Events
1. We have a problem with calculatiing the offset. Basically we are counting symbols to get the offset. The problem is that inline tags (e.g. <b>) have width = 1.
But if we fetch text via getTextContent(), it returns pure text without the inline tags which means that if we calculate the offset by counting characters, we'll get shifted by the amount of stripped inline tags.
2. We use insertXMLFragment("<myTag1/>", offset)
or
insertMultipleElements( ....)
Regards,
Max
-
- Posts: 4141
- Joined: Fri Mar 28, 2003 2:12 pm
Re: oXygene Editor Events
Post by sorin_ristache »
Regards,
Sorin
-
- Posts: 4141
- Joined: Fri Mar 28, 2003 2:12 pm
Re: oXygene Editor Events
Post by sorin_ristache »
Regards,
Sorin
-
- Posts: 4141
- Joined: Fri Mar 28, 2003 2:12 pm
Re: oXygene Editor Events
Post by sorin_ristache »
You cannot get a list that includes the text represented as separate nodes. You have the selected text with start offset and end offset (as index into a string that represents the whole document content) and also you have the current node with start offset and end offset. For example in your case for transforming
Code: Select all
<para>First line. In this section of the book <b>shall</b> I will explain different XML applications.</para>
Code: Select all
<para>First line. In this <MyTag1>section</MyTag1>of the book <MyTag2><b>shall</b></MyTag2> I will explain different XML applications.</para>
Code: Select all
public void doOperation(AuthorAccess authorAccess, ArgumentsMap arguments)
throws IllegalArgumentException, AuthorOperationException {
AuthorEditorAccess editorAccess = authorAccess.getEditorAccess();
int start = editorAccess.getSelectionStart();
int end = editorAccess.getSelectionEnd();
String selection = editorAccess.getSelectedText();
try {
AuthorDocumentController controller = authorAccess.getDocumentController();
AuthorNode currentNode = controller.getNodeAtOffset(editorAccess.getCaretOffset());
if (currentNode.getTextContent().equals(selection)) {
// The case "<b>shall</b>"
AuthorDocumentFragment selectionAsAFragment = controller.createDocumentFragment(start, end);
String selectionAsXML = controller.serializeFragmentToXML(selectionAsAFragment);
controller.deleteNode(currentNode);
controller.insertXMLFragment("<MyTag2>" + selectionAsXML + "</MyTag2>", editorAccess.getCaretOffset());
} else {
// The case "section"
controller.delete(start, end);
controller.insertXMLFragment("<MyTag1>" + selection + "</MyTag1>", start);
}
} catch (BadLocationException e) {
e.printStackTrace();
}
}
Regards,
Sorin
-
- Posts: 55
- Joined: Tue Jun 09, 2009 4:47 pm
Re: oXygene Editor Events
Thank you for the solution given. We've already solved the problem ourselves, but we found useful for us elements in your solution.
We have such a question:
Does the editor differentiate the tags <MyTag></MyTag> and <MyTag/>? How can we differ them in the editor?
To take into account the offset if node has Children we use the following formula:
Correction = NumberOfChilds * 2;
i.e. tags <MyTag>some text...</MyTag> with the length = 1.
But we can't catch how to take into acount such tags as <MyTag></MyTag> (empty tag) and <MyTag/>.
What width do they have?
Best regards,
Max
-
- Posts: 4141
- Joined: Fri Mar 28, 2003 2:12 pm
Re: oXygene Editor Events
Post by sorin_ristache »
In Author mode there is no difference between the two forms. Both <MyTag></MyTag> and <MyTag/> take two 0 (zero) characters in the string with the document content. Every XML tag takes one 0 (zero) character.Max wrote:Does the editor differentiate the tags <MyTag></MyTag> and <MyTag/>? How can we differ them in the editor?
<MyTag> has width 1, </MyTag> has width 1, <MyTag/> has width 2 (as for the equivalent form <MyTag></MyTag>).Max wrote:But we can't catch how to take into acount such tags as <MyTag></MyTag> (empty tag) and <MyTag/>.
What width do they have?
Regards,
Sorin
-
- Posts: 55
- Joined: Tue Jun 09, 2009 4:47 pm
Re: oXygene Editor Events
Thanx for detailed answer!
We have tested our plugin on simple xml (Elements + Text Nodes).
Now it crashes on comments nodes (<!-- some text -->),
because when we are trying to enumerate children this code raises exception:
Code: Select all
((AuthorElement)aList.get(aIndex)).getType();
((AuthorElement)aList.get(aIndex)).getName();
Regards,
Max
-
- Posts: 4141
- Joined: Fri Mar 28, 2003 2:12 pm
Re: oXygene Editor Events
Post by sorin_ristache »
Code: Select all
if (AuthorNode.NODE_TYPE_COMMENT == ((AuthorNode)aList.get(aIndex)).getType()) ...
Regards,
Sorin
-
- Posts: 55
- Joined: Tue Jun 09, 2009 4:47 pm
Re: oXygene Editor Events
Now our plugin successfully processes XML comments.
We've tested the plugin on the following example: samples\dita\flowers\tasks\pruning.xml.
Unfortunately it works increadibly slow: highlight each word with a different color in this short text takes approx 15 seconds (!!)
We need to optimize it somehow.
After investgating the problem we discovered this function
insertMultipleElements(AuthorElement parentElement, java.lang.String[] elementNames, int[] offsets, java.lang.String namespace)
The function inserts multiple elements at the given offsets.
Do you think it is worth digging further and it will give us a nice speedup?
Or you may suggest alternative ways of highlighting words, with e.g. Processing Instructions?
Source:
<para>First line. In this section of the book <b>shall</b> I will explain different XML applications.</para>
Target:
<para>First line. In <MyTag1>this</MyTag1> section of the <MyTag1>book</MyTag1> <MyTag1><b>shall</b></MyTag1> I will explain <MyTag1>different</MyTag1> XML applications.</para>
Regards,
Max
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service