URL chooser for a custom action

Having trouble deploying Oxygen XML Web Author? Got a bug to report? Post it all here.
NicoAMP
Posts: 97
Joined: Tue Mar 06, 2018 2:07 pm
Contact:

URL chooser for a custom action

Post by NicoAMP »

Hi,

I would like to add a custom action to add a mapref in a ditamap.

So I add this code, but I don't know how to invoke an "URL chooser" to get get link to .ditamap and use the result with ro.sync.ecss.extensions.commons.operations.IFragmentOperation (see "var url = ????").

Code: Select all

    MaprefAction = function(editor) {
      this.editor = editor;
    };
        
    MaprefAction.prototype.getDisplayName = function() {
      return 'Insert a mapref element';
    };
    
    // The actual action execution.
    MaprefAction.prototype.actionPerformed = function(callback) {
      var url = ????
      
      if (url) {
        this.editor.getActionsManager().invokeOperation(
          'ro.sync.ecss.extensions.commons.operations.IFragmentOperation', {
            fragment: '<' + 'mapref href="' + url + '"/>'
          }, callback);
      } else {
        callback && callback();
      }
    };
And just another thing, I put framework.js in a folder shared by 2 frameworks (one for dita topic and another for ditamap).
This file is recognized only by "dita topic" framework (I can see custom actions in toolbar) but not by "ditamap" framework. Do you know why ?

Thanks a lot for your help.
Nicolas Delobel
AmeXio
nicolas.delobel at group.amexio.net
cristi_talau
Posts: 496
Joined: Thu Sep 04, 2014 4:22 pm

Re: URL chooser for a custom action

Post by cristi_talau »

Hello,

First of all I noticed that IFragmentOperation is not the name of the builtin operation. I expect that it is a custom operation that you implemented yourself.

Regarding the URL chooser, the simplest way is to use an ${ask} variable with type relative_url [1]. In this case, you do not need any JS code. Just configure the action in the Document Type Configuration Dialog box in an Oxygen XML Editor application.

Alternatively, you can use workspace.getUrlChooser() from the JS code which returns a sync.api.UrlChooser [2]. I was surprised that it is not documented as API - it will be in the next version.

Best,
Cristian

[1] https://www.oxygenxml.com/doc/versions/ ... tml?hl=ask
[2] https://www.oxygenxml.com/maven/com/oxy ... ooser.html
NicoAMP
Posts: 97
Joined: Tue Mar 06, 2018 2:07 pm
Contact:

Re: URL chooser for a custom action

Post by NicoAMP »

Hi Cristian,

IFragmentOperation is a typo error, I use a classic InsertFragmentOperation.

I follow your advice using an action in Document Type Configuration Dialog box, with the following fragment:

Code: Select all

<mapref href="${ask('DITA Map', relative_url, '')}"/>
Thanks for your help.

Regards,
Nicolas
Nicolas Delobel
AmeXio
nicolas.delobel at group.amexio.net
NicoAMP
Posts: 97
Joined: Tue Mar 06, 2018 2:07 pm
Contact:

Re: URL chooser for a custom action

Post by NicoAMP »

Hi Cristian,

Is it possible to get a relative URL using sync.api.UrlChooser?
Or resolve the url obtained against the current document path?

Thanks.
Regards,
Nicolas
Nicolas Delobel
AmeXio
nicolas.delobel at group.amexio.net
cosminef
Site Admin
Posts: 84
Joined: Wed Aug 30, 2023 2:33 pm

Re: URL chooser for a custom action

Post by cosminef »

Hello,

For your use case, you can use makeRelative(base, url) API [1]

[1] https://www.oxygenxml.com/maven/com/oxy ... ve__anchor

Best Regards,
Cosmin
Cosmin Eftenie
www.oxygenxml.com
NicoAMP
Posts: 97
Joined: Tue Mar 06, 2018 2:07 pm
Contact:

Re: URL chooser for a custom action

Post by NicoAMP »

Hello Cosmin,

I resoled the url using the current editing document and it works fine:

Code: Select all

let currentUrl = workspace.currentEditor.getUrl();
let relativeUrl = workspace.makeRelative(currentUrl,url);
Thanks for your help.

Regards,
Nicolas
Nicolas Delobel
AmeXio
nicolas.delobel at group.amexio.net
cosminef
Site Admin
Posts: 84
Joined: Wed Aug 30, 2023 2:33 pm

Re: URL chooser for a custom action

Post by cosminef »

Hello,
We're delighted to hear that! We're at your disposal in case you have any further questions
Best,
Cosmin
Cosmin Eftenie
www.oxygenxml.com
Post Reply