variables.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574
  1. /**
  2. * @license
  3. * Visual Blocks Editor
  4. *
  5. * Copyright 2012 Google Inc.
  6. * https://developers.google.com/blockly/
  7. *
  8. * Licensed under the Apache License, Version 2.0 (the "License");
  9. * you may not use this file except in compliance with the License.
  10. * You may obtain a copy of the License at
  11. *
  12. * http://www.apache.org/licenses/LICENSE-2.0
  13. *
  14. * Unless required by applicable law or agreed to in writing, software
  15. * distributed under the License is distributed on an "AS IS" BASIS,
  16. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17. * See the License for the specific language governing permissions and
  18. * limitations under the License.
  19. */
  20. /**
  21. * @fileoverview Variable blocks for Blockly.
  22. * @author fraser@google.com (Neil Fraser)
  23. */
  24. 'use strict';
  25. goog.provide('Blockly.Blocks.variables');
  26. goog.require('Blockly.Blocks');
  27. Blockly.Blocks['variables_get'] = {
  28. /**
  29. * Block for variable getter.
  30. * @this Blockly.Block
  31. */
  32. init: function() {
  33. // this.initialized_type = 0; // for blockscad - to keep onchange from churning
  34. this.setHelpUrl(Blockly.Msg.VARIABLES_GET_HELPURL);
  35. this.setColour(Blockscad.Toolbox.HEX_VARIABLE);
  36. this.appendDummyInput()
  37. .appendField(new Blockly.FieldVariable(
  38. Blockly.Msg.VARIABLES_DEFAULT_NAME), 'VAR');
  39. this.setOutput(true);
  40. this.setTooltip(Blockly.Msg.VARIABLES_GET_TOOLTIP);
  41. this.contextMenuMsg_ = Blockly.Msg.VARIABLES_GET_CREATE_SET;
  42. // get my "type" from my corresponding variables_set block
  43. var all_of_them = Blockly.Variables.getInstances(this.getFieldValue('VAR'), this.workspace);
  44. // console.log(all_of_them);
  45. var found_it = 0;
  46. for (var i = 0; i < all_of_them.length; i++) {
  47. if (all_of_them[i].type == 'variables_set') {
  48. this.outputConnection.setCheck(all_of_them[i].myType_);
  49. // console.log("vars_get " + this.id + " was initialized to " + all_of_them[i].myType_);
  50. found_it = 1;
  51. break;
  52. }
  53. if (all_of_them[i].type == 'controls_for' || all_of_them[i].type == 'controls_for_chainhull') {
  54. this.outputConnection.setCheck(null);
  55. found_it = 1;
  56. }
  57. }
  58. if (!found_it) {
  59. // this has no variables_set block... Could be from a procedure.
  60. // since I don't know it's type, set it to null.
  61. // console.log("is there a variable instance from a procedure here?");
  62. this.outputConnection.setCheck(null);
  63. }
  64. },
  65. contextMenuType_: 'variables_set',
  66. // /**
  67. // * Return all variables referenced by this block.
  68. // * @return {!Array.<string>} List of variable names.
  69. // * @this Blockly.Block
  70. // */
  71. // getVars: function() {
  72. // return [this.getFieldValue('VAR')];
  73. // },
  74. // /**
  75. // * Notification that a variable is renaming.
  76. // * If the name matches one of this block's variables, rename it.
  77. // * @param {string} oldName Previous name of variable.
  78. // * @param {string} newName Renamed variable.
  79. // * @this Blockly.Block
  80. // */
  81. // renameVar: function(oldName, newName) {
  82. // if (Blockly.Names.equals(oldName, this.getFieldValue('VAR'))) {
  83. // this.setFieldValue(newName, 'VAR');
  84. // }
  85. // },
  86. /**
  87. * onchange: happens on EVERY WORKSPACE CHANGE
  88. * because I need to type variables_get blocks before the user
  89. * has a chance to try plugging them in
  90. * - could I do this code during init? Would that make sense?
  91. */
  92. // onchange: function() {
  93. // if (this.initialized_type == 0) {
  94. // // console.log("initializing a new variables_get: id ", this.id);
  95. // this.initialized_type = 1;
  96. // // get my "type" from my corresponding variables_set block
  97. // var all_of_them = Blockly.Variables.getInstances(this.getFieldValue('VAR'), this.workspace);
  98. // var found_it = 0;
  99. // for (var i = 0; i < all_of_them.length; i++) {
  100. // if (all_of_them[i].type == 'variables_set') {
  101. // this.outputConnection.setCheck(all_of_them[i].myType_);
  102. // console.log("vars_get " + this.id + " was initialized to " + all_of_them[i].myType_);
  103. // found_it = 1;
  104. // break;
  105. // }
  106. // if (all_of_them[i].type == 'controls_for' || all_of_them[i].type == 'controls_for_chainhull') {
  107. // this.outputConnection.setCheck(null);
  108. // found_it = 1;
  109. // }
  110. // }
  111. // if (!found_it) {
  112. // // this has no variables_set block... Could be from a procedure.
  113. // // since I don't know it's type, set it to null.
  114. // // console.log("is there a variable instance from a procedure here?");
  115. // this.outputConnection.setCheck(null);
  116. // }
  117. // }
  118. // },
  119. /**
  120. * Add menu option to create getter/setter block for this setter/getter.
  121. * @param {!Array} options List of menu options to add to.
  122. * @this Blockly.Block
  123. */
  124. customContextMenu: function(options) {
  125. var option = {enabled: true};
  126. var name = this.getFieldValue('VAR');
  127. option.text = this.contextMenuMsg_.replace('%1', name);
  128. var xmlField = goog.dom.createDom('field', null, name);
  129. xmlField.setAttribute('name', 'VAR');
  130. var xmlBlock = goog.dom.createDom('block', null, xmlField);
  131. xmlBlock.setAttribute('type', this.contextMenuType_);
  132. option.callback = Blockly.ContextMenu.callbackFactory(this, xmlBlock);
  133. options.push(option);
  134. // for BlocksCAD,
  135. var option = {enabled: true};
  136. option.text = Blockscad.Msg.HIGHLIGHT_INSTANCES.replace("%1", name);
  137. var workspace = this.workspace;
  138. var thisVar = this;
  139. option.callback = function() {
  140. var instances = Blockly.Variables.getInstances(name,workspace);
  141. workspace.clearBacklight();
  142. thisVar.unselect();
  143. for (var i = 0; instances && i < instances.length; i++) {
  144. instances[i] && instances[i].backlight();
  145. // if caller block is in a collapsed parent, highlight collapsed parent too
  146. var others = instances[i].collapsedParents();
  147. if (others)
  148. for (var j=0; j < others.length; j++)
  149. others[j].backlight();
  150. }
  151. };
  152. options.push(option);
  153. }
  154. };
  155. Blockly.Blocks['variables_set'] = {
  156. /**
  157. * Block for variable setter.
  158. * @this Blockly.Block
  159. */
  160. init: function() {
  161. this.myType_ = null; // for blocksCAD
  162. this.backlightBlocks = []; // for blocksCAD
  163. this.jsonInit({
  164. "message0": Blockly.Msg.VARIABLES_SET,
  165. "args0": [
  166. {
  167. "type": "field_variable",
  168. "name": "VAR",
  169. "variable": Blockly.Msg.VARIABLES_DEFAULT_NAME
  170. },
  171. {
  172. "type": "input_value",
  173. "name": "VALUE"
  174. }
  175. ],
  176. "inputsInline": true
  177. });
  178. this.setHelpUrl(Blockly.Msg.VARIABLES_SET_HELPURL);
  179. this.setColour(Blockscad.Toolbox.HEX_VARIABLE);
  180. // this.setPreviousStatement(true,['VariableSet']);
  181. // this.setNextStatement(true, ['VariableSet','CAG','CSG']);
  182. this.setPreviousStatement(true);
  183. this.setNextStatement(true);
  184. this.setTooltip(Blockly.Msg.VARIABLES_SET_TOOLTIP);
  185. this.contextMenuMsg_ = Blockly.Msg.VARIABLES_SET_CREATE_GET;
  186. },
  187. contextMenuType_: 'variables_get',
  188. // g
  189. // * Return all variables referenced by this block.
  190. // * @return {!Array.<string>} List of variable names.
  191. // * @this Blockly.Block
  192. // getVars: function() {
  193. // return [this.getFieldValue('VAR')];
  194. // },
  195. /**
  196. * if this variable is set to a value, set the associated variable blocks to
  197. * the type of the value block.
  198. * @this Blockly.Block
  199. */
  200. // setType: function(type) { // for blocksCAD
  201. // console.log("in variable_set setType: old:" + this.myType_ + " and new:" + type);
  202. // if (!this.workspace) {
  203. // // Block has been deleted.
  204. // return;
  205. // }
  206. // if (this.myType_ == type) {
  207. // console.log("type didn't actually change. Returning without doing work.");
  208. // return;
  209. // }
  210. // var oldtype = this.myType_;
  211. // // var instances = this.getVars();
  212. // var instances = Blockly.Variables.getInstances(this.getFieldValue('VAR'), this.workspace);
  213. // var numBumped = [];
  214. // var parentAccepts;
  215. // // go through instances, pulling out the variables_get blocks.
  216. // // if the variables have a parent block, they might need to get bumped
  217. // // console.log("firing events now - something should have been bumped");
  218. // // lets get the group event
  219. // var eventGroup = true;
  220. // if (Blockscad.workspace.undoStack_.length)
  221. // eventGroup = Blockscad.workspace.undoStack_[Blockscad.workspace.undoStack_.length - 1].group;
  222. // // console.log("event group is: ", eventGroup);
  223. // Blockly.Events.setGroup(eventGroup);
  224. // if (instances.length > 0) {
  225. // for (var i = 0; i < instances.length; i++) {
  226. // // console.log("found an instance: ", instances[i].id , " ", instances[i].type);
  227. // if (instances[i].type != "variables_get")
  228. // continue;
  229. // var parent = instances[i].getParent();
  230. // if (type != null) {
  231. // // this is a variables_get block, so the parent is the block connected
  232. // // to the output connection. let's handle any bumpage that occurs.
  233. // if (parent) {
  234. // // console.log("found instance with parent: ", parent.type);
  235. // parentAccepts = instances[i].outputConnection.targetConnection.check_;
  236. // if (parentAccepts != null)
  237. // parentAccepts = parentAccepts[0];
  238. // // console.log("types parent accepts: ",parentAccepts);
  239. // // take care of bumps
  240. // if (parentAccepts != null && parentAccepts != type[0]) {
  241. // // I have a type mismatch with this variable. it is going to be bumped.
  242. // // console.log("block " + instances[i].id + " will be kicked out.");
  243. // numBumped.push(instances[i]);
  244. // // instances[i].backlight();
  245. // // this.backlightBlocks.push(instances[i].id);
  246. // // if the instance is in a collapsed stack, find collapsed parent and expand
  247. // var topBlock = instances[i].collapsedParents();
  248. // if (topBlock)
  249. // for (var j = 0; j < topBlock.length; j++)
  250. // topBlock[j].setCollapsed(false);
  251. // }
  252. // } // end if (parent)
  253. // } // end if type == null
  254. // // actually set the type here
  255. // // console.log("setting block :" + instances[i].id + " to type " + type);
  256. // instances[i].outputConnection.setCheck(type);
  257. // if (Blockly.Events.isEnabled() && numBumped.length) {
  258. // Blockly.Events.fire(new Blockly.Events.Typing(instances[i], oldtype,type));
  259. // }
  260. // // what if a parent is a variables_set of a different variable?
  261. // // then I want to call Blockscad.assignVarTypes for that parent.
  262. // if (parent && parent.type == "variables_set") {
  263. // // console.log("found a variables_set parent from inside variables code");
  264. // console.log("setting var_set type in loopable area");
  265. // this.myType_ = type;
  266. // Blockscad.assignVarTypes(parent);
  267. // }
  268. // } // end looping through instances
  269. // } // end if instances.length > 0
  270. // Blockly.Events.setGroup(false);
  271. // if (numBumped.length) {
  272. // // I've already changed the types, so bumping should have happened. Now do the
  273. // // backlighting and warning text.
  274. // for (var i = 0; i < numBumped.length; i++) {
  275. // numBumped[i].backlight();
  276. // this.backlightBlocks.push(numBumped[i].id);
  277. // }
  278. // var text = '';
  279. // // text += numBumped.length + " ";
  280. // // took out the name so I wouldn't have to deal with renaming the proc.
  281. // text += Blockscad.Msg.VARIABLES_BUMPED_ONE.replace("%1", numBumped.length) + '\n';
  282. // text += Blockscad.Msg.VARIABLES_BUMPED_TWO.replace("%1",this.getFieldValue('VAR')).replace("%2", parentAccepts).replace("%3", type[0]);
  283. // this.setWarningText(text);
  284. // }
  285. // else
  286. // this.setWarningText(null);
  287. // // set the variables_set type - important for stopping infinite typing loops
  288. // console.log("setting variable set type");
  289. // this.myType_ = type;
  290. // }, // end for blocksCAD
  291. setType: function(type) { // for blocksCAD
  292. if (!this.workspace) {
  293. // Block has been deleted.
  294. return;
  295. }
  296. if (type != null && !goog.isArray(type)) {
  297. type = [type];
  298. }
  299. // console.log("in variable_set setType: old:" + this.myType_ + " and new:" + type);
  300. if (Blockscad.arraysEqual(type, this.myType_)) {
  301. // console.log("type didn't actually change. Returning without doing work.");
  302. return;
  303. }
  304. var oldtype = this.myType_;
  305. // set the type of the setter.
  306. this.myType_ = type;
  307. var instances = Blockly.Variables.getInstances(this.getFieldValue('VAR'), this.workspace);
  308. var numBumped = [];
  309. var parentAccepts;
  310. // go through instances, pulling out the variables_get blocks.
  311. // if the variables have a parent block, they might need to get bumped
  312. // Group the events during bumping so undo will work as a unit.
  313. var eventGroup = true;
  314. if (Blockscad.workspace.undoStack_.length)
  315. eventGroup = Blockscad.workspace.undoStack_[Blockscad.workspace.undoStack_.length - 1].group;
  316. // console.log("event group is: ", eventGroup);
  317. Blockly.Events.setGroup(eventGroup);
  318. if (instances.length > 0) {
  319. for (var i = 0; i < instances.length; i++) {
  320. // console.log("found an instance: ", instances[i].id , " ", instances[i].type);
  321. if (instances[i].type != "variables_get")
  322. continue;
  323. var parent = instances[i].getParent();
  324. if (this.myType_ != null) {
  325. // this is a variables_get block, so the parent is the block connected
  326. // to the output connection. let's handle any bumpage that occurs.
  327. if (parent) {
  328. // console.log("found instance with parent: ", parent.type);
  329. parentAccepts = instances[i].outputConnection.targetConnection.check_;
  330. if (parentAccepts != null)
  331. parentAccepts = parentAccepts[0];
  332. // console.log("Test for bumping. types were: " + parentAccepts + " and " + type[0]);
  333. // take care of bumps
  334. if (parentAccepts != null && type != null && parentAccepts != type[0]) {
  335. // console.log(" variable block " + instances[i].id + " will be kicked out.");
  336. // console.log("parent accepts: " + parentAccepts + ", type is:", type);
  337. numBumped.push(instances[i]);
  338. // if the instance is in a collapsed stack, find collapsed parent and expand
  339. var topBlock = instances[i].collapsedParents();
  340. if (topBlock)
  341. for (var j = 0; j < topBlock.length; j++)
  342. topBlock[j].setCollapsed(false);
  343. }
  344. } // end if (parent)
  345. } // end if type == null
  346. // actually set the caller's type here
  347. // console.log("setting block :" + instances[i].id + " to type " + type);
  348. instances[i].outputConnection.setCheck(type);
  349. if (Blockly.Events.isEnabled() && numBumped.length) {
  350. Blockly.Events.fire(new Blockly.Events.Typing(instances[i], oldtype,type));
  351. }
  352. // console.log("trying to call hasParentOfType",callers[i]);
  353. // caller has a parent that is a setter - either a variable or a function definition.
  354. var setterParent = Blockscad.hasParentOfType(instances[i], "procedures_defreturn");
  355. if (!setterParent)
  356. setterParent = Blockscad.hasParentOfType(instances[i],"variables_set");
  357. // Be careful here. Even if you have a setter parent, if there is a ternary parent,
  358. // it will _change_ your type from boolean to number. Don't set your setter parent's
  359. // type to boolean!
  360. // of course, right now ternary typing is borked anyway, because it ALWAYS returns a number.
  361. // though you really should be able to have shapes, text, etc coming out of that.
  362. // but for now, I'm just going to ignore setting a type if a ternary parent is involved.
  363. var ternaryParent = Blockscad.hasParentOfType(instances[i], "logic_ternary");
  364. setTimeout(function() {
  365. // console.log("this caller function is inside a setter. Set its type to: ",type);
  366. if (setterParent && !ternaryParent) setterParent.setType(type);
  367. }, 0);
  368. } // end looping through instances
  369. } // end if instances.length > 0
  370. Blockly.Events.setGroup(false);
  371. if (numBumped.length) {
  372. // I've already changed the types, so bumping should have happened. Now do the
  373. // backlighting and warning text.
  374. for (var i = 0; i < numBumped.length; i++) {
  375. numBumped[i].backlight();
  376. this.backlightBlocks.push(numBumped[i].id);
  377. }
  378. var text = '';
  379. // text += numBumped.length + " ";
  380. // took out the name so I wouldn't have to deal with renaming the proc.
  381. text += Blockscad.Msg.VARIABLES_BUMPED_ONE.replace("%1", numBumped.length) + '\n';
  382. text += Blockscad.Msg.VARIABLES_BUMPED_TWO.replace("%1",this.getFieldValue('VAR')).replace("%2", parentAccepts).replace("%3", type);
  383. this.setWarningText(text);
  384. }
  385. else
  386. this.setWarningText(null);
  387. }, // end for blocksCAD
  388. // setType: function(type, drawMe) {
  389. // if (!this.workspace) {
  390. // // Block has been deleted.
  391. // return;
  392. // }
  393. // // // compare to see if type matches this.myType_
  394. // var oldtype = this.myType_;
  395. // var ret = this.getInput('RETURN');
  396. // // console.log("in setType for function. here is the input:",ret);
  397. // if (ret.connection.targetConnection) {
  398. // if (ret.connection.targetConnection.check_ == 'Number')
  399. // type = 'Number';
  400. // else if (ret.connection.targetConnection.check_ == 'Boolean')
  401. // type = 'Boolean';
  402. // else if (ret.connection.targetConnection.check_ == 'String')
  403. // type = 'String';
  404. // else
  405. // type = null;
  406. // }
  407. // else type = null;
  408. // // console.log("starting func ST with oldtype:" + this.myType_ + " and newtype:" + type);
  409. // if (this.myType_ == type) {
  410. // console.log("in func ST. returning because types didn't change.");
  411. // return;
  412. // }
  413. // // set the function def's type to what is now connected to its output
  414. // this.myType_ = type;
  415. // var callers = Blockly.Procedures.getCallers(this.getFieldValue('NAME'), this.workspace);
  416. // var numBumped = [];
  417. // var conType = null; // type of a caller's output connection
  418. // var parentAccepts;
  419. // // start grouping events in case some blocks are bumped out, so that undo will work easily.
  420. // var eventGroup = true;
  421. // if (Blockscad.workspace.undoStack_.length)
  422. // eventGroup = Blockscad.workspace.undoStack_[Blockscad.workspace.undoStack_.length - 1].group;
  423. // // console.log("event group is: ", eventGroup);
  424. // Blockly.Events.setGroup(eventGroup);
  425. // // now, set my caller block's types
  426. // if (callers.length) {
  427. // for (var i = 0; i < callers.length; i++) {
  428. // // the caller block only gets bumped if it has a parent.
  429. // var parent = callers[i].getParent();
  430. // // get caller's connection type here
  431. // if (parent) {
  432. // // console.log("found instance with parent: ", parent.type);
  433. // parentAccepts = callers[i].outputConnection.targetConnection.check_;
  434. // if (parentAccepts != null && goog.isArray(parentAccepts))
  435. // parentAccepts = parentAccepts[0];
  436. // var callerAccepts = callers[i].outputConnection.check_;
  437. // // take care of bumps
  438. // if (parentAccepts != null && this.myType_ != null && parentAccepts != this.myType_) {
  439. // // I have a type mismatch with this variable. it is going to be bumped.
  440. // // console.log("warning message! call block id", callers[i].id, "will be kicked out and backlit");
  441. // numBumped.push(callers[i]);
  442. // // instances[i].backlight();
  443. // // this.backlightBlocks.push(instances[i].id);
  444. // // if the instance is in a collapsed stack, find collapsed parent and expand
  445. // var topBlock = callers[i].collapsedParents();
  446. // if (topBlock)
  447. // for (var j = 0; j < topBlock.length; j++)
  448. // topBlock[j].setCollapsed(false);
  449. // }
  450. // } // end if (parent)
  451. // // change caller's type - this is the command that actually prompts Blockly to bump blocks out
  452. // // console.log("Set the caller's output check to ", this.myType_);
  453. // callers[i].outputConnection.setCheck(this.myType_);
  454. // if (this.myType_ == 'Number')
  455. // callers[i].category = 'NUMBER'
  456. // else if (this.myType_ == 'Boolean')
  457. // callers[i].category = 'BOOLEAN';
  458. // else if (this.myType_ == 'String')
  459. // callers[i].category == 'STRING';
  460. // else callers[i].category = 'UNKNOWN';
  461. // // console.log("tried to set caller type to ",this.myType_, callers[i]);
  462. // // if it was a bumping change, fire a typing event
  463. // if (Blockly.Events.isEnabled() && numBumped.length) {
  464. // Blockly.Events.fire(new Blockly.Events.Typing(callers[i], oldtype,type));
  465. // }
  466. // // if caller is inside of another setter block, that setter's type needs to be changed. Do so.
  467. // // note that this can lead to an infinite loop if procedures are circularly defined - that is why
  468. // // setType MUST exit immediately if it is called with the type not changing.
  469. // // what if a parent is a variables_set of a different variable?
  470. // // then I want to call Blockscad.assignVarTypes for that parent.
  471. // // console.log("trying to call hasParentOfType",callers[i]);
  472. // var setterParent = Blockscad.hasParentOfType(callers[i], "procedures_defreturn");
  473. // if (!setterParent)
  474. // setterParent = Blockscad.hasParentOfType(callers[i],"variables_set");
  475. // if (setterParent) {
  476. // setTimeout(function() {
  477. // console.log("this caller function is inside a setter. Set its type to: ",type);
  478. // setterParent.setType(type);
  479. // }, 0);
  480. // }
  481. // }
  482. // } // end of going through all callers to set their types.
  483. // // turn off event grouping
  484. // Blockly.Events.setGroup(false);
  485. // // handle backlighting and warning text - do this later so that
  486. // // the bumping process itself (which now selects and deselects the blocks) doesn't
  487. // // just immediately turn the backlighting off.
  488. // for (var k = 0; k < numBumped.length; k++) {
  489. // numBumped[k].backlight();
  490. // this.backlightBlocks.push(numBumped[k].id);
  491. // // finally, set a warning message on the procedure definition that counts how many callers were bumped.
  492. // var text = '';
  493. // text += Blockscad.Msg.BLOCKS_BUMPED_OUT_TYPES.replace("%1", numBumped.length).replace("%2", parentAccepts).replace("%3",type);
  494. // this.setWarningText(text);
  495. // }
  496. // },
  497. /**
  498. * Notification that a variable is renaming.
  499. * If the name matches one of this block's variables, rename it.
  500. * @param {string} oldName Previous name of variable.
  501. * @param {string} newName Renamed variable.
  502. * @this Blockly.Block
  503. */
  504. // renameVar: function(oldName, newName) {
  505. // if (Blockly.Names.equals(oldName, this.getFieldValue('VAR'))) {
  506. // this.setFieldValue(newName, 'VAR');
  507. // }
  508. // },
  509. customContextMenu: Blockly.Blocks['variables_get'].customContextMenu
  510. };