B2G/gecko/browser/devtools/scratchpad/scratchpad.js
/**
   * Open a file to edit in the Scratchpad.
   *
   * @param integer aIndex
   *        Optional integer: clicked menuitem in the 'Open Recent'-menu.
   */
Open a file to edit in the Scratchpad.
@param integer aIndex
Optional integer: clicked menuitem in the 'Open Recent'-menu.
Open a file to edit in the Scratchpad . @param integer aIndex Optional integer : clicked menuitem in the ' Open Recent ' - menu .
function SP_openFile(aIndex)
  {
    let promptCallback = function(aFile) {
      this.promptSave(function(aCloseFile, aSaved, aStatus) {
        let shouldOpen = aCloseFile;
        if (aSaved && !Components.isSuccessCode(aStatus)) {
          shouldOpen = false;
        }
        if (shouldOpen) {
          this._skipClosePrompt = true;
          let file;
          if (aFile) {
            file = aFile;
          } else {
            file = Components.classes["@mozilla.org/file/local;1"].
                   createInstance(Components.interfaces.nsILocalFile);
            let filePath = this.getRecentFiles()[aIndex];
            file.initWithPath(filePath);
          }
          this.setFilename(file.path);
          this.importFromFile(file, false);
          this.setRecentFile(file);
        }
      }.bind(this));
    }.bind(this);
    if (aIndex > -1) {
      promptCallback();
    } else {
      let fp = Cc["@mozilla.org/filepicker;1"].createInstance(Ci.nsIFilePicker);
      let fpCallback = function fpCallback_done(aResult) {
        if (aResult != Ci.nsIFilePicker.returnCancel) {
          promptCallback(fp.file);
        }
      };
      fp.init(window, this.strings.GetStringFromName("openFile.title"),
              Ci.nsIFilePicker.modeOpen);
      fp.defaultString = "";
      fp.open(fpCallback);
    }
  }
function SP_openFile ( aIndex ) { let promptCallback = function ( aFile ) { this . promptSave ( function ( aCloseFile , aSaved , aStatus ) { let shouldOpen = aCloseFile ; if ( aSaved && ! Components . isSuccessCode ( aStatus ) ) { shouldOpen = false ; } if ( shouldOpen ) { this . _skipClosePrompt = true ; let file ; if ( aFile ) { file = aFile ; } else { file = Components . classes [ "@mozilla.org/file/local;1" ] . createInstance ( Components . interfaces . nsILocalFile ) ; let filePath = this . getRecentFiles ( ) [ aIndex ] ; file . initWithPath ( filePath ) ; } this . setFilename ( file . path ) ; this . importFromFile ( file , false ) ; this . setRecentFile ( file ) ; } } . bind ( this ) ) ; } . bind ( this ) ; if ( aIndex > - 1 ) { promptCallback ( ) ; } else { let fp = Cc [ "@mozilla.org/filepicker;1" ] . createInstance ( Ci . nsIFilePicker ) ; let fpCallback = function fpCallback_done ( aResult ) { if ( aResult != Ci . nsIFilePicker . returnCancel ) { promptCallback ( fp . file ) ; } } ; fp . init ( window , this . strings . GetStringFromName ( "openFile.title" ) , Ci . nsIFilePicker . modeOpen ) ; fp . defaultString = "" ; fp . open ( fpCallback ) ; } }
Open a file to edit in the Scratchpad.
Open a file to edit in the Scratchpad .