How to modify autocomplete code templates?

Having trouble installing Oxygen? Got a bug to report? Post it all here.
Frank Ralf
Posts: 482
Joined: Thu Jan 23, 2014 2:29 pm
Location: Hamburg
Contact:

How to modify autocomplete code templates?

Post by Frank Ralf »

Hi,

When typing <dl> in Text mode, oXygen will autocomplete this to

Code: Select all


<dl>
<dlentry>
<dt></dt>
<dd></dd>
</dlentry>
</dl>
Where can I modify or override these code snippets? Are Code templates the correct place? Or do I have to look somewhere else in the framework files like when overriding the Smart Paste function?

TIA
Frank
Frank Ralf
parson AG
www.parson-europe.com
Radu
Posts: 9449
Joined: Fri Jul 09, 2004 5:18 pm

Re: How to modify autocomplete code templates?

Post by Radu »

Hi Frank,

Oxygen does not use code templates for this. Oxygen looks at the DTD/schema associated to the XML and the DTD specifies a content model for each element. For example for <dl> the DTD says that it requires a child element called <dlentry> being inserted and <dlentry> in its turn requires a <dt>, and so on. So Oxygen tries as much as possible to insert a valid XML fragment based on the DTD.
In the Oxygen Preferences->"Editor / Content Completion" page there are three checkboxes called Add element content, Add optional content and Add first choice particle which are the only settings we have in this regard.

If you define a new code template for inserting a dl, when working in the Text editing mode you will be able to invoke Ctrl-Shift-Space to show the dialog which presents available code templates and to insert the code template instead of relying on our content completion window.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Frank Ralf
Posts: 482
Joined: Thu Jan 23, 2014 2:29 pm
Location: Hamburg
Contact:

Re: How to modify autocomplete code templates?

Post by Frank Ralf »

Hi Radu,

Thanks for the quick reply and the thorough explanation. I think I'll give the code templates a try ;-)

Frank
Frank Ralf
parson AG
www.parson-europe.com
Frank Ralf
Posts: 482
Joined: Thu Jan 23, 2014 2:29 pm
Location: Hamburg
Contact:

Re: How to modify autocomplete code templates?

Post by Frank Ralf »

Hi,

Content Completion
For another project, I face a similar problem: When inserting a <section>, the section should also automatically get a <title> (which is not required by the schema). The default "section" Author Action does this already (but is only triggered via a menu or a toolbar). The Content Completion mechanism only inserts a plain section without a title. Therefore I've added the default "section" Author Action to the Content Completion mechanism (see Configure Content Completion for a Framework).

This does work as promised, with only a minor flaw: The added option is only shown at valid positions, whereas with the default Content Completion options I can choose them even at an invalid position and oXygen will then suggest inserting them at one of the nearest valid positions. I suppose there's nothing I can do about this?

Kind regards,
Frank
Frank Ralf
parson AG
www.parson-europe.com
Radu
Posts: 9449
Joined: Fri Jul 09, 2004 5:18 pm

Re: How to modify autocomplete code templates?

Post by Radu »

Hi Frank,

I'm afraid I don't have a solution for this. Other than using a particular DITA specialization which makes the title required :)

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Frank Ralf
Posts: 482
Joined: Thu Jan 23, 2014 2:29 pm
Location: Hamburg
Contact:

Re: How to modify autocomplete code templates?

Post by Frank Ralf »

Hi Radu,

Thanks for your quick reply. As we have also use cases where we use sections without a title, making the title a required element is unfortunately not an option for this project.

But come to think of it. How does oXygen know whether an Author Action is valid at a given position? Usually, this is done evaluating an XPath expression. If this is also true for Content Completion, I could create my own modified version of the "section" action.

Kind regards,
Frank
Frank Ralf
parson AG
www.parson-europe.com
Radu
Posts: 9449
Joined: Fri Jul 09, 2004 5:18 pm

Re: How to modify autocomplete code templates?

Post by Radu »

Or of course, using our AuthorDocumentController.setDocumentFilter(AuthorDocumentFilter) Java API to detect when an empy section is inserted and insert it with a title instead.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Frank Ralf
Posts: 482
Joined: Thu Jan 23, 2014 2:29 pm
Location: Hamburg
Contact:

Re: How to modify autocomplete code templates?

Post by Frank Ralf »

Thanks for this additional pointer, Radu.
Frank Ralf
parson AG
www.parson-europe.com
Radu
Posts: 9449
Joined: Fri Jul 09, 2004 5:18 pm

Re: How to modify autocomplete code templates?

Post by Radu »

Hi Frank,

About this remark:
How does oXygen know whether an Author Action is valid at a given position? Usually, this is done evaluating an XPath expression. If this is also true for Content Completion, I could create my own modified version of the "section" action.
Right, Oxygen checks if at least one XPath activation mode is evaluated as true before adding the action to the content completion window.
Indeed, I guess you could have an action which would have various XPath activation modes. The first XPath mode would be for the case in which the <section> element is actually valid at the caret offset. And you could use our XPath function extension to do this:

http://www.oxygenxml.com/doc/versions/1 ... ement.html

The other activation mode could (for example) have an XPath like: true() so the action would always be enabled. But it would need to find a valid place in the document where to insert the section by setting a proper value for the insertLocation parameter of the InsertFragmentOperation (if you are using this operation).

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Frank Ralf
Posts: 482
Joined: Thu Jan 23, 2014 2:29 pm
Location: Hamburg
Contact:

Re: How to modify autocomplete code templates?

Post by Frank Ralf »

Hi Radu,

Thanks again for this detailed information. I will give it a try when tampering with the Author Actions next time ;-)

Kind regards,
Frank
Frank Ralf
parson AG
www.parson-europe.com
Frank Ralf
Posts: 482
Joined: Thu Jan 23, 2014 2:29 pm
Location: Hamburg
Contact:

Re: How to modify autocomplete code templates?

Post by Frank Ralf »

Hi,

I've successfully added the default Author Action "section" to Content Completion; this action already inserts a <title> element. This works as expected when using Content Completion in Author mode.

However, when I also add the action to the Element View, my new item "section (with title)" also shows up at invalid places in the Element View. When actually inserting this item, oXygen moves it to the next valid place in the document.

It looks as if the context validation XPath of the Author Action isn't evaluated correctly for the Element View. Is this the desired behavior, some misconfiguration on my side or a bug?

Kind regards,
Frank
Frank Ralf
parson AG
www.parson-europe.com
Radu
Posts: 9449
Joined: Fri Jul 09, 2004 5:18 pm

Re: How to modify autocomplete code templates?

Post by Radu »

Hi Frank,

From what I checked, if an Author action has xpath activation modes and at a certain offset all xpath activation modes evaluate to false() the action is not shown both for the content completion windows and for the Elements view.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Frank Ralf
Posts: 482
Joined: Thu Jan 23, 2014 2:29 pm
Location: Hamburg
Contact:

Re: How to modify autocomplete code templates?

Post by Frank Ralf »

Hi Radu,

Thanks for your quick reply. That's what I would expect. I will double-check and report back.

Kind regards,
Frank
Frank Ralf
parson AG
www.parson-europe.com
mknebel
Posts: 2
Joined: Tue Mar 03, 2015 10:41 pm
Location: Germany
Contact:

Re: How to modify autocomplete code templates?

Post by mknebel »

Hi,

We have now fixed the content completion action for the section element, but I have a another question:

Why does the auto completion (based on the schema/DTD) only work if you insert an element via the inplace menu in the Author view, but not the Elements view?

Our client used to work with FrameMaker, which has something similar to the Elements view. They very much would like to use auto completion with it, too. Is there any way to fix this without having to define additional content completion actions?

best regards
Marion
Marion Knebel
parson AG
www.parson-europe.com
Radu
Posts: 9449
Joined: Fri Jul 09, 2004 5:18 pm

Re: How to modify autocomplete code templates?

Post by Radu »

Hi Marion,
Why does the auto completion (based on the schema/DTD) only work if you insert an element via the inplace menu in the Author view, but not the Elements view?
I do not understand what you mean, could you give me a small example?

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