📄 nshelperappdlg.js
字号:
this.mLauncher.MIMEInfo.preferredAction = this.nsIMIMEInfo.useSystemDefault; } else if ( this.dialogElement( "openUsing" ).selected ) { // 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 = ""; } } // Only care about the state of "always ask" if this dialog wasn't forced if ( this.mReason == REASON_CANTHANDLE ) { // We will also need to update if the "always ask" flag has changed. needUpdate = needUpdate || this.mLauncher.MIMEInfo.alwaysAskBeforeHandling == this.dialogElement( "alwaysHandle" ).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( "alwaysHandle" ).checked; } return needUpdate; }, // See if the user changed things, and if so, update the // mimeTypes.rdf entry for this mime type. updateHelperAppPref: function() { // We update by passing this mime info into the "Edit Type" helper app // pref dialog. It will update the data source and close the dialog // automatically. this.mDialog.openDialog( "chrome://communicator/content/pref/pref-applications-edit.xul", "_blank", "chrome,modal=yes,resizable=no", this ); }, // onOK: onOK: function() { // Verify typed app path, if necessary. if ( this.dialogElement( "openUsing" ).selected ) { var helperApp = this.helperAppChoice(); if ( !helperApp || !helperApp.exists() ) { // Show alert and try again. var msg = this.replaceInsert( this.getString( "badApp" ), 1, this.dialogElement( "appPath" ).value ); var svc = Components.classes[ "@mozilla.org/embedcomp/prompt-service;1" ] .getService( Components.interfaces.nsIPromptService ); svc.alert( this.mDialog, this.getString( "badApp.title" ), msg ); // Disable the OK button. this.mDialog.document.documentElement.getButton( "accept" ).disabled = true; // Select and focus the input field if input field is not disabled var path = this.dialogElement( "appPath" ); if ( !path.disabled ) { path.select(); path.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( "saveToDisk" ).selected ) 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. 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: Try cache; obtain from document if not there. dialogElement: function( id ) { // Check if we've already fetched it. if ( !( id in this.elements ) ) { // No, then get it from dialog. this.elements[ id ] = this.mDialog.document.getElementById( id ); } return this.elements[ 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.getString( "chooseAppFilePickerTitle" ), nsIFilePicker.modeOpen ); // XXX - We want to say nsIFilePicker.filterExecutable or something fp.appendFilters( nsIFilePicker.filterAll ); if ( fp.show() == nsIFilePicker.returnOK && fp.file ) { // Remember the file they chose to run. this.chosenApp = fp.file; // Update dialog. this.dialogElement( "appPath" ).value = this.getPath(this.chosenApp); } }, // 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" ); } }, // getString: Fetch data string from dialog content (and cache it). getString: function( id ) { // Check if we've fetched this string already. if ( !( id in this.strings ) ) { // Try to get it. var elem = this.mDialog.document.getElementById( id ); if ( elem && elem.firstChild && elem.firstChild.nodeValue ) { this.strings[ id ] = elem.firstChild.nodeValue; } else { // If unable to fetch string, use an empty string. this.strings[ id ] = ""; } } return this.strings[ id ]; }, // replaceInsert: Replace given insert with replacement text and return the result. replaceInsert: function( text, insertNo, replacementText ) { var result = text; var regExp = new RegExp("#"+insertNo); result = result.replace( regExp, replacementText ); return result; }}// 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, "Mozilla Helper App Launcher 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 nsHelperAppDialog()).QueryInterface(iid); } }, // canUnload: n/a (returns true) canUnload: function(compMgr) { return true; }};// NSGetModule: Return the nsIModule object.function NSGetModule(compMgr, fileSpec) { return module;}// Since we're automatically downloading, we don't get the file picker's// logic to check for existing files, so we need to do that here.//// Note - this code is identical to that in contentAreaUtils.js.// If you are updating this code, update that code too! We can't share code// here since this is called in a js component.function uniqueFile(aLocalFile) { while (aLocalFile.exists()) { parts = /(-\d+)?(\.[^.]+)?$/.test(aLocalFile.leafName); aLocalFile.leafName = RegExp.leftContext + (RegExp.$1 - 1) + RegExp.$2; } return aLocalFile;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -