?? downloadactions.js
字號:
# -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-# ***** BEGIN LICENSE BLOCK *****# Version: MPL 1.1/GPL 2.0/LGPL 2.1## 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 the Download Actions Manager.## The Initial Developer of the Original Code is# Ben Goodger.# Portions created by the Initial Developer are Copyright (C) 2000-2005# the Initial Developer. All Rights Reserved.## Contributor(s):# Ben Goodger <ben@mozilla.org>## Alternatively, the contents of this file may be used under the terms of# either the GNU General Public License Version 2 or later (the "GPL"), or# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),# in which case the provisions of the GPL or the LGPL are applicable instead# of those above. If you wish to allow use of your version of this file only# under the terms of either the GPL or the LGPL, and not to allow others to# use your version of this file under the terms of the MPL, indicate your# decision by deleting the provisions above and replace them with the notice# and other provisions required by the GPL or the LGPL. If you do not delete# the provisions above, a recipient may use your version of this file under# the terms of any one of the MPL, the GPL or the LGPL.## ***** END LICENSE BLOCK *****const kRootTypePrefix = "urn:mimetype:";///////////////////////////////////////////////////////////////////////////////// MIME Types Datasource RDF Utilsfunction NC_URI(aProperty){ return "http://home.netscape.com/NC-rdf#" + aProperty;}function MIME_URI(aType){ return "urn:mimetype:" + aType;}function HANDLER_URI(aHandler){ return "urn:mimetype:handler:" + aHandler;}function APP_URI(aType){ return "urn:mimetype:externalApplication:" + aType;}var gDownloadActionsWindow = { _tree : null, _editButton : null, _removeButton : null, _actions : [], _plugins : {}, _bundle : null, _pref : Components.classes["@mozilla.org/preferences-service;1"] .getService(Components.interfaces.nsIPrefBranch), _mimeSvc : Components.classes["@mozilla.org/uriloader/external-helper-app-service;1"] .getService(Components.interfaces.nsIMIMEService), _excludingPlugins : false, _excludingMissingExtensions : false, init: function () { (this._editButton = document.getElementById("editFileHandler")).disabled = true; (this._removeButton = document.getElementById("removeFileHandler")).disabled = true; // Initialize the File Type list this._bundle = document.getElementById("bundlePreferences"); this._tree = document.getElementById("fileHandlersList"); this._loadView(); // Determine any exclusions being applied - e.g. don't show types for which // only a plugin handler exists, don't show types lacking extensions, etc. this._view._rowCount = this._updateExclusions(); this._tree.treeBoxObject.view = this._view; var indexToSelect = parseInt(this._tree.getAttribute("lastSelected")); if (indexToSelect < this._tree.view.rowCount) this._tree.view.selection.select(indexToSelect); this._tree.focus(); }, _loadView: function () { // Reset ALL the collections and state flags, because we can call this after // the window has initially displayed by resetting the filter. this._actions = []; this._plugins = {}; this._view._filtered = false; this._view._filterSet = []; this._view._usingExclusionSet = false; this._view._exclusionSet = []; this._view._filterValue = ""; this._loadPluginData(); this._loadMIMERegistryData(); }, _updateRowCount: function (aNewRowCount) { var oldCount = this._view._rowCount; this._view._rowCount = 0; this._tree.treeBoxObject.rowCountChanged(0, -oldCount); this._view._rowCount = aNewRowCount; this._tree.treeBoxObject.rowCountChanged(0, aNewRowCount); }, uninit: function () { }, _updateExclusions: function () { this._excludingPlugins = true; this._excludingMissingExtensions = true; this._view._exclusionSet = [].concat(this._actions); if (this._excludingMissingExtensions) { this._view._usingExclusionSet = true; for (var i = 0; i < this._view._exclusionSet.length;) { if (!this._view._exclusionSet[i].hasExtension) this._view._exclusionSet.splice(i, 1); else ++i; } } if (this._excludingPlugins) { this._view._usingExclusionSet = true; for (i = 0; i < this._view._exclusionSet.length;) { if (this._view._exclusionSet[i].handledOnlyByPlugin) this._view._exclusionSet.splice(i, 1); else ++i } } return this._view._usingExclusionSet ? this._view._exclusionSet.length : this._view._filtered ? this._view._filterSet.length : this._actions.length; }, _loadPluginData: function () { }, _createAction: function (aMIMEType, aActionName, aIsEditable, aHandleMode, aCustomHandler, aPluginAvailable, aPluginEnabled, aHandledOnlyByPlugin) { var newAction = !(aMIMEType in this._plugins); var action = newAction ? new FileAction() : this._plugins[aMIMEType]; action.type = aMIMEType; var info = this._mimeSvc.getFromTypeAndExtension(action.type, null); // File Extension try { action.extension = info.primaryExtension; } catch (e) { action.extension = this._bundle.getString("extensionNone"); action.hasExtension = false; } // Large and Small Icon try { action.smallIcon = "moz-icon://goat." + info.primaryExtension + "?size=16"; action.bigIcon = "moz-icon://goat." + info.primaryExtension + "?size=32"; } catch (e) { action.smallIcon = "moz-icon://goat?size=16&contentType=" + info.MIMEType; action.bigIcon = "moz-icon://goat?contentType=" + info.MIMEType + "&size=32"; } // Pretty Type Name if (info.description == "") { try { action.typeName = this._bundle.getFormattedString("fileEnding", [info.primaryExtension.toUpperCase()]); } catch (e) { // Wow, this sucks, just show the MIME type as a last ditch effort to display // the type of file that this is. action.typeName = info.MIMEType; } } else action.typeName = info.description; // Pretty Action Name if (aActionName) action.action = aActionName; action.pluginAvailable = aPluginAvailable; action.pluginEnabled = aPluginEnabled; action.editable = aIsEditable; action.handleMode = aHandleMode; action.customHandler = aCustomHandler; action.mimeInfo = info; action.handledOnlyByPlugin = aHandledOnlyByPlugin if (newAction && !(action.handledOnlyByPlugin && !action.pluginEnabled)) { this._actions.push(action); this._plugins[action.type] = action; } return action; }, _loadMIMEDS: function () { var fileLocator = Components.classes["@mozilla.org/file/directory_service;1"] .getService(Components.interfaces.nsIProperties); var file = fileLocator.get("UMimTyp", Components.interfaces.nsIFile); var ioService = Components.classes["@mozilla.org/network/io-service;1"] .getService(Components.interfaces.nsIIOService); var fileHandler = ioService.getProtocolHandler("file") .QueryInterface(Components.interfaces.nsIFileProtocolHandler); this._mimeDS = this._rdf.GetDataSourceBlocking(fileHandler.getURLSpecFromFile(file)); }, _getLiteralValue: function (aResource, aProperty) { var property = this._rdf.GetResource(NC_URI(aProperty)); var value = this._mimeDS.GetTarget(aResource, property, true); if (value) return value.QueryInterface(Components.interfaces.nsIRDFLiteral).Value; return ""; }, _getChildResource: function (aResource, aProperty) { var property = this._rdf.GetResource(NC_URI(aProperty)); return this._mimeDS.GetTarget(aResource, property, true); }, _getDisplayNameForFile: function (aFile) {#ifdef XP_WIN if (aFile instanceof Components.interfaces.nsILocalFileWin) return aFile.getVersionInfoField("FileDescription"); #else // XXXben - Read the bundle name on OS X. var ios = Components.classes["@mozilla.org/network/io-service;1"] .getService(Components.interfaces.nsIIOService); var url = ios.newFileURI(aFile).QueryInterface(Components.interfaces.nsIURL); return url.fileName;#endif }, _loadMIMERegistryData: function () { this._rdf = Components.classes["@mozilla.org/rdf/rdf-service;1"] .getService(Components.interfaces.nsIRDFService); this._loadMIMEDS(); var root = this._rdf.GetResource("urn:mimetypes:root"); var container = Components.classes["@mozilla.org/rdf/container;1"] .createInstance(Components.interfaces.nsIRDFContainer); container.Init(this._mimeDS, root); var elements = container.GetElements(); while (elements.hasMoreElements()) { var type = elements.getNext(); if (!(type instanceof Components.interfaces.nsIRDFResource)) break; var editable = this._getLiteralValue(type, "editable") == "true"; if (!editable) continue; var handler = this._getChildResource(type, "handlerProp"); var alwaysAsk = this._getLiteralValue(handler, "alwaysAsk") == "true"; if (alwaysAsk) continue; var saveToDisk = this._getLiteralValue(handler, "saveToDisk") == "true"; var useSystemDefault = this._getLiteralValue(handler, "useSystemDefault") == "true"; var editable = this._getLiteralValue(type, "editable") == "true"; var handledInternally = this._getLiteralValue(handler, "handleInternal") == "true"; var externalApp = this._getChildResource(handler, "externalApplication"); var externalAppPath = this._getLiteralValue(externalApp, "path"); try { var customHandler = Components.classes["@mozilla.org/file/local;1"] .createInstance(Components.interfaces.nsILocalFile); customHandler.initWithPath(externalAppPath); } catch (e) { customHandler = null; } if (customHandler && !customHandler.exists()) customHandler = null; var mimeType = this._getLiteralValue(type, "value"); var typeInfo = this._mimeSvc.getFromTypeAndExtension(mimeType, null); // Determine the pretty name of the associated action. var actionName = ""; var handleMode = 0; if (saveToDisk) { // Save the file to disk actionName = this._bundle.getString("saveToDisk"); handleMode = FILEACTION_SAVE_TO_DISK; } else if (useSystemDefault) { // Use the System Default handler actionName = this._bundle.getFormattedString("openWith", [typeInfo.defaultDescription]); handleMode = FILEACTION_OPEN_DEFAULT; } else { // Custom Handler if (customHandler) { actionName = this._bundle.getFormattedString("openWith", [this._getDisplayNameForFile(customHandler)]); handleMode = FILEACTION_OPEN_CUSTOM; } else { // Corrupt datasource, invalid custom handler path. Revert to default. actionName = this._bundle.getFormattedString("openWith", [typeInfo.defaultDescription]); handleMode = FILEACTION_OPEN_DEFAULT; } } if (handledInternally) handleMode = FILEACTION_OPEN_INTERNALLY; var pluginAvailable = mimeType in this._plugins && this._plugins[mimeType].pluginAvailable; var pluginEnabled = pluginAvailable && this._plugins[mimeType].pluginEnabled; if (pluginEnabled) { handleMode = FILEACTION_OPEN_PLUGIN; actionName = null; } var action = this._createAction(mimeType, actionName, editable, handleMode, customHandler, pluginAvailable, pluginEnabled, false); } }, _view: { _filtered : false, _filterSet : [], _usingExclusionSet : false, _exclusionSet : [], _filterValue : "", _rowCount: 0, get rowCount() { return this._rowCount; }, get activeCollection () { return this._filtered ? this._filterSet : this._usingExclusionSet ? this._exclusionSet : gDownloadActionsWindow._actions; }, getItemAtIndex: function (aIndex) { return this.activeCollection[aIndex]; }, getCellText: function (aIndex, aColumn) { switch (aColumn.id) { case "fileExtension": return this.getItemAtIndex(aIndex).extension.toUpperCase(); case "fileType": return this.getItemAtIndex(aIndex).typeName; case "fileMIMEType": return this.getItemAtIndex(aIndex).type; case "fileHandler": return this.getItemAtIndex(aIndex).action; }
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -