function(options) {
    var fieldName = 'VARIABLE';
    if (this.isCollapsed()) {
      return;
    }
    var currentVarName = this.getField(fieldName).text_;
    if (!this.isInFlyout) {
      var variablesList = this.workspace.getVariablesOfType('');
      variablesList.sort(function(a, b) {
        return Blockly.scratchBlocksUtils.compareStrings(a.name, b.name);
      });
      for (var i = 0; i < variablesList.length; i++) {
        var varName = variablesList[i].name;
        if (varName == currentVarName) continue;
        var option = {enabled: true};
        option.text = varName;

        option.callback =
            Blockly.Constants.Data.VARIABLE_OPTION_CALLBACK_FACTORY(this,
                variablesList[i].getId(), fieldName);
        options.push(option);
      }
    } else {
      var renameOption = {
        text: Blockly.Msg.RENAME_VARIABLE,
        enabled: true,
        callback: Blockly.Constants.Data.RENAME_OPTION_CALLBACK_FACTORY(this,
            fieldName)
      };
      var deleteOption = {
        text: Blockly.Msg.DELETE_VARIABLE.replace('%1', currentVarName),
        enabled: true,
        callback: Blockly.Constants.Data.DELETE_OPTION_CALLBACK_FACTORY(this,
            fieldName)
      };
      options.push(renameOption);
      options.push(deleteOption);
    }
  }
function(options) {
    var fieldName = 'VARIABLE';
    if (this.isCollapsed()) {
      return;
    }
    var currentVarName = this.getField(fieldName).text_;
    if (!this.isInFlyout) {
      var variablesList = this.workspace.getVariablesOfType('');
      variablesList.sort(function(a, b) {
        return Blockly.scratchBlocksUtils.compareStrings(a.name, b.name);
      });
      for (var i = 0; i < variablesList.length; i++) {
        var varName = variablesList[i].name;
        if (varName == currentVarName) continue;
        var option = {enabled: true};
        option.text = varName;

        option.callback =
            Blockly.Constants.Data.VARIABLE_OPTION_CALLBACK_FACTORY(this,
                variablesList[i].getId(), fieldName);
        options.push(option);
      }
    } else {
      var renameOption = {
        text: Blockly.Msg.RENAME_VARIABLE,
        enabled: true,
        callback: Blockly.Constants.Data.RENAME_OPTION_CALLBACK_FACTORY(this,
            fieldName)
      };
      var deleteOption = {
        text: Blockly.Msg.DELETE_VARIABLE.replace('%1', currentVarName),
        enabled: true,
        callback: Blockly.Constants.Data.DELETE_OPTION_CALLBACK_FACTORY(this,
            fieldName)
      };
      options.push(renameOption);
      options.push(deleteOption);
    }
  }
function ( options ) { var fieldName = 'VARIABLE' ; if ( this . isCollapsed ( ) ) { return ; } var currentVarName = this . getField ( fieldName ) . text_ ; if ( ! this . isInFlyout ) { var variablesList = this . workspace . getVariablesOfType ( '' ) ; variablesList . sort ( function ( a , b ) { return Blockly . scratchBlocksUtils . compareStrings ( a . name , b . name ) ; } ) ; for ( var i = 0 ; i < variablesList . length ; i ++ ) { var varName = variablesList [ i ] . name ; if ( varName == currentVarName ) continue ; var option = { enabled : true } ; option . text = varName ; option . callback = Blockly . Constants . Data . VARIABLE_OPTION_CALLBACK_FACTORY ( this , variablesList [ i ] . getId ( ) , fieldName ) ; options . push ( option ) ; } } else { var renameOption = { text : Blockly . Msg . RENAME_VARIABLE , enabled : true , callback : Blockly . Constants . Data . RENAME_OPTION_CALLBACK_FACTORY ( this , fieldName ) } ; var deleteOption = { text : Blockly . Msg . DELETE_VARIABLE . replace ( '%1' , currentVarName ) , enabled : true , callback : Blockly . Constants . Data . DELETE_OPTION_CALLBACK_FACTORY ( this , fieldName ) } ; options . push ( renameOption ) ; options . push ( deleteOption ) ; } }
Add context menu option to change the selected variable.
@param {!Array} options List of menu options to add to.
@this Blockly.Block
Add context menu option to change the selected variable .
Add variable option to options array.