nsIFileView 编辑
toolkit/components/filepicker/public/nsIFileView.idl
Scriptable This interface displays a list of files in a treebox. Inherits from: nsISupports
Last changed in Gecko 1.7 Note: nsIFileView is Linux-only interface. It's not included in Windows or Mac builds. Note: A quirk of the nsIFileView is that it requires an appropriate treecols section in the tree tag, by default fileview will return the file size in the column. If the treecol id is "FilenameColumn" fileview will return the file name, if the id is "LastModifiedColumn" it will return the date of last modification. Currently no other file stats are implemented.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);
Method overview
void setDirectory(in nsIFile directory); |
void setFilter(in AString filterString); |
void sort(in short sortType, in boolean reverseSort); |
Attributes
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. |
Constants
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. |
Methods
setDirectory()
Set the directory to be browsed.
void setDirectory( in nsIFile directory );
Parameters
directory
- The directory to be browsed.
setFilter()
Set the filter to be applied to the file list, for example "*.jpg" would only return jpg files.
void setFilter( in AString filterString );
Parameters
filterString
- The filter to be applied to the file list.
sort()
Set the method used for sorting.
void sort( in short sortType, in boolean reverseSort );
Parameters
sortType
- One of the sort* constants.
reverseSort
true,
results will be sorted in ascending order.
Example
<?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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论