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

XUL file picker



The FilePicker class is available in all scripts to create a file picker.

FilePicker API

The FilePicker has the following interface:

public class FilePicker


Modifier and Type Method and Description
boolean appendFilters(String description, String extensions)
Add a file filter to the FilePicker
File getFile()
Return the selected File
void init(Object parent, String mode)
set the mode of the FilePicker, usable in all scripts, including XUL Javascript scripts. The parent can be a XULDocument or a XULWidget, or even be null
void init(XULWidget parent, String title, String mode)
Same method for non Javascript scripts
int show()
Show the FilePicker chooser an return the value

Initialization

The init(java.lang.Object, java.lang.String, java.lang.String) and init(org.xul.script.xul.model.XULWidget, java.lang.String, java.lang.String) methods allow to initialize the FilePicker.

The parent can be a XULDocument or a XULWidget, or even be null.

The String mode can be:
  • "openMode" to set the FilePicker in Open Mode
  • "saveMode" to set the FilePicker in Save Mode
For example (in XUL Javascript):
      var filepicker = new FilePicker();
      filepicker.init(document, "openMode");    

Append filters

To append a filter, you have to use the appendFilters(java.lang.String, java.lang.String) method.
  • The first parameter is the description of the filter (for example "XUL Files")
  • The first parameter is the specification of the filter (for example "*.xul; *.xml")
For example (in XUL Javascript):
      var filepicker = new FilePicker();
      filepicker.appendFilters("The XUL files", "*.xul");      
In XUL Groovy:
      FilePicker filepicker = new FilePicker();
      filepicker.appendFilters("The XUL files", "*.xul");      

Example

In XUL Javascript):
      <window title="FilePicker" width="400" height="400" 
              xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
         <script>
            function open() {
              var filepicker = new FilePicker();
              var parent = document.getElementById("open");
              filepicker.appendFilters("The XUL files", "*.xul");
              filepicker.init(parent, "Select File", "modeOpen");
              var ret = filepicker.show();
              if (ret == filepicker.returnOK) { 
                var text = helper.getText(filepicker.file);
                var textbox = document.getElementById("text");
                textbox.value = text;
              }
            }   
         </script>
         <menubar>      
            <menu label="File">
               <menupopup>
                  <menuitem id="open" label="Open" oncommand="open()"/>
               </menupopup>
            </menu>
         </menubar>        
         <textbox id="text" multiline="true" value=""  cols="30" rows="20"/>  
      </window>

Categories: builtin-applis

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