📄 nshelperappdlg.js
字号:
return this.dialogElement("open").selected && this.dialogElement("openHandler").selectedIndex == 1; }, get useSystemDefault() { return this.dialogElement("open").selected && this.dialogElement("openHandler").selectedIndex == 0; }, toggleRememberChoice: function (aCheckbox) { this.dialogElement("settingsChange").hidden = !aCheckbox.checked; this.mDialog.sizeToContent(); }, openHandlerCommand: function () { var openHandler = this.dialogElement("openHandler"); if (openHandler.selectedItem.id == "choose") this.chooseApp(); else openHandler.setAttribute("lastSelectedItemID", openHandler.selectedItem.id); }, updateOKButton: function() { var ok = false; if (this.dialogElement("save").selected) { // This is always OK. ok = true; } else if (this.dialogElement("open").selected) { switch (this.dialogElement("openHandler").selectedIndex) { case 0: // No app need be specified in this case. ok = true; break; case 1: // only enable the OK button if we have a default app to use or if // the user chose an app.... ok = this.chosenApp || /\S/.test(this.dialogElement("otherHandler").getAttribute("path")); break; } } // Enable Ok button if ok to press. this.mDialog.document.documentElement.getButton("accept").disabled = !ok; }, // Returns true iff the user-specified helper app has been modified. appChanged: function() { return this.helperAppChoice() != this.mLauncher.MIMEInfo.preferredApplicationHandler; }, updateMIMEInfo: function() { var needUpdate = false; // If current selection differs from what's in the mime info object, // then we need to update. if (this.saveToDisk) { needUpdate = this.mLauncher.MIMEInfo.preferredAction != this.nsIMIMEInfo.saveToDisk; if (needUpdate) this.mLauncher.MIMEInfo.preferredAction = this.nsIMIMEInfo.saveToDisk; } else if (this.useSystemDefault) { needUpdate = this.mLauncher.MIMEInfo.preferredAction != this.nsIMIMEInfo.useSystemDefault; if (needUpdate) this.mLauncher.MIMEInfo.preferredAction = this.nsIMIMEInfo.useSystemDefault; } else { // For "open with", we need to check both preferred action and whether the user chose // a new app. needUpdate = this.mLauncher.MIMEInfo.preferredAction != this.nsIMIMEInfo.useHelperApp || this.appChanged(); if (needUpdate) { this.mLauncher.MIMEInfo.preferredAction = this.nsIMIMEInfo.useHelperApp; // App may have changed - Update application and description var app = this.helperAppChoice(); this.mLauncher.MIMEInfo.preferredApplicationHandler = app; this.mLauncher.MIMEInfo.applicationDescription = ""; } } // We will also need to update if the "always ask" flag has changed. needUpdate = needUpdate || this.mLauncher.MIMEInfo.alwaysAskBeforeHandling != (!this.dialogElement("rememberChoice").checked); // One last special case: If the input "always ask" flag was false, then we always // update. In that case we are displaying the helper app dialog for the first // time for this mime type and we need to store the user's action in the mimeTypes.rdf // data source (whether that action has changed or not; if it didn't change, then we need // to store the "always ask" flag so the helper app dialog will or won't display // next time, per the user's selection). needUpdate = needUpdate || !this.mLauncher.MIMEInfo.alwaysAskBeforeHandling; // Make sure mime info has updated setting for the "always ask" flag. this.mLauncher.MIMEInfo.alwaysAskBeforeHandling = !this.dialogElement("rememberChoice").checked; return needUpdate; }, // See if the user changed things, and if so, update the // mimeTypes.rdf entry for this mime type. updateHelperAppPref: function() { var ha = new this.mDialog.HelperApps(); ha.updateTypeInfo(this.mLauncher.MIMEInfo); ha.destroy(); }, // onOK: onOK: function() { // Verify typed app path, if necessary. if (this.useOtherHandler) { var helperApp = this.helperAppChoice(); if (!helperApp || !helperApp.exists()) { // Show alert and try again. var bundle = this.dialogElement("strings"); var msg = bundle.getFormattedString("badApp", [this.dialogElement("otherHandler").path]); var svc = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService); svc.alert(this.mDialog, bundle.getString("badApp.title"), msg); // Disable the OK button. this.mDialog.document.documentElement.getButton("accept").disabled = true; this.dialogElement("mode").focus(); // Clear chosen application. this.chosenApp = null; // Leave dialog up. return false; } } // Remove our web progress listener (a progress dialog will be // taking over). this.mLauncher.setWebProgressListener(null); // saveToDisk and launchWithApplication can return errors in // certain circumstances (e.g. The user clicks cancel in the // "Save to Disk" dialog. In those cases, we don't want to // update the helper application preferences in the RDF file. try { var needUpdate = this.updateMIMEInfo(); if (this.dialogElement("save").selected) { // If we're using a default download location, create a path // for the file to be saved to to pass to |saveToDisk| - otherwise // we must ask the user to pick a save name.//@line 887 "/c/builds/1813/mozilla/toolkit/mozapps/downloads/src/nsHelperAppDlg.js.in" this.mLauncher.saveToDisk(null, false); } else this.mLauncher.launchWithApplication(null, false); // Update user pref for this mime type (if necessary). We do not // store anything in the mime type preferences for the ambiguous // type application/octet-stream. We do NOT do this for // application/x-msdownload since we want users to be able to // autodownload these to disk. if (needUpdate && this.mLauncher.MIMEInfo.MIMEType != "application/octet-stream") this.updateHelperAppPref(); } catch(e) { } // Unhook dialog from this object. this.mDialog.dialog = null; // Close up dialog by returning true. return true; }, // onCancel: onCancel: function() { // Remove our web progress listener. this.mLauncher.setWebProgressListener(null); // Cancel app launcher. try { const NS_BINDING_ABORTED = 0x804b0002; this.mLauncher.cancel(NS_BINDING_ABORTED); } catch(exception) { } // Unhook dialog from this object. this.mDialog.dialog = null; // Close up dialog by returning true. return true; }, // dialogElement: Convenience. dialogElement: function(id) { return this.mDialog.document.getElementById(id); }, // chooseApp: Open file picker and prompt user for application. chooseApp: function() { var nsIFilePicker = Components.interfaces.nsIFilePicker; var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker); fp.init(this.mDialog, this.dialogElement("strings").getString("chooseAppFilePickerTitle"), nsIFilePicker.modeOpen); fp.appendFilters(nsIFilePicker.filterApps); if (fp.show() == nsIFilePicker.returnOK && fp.file) { // Show the "handler" menulist since we have a (user-specified) // application now. this.dialogElement("modeDeck").setAttribute("selectedIndex", "0"); // Remember the file they chose to run. this.chosenApp = fp.file; // Update dialog. var otherHandler = this.dialogElement("otherHandler"); otherHandler.removeAttribute("hidden"); otherHandler.setAttribute("path", this.getPath(this.chosenApp)); otherHandler.label = this.chosenApp.leafName; this.dialogElement("openHandler").selectedIndex = 1; this.dialogElement("openHandler").setAttribute("lastSelectedItemID", "otherHandler"); this.dialogElement("mode").selectedItem = this.dialogElement("open"); } else { var openHandler = this.dialogElement("openHandler"); var lastSelectedID = openHandler.getAttribute("lastSelectedItemID"); if (!lastSelectedID) lastSelectedID = "defaultHandler"; openHandler.selectedItem = this.dialogElement(lastSelectedID); } }, // Turn this on to get debugging messages. debug: false, // Dump text (if debug is on). dump: function( text ) { if ( this.debug ) { dump( text ); } }, // dumpInfo: doDebug: function() { const nsIProgressDialog = Components.interfaces.nsIProgressDialog; // Open new progress dialog. var progress = Components.classes[ "@mozilla.org/progressdialog;1" ] .createInstance( nsIProgressDialog ); // Show it. progress.open( this.mDialog ); }, // dumpObj: dumpObj: function( spec ) { var val = "<undefined>"; try { val = eval( "this."+spec ).toString(); } catch( exception ) { } this.dump( spec + "=" + val + "\n" ); }, // dumpObjectProperties dumpObjectProperties: function( desc, obj ) { for( prop in obj ) { this.dump( desc + "." + prop + "=" ); var val = "<undefined>"; try { val = obj[ prop ]; } catch ( exception ) { } this.dump( val + "\n" ); } }}// This Component's module implementation. All the code below is used to get this// component registered and accessible via XPCOM.var module = { firstTime: true, // registerSelf: Register this component. registerSelf: function (compMgr, fileSpec, location, type) { if (this.firstTime) { this.firstTime = false; throw Components.results.NS_ERROR_FACTORY_REGISTER_AGAIN; } compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar); compMgr.registerFactoryLocation( this.cid, "Unknown Content Type Dialog", this.contractId, fileSpec, location, type ); }, // getClassObject: Return this component's factory object. getClassObject: function (compMgr, cid, iid) { if (!cid.equals(this.cid)) { throw Components.results.NS_ERROR_NO_INTERFACE; } if (!iid.equals(Components.interfaces.nsIFactory)) { throw Components.results.NS_ERROR_NOT_IMPLEMENTED; } return this.factory; }, /* CID for this class */ cid: Components.ID("{F68578EB-6EC2-4169-AE19-8C6243F0ABE1}"), /* Contract ID for this class */ contractId: "@mozilla.org/helperapplauncherdialog;1", /* factory object */ factory: { // createInstance: Return a new nsProgressDialog object. createInstance: function (outer, iid) { if (outer != null) throw Components.results.NS_ERROR_NO_AGGREGATION; return (new nsUnknownContentTypeDialog()).QueryInterface(iid); } }, // canUnload: n/a (returns true) canUnload: function(compMgr) { return true; }};// NSGetModule: Return the nsIModule object.function NSGetModule(compMgr, fileSpec) { return module;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -