зеркало из https://github.com/mozilla/gecko-dev.git
xp file picker
This commit is contained in:
Родитель
4c43ddcc27
Коммит
ce7ae00400
|
@ -0,0 +1,293 @@
|
|||
/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
|
||||
const nsIFile = Components.interfaces.nsIFile;
|
||||
const nsILocalFile = Components.interfaces.nsILocalFile;
|
||||
const nsILocalFile_PROGID = "component://mozilla/file/local";
|
||||
|
||||
var sfile = Components.classes[nsILocalFile_PROGID].createInstance(nsILocalFile);
|
||||
var retvals;
|
||||
|
||||
function onLoad() {
|
||||
|
||||
if (window.arguments) {
|
||||
var o = window.arguments[0];
|
||||
retvals = o.retvals; /* set this to a global var so we can set return values */
|
||||
var title = o.title;
|
||||
var mode = o.mode;
|
||||
var numFilters = o.filters.length;
|
||||
var filterTitles = o.filters.titles;
|
||||
var filterTypes = o.filters.types;
|
||||
|
||||
window.title = title;
|
||||
|
||||
/* build filter popup */
|
||||
var filterPopup = document.createElement("menupopup");
|
||||
|
||||
for (var i = 0; i < numFilters; i++) {
|
||||
var menuItem = document.createElement("menuitem");
|
||||
menuItem.setAttribute("value", filterTitles[i] + " (" + filterTypes[i] + ")");
|
||||
filterPopup.appendChild(menuItem);
|
||||
}
|
||||
|
||||
var filterMenuList = document.getElementById("filterMenuList");
|
||||
filterMenuList.appendChild(filterPopup);
|
||||
|
||||
}
|
||||
|
||||
// setup the dialogOverlay.xul button handlers
|
||||
doSetOKCancel(onOK, onCancel);
|
||||
|
||||
sfile.initWithPath("/");
|
||||
getDirectoryContents(document.getElementById("directoryList"), sfile.directoryEntries);
|
||||
}
|
||||
|
||||
function onOK()
|
||||
{
|
||||
textInput = document.getElementById("textInput");
|
||||
|
||||
var file = Components.classes[nsILocalFile_PROGID].createInstance(nsILocalFile);
|
||||
file.initWithPath(textInput.value);
|
||||
|
||||
if (file.isFile() && !file.isDirectory()) {
|
||||
retvals.file = file.QueryInterface(nsIFile);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function onCancel()
|
||||
{
|
||||
// Close the window.
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
function onClick(e) {
|
||||
|
||||
sfile.initWithPath(e.target.parentNode.getAttribute("path"));
|
||||
|
||||
textInput = document.getElementById("textInput");
|
||||
textInput.value = sfile.path;
|
||||
|
||||
if (e.clickCount == 2) {
|
||||
|
||||
if (sfile.isDirectory()) {
|
||||
loadDirectory();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function dirSort(e1, e2)
|
||||
{
|
||||
if (e1.leafName == e2.leafName)
|
||||
return 0;
|
||||
|
||||
if (e1.leafName > e2.leafName)
|
||||
return 1;
|
||||
|
||||
if (e1.leafName < e2.leafName)
|
||||
return -1;
|
||||
}
|
||||
|
||||
function createTree(parentElement, dirArray)
|
||||
{
|
||||
var treeChildren = document.createElement("treechildren");
|
||||
|
||||
var len = dirArray.length;
|
||||
var file;
|
||||
|
||||
/* create the elements in the tree */
|
||||
for (var i=0; i < len; i++)
|
||||
{
|
||||
file = dirArray[i];
|
||||
|
||||
var styleClass = "";
|
||||
|
||||
var isSymlink = false;
|
||||
var isHidden = false;
|
||||
var isDirectory = false;
|
||||
var isFile = false;
|
||||
|
||||
try {
|
||||
if (file.isSymlink()) {
|
||||
isSymlink = true;
|
||||
}
|
||||
if (file.isHidden()) {
|
||||
isHidden = true;
|
||||
}
|
||||
if (file.isDirectory()) {
|
||||
isDirectory = true;
|
||||
}
|
||||
if (file.isHidden()) {
|
||||
isHidden = true;
|
||||
}
|
||||
if (file.isFile()) {
|
||||
isFile = true;
|
||||
}
|
||||
} catch(ex) { dump("couldn't stat one of the files\n"); }
|
||||
|
||||
/* treeItem */
|
||||
var treeItem = document.createElement("treeitem");
|
||||
/* set hidden on the tree item so that we use grey text for the entire row */
|
||||
if (isHidden)
|
||||
treeItem.setAttribute("class", "hidden");
|
||||
|
||||
/* treeRow */
|
||||
var treeRow = document.createElement("treerow");
|
||||
treeRow.setAttribute("path", file.path);
|
||||
|
||||
/* treeCell -- name */
|
||||
var treeCell = document.createElement("treecell");
|
||||
/* treeCell.setAttribute("indent", "true");*/
|
||||
treeCell.setAttribute("value", file.leafName);
|
||||
if (isDirectory)
|
||||
treeCell.setAttribute("class", "directory");
|
||||
else if (isFile)
|
||||
treeCell.setAttribute("class", "file");
|
||||
treeRow.appendChild(treeCell);
|
||||
|
||||
/* treeCell -- size */
|
||||
treeCell = document.createElement("treecell");
|
||||
try {
|
||||
if (file.fileSize != 0) {
|
||||
treeCell.setAttribute("value", file.fileSize);
|
||||
}
|
||||
} catch(ex) { }
|
||||
treeRow.appendChild(treeCell);
|
||||
|
||||
/* treeCell -- permissions */
|
||||
treeCell = document.createElement("treecell");
|
||||
try {
|
||||
const p = file.permissions;
|
||||
var perms = "";
|
||||
dump(p + " ");
|
||||
if (isSymlink) {
|
||||
perms += "lrwxrwxrwx";
|
||||
} else {
|
||||
perms += (isDirectory) ? "d" : "-";
|
||||
perms += (p & 00400) ? "r" : "-";
|
||||
perms += (p & 00200) ? "w" : "-";
|
||||
perms += (p & 00100) ? "x" : "-";
|
||||
perms += (p & 00040) ? "r" : "-";
|
||||
perms += (p & 00020) ? "w" : "-";
|
||||
perms += (p & 00010) ? "x" : "-";
|
||||
perms += (p & 00004) ? "r" : "-";
|
||||
perms += (p & 00002) ? "w" : "-";
|
||||
perms += (p & 00001) ? "x" : "-";
|
||||
dump(perms + "\n");
|
||||
}
|
||||
treeCell.setAttribute("value", perms);
|
||||
} catch(ex) { }
|
||||
treeRow.appendChild(treeCell);
|
||||
|
||||
/* append treeRow to treeItem */
|
||||
treeItem.appendChild(treeRow);
|
||||
|
||||
/* append treeItem to treeChildren */
|
||||
treeChildren.appendChild(treeItem);
|
||||
}
|
||||
|
||||
/* append treeChildren to parent (tree) */
|
||||
parentElement.appendChild(treeChildren);
|
||||
}
|
||||
|
||||
function getDirectoryContents(parentElement, dirContents)
|
||||
{
|
||||
var i = 0;
|
||||
var array = new Array();
|
||||
while (dirContents.HasMoreElements()) {
|
||||
array[i] = dirContents.GetNext().QueryInterface(nsIFile);
|
||||
i++;
|
||||
}
|
||||
|
||||
/* sort the array */
|
||||
array.sort(dirSort);
|
||||
|
||||
createTree(parentElement, array);
|
||||
}
|
||||
|
||||
function clearTree() {
|
||||
var tree = document.getElementById("directoryList");
|
||||
|
||||
/* lets make an assumption that the tree children are at the end of the tree... */
|
||||
if (tree.lastChild)
|
||||
tree.removeChild(tree.lastChild);
|
||||
}
|
||||
|
||||
|
||||
function addToHistory(directoryName) {
|
||||
var menuList = document.getElementById("lookInMenuList");
|
||||
var menu = document.getElementById("lookInMenu");
|
||||
var menuItem = document.createElement("menuitem");
|
||||
menuItem.setAttribute("value", directoryName);
|
||||
menu.appendChild(menuItem);
|
||||
|
||||
menuList.selectedItem = menuItem;
|
||||
}
|
||||
|
||||
function goUp() {
|
||||
try {
|
||||
var parent = sfile.parent;
|
||||
} catch(ex) { dump("can't get parent directory\n"); }
|
||||
|
||||
if (parent) {
|
||||
sfile = parent.QueryInterface(Components.interfaces.nsILocalFile);
|
||||
loadDirectory();
|
||||
}
|
||||
}
|
||||
|
||||
function loadDirectory() {
|
||||
try {
|
||||
if (sfile.isDirectory()) {
|
||||
clearTree();
|
||||
try {
|
||||
getDirectoryContents(document.getElementById("directoryList"), sfile.directoryEntries);
|
||||
} catch(ex) { dump("getDirectoryContents() failed\n"); }
|
||||
addToHistory(sfile.path);
|
||||
document.getElementById("textInput").value = "";
|
||||
}
|
||||
} catch(ex) { dump("isDirectory failed\n"); }
|
||||
}
|
||||
|
||||
function gotoDirectory(directoryName) {
|
||||
sfile.initWithPath(directoryName);
|
||||
loadDirectory();
|
||||
}
|
||||
|
||||
|
||||
|
||||
function textEntered(name) {
|
||||
var file = Components.classes[nsILocalFile_PROGID].createInstance(nsILocalFile);
|
||||
file.initWithPath(name);
|
||||
dump("*** " + file + "\n*** " + file.path + "\n");
|
||||
if (file.exists()) {
|
||||
if (file.isDirectory()) {
|
||||
if (!sfile.equals(file)) {
|
||||
sfile.initWithPath(name);
|
||||
sfile.normalize();
|
||||
loadDirectory();
|
||||
}
|
||||
return;
|
||||
} else if (file.isFile()) {
|
||||
retvals.file = file;
|
||||
window.close();
|
||||
}
|
||||
} else {
|
||||
/* look for something in our current directory */
|
||||
var nfile = sfile.clone();
|
||||
nfile.append(file.path);
|
||||
dump(nfile.path);
|
||||
if (nfile.isFile()) {
|
||||
retvals.file = nfile;
|
||||
window.close();
|
||||
} else if (nfile.isDirectory()) {
|
||||
sfile.initWithPath(nfile.path);
|
||||
sfile.normalize();
|
||||
loadDirectory();
|
||||
} else {
|
||||
dump("can't find file \"" + nfile.path + "\"");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
<?xml version="1.0"?> <!-- -*- Mode: HTML -*- -->
|
||||
|
||||
<?xml-stylesheet href="chrome://global/skin/filepicker.css" type="text/css"?>
|
||||
|
||||
<?xul-overlay href="chrome://global/content/dialogOverlay.xul"?>
|
||||
|
||||
<window id="main-window" xmlns:html="http://www.w3.org/TR/REC-html40"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
||||
align="vertical"
|
||||
onload="onLoad();"
|
||||
width="426" height="300"
|
||||
class="dialog">
|
||||
|
||||
<html:script src="chrome://global/content/filepicker.js"/>
|
||||
|
||||
<box align="horizontal">
|
||||
<text value="Look in:"/>
|
||||
<menulist id="lookInMenuList" flex="1">
|
||||
<menupopup id="lookInMenu"/>
|
||||
</menulist>
|
||||
|
||||
<button value="up" onclick="goUp();"/>
|
||||
<button value="n"/>
|
||||
</box>
|
||||
|
||||
<box align="horizontal">
|
||||
<tree id="directoryList" onclick="onClick(event);" flex="1">
|
||||
<treehead>
|
||||
<treerow>
|
||||
<treecell value="Name"/>
|
||||
<treecell value="Size"/>
|
||||
<treecell value="Permissions"/>
|
||||
</treerow>
|
||||
</treehead>
|
||||
</tree>
|
||||
</box>
|
||||
|
||||
<box align="horizontal">
|
||||
<text value="File name:"/>
|
||||
<html:input type="text" id="textInput" onkeyup="if (event.which == 13) { textEntered(event.target.value); }" flex="1"/>
|
||||
</box>
|
||||
|
||||
<box align="horizontal">
|
||||
<text value="Files of type:"/>
|
||||
<menulist id="filterMenuList" flex="1"/>
|
||||
</box>
|
||||
|
||||
<box id="okCancelButtons"/>
|
||||
|
||||
</window>
|
Двоичный файл не отображается.
После Ширина: | Высота: | Размер: 74 B |
Двоичный файл не отображается.
После Ширина: | Высота: | Размер: 122 B |
Двоичный файл не отображается.
После Ширина: | Высота: | Размер: 123 B |
|
@ -0,0 +1,22 @@
|
|||
@import url(chrome://global/skin/);
|
||||
|
||||
treecell.directory > .tree-button {
|
||||
list-style-image: url("chrome://nav/skin/dir-closed.gif");
|
||||
}
|
||||
|
||||
treecell.directory[open="true"] > .tree-button {
|
||||
list-style-image: url("chrome://nav/skin/dir-open.gif");
|
||||
}
|
||||
|
||||
treecell.file > .tree-button {
|
||||
list-style-image: url("chrome://nav/skin/blank.gif");
|
||||
}
|
||||
|
||||
treeitem.hidden > treerow > treecell > .tree-button {
|
||||
color: #CCCCCC;
|
||||
}
|
||||
|
||||
treeitem.hidden > treerow > treecell > .tree-icon {
|
||||
list-style-image: url"chrome://nav/skin/blank.gif");
|
||||
}
|
||||
|
|
@ -0,0 +1,160 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2000 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s): Stuart Parmenter <pavlov@netscape.com>
|
||||
*/
|
||||
|
||||
/*
|
||||
* No magic constructor behaviour, as is de rigeur for XPCOM.
|
||||
* If you must perform some initialization, and it could possibly fail (even
|
||||
* due to an out-of-memory condition), you should use an Init method, which
|
||||
* can convey failure appropriately (thrown exception in JS,
|
||||
* NS_FAILED(nsresult) return in C++).
|
||||
*
|
||||
* In JS, you can actually cheat, because a thrown exception will cause the
|
||||
* CreateInstance call to fail in turn, but not all languages are so lucky.
|
||||
* (Though ANSI C++ provides exceptions, they are verboten in Mozilla code
|
||||
* for portability reasons -- and even when you're building completely
|
||||
* platform-specific code, you can't throw across an XPCOM method boundary.)
|
||||
*/
|
||||
|
||||
|
||||
const DEBUG = true; /* set to false to suppress debug messages */
|
||||
const FILEPICKER_PROGID = "component://mozilla/filepicker";
|
||||
const FILEPICKER_CID = Components.ID("{54ae32f8-1dd2-11b2-a209-df7c505370f8}");
|
||||
const nsILocalFile = Components.interfaces.nsILocalFile;
|
||||
const nsISupports = Components.interfaces.nsISupports;
|
||||
const nsIFactory = Components.interfaces.nsIFactory;
|
||||
const nsIFile = Components.interfaces.nsIFile;
|
||||
const nsIFilePicker = Components.interfaces.nsIFilePicker;
|
||||
|
||||
function nsFilePicker()
|
||||
{
|
||||
/* attributes */
|
||||
this.mSelectedFilter = 0;
|
||||
this.mDefaultString = "";
|
||||
this.mDisplayDirectory = "";
|
||||
}
|
||||
|
||||
nsFilePicker.prototype = {
|
||||
|
||||
/* attribute nsIFile displayDirectory; */
|
||||
set displayDirectory(a) { this.mDisplayDirectory = a; },
|
||||
get displayDirectory() { return this.mDisplayDirectory; },
|
||||
|
||||
/* readonly attribute nsIFile file; */
|
||||
set file(a) { throw "readonly property"; },
|
||||
get file() { debug("getter called " + this.mFile); return this.mFile; },
|
||||
|
||||
/* readonly attribute long selectedFilter; */
|
||||
set selectedFilter(a) { throw "readonly property"; },
|
||||
get selectedFilter() { return this.mSelectedFilter; },
|
||||
|
||||
/* attribute wstring defaultString; */
|
||||
set defaultString(a) { throw "readonly property"; },
|
||||
get defaultString() { return this.mSelectedFilter; },
|
||||
|
||||
/* methods */
|
||||
create: function(parent, title, mode) {
|
||||
this.mParentWindow = parent;
|
||||
this.mTitle = title;
|
||||
this.mMode = mode;
|
||||
},
|
||||
|
||||
setFilterList: function(numFilters, titles, types) {
|
||||
this.mNumFilters = numFilters;
|
||||
this.mFilterTitles = titles;
|
||||
this.mFilterTypes = types;
|
||||
},
|
||||
|
||||
show: function() {
|
||||
var o = new Object();
|
||||
o.title = this.mTitle;
|
||||
o.mode = this.mMode;
|
||||
o.filters = new Object();
|
||||
o.filters.length = this.mNumFilters;
|
||||
o.filters.titles = this.mFilterTitles;
|
||||
o.filters.types = this.mFilterTypes;
|
||||
o.retvals = new Object();
|
||||
|
||||
this.mParentWindow.openDialog("chrome://global/content/filepicker.xul",
|
||||
"",
|
||||
"chrome,modal,resizeable=yes,dependent=yes",
|
||||
o);
|
||||
|
||||
this.mFile = o.retvals.file;
|
||||
}
|
||||
}
|
||||
|
||||
if (DEBUG)
|
||||
debug = function (s) { dump("-*- filepicker: " + s + "\n"); }
|
||||
else
|
||||
debug = function (s) {}
|
||||
|
||||
/* module foo */
|
||||
|
||||
var filePickerModule = new Object();
|
||||
|
||||
filePickerModule.registerSelf =
|
||||
function (compMgr, fileSpec, location, type)
|
||||
{
|
||||
debug("registering (all right -- a JavaScript module!)");
|
||||
compMgr.registerComponentWithType(FILEPICKER_CID, "FilePicker JS Component",
|
||||
FILEPICKER_PROGID, fileSpec, location,
|
||||
true, true, type);
|
||||
}
|
||||
|
||||
filePickerModule.getClassObject =
|
||||
function (compMgr, cid, iid) {
|
||||
if (!cid.equals(FILEPICKER_CID))
|
||||
throw Components.results.NS_ERROR_NO_INTERFACE;
|
||||
|
||||
if (!iid.equals(Components.interfaces.nsIFactory))
|
||||
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
|
||||
|
||||
return filePickerFactory;
|
||||
}
|
||||
|
||||
filePickerModule.canUnload =
|
||||
function(compMgr)
|
||||
{
|
||||
debug("Unloading component.");
|
||||
return true;
|
||||
}
|
||||
|
||||
/* factory object */
|
||||
filePickerFactory = new Object();
|
||||
|
||||
filePickerFactory.CreateInstance =
|
||||
function (outer, iid) {
|
||||
debug("CI: " + iid);
|
||||
debug("IID:" + nsIFilePicker);
|
||||
if (outer != null)
|
||||
throw Components.results.NS_ERROR_NO_AGGREGATION;
|
||||
|
||||
if (!iid.equals(nsIFilePicker) && !iid.equals(nsISupports))
|
||||
throw Components.results.NS_ERROR_INVALID_ARG;
|
||||
|
||||
return new nsFilePicker();
|
||||
}
|
||||
|
||||
/* entrypoint */
|
||||
function NSGetModule(compMgr, fileSpec) {
|
||||
return filePickerModule;
|
||||
}
|
|
@ -0,0 +1,160 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2000 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s): Stuart Parmenter <pavlov@netscape.com>
|
||||
*/
|
||||
|
||||
/*
|
||||
* No magic constructor behaviour, as is de rigeur for XPCOM.
|
||||
* If you must perform some initialization, and it could possibly fail (even
|
||||
* due to an out-of-memory condition), you should use an Init method, which
|
||||
* can convey failure appropriately (thrown exception in JS,
|
||||
* NS_FAILED(nsresult) return in C++).
|
||||
*
|
||||
* In JS, you can actually cheat, because a thrown exception will cause the
|
||||
* CreateInstance call to fail in turn, but not all languages are so lucky.
|
||||
* (Though ANSI C++ provides exceptions, they are verboten in Mozilla code
|
||||
* for portability reasons -- and even when you're building completely
|
||||
* platform-specific code, you can't throw across an XPCOM method boundary.)
|
||||
*/
|
||||
|
||||
|
||||
const DEBUG = true; /* set to false to suppress debug messages */
|
||||
const FILEPICKER_PROGID = "component://mozilla/filepicker";
|
||||
const FILEPICKER_CID = Components.ID("{54ae32f8-1dd2-11b2-a209-df7c505370f8}");
|
||||
const nsILocalFile = Components.interfaces.nsILocalFile;
|
||||
const nsISupports = Components.interfaces.nsISupports;
|
||||
const nsIFactory = Components.interfaces.nsIFactory;
|
||||
const nsIFile = Components.interfaces.nsIFile;
|
||||
const nsIFilePicker = Components.interfaces.nsIFilePicker;
|
||||
|
||||
function nsFilePicker()
|
||||
{
|
||||
/* attributes */
|
||||
this.mSelectedFilter = 0;
|
||||
this.mDefaultString = "";
|
||||
this.mDisplayDirectory = "";
|
||||
}
|
||||
|
||||
nsFilePicker.prototype = {
|
||||
|
||||
/* attribute nsIFile displayDirectory; */
|
||||
set displayDirectory(a) { this.mDisplayDirectory = a; },
|
||||
get displayDirectory() { return this.mDisplayDirectory; },
|
||||
|
||||
/* readonly attribute nsIFile file; */
|
||||
set file(a) { throw "readonly property"; },
|
||||
get file() { debug("getter called " + this.mFile); return this.mFile; },
|
||||
|
||||
/* readonly attribute long selectedFilter; */
|
||||
set selectedFilter(a) { throw "readonly property"; },
|
||||
get selectedFilter() { return this.mSelectedFilter; },
|
||||
|
||||
/* attribute wstring defaultString; */
|
||||
set defaultString(a) { throw "readonly property"; },
|
||||
get defaultString() { return this.mSelectedFilter; },
|
||||
|
||||
/* methods */
|
||||
create: function(parent, title, mode) {
|
||||
this.mParentWindow = parent;
|
||||
this.mTitle = title;
|
||||
this.mMode = mode;
|
||||
},
|
||||
|
||||
setFilterList: function(numFilters, titles, types) {
|
||||
this.mNumFilters = numFilters;
|
||||
this.mFilterTitles = titles;
|
||||
this.mFilterTypes = types;
|
||||
},
|
||||
|
||||
show: function() {
|
||||
var o = new Object();
|
||||
o.title = this.mTitle;
|
||||
o.mode = this.mMode;
|
||||
o.filters = new Object();
|
||||
o.filters.length = this.mNumFilters;
|
||||
o.filters.titles = this.mFilterTitles;
|
||||
o.filters.types = this.mFilterTypes;
|
||||
o.retvals = new Object();
|
||||
|
||||
this.mParentWindow.openDialog("chrome://global/content/filepicker.xul",
|
||||
"",
|
||||
"chrome,modal,resizeable=yes,dependent=yes",
|
||||
o);
|
||||
|
||||
this.mFile = o.retvals.file;
|
||||
}
|
||||
}
|
||||
|
||||
if (DEBUG)
|
||||
debug = function (s) { dump("-*- filepicker: " + s + "\n"); }
|
||||
else
|
||||
debug = function (s) {}
|
||||
|
||||
/* module foo */
|
||||
|
||||
var filePickerModule = new Object();
|
||||
|
||||
filePickerModule.registerSelf =
|
||||
function (compMgr, fileSpec, location, type)
|
||||
{
|
||||
debug("registering (all right -- a JavaScript module!)");
|
||||
compMgr.registerComponentWithType(FILEPICKER_CID, "FilePicker JS Component",
|
||||
FILEPICKER_PROGID, fileSpec, location,
|
||||
true, true, type);
|
||||
}
|
||||
|
||||
filePickerModule.getClassObject =
|
||||
function (compMgr, cid, iid) {
|
||||
if (!cid.equals(FILEPICKER_CID))
|
||||
throw Components.results.NS_ERROR_NO_INTERFACE;
|
||||
|
||||
if (!iid.equals(Components.interfaces.nsIFactory))
|
||||
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
|
||||
|
||||
return filePickerFactory;
|
||||
}
|
||||
|
||||
filePickerModule.canUnload =
|
||||
function(compMgr)
|
||||
{
|
||||
debug("Unloading component.");
|
||||
return true;
|
||||
}
|
||||
|
||||
/* factory object */
|
||||
filePickerFactory = new Object();
|
||||
|
||||
filePickerFactory.CreateInstance =
|
||||
function (outer, iid) {
|
||||
debug("CI: " + iid);
|
||||
debug("IID:" + nsIFilePicker);
|
||||
if (outer != null)
|
||||
throw Components.results.NS_ERROR_NO_AGGREGATION;
|
||||
|
||||
if (!iid.equals(nsIFilePicker) && !iid.equals(nsISupports))
|
||||
throw Components.results.NS_ERROR_INVALID_ARG;
|
||||
|
||||
return new nsFilePicker();
|
||||
}
|
||||
|
||||
/* entrypoint */
|
||||
function NSGetModule(compMgr, fileSpec) {
|
||||
return filePickerModule;
|
||||
}
|
Загрузка…
Ссылка в новой задаче