Customize insertimage macro

Bruno.Ballarin
Posts: 25
Joined: Thu Aug 07, 2014 3:40 pm

Customize insertimage macro

Post by Bruno.Ballarin » Wed Oct 15, 2014 7:54 pm

Using DITA framework, I have started creating custom actions and brought them into the toolbar with some buttons.

Right now I would appreciate to get help to customize the ${i18n(insert.image)} default Action so that it "format" the image in addition to just bringing it.

in other words I would like the insert.image action to insert something looking like this in my text view:

Code: Select all


<fig id="ID010-195" frame="all">
<title>my_image_title</title>
<image href="my_image.svg" placement="break" width="14.25cm" align="center"/>
</fig>
("my_image_title" can be a default text that I can edit later in the author view)

rather than just this:

Code: Select all


<image href="my_image.svg"/>

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

Re: Customize insertimage macro

Post by Radu » Thu Oct 16, 2014 8:53 am

Hi Bruno,

So after the user would click the custom action to insert an image reference, he would need to be asked several questions like:

1) If to insert a figure or a simple image reference. If a figure is inserted, then the user would provide a Figure ID
2) Image href
3) Image placement
4) Image width
5) Image align

Probably it would be the best for you to construct your own ro.sync.ecss.extensions.api.AuthorOperation Java implementatation which shows a Swing-based dialog to the user asking him for all these extra settings:

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

An alternative without writing Java code for this would be to use an existing ro.sync.ecss.extensions.commons.operations.InsertFragmentOperation operation to insert an XML fragment which makes use of Oxygen editor variables like:

Code: Select all

<fig id="${ask('Figure ID?')}" frame="${ask('Frame?')}">
<title>${ask('Title?')}</title>
<image href="${ask('Href?', relative_url)}" placement="${ask('Placement?')}" width="${ask('Width?')}" align="${ask('Align?')}"/>
</fig>
Oxygen will ask the user separately to insert a value for each of those attributes. But this may be annoying to the end user + the end user might not want to provide an attribute at all for a certain element.

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

Bruno.Ballarin
Posts: 25
Joined: Thu Aug 07, 2014 3:40 pm

Re: Customize insertimage macro

Post by Bruno.Ballarin » Wed Oct 22, 2014 10:55 am

Hi Radu,

solution 2 without writing java code is working perfectly for me.

I customized it by replacing most of the prompts by constants (our documentation formalism imposes for instance the presence of a figure frame, 14.25cm width image, etc. So in the end, the end user is only asked for the title and the Href (that can be left empty and populated later by the way).

I also learnt how to condition the availability of this button based on the cursor location using the xpath ecpression:

Code: Select all

oxy:allows-child-element("fig")
I also created a button to insert an image in an existing figure frame. Just one refinment I don't know how to do yet would be that this insert image button works as a "replace" image if I invoke it while the cursor is selecting an existing image in the frame. I would need some kind of "delete_current_fragment" type of operation.

Cheers,

Bruno

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

Re: Customize insertimage macro

Post by Radu » Wed Oct 22, 2014 11:04 am

Hi Bruno,

I'm glad this works for you.

About this remark:
I also created a button to insert an image in an existing figure frame. Just one refinement I don't know how to do yet would be that this insert image button works as a "replace" image if I invoke it while the cursor is selecting an existing image in the frame. I would need some kind of "delete_current_fragment" type of operation.
We'll look into adding another parameter to the "InsertFragmentOperation" which would control deleting the current selection before the fragment is inserted.

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

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

Re: Customize insertimage macro

Post by Radu » Mon Jun 22, 2015 4:25 pm

Hi,

Just to update this thread, Oxygen 17 has a new and improved Insert Image which allows you to set image sizes, align and alternate text.

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

sorin_carbunaru
Posts: 326
Joined: Mon May 09, 2016 9:37 am

Re: Customize insertimage macro

Post by sorin_carbunaru » Wed Oct 12, 2016 11:49 am

Hello,

I would like to bring to your attention the fact that oXygen also provides the ro.sync.ecss.extensions.commons.operations.InsertOrReplaceFragmentOperation API that can be used for replacing a fragment with another one. Its insertPosition argument has a Replace possible value that can be used for this purpose.

Best wishes,
Sorin Carbunaru
oXygen XML

Post Reply