📄 nshelperappdlg.js
字号:
this.dialogElement("contentTypeImage").setAttribute("src", iconString); this.initAppAndSaveToDiskValues(); // Initialize "always ask me" box. This should always be disabled // and set to true for the ambiguous type application/octet-stream. // Same if this dialog was forced due to a server request or type // sniffing var alwaysHandleCheckbox = this.dialogElement( "alwaysHandle" ); if (this.mReason != REASON_CANTHANDLE || this.mLauncher.MIMEInfo.MIMEType == "application/octet-stream"){ alwaysHandleCheckbox.checked = false; alwaysHandleCheckbox.disabled = true; } else { alwaysHandleCheckbox.checked = !this.mLauncher.MIMEInfo.alwaysAskBeforeHandling; } // Position it. if ( this.mDialog.opener ) { this.mDialog.moveToAlertPosition(); } else { this.mDialog.sizeToContent(); this.mDialog.centerWindowOnScreen(); } // Set initial focus this.dialogElement( "mode" ).focus(); this.mDialog.document.documentElement.getButton("accept").disabled = true; const nsITimer = Components.interfaces.nsITimer; this._timer = Components.classes["@mozilla.org/timer;1"] .createInstance(nsITimer); this._timer.initWithCallback(this, 1000, nsITimer.TYPE_ONE_SHOT); }, // initIntro: initIntro: function(url, filename) { var intro = this.dialogElement( "intro" ); var desc = this.mLauncher.MIMEInfo.description; var text; if ( this.mReason == REASON_CANTHANDLE ) text = "intro."; else if (this.mReason == REASON_SERVERREQUEST ) text = "intro.attachment."; else if (this.mReason == REASON_TYPESNIFFED ) text = "intro.sniffed."; var modified; if (desc) modified = this.replaceInsert( this.getString( text + "label" ), 1, desc ); else modified = this.getString( text + "noDesc.label" ); modified = this.replaceInsert( modified, 2, this.mLauncher.MIMEInfo.MIMEType ); modified = this.replaceInsert( modified, 3, filename); modified = this.replaceInsert( modified, 4, this.getString( "brandShortName" )); // if mSourcePath is a local file, then let's use the pretty path name instead of an ugly // url... var pathString = url.prePath; try { var fileURL = url.QueryInterface(Components.interfaces.nsIFileURL); if (fileURL) { var fileObject = fileURL.file; if (fileObject) { var parentObject = fileObject.parent; if (parentObject) { pathString = parentObject.path; } } } } catch(ex) {} intro.firstChild.nodeValue = ""; intro.firstChild.nodeValue = modified; // Set the location text, which is separate from the intro text so it can be cropped var location = this.dialogElement( "location" ); location.value = pathString; location.setAttribute( "tooltiptext", this.mSourcePath ); }, _timer: null, notify: function (aTimer) { try { // The user may have already canceled the dialog. if (!this._blurred) this.mDialog.document.documentElement.getButton('accept').disabled = false; } catch (ex) {} this._timer = null; }, _blurred: false, onBlur: function(aEvent) { if (aEvent.target != this.mDialog.document) return; this._blurred = true; this.mDialog.document.documentElement.getButton("accept").disabled = true; }, onFocus: function(aEvent) { if (aEvent.target != this.mDialog.document) return; this._blurred = false; if (!this._timer) { // Don't enable the button if the initial timer is running var script = "document.documentElement.getButton('accept').disabled = false"; this.mDialog.setTimeout(script, 1000); } }, // Returns true iff opening the default application makes sense. openWithDefaultOK: function() { var result; // The checking is different on Windows... if ( this.mDialog.navigator.platform.indexOf( "Win" ) != -1 ) { // Windows presents some special cases. // We need to prevent use of "system default" when the file is // executable (so the user doesn't launch nasty programs downloaded // from the web), and, enable use of "system default" if it isn't // executable (because we will prompt the user for the default app // in that case). // Need to get temporary file and check for executable-ness. var tmpFile = this.mLauncher.targetFile; // Default is Ok if the file isn't executable (and vice-versa). result = !tmpFile.isExecutable(); } else { // On other platforms, default is Ok if there is a default app. // Note that nsIMIMEInfo providers need to ensure that this holds true // on each platform. result = this.mLauncher.MIMEInfo.hasDefaultHandler; } return result; }, // Set "default" application description field. initDefaultApp: function() { // Use description, if we can get one. var desc = this.mLauncher.MIMEInfo.defaultDescription; if ( desc ) { this.dialogElement( "useSystemDefault" ).label = this.replaceInsert( this.getString( "defaultApp" ), 1, desc ); } }, // getPath: getPath: function(file) { if (this.mIsMac) { return file.leafName || file.path; } return file.path; }, // initAppAndSaveToDiskValues: initAppAndSaveToDiskValues: function() { // Fill in helper app info, if there is any. this.chosenApp = this.mLauncher.MIMEInfo.preferredApplicationHandler; // Initialize "default application" field. this.initDefaultApp(); // Fill application name textbox. if (this.chosenApp && this.chosenApp.path) { this.dialogElement( "appPath" ).value = this.getPath(this.chosenApp); } var useDefault = this.dialogElement( "useSystemDefault" );; if (this.mLauncher.MIMEInfo.preferredAction == this.nsIMIMEInfo.useSystemDefault && this.mReason != REASON_SERVERREQUEST) { // Open (using system default). useDefault.radioGroup.selectedItem = useDefault; } else if (this.mLauncher.MIMEInfo.preferredAction == this.nsIMIMEInfo.useHelperApp && this.mReason != REASON_SERVERREQUEST) { // Open with given helper app. var openUsing = this.dialogElement( "openUsing" ); openUsing.radioGroup.selectedItem = openUsing; } else { // Save to disk. var saveToDisk = this.dialogElement( "saveToDisk" ); saveToDisk.radioGroup.selectedItem = saveToDisk; } // If we don't have a "default app" then disable that choice. if ( !this.openWithDefaultOK() ) { // Disable that choice. useDefault.hidden = true; // If that's the default, then switch to "save to disk." if ( useDefault.selected ) { useDefault.radioGroup.selectedItem = this.dialogElement( "saveToDisk" ); } } // Enable/Disable choose application button and textfield this.toggleChoice(); }, // Enable pick app button if the user chooses that option. toggleChoice : function () { // See what option is selected. var openUsing = this.dialogElement( "openUsing" ).selected; this.dialogElement( "chooseApp" ).disabled = !openUsing; // appPath is always disabled on Mac this.dialogElement( "appPath" ).disabled = !openUsing || this.mIsMac; this.updateOKButton(); }, // Returns the user-selected application helperAppChoice: function() { var result = this.chosenApp; if (!this.mIsMac) { var typed = this.dialogElement( "appPath" ).value; // First, see if one was chosen via the Choose... button. if ( result ) { // Verify that the user didn't type in something different later. if ( typed != result.path ) { // Use what was typed in. try { result.QueryInterface( Components.interfaces.nsILocalFile ).initWithPath( typed ); } catch( e ) { // Invalid path was typed. result = null; } } } else { // The user didn't use the Choose... button, try using what they typed in. result = Components.classes[ "@mozilla.org/file/local;1" ] .createInstance( Components.interfaces.nsILocalFile ); try { result.initWithPath( typed ); } catch( e ) { result = null; } } // Remember what was chosen. this.chosenApp = result; } return result; }, updateOKButton: function() { var ok = false; if ( this.dialogElement( "saveToDisk" ).selected ) { // This is always OK. ok = true; } else if ( this.dialogElement( "useSystemDefault" ).selected ) { // No app need be specified in this case. ok = true; } else { // 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( "appPath" ).value ); } // 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. // However, we don't want to change the action all nsIMIMEInfo objects to // saveToDisk if mReason is REASON_SERVERREQUEST. if ( this.dialogElement( "saveToDisk" ).selected && this.mReason != REASON_SERVERREQUEST ) { needUpdate = this.mLauncher.MIMEInfo.preferredAction != this.nsIMIMEInfo.saveToDisk; if ( needUpdate ) this.mLauncher.MIMEInfo.preferredAction = this.nsIMIMEInfo.saveToDisk; } else if ( this.dialogElement( "useSystemDefault" ).selected ) { needUpdate = this.mLauncher.MIMEInfo.preferredAction != this.nsIMIMEInfo.useSystemDefault; if ( needUpdate )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -