Custom framework: copy&paste and auto id behavior

Post here questions and problems related to oXygen frameworks/document types.
Patrik
Posts: 280
Joined: Thu Nov 28, 2013 9:32 am
Location: Hamburg/Germany
Contact:

Custom framework: copy&paste and auto id behavior

Post by Patrik »

Hi,

I'm having some issues in my custom framework derived from DITA. I can't see what I'm doing differently form the standard dita framework - still there it works and in my framework it doesn't!?


1. Ids for new documents
When creating a new document from a template the ids are not generated through my own method generateUniqueIDFor - those for new elements do. I'm returning an instance of a class derived from DITAUniqueAttributesRecognizer in the following methods:

Code: Select all

private GdvdlDitaUniqueAttributesRecognizer uniqueAttributesRecognizer;

@Override
public AuthorExtensionStateListener createAuthorExtensionStateListener() {
uniqueAttributesRecognizer = new GdvdlDitaUniqueAttributesRecognizer();
return uniqueAttributesRecognizer;
}

@Override
public ClipboardFragmentProcessor getClipboardFragmentProcessor() {
return uniqueAttributesRecognizer;
}

@Override
public UniqueAttributesRecognizer getUniqueAttributesIdentifier() {
return uniqueAttributesRecognizer;
}
What am I missing?

2. Ids for copied elements
When adding content by copy&paste (for instance a topic) the pasted element gets no default attribute in my framework. Even when using the standard DITAExtensionsBundle it doesn't work. Thus, it seems to be no matter of my class!?

3. Rendering of copied elements
When adding content by copy&paste the new elements are not displayed correctly - just as if the default attributes are not used (all text in a single line). After saving and refresh it works. For testing I used the standard DITA css and extension bundle and had the same effect...


Any ideas, what I might be missing?

One difference I noticed is that my framwork uses an xsd rather than a dtd.

Thanks and regards,

Patrik
Radu
Posts: 9046
Joined: Fri Jul 09, 2004 5:18 pm

Re: Custom framework: copy&paste and auto id behavior

Post by Radu »

Hi Patrik,
1. Ids for new documents
The unique IDs generator works only while the user is actively editing inside the document so indeed it is not called when a new document is created.
But you could use our API and set a new ID on the root element when you receive the callback ro.sync.exml.workspace.api.listeners.WSEditorChangeListener.editorOpened(URL) for example or on the first "ro.sync.ecss.extensions.api.AuthorExtensionStateListener.activated(AuthorAccess)" callback.
2. Ids for copied elements
3. Rendering of copied elements
Probably these are the same thing, because the default attributes are not detected on the pasted elements, the CSSs which select based on them do not match the elements.
I think I managed to reproduce this on our side with the default XSD-based DITA topics support we have. I will get back to you on this one after I look a little bit in the code.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Radu
Posts: 9046
Joined: Fri Jul 09, 2004 5:18 pm

Re: Custom framework: copy&paste and auto id behavior

Post by Radu »

Hi,

One extra remark about 2 and 3, I managed to reproduce the issue only when selecting the element in the Outline tree, using "Ctrl-C" and then pasting in the visual editor at a certain offset.
When I copied the content directly in the focused editor and pasted in the same editor, I could not reproduce the behavior.
Could you tell me precisely how you are performing the copy/paste on your side?

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Patrik
Posts: 280
Joined: Thu Nov 28, 2013 9:32 am
Location: Hamburg/Germany
Contact:

Re: Custom framework: copy&paste and auto id behavior

Post by Patrik »

Hi Radu,

for 1. I will experiment witrh the callbacks you suggested. This should solve the problem...

For 2&3: Indeed. Both, the rendering and the id generation, is working when selecting the content in the author view. So that's already a workaround. However, it is much easier to precisely select an element in the outline tree - that's why we always did it this way...

Thanks and regards,

Patrik
Radu
Posts: 9046
Joined: Fri Jul 09, 2004 5:18 pm

Re: Custom framework: copy&paste and auto id behavior

Post by Radu »

Hi Patrik,
However, it is much easier to precisely select an element in the outline tree - that's why we always did it this way...
The bug will be fixed in Oxygen 16. As a side note you can also triple click inside an element's text content to select it, or click it in the top-level breadcrumb path.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Patrik
Posts: 280
Joined: Thu Nov 28, 2013 9:32 am
Location: Hamburg/Germany
Contact:

Re: Custom framework: copy&paste and auto id behavior

Post by Patrik »

Hi Radu,

Thanks for the tip - this indeed is very comfortable.

Patrik
Patrik
Posts: 280
Joined: Thu Nov 28, 2013 9:32 am
Location: Hamburg/Germany
Contact:

Re: Custom framework: copy&paste and auto id behavior

Post by Patrik »

Hi Radu,

I just implemented the recreation for @id on new documents within AuthorExtensionStateListener.activated simply by going recursively through all elements and set all existing id-attributes. This works fine and looks good in author mode. However, when switching to text mode the ids are not changed. Is there any method I need to call to re-synchronize the author-document with the text-document?

Thanks and regards,

Patrik
Radu
Posts: 9046
Joined: Fri Jul 09, 2004 5:18 pm

Re: Custom framework: copy&paste and auto id behavior

Post by Radu »

Hi Patrik,

Let me see if I understand.
So you open the XML document and it opens in the Author editing mode. This triggers your extensions listener which sets IDs where necessary. These IDs should be set using the AuthorDocumentController.setAttribute(String, AttrValue, AuthorElement) API and not by directly setting attributes on each node. The API is necessary because it creates undoable edits for each set attribute and also marks the document as modified.
Then you switch to the Text mode and although the extension has set the attributes in the Author mode the Text mode does not contain the changes?

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Patrik
Posts: 280
Joined: Thu Nov 28, 2013 9:32 am
Location: Hamburg/Germany
Contact:

Re: Custom framework: copy&paste and auto id behavior

Post by Patrik »

Hi Radu,

I used AuthorElement.setAttribute(String, AttrValue) rather than AuthorDocumentController.setAttribute(String, AttrValue, AuthorElement). Making the changes undoable and marking the document as modified is not necessary, however, using the document controller it's working now.

Thanks again

Patrik
Radu
Posts: 9046
Joined: Fri Jul 09, 2004 5:18 pm

Re: Custom framework: copy&paste and auto id behavior

Post by Radu »

Hi Patrik,

Great, you should probably also call ro.sync.ecss.extensions.api.AuthorDocumentController.beginCompoundEdit() before making the first change and ro.sync.ecss.extensions.api.AuthorDocumentController.endCompoundEdit() after the last attribute change has been made in order to signal to Oxygen that this multiple change of attributes should be interpreted as one compound undoable edit (user presses Undo once and all attribute set changes are reverted).

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Radu
Posts: 9046
Joined: Fri Jul 09, 2004 5:18 pm

Re: Custom framework: copy&paste and auto id behavior

Post by Radu »

Hi Patrik,

Oxygen 16.0 also has a fix for the issue in which copy/pasting from the Outline did not preserve the default attribute values for XML documents with associated XML Schema grammars.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Post Reply