nsIFileView 编辑

toolkit/components/filepicker/public/nsIFileView.idlScriptable 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

AttributeTypeDescription
reverseSortbooleanIf true results will be sorted in ascending order. Read only.
selectedFilesnsIArrayAn nsIArray of selected files, which contains nsIArray instances. Read only.
showHiddenFilesbooleanIf true hidden files will be shown.
showOnlyDirectoriesbooleanIf true only directory entries will be returned.
sortTypeshortThe current sort type in effect. Read only.

Constants

ConstantValueDescription
sortName0Sort by file name.
sortSize1Sort by file size.
sortDate2Sort 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:52 次

字数:7450

最后编辑:7 年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文