Page 1 of 1

URL chooser for a custom action

Posted: Tue Apr 07, 2020 5:51 pm
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.

Re: URL chooser for a custom action

Posted: Tue Apr 07, 2020 6:17 pm
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

Re: URL chooser for a custom action

Posted: Wed Apr 08, 2020 10:22 am
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

Re: URL chooser for a custom action

Posted: Tue Nov 07, 2023 6:26 pm
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

Re: URL chooser for a custom action

Posted: Wed Nov 08, 2023 12:21 pm
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

Re: URL chooser for a custom action

Posted: Fri Nov 10, 2023 3:35 pm
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

Re: URL chooser for a custom action

Posted: Fri Nov 10, 2023 5:00 pm
by cosminef
Hello,
We're delighted to hear that! We're at your disposal in case you have any further questions
Best,
Cosmin