Page 1 of 1

How to modify autocomplete code templates?

Posted: Tue Aug 12, 2014 12:01 pm
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

Re: How to modify autocomplete code templates?

Posted: Tue Aug 12, 2014 12:23 pm
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

Re: How to modify autocomplete code templates?

Posted: Tue Aug 12, 2014 12:29 pm
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

Re: How to modify autocomplete code templates?

Posted: Mon Sep 21, 2015 2:40 pm
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

Re: How to modify autocomplete code templates?

Posted: Mon Sep 21, 2015 3:23 pm
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

Re: How to modify autocomplete code templates?

Posted: Mon Sep 21, 2015 3:40 pm
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

Re: How to modify autocomplete code templates?

Posted: Mon Sep 21, 2015 3:41 pm
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

Re: How to modify autocomplete code templates?

Posted: Mon Sep 21, 2015 3:49 pm
by Frank Ralf
Thanks for this additional pointer, Radu.

Re: How to modify autocomplete code templates?

Posted: Mon Sep 21, 2015 3:53 pm
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

Re: How to modify autocomplete code templates?

Posted: Mon Sep 21, 2015 4:25 pm
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

Re: How to modify autocomplete code templates?

Posted: Thu Oct 01, 2015 2:52 pm
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

Re: How to modify autocomplete code templates?

Posted: Thu Oct 01, 2015 4:00 pm
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

Re: How to modify autocomplete code templates?

Posted: Thu Oct 01, 2015 4:36 pm
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

Re: How to modify autocomplete code templates?

Posted: Fri Oct 02, 2015 3:48 pm
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

Re: How to modify autocomplete code templates?

Posted: Fri Oct 02, 2015 3:54 pm
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