nsISupports
Last changed in Gecko 1.7 The nsIFileView
provides a configuration interface to @mozilla.org/filepicker/fileview;1 , which also implements nsITreeView
so that it can be passed as a tree view.
Implemented by: @mozilla.org/filepicker/fileview;1
. To create an instance, use:
var fileView = Components.classes["@mozilla.org/filepicker/fileview;1"] .createInstance(Components.interfaces.nsIFileView);
void setDirectory(in nsIFile directory); |
void setFilter(in AString filterString); |
void sort(in short sortType, in boolean reverseSort); |
Attribute | Type | Description |
reverseSort | boolean | If true results will be sorted in ascending order. Read only. |
selectedFiles |
| An nsIArray of selected files, which contains nsIArray instances. Read only. |
showHiddenFiles | boolean | If true hidden files will be shown. |
showOnlyDirectories | boolean | If true only directory entries will be returned. |
sortType | short | The current sort type in effect. Read only. |
Constant | Value | Description |
sortName | 0 | Sort by file name. |
sortSize | 1 | Sort by file size. |
sortDate | 2 | Sort by the date of the last modification. |
Set the directory to be browsed.
void setDirectory( in nsIFile directory );
directory
Set the filter to be applied to the file list, for example "*.jpg" would only return jpg files.
void setFilter( in AString filterString );
filterString
Set the method used for sorting.
void sort( in short sortType, in boolean reverseSort );
sortType
reverseSort
true,
results will be sorted in ascending order.<?xml version="1.0" ?> <?xml-stylesheet href="chrome://global/skin/" type="text/css" ?> <window id="test" title="Test" width="640" height="480" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> <tree flex="1" id="ftree"> <treecols> <-- The default Column type is size unless an appropriate id is passed, nsIFileView relies on the treecols section --> <treecol id="FilenameColumn" label="Name" flex="1" primary="true"/> <treecol id="LastModifiedColumn" label="Date" flex="1"/> <treecol id="Size" label="Size" flex="1"/> </treecols> <treechildren/> </tree> <script> var DIR="/home/"; //The directory to be opened var ftree = document.getElementById("ftree"); //The XUL tree element var lfile = Components.classes["@mozilla.org/file/local;1"] .createInstance(Components.interfaces.nsILocalFile); lfile.initWithPath(DIR); // Open the directory var fview = Components.classes["@mozilla.org/filepicker/fileview;1"] .createInstance(Components.interfaces.nsIFileView); //Create an instance of the component tview = fview.QueryInterface(Components.interfaces.nsITreeView); //Get the nsITreeView interface fview.setDirectory(lfile.QueryInterface(Components.interfaces.nsIFile)); //Set the directory fview.setFilter("*"); //Add an appropriate file filter fview.sort(fview.sortName, false); //Set the sort type ftree.view = tview; //Set the view on the tree object </script> </window>