Page 1 of 1

Creating shortcut for note tag with para

Posted: Thu Oct 31, 2013 2:40 pm
by Ioana
I'm trying to add a new DocBook action in Options > Preferences > Document Type Associations and I managed to do it halfway, but I got stuck. What I would like is to create a "note" shortcut, which would enclose the selected text like so:

Code: Select all

<note><para>My text</para></note>
. I figured out how to enclose the text in

Code: Select all

<note> </note>
tags, but I don't know how to get oXygen to add that second level of

Code: Select all

<para> </para>
. Is this possible? Thanks in advance!

Re: Creating shortcut for note tag with para

Posted: Thu Oct 31, 2013 3:06 pm
by Radu
Hi Ioana,

So in the Preferences->Document Type Association options page you edited the Docbook (4 or 5) document type, right?
Then in the Author->Actions tab you probably created a new action and then customized it in the dialog:

http://www.oxygenxml.com/doc/ug-oxygen/ ... ction.html

For this action you should choose an operation of type ro.sync.ecss.extensions.commons.operations.SurroundWithFragmentOperation and as the fragment of the operation you should set:

Code: Select all

<note><para/></note>
The surrounded text will be set in the first leaf of the inserted XML fragment.

Another alternative to defining an action (if you just want this for personal use) is to create a new code template in the Editor / Templates / Code Templates Preferences page. A code template can use editor variables like ${selection} and it appears in the content completion window when pressing ENTER in the Author mode.

Regards,
Radu

Re: Creating shortcut for note tag with para

Posted: Thu Oct 31, 2013 4:35 pm
by Ioana
Thanks Radu! I was using SurroundWithElementOperation, not SurroundWithFragmentOperation. I used the correct operation and now it's working.

Two additional questions:
1. When I use the new action, the following is inserted:

Code: Select all

<note xmlns="">
Can I set this up so that xmlsn is not inserted, so that I get a simple <note>?

2. My text is already between <para> tags. Is it possible to delete these when I use the new action?
For example, I have:

Code: Select all

<para>This should be a note.</para>
When I use my new actions, I get:

Code: Select all

<para><note><para>This should be a note.</para></note></para>
Is there a way to get rid of that initial <para> tag, so that the result would be

Code: Select all

<note><para>This should be a note.</para></note>

Re: Creating shortcut for note tag with para

Posted: Thu Oct 31, 2013 5:10 pm
by Radu
Hi Ioana,

Please see some comments below:
1. When I use the new action, the following is inserted:

Code: Select all


    <note xmlns="">
Can I set this up so that xmlsn is not inserted, so that I get a simple <note>?
So you are using Docbook 5. The XML fragment which you specify in the action mode should be like:

Code: Select all

<note xmlns="http://docbook.org/ns/docbook"><para/></note>
The namespace attribute will be stripped by Oxygen when the fragment is inserted because it is already declared in the XML document. So the XML fragment needs to be self contained, to specify all namespace declarations on it.
2. My text is already between <para> tags. Is it possible to delete these when I use the new action?
An action can have several action modes.
Each action mode defines an XPath expression in the context of which the mode will be called.
So in your case the action could have two action modes:

1) The first action mode would have the activation XPath ancestor-or-self::*:para and would call the SurroundWithFragmentOperation with the XML:

Code: Select all

<note xmlns="http://docbook.org/ns/docbook"/>
This mode would get triggered when the caret is already inside a paragraph.

2) The second mode would be a fallback, it could have the XPath true() and would call the SurroundWithFragmentOperation with the XML:

Code: Select all

<note xmlns="http://docbook.org/ns/docbook"><para/></note>
Regards,
Radu

Re: Creating shortcut for note tag with para

Posted: Thu Oct 31, 2013 6:59 pm
by Ioana
1. Yes, DocBook5. I added the namespace declaration and now it's working fine.

2. I think I'm doing something wrong here. I defined the two action modes and tried to apply them in two ways, but I'm not getting the right results.
a. If I select the paragraph (with the mouse) and use my shortcut. I get the note inside of the paragraph:

Code: Select all

<para><note>Note text</note></para>
b. If I select the paragraph by clicking on "para" in the breadcrumbs and use my shortcut, I get two paragraphs:

Code: Select all

<note><para><para>Note text</para></para></note>
On the bright side, I realized that if I define the action without an activation XPath, with a <simple note> tag, and I select the paragraph by clicking the breadcrumb, it does exactly what I want :)

Re: Creating shortcut for note tag with para

Posted: Fri Nov 01, 2013 11:31 am
by Radu
Hi Ioana,

Please see some comments below:
a. If I select the paragraph (with the mouse) and use my shortcut. I get the note inside of the paragraph
This is because you are only selecting the text inside the paragraph and not the entire paragraph.
On the toolbar there is a drop-down button allowing you to configure if tags are visible or not in the editor. You can switch to "Full Tags" to see what exactly is selected in the editor:

http://www.oxygenxml.com/doc/ug-oxygen/ ... arkup.html

You can also click an element's tag to select it completely, the same thing as clicking the element in the Breadcrumb or in the Outline view. Or you can triple click inside the paragraph to select it completely.
b. If I select the paragraph by clicking on "para" in the breadcrumbs and use my shortcut, I get two paragraphs:
Indeed clicking in the breadcrumb allows you to select completely an element.
The problem when an element is fully selected is that the caret is actually after the element (after the element's end tag) and the XPath activation expression looks at the caret position.
We added a special XPath function in Oxygen 15.1 to address such cases:

http://www.oxygenxml.com/doc/ug-oxygen/ ... ement.html

So for the case in which an entire paragraph is selected and if you are using Oxygen 15.1, the XPath activation expression would be:

Code: Select all

oxy:current-selected-element()[self::*:para]
and it would call a surround operation with the XML fragment:

Code: Select all

<note xmlns="http://docbook.org/ns/docbook"/>
Regards,
Radu

Re: Creating shortcut for note tag with para

Posted: Fri Nov 01, 2013 4:25 pm
by Ioana
Thanks for the detailed explanations! I'll update to 15.1 and update my action.