Home
Categories
Dictionary
Glossary
Download
Project Details
Changes Log
What Links Here
FAQ
License

XUL Script helper



A global helper is available in all the XUL scripts.

The script helper is available through the helper field in your script.

For example to get the current widget in a Groovy script:
      public void clicked() {
         XULWidget widget = helper.getCurrentWidget();
      }

Helper API

By default the helper has the following methods:

public class ScriptHelper


Modifier and Type Method and Description
Object evalScript(String method, Object... args)
Evaluate a script method
Object evalScript(String method)
Evaluate a script method without arguments
ScriptContext getContext()
Return the script context
XULDocument getCurrentDocument()
Return the current document
XULWidget getCurrentWidget()
Return the current widget
String getText(File file)
Return the text associated with a text File
boolean setText(File file, String text)
Set the text for a text File

Evaluating script methods

The evalScript(String method, Object... args) andevalScript(String method) methods will evaluate a method or function for any script referenced in the same XUL document as the script (for embedded scripts of external scripts).

For example, the following XUL file is valid:
      <window id="Hello" title="Hello" orient="horizontal" width="250" height="100"  
      xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">        
          <script> 
      function clicked(){
      var value = compute();
        alert('Hello World...' + value);
      }
          </script> 
          <script> 
      function compute(){
        return 10;
      }
          </script>                   
          <button label="Push Me!" oncommand="clicked()" />
      </window>

Returning the current document or widget

The getCurrentDocument() and getCurrentWidget() will return the XUL document or widget from which originates the last event. It will return null before any event have been triggered.

For example to get the current widget in a Groovy script:
      public void clicked() {
         XULWidget widget = helper.getCurrentWidget();
      }

See also


Categories: builtin-applis

Copyright 2017-2020 Dassault Aviation. All Rights Reserved. Documentation and source under the LGPL v3 licence