B2G/gecko/browser/devtools/scratchpad/scratchpad.js
/**
   * Read the content of a file and put it into the textbox.
   *
   * @param nsILocalFile aFile
   *        The file you want to save the textbox content into.
   * @param boolean aSilentError
   *        True if you do not want to display an error when file load fails,
   *        false otherwise.
   * @param function aCallback
   *        Optional function you want to call when file load completes. It will
   *        get the following arguments:
   *        1) the nsresult status code for the import operation.
   *        2) the data that was read from the file, if any.
   */
Read the content of a file and put it into the textbox.
@param nsILocalFile aFile
The file you want to save the textbox content into.
@param boolean aSilentError
True if you do not want to display an error when file load fails,
false otherwise.
@param function aCallback
Optional function you want to call when file load completes. It will
get the following arguments:
1) the nsresult status code for the import operation.
2) the data that was read from the file, if any.
Read the content of a file and put it into the textbox . @param nsILocalFile aFile The file you want to save the textbox content into . @param boolean aSilentError True if you do not want to display an error when file load fails false otherwise . @param function aCallback Optional function you want to call when file load completes . It will get the following arguments : 1 ) the nsresult status code for the import operation . 2 ) the data that was read from the file if any .
function SP_importFromFile(aFile, aSilentError, aCallback)
  {
    let channel = NetUtil.newChannel(aFile);
    channel.contentType = "application/javascript";
    let self = this;
    NetUtil.asyncFetch(channel, function(aInputStream, aStatus) {
      let content = null;
      if (Components.isSuccessCode(aStatus)) {
        let converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"].
                        createInstance(Ci.nsIScriptableUnicodeConverter);
        converter.charset = "UTF-8";
        content = NetUtil.readInputStreamToString(aInputStream,
                                                  aInputStream.available());
        content = converter.ConvertToUnicode(content);
        self.setText(content);
        self.editor.resetUndo();
      }
      else if (!aSilentError) {
        window.alert(self.strings.GetStringFromName("openFile.failed"));
      }
      if (aCallback) {
        aCallback.call(self, aStatus, content);
      }
    });
  }
function SP_importFromFile ( aFile , aSilentError , aCallback ) { let channel = NetUtil . newChannel ( aFile ) ; channel . contentType = "application/javascript" ; let self = this ; NetUtil . asyncFetch ( channel , function ( aInputStream , aStatus ) { let content = null ; if ( Components . isSuccessCode ( aStatus ) ) { let converter = Cc [ "@mozilla.org/intl/scriptableunicodeconverter" ] . createInstance ( Ci . nsIScriptableUnicodeConverter ) ; converter . charset = "UTF-8" ; content = NetUtil . readInputStreamToString ( aInputStream , aInputStream . available ( ) ) ; content = converter . ConvertToUnicode ( content ) ; self . setText ( content ) ; self . editor . resetUndo ( ) ; } else if ( ! aSilentError ) { window . alert ( self . strings . GetStringFromName ( "openFile.failed" ) ) ; } if ( aCallback ) { aCallback . call ( self , aStatus , content ) ; } } ) ; }
Read the content of a file and put it into the textbox.
Read the content of a file and put it into the textbox .
// Prevent file type detection.