B2G/gecko/browser/devtools/scratchpad/scratchpad.js
/**
   * Export the textbox content to a file.
   *
   * @param nsILocalFile aFile
   *        The file where you want to save the textbox content.
   * @param boolean aNoConfirmation
   *        If the file already exists, ask for confirmation?
   * @param boolean aSilentError
   *        True if you do not want to display an error when file save fails,
   *        false otherwise.
   * @param function aCallback
   *        Optional function you want to call when file save completes. It will
   *        get the following arguments:
   *        1) the nsresult status code for the export operation.
   */
Export the textbox content to a file.
@param nsILocalFile aFile
The file where you want to save the textbox content.
@param boolean aNoConfirmation
If the file already exists, ask for confirmation.
@param boolean aSilentError
True if you do not want to display an error when file save fails,
false otherwise.
@param function aCallback
Optional function you want to call when file save completes. It will
get the following arguments:
1) the nsresult status code for the export operation.
Export the textbox content to a file . @param nsILocalFile aFile The file where you want to save the textbox content . @param boolean aNoConfirmation If the file already exists ask for confirmation . @param boolean aSilentError True if you do not want to display an error when file save fails false otherwise . @param function aCallback Optional function you want to call when file save completes . It will get the following arguments : 1 ) the nsresult status code for the export operation .
function SP_exportToFile(aFile, aNoConfirmation, aSilentError,
                                         aCallback)
  {
    if (!aNoConfirmation && aFile.exists() &&
        !window.confirm(this.strings.
                        GetStringFromName("export.fileOverwriteConfirmation"))) {
      return;
    }
    let fs = Cc["@mozilla.org/network/file-output-stream;1"].
             createInstance(Ci.nsIFileOutputStream);
    let modeFlags = 0x02 | 0x08 | 0x20;
    fs.init(aFile, modeFlags, 420 , fs.DEFER_OPEN);
    let converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"].
                    createInstance(Ci.nsIScriptableUnicodeConverter);
    converter.charset = "UTF-8";
    let input = converter.convertToInputStream(this.getText());
    let self = this;
    NetUtil.asyncCopy(input, fs, function(aStatus) {
      if (!aSilentError && !Components.isSuccessCode(aStatus)) {
        window.alert(self.strings.GetStringFromName("saveFile.failed"));
      }
      if (aCallback) {
        aCallback.call(self, aStatus);
      }
    });
  }
function SP_exportToFile ( aFile , aNoConfirmation , aSilentError , aCallback ) { if ( ! aNoConfirmation && aFile . exists ( ) && ! window . confirm ( this . strings . GetStringFromName ( "export.fileOverwriteConfirmation" ) ) ) { return ; } let fs = Cc [ "@mozilla.org/network/file-output-stream;1" ] . createInstance ( Ci . nsIFileOutputStream ) ; let modeFlags = 0x02 | 0x08 | 0x20 ; fs . init ( aFile , modeFlags , 420 , fs . DEFER_OPEN ) ; let converter = Cc [ "@mozilla.org/intl/scriptableunicodeconverter" ] . createInstance ( Ci . nsIScriptableUnicodeConverter ) ; converter . charset = "UTF-8" ; let input = converter . convertToInputStream ( this . getText ( ) ) ; let self = this ; NetUtil . asyncCopy ( input , fs , function ( aStatus ) { if ( ! aSilentError && ! Components . isSuccessCode ( aStatus ) ) { window . alert ( self . strings . GetStringFromName ( "saveFile.failed" ) ) ; } if ( aCallback ) { aCallback . call ( self , aStatus ) ; } } ) ; }
Export the textbox content to a file.
Export the textbox content to a file .
/* 0644 */