From a065e04d529da1d847b5062a12c46d916408bf32 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 21:46:22 -0500 Subject: update based on https://github.com/mdn/yari/issues/2028 --- .../reference/interface/nsifilepicker/index.html | 376 --------------------- 1 file changed, 376 deletions(-) delete mode 100644 files/zh-cn/mozilla/tech/xpcom/reference/interface/nsifilepicker/index.html (limited to 'files/zh-cn/mozilla/tech/xpcom/reference/interface/nsifilepicker/index.html') diff --git a/files/zh-cn/mozilla/tech/xpcom/reference/interface/nsifilepicker/index.html b/files/zh-cn/mozilla/tech/xpcom/reference/interface/nsifilepicker/index.html deleted file mode 100644 index 7122dcd1ef..0000000000 --- a/files/zh-cn/mozilla/tech/xpcom/reference/interface/nsifilepicker/index.html +++ /dev/null @@ -1,376 +0,0 @@ ---- -title: nsIFilePicker -slug: Mozilla/Tech/XPCOM/Reference/Interface/nsIFilePicker -tags: - - Filepicker - - 文件选取器 -translation_of: Mozilla/Tech/XPCOM/Reference/Interface/nsIFilePicker ---- -

-
widget/nsIFilePicker.idl脚本化
- - -文件选择器组件是通过显示标准的用户界面来让用户来选择文件和目录,以及选择目的地来命名和新建文件。 - - -
-继承于: nsISupports -最后修改于Gecko 17.0 (Firefox 17.0 / Thunderbird 17.0 / SeaMonkey 2.14)
-

- -

实现自: @mozilla.org/filepicker;1。要创建一个实例,使用以下代码:

- -
var filePicker = Components.classes["@mozilla.org/filepicker;1"]
-                 .createInstance(Components.interfaces.nsIFilePicker);
-
- -

方法概述

- - - - - - - - - - - - - - - - - - - -
void appendFilter(in AString title, in AString filter);
void appendFilters(in long filterMask);
void init(in nsIDOMWindow parent, in AString title, in short mode);
void open(in nsIFilePickerShownCallback aFilePickerShownCallback);
short show(); 已废弃 Gecko 17.0
- -

属性

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
属性类型说明
addToRecentDocs booleanIf true, the file is added to the operating system's "recent documents" list (if the operating system has one; nothing happens if there is no such concept on the user's platform). This attribute has no effect if private browsing mode is in effect.
defaultExtensionAStringThe extension for the type of files you want to work with. On some platforms, this is automatically appended to filenames the user enters, if required.  Specify it without a leading dot, for example "jpg".
defaultStringAStringThe filename, including extension, that should be suggested to the user as a default. This should be set this before calling open() or show(). -
Exceptions thrown
- -
-
NS_ERROR_FAILURE
-
If you try to read this attribute.
-
-
displayDirectorynsILocalFileThe directory that the file picker dialog should initially display. This should be set this before calling open() or show() to specify a starting point.
filensILocalFileThe currently selected file or directory. Read only.
filesnsISimpleEnumerator -

An enumerator of the currently selected files. Read only.

-
Note: Only works with modeOpenMultiple mode.
fileURLnsIURIThe URI of the currently selected file or directory. Read only.
filterIndexlongThe (0-based) index of the filter which is currently selected in the file picker dialog. Set this to choose a particular filter to be selected by default.
- -

常量

- -

模式常量

- -

These constants are used to specify the type of file picker to create when calling init().

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
常量说明
modeOpen0Load a file or directory.
modeSave1Save a file or directory.
modeGetFolder2Select a folder/directory.
modeOpenMultiple3Load multiple files.
- -

返回值常量

- -

These values are returned by show(), indicating the result of the file picker activity.

- - - - - - - - - - - - - - - - - - - - - - - - -
ConstantValueDescription
returnOK0The file picker dialog was closed by the user hitting 'Ok'
returnCancel1The file picker dialog was closed by the user hitting 'Cancel'
returnReplace2The user chose an existing file and acknowledged that they want to overwrite the file
- -

筛选器常量

- -

These constants are used to create filters for commonly-used file types. For the most up to date list see filepicker.properties.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ConstantValueDescription
filterAll0x001Corresponds to the *.* filter for file extensions. All files will pass through the filter.
filterHTML0x002Corresponds to the *.html, *.htm, *.shtml and *.xhtml filters for file extensions.
filterText0x004Corresponds to the *.txt and *.text filter for file extensions.
filterImages0x008Corresponds to the *.jpe, *.jpg, *.jpeg, *.gif, *.png, *.bmp, *.ico, *.svg, *.svgz, *.tif, *.tiff, *.ai, *.drw, *.pct, *.psp, *.xcf, *.psd and *.raw filters for file extensions.
filterXML0x010Corresponds to the *.xml filter for file extensions.
filterXUL0x020Corresponds to the *.xul filter for file extensions.
filterApps0x040Corresponds to the platform specific application filter for file extensions. Application files for the user's platform will pass through the filter.
filterAllowURLs0x80Allow URLs.
filterAudio0x100Corresponds to the *.aac, *.aif, *.flac, *.iff, *.m4a, *.m4b, *.mid, *.midi, *.mp3, *.mpa, *.mpc, *.oga, *.ogg, *.ra, *.ram, *.snd, *.wav and *.wma filters for file extensions.
filterVideo0x200Corresponds to the *.avi, *.divx, *.flv, *.m4v, *.mkv, *.mov, *.mp4, *.mpeg, *.mpg, *.ogm, *.ogv, *.ogx, *.rm, *.rmvb, *.smil, *.webm, *.wmv and *.xvid filters for file extensions.
- -

方法

- -

appendFilter()

- -

Appends a custom file extension filter to the dialog. The filter appended first will be used to display the nsIFilePicker dialog, the user may then select another from the list.

- -
void appendFilter(
-  in AString title,
-  in AString filter
-);
-
- -
Parameters
- -
-
title
-
The title of the filter.
-
filter
-
The filter string. Multiple extensions may be included, separated by a semicolon and a space.
-
- -
Example
- -

Some example filter strings:

- - - -

appendFilters()

- -

Appends a list of file extension filters, from the predefined list, to the dialog.

- -
void appendFilters(
-  in long filterMask
-);
-
- -
Parameters
- -
Note: If appendFilters is the first (or only) call to set the file filters the filter with the smallest code will be used as default filter when displaying the nsIFilePicker dialog. If you would like to use another you must append it separately before the others you want to go into the drop down list.
- -
-
filterMask
-
A combination of the filters you wish to use. You may OR multiple filters together; for example filterAll | filterHTML.
-
- -

init()

- -

Initialize the file picker widget. The file picker is not valid until this method is called.

- -
void init(
-  in nsIDOMWindow parent,
-  in AString title,
-  in short mode
-);
-
- -
Parameters
- -
-
parent
-
The nsIDOMWindow parent. This dialog will be dependent on this parent. Must be non-null.
-
title
-
The file picker dialog title. If this is null, the dialog will have the default title.
-
mode
-
One of the mode constants, indicating the type of picker to create.
-
- -

open

- -

Opens the file dialog asynchrounously. The passed in object's done method will be called upon completion.

- -
void open(
-  in nsIFilePickerShownCallback aFilePickerShownCallback
-);
-
- -
Parameters
- -
-
aFilePickerShownCallback
-
The nsIFilePickerShownCallback to be called on completion.
-
- -

show

- -

Displays the file picker dialog. The dialog is displayed modally.

- -
short show();
-
- -
Parameters
- -

None.

- -
Return value
- -

One of the return constants.

- -

示例

- -

Here's an example:

- -
const nsIFilePicker = Components.interfaces.nsIFilePicker;
-
-var fp = Components.classes["@mozilla.org/filepicker;1"]
-	           .createInstance(nsIFilePicker);
-fp.init(window, "Dialog Title", nsIFilePicker.modeOpen);
-fp.appendFilters(nsIFilePicker.filterAll | nsIFilePicker.filterText);
-
-var rv = fp.show();
-if (rv == nsIFilePicker.returnOK || rv == nsIFilePicker.returnReplace) {
-  var file = fp.file;
-  // Get the path as string. Note that you usually won't
-  // need to work with the string paths.
-  var path = fp.file.path;
-  // work with returned nsILocalFile...
-}
-
- -

If your code is a component and window is not defined, you can get one using nsIWindowMediator.

- -

When selecting multiple files:

- -
    ....
-    fp.init(window, "Dialog Title", nsIFilePicker.modeOpenMultiple);
-    ....
-
-    var files = fp.files;
-    var paths = [];
-    while (files.hasMoreElements())
-    {
-        var arg = files.getNext().QueryInterface(Components.interfaces.nsILocalFile).path;
-        paths.push(arg);
-    }
-
-- cgit v1.2.3-54-g00ecf