Page 1 of 1

get Value of Custom Editor Variable in JSOperation

Posted: Wed Jun 07, 2023 5:51 pm
by larsS
Hello,
I added a custom Editor variable and want to use it in an JSOperation Action. I try to understand the solution of the wsAccess github. But how far I understand, because I am not a Java programmer, with

Code: Select all

addCustomEditorVariablesResolver
I add a custom editor variable.
I searched and searched the total API for a getCustomEditorVariable(string) method or function.
Please help.
Thank you very much.
Greets Lars

Re: get Value of Custom Editor Variable in JSOperation

Posted: Wed Jun 07, 2023 6:39 pm
by larsS
I did find the solution.

Code: Select all

  var utilAccess = authorAccess.getUtilAccess();
  var myVar = utilAccess.expandEditorVariables("${myVar}", null);
  Packages.javax.swing.JOptionPane.showMessageDialog(parentFrame, myVar);
  
Interesting that the name is 'expand'.

Re: get Value of Custom Editor Variable in JSOperation

Posted: Thu Jun 08, 2023 6:09 am
by Radu
Hi,

Thanks for posting the solution.
I assume you added the editor variables resolver from a Javascript-based Oxygen plugin, right? Like in this sample:
https://github.com/oxygenxml/wsaccess-j ... sAccess.js
Yes, the way in which you expand the editor variable using our API in the Javascript operation looks fine to me.
About this remark:
Interesting that the name is 'expand'.
Were you expecting another name for the method? Maybe "resolve"? I think you may be right but as this is API we will probably leave the name of the method as it is :(

Regards,
Radu

Re: get Value of Custom Editor Variable in JSOperation

Posted: Thu Jun 08, 2023 12:31 pm
by larsS
Hello Radu,
I don't want to be rude. Sorry for the maybe not so kind words. English is not my native language and as I said, I am not a Java developer.
As I understand it, the resolver is more of a setter for resolving an object/class that is passed to the method and adds a new editor variable to the "scope".
I didn't understand it to do this permanently or only in the current session, like a local store in browsers. This would be my only future question. ;)
As extender I interpret a method that interpolate or enlarge an existing scope and does not get the value of a variable.
But if the functionality or the naming is according to Java conventions then it's probably because extend means something like unfold or expand and this I do not or did not know before.
Thank you very much for your time to answer.

Re: get Value of Custom Editor Variable in JSOperation

Posted: Mon Jun 12, 2023 7:42 am
by Radu
Hi,
Please see some answers below:
I don't want to be rude. Sorry for the maybe not so kind words.
There is no rudeness in discussing our APIs, we are happy to receive feedback.
English is not my native language
Neither for us ;)
and as I said, I am not a Java developer.
Oxygen is a Java application, our API is Java based and most plugins are implemented in Java, so most of plugin developers would use Java to implement Oxygen plugins, but indeed we have this possibility to use Javascript to implement an Oxygen plugin.
As I understand it, the resolver is more of a setter for resolving an object/class that is passed to the method and adds a new editor variable to the "scope".
Basically from Javascript when someone adds an editor variables resolver, this API method will be called from our Java API:
https://www.oxygenxml.com/InstData/Edit ... sResolver-
I didn't understand it to do this permanently or only in the current session, like a local store in browsers. This would be my only future question. ;)
An Oxygen plugin is instantiated when Oxygen starts up and is active while Oxygen is running. The plugin runs in the entire application context. So if I add from a plugin an EditorVariablesResolver, if you call from any opened document the "utilAccess.expandEditorVariables" API, the resolver will be used when expanding editor variables..
As extender I interpret a method that interpolate or enlarge an existing scope and does not get the value of a variable.
But if the functionality or the naming is according to Java conventions then it's probably because extend means something like unfold or expand and this I do not or did not know before.
The method name is "expandEditorVariables", I think "expand" is appropriate for it as if takes a string containing one or multiple editor variables and it replaces the editor variables with their values.
By default Oxygen knows how to expand these editor variables:
https://www.oxygenxml.com/doc/versions/ ... ables.html

Regards,
Radu