Hiding dropdown fields in a variable (Rename Var, Create new Var)

519 views
Skip to first unread message

Sandeep Nimmagadda

unread,
Jun 14, 2016, 1:16:46 PM6/14/16
to Blockly
Hi,

Can someone show me how to hide dropdown options when selecting a variable such as Rename variable, create new variable.

Thank you!

Wolfgang Koehler

unread,
Jun 15, 2016, 4:52:04 AM6/15/16
to Blockly

Anthony Morphett

unread,
Jun 15, 2016, 6:30:50 PM6/15/16
to blo...@googlegroups.com
Hi Sandeep

The variable menu is created in Blockly.FieldVariable.dropdownCreate, see field_variable.js line 127 . To remove the 'new variable' or 'rename variable' you will have to modify Blockly.FieldVariable.dropdownCreate. Try something like the following, it should work anywhere in your main .js file.

Blockly.FieldVariable.dropdownCreate = function () {
  if (this.sourceBlock_ && this.sourceBlock_.workspace) {
    var variableList =
        Blockly.Variables.allVariables(this.sourceBlock_.workspace);
  } else {
    var variableList = [];
  }
  // Ensure that the currently selected variable is an option.
  var name = this.getText();
  if (name && variableList.indexOf(name) == -1) {
    variableList.push(name);
  }
  variableList.sort(goog.string.caseInsensitiveCompare);

/* Next two lines add the 'New variable' and 'Rename variable' options so we comment them out */
//  variableList.push(Blockly.Msg.RENAME_VARIABLE);
//  variableList.push(Blockly.Msg.NEW_VARIABLE);

  // Variables are not language-specific, use the name as both the user-facing
  // text and the internal representation.
  var options = [];
  for (var x = 0; x < variableList.length; x++) {
    options[x] = [variableList[x], variableList[x]];
  }
  return options;
};

Regards,
Anthony


--
You received this message because you are subscribed to the Google Groups "Blockly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blockly+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Sandeep Nimmagadda

unread,
Jun 30, 2016, 5:17:38 PM6/30/16
to Blockly
Hi Anthony,

I tried doing this, but I'm still getting the options. I know logically I shouldn't be getting these options since i commented them out. Do you know why is this not working?

Thank you!

Neil Fraser

unread,
Jun 30, 2016, 8:41:44 PM6/30/16
to blo...@googlegroups.com
Just a quick check that you are aware of the compile cycle needed when editing the core directory.
First check tests/playground.html to see if your changes are taking effect since the playground uses the uncompressed code.  If they look good there, then recompile with 'build.py' to generate the compressed JS files.

--
You received this message because you are subscribed to the Google Groups "Blockly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blockly+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages