dicts.js 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 Dictionary blocks for Blockly.
  22. * @author acbart@vt.edu (Austin Cory Bart)
  23. */
  24. 'use strict';
  25. goog.provide('Blockly.Blocks.dicts');
  26. goog.require('Blockly.Blocks');
  27. Blockly.Blocks.dicts.HUE = 0;
  28. Blockly.Blocks['dict_get'] = {
  29. // Set element at index.
  30. init: function() {
  31. this.setColour(Blockly.Blocks.dicts.HUE);
  32. this.appendValueInput('ITEM');
  33. this.appendValueInput('DICT')
  34. .setCheck('dict')
  35. .appendField(Blockly.Msg.DICT_GET_TO);
  36. this.setInputsInline(false);
  37. this.setOutput(true);
  38. //this.setPreviousStatement(true);
  39. //this.setNextStatement(true);
  40. }
  41. };
  42. Blockly.Blocks['dict_get_literal'] = {
  43. // Set element at index.
  44. init: function() {
  45. this.setColour(Blockly.Blocks.dicts.HUE);
  46. this.appendValueInput('DICT')
  47. //.appendField('get') // TODO: fix this to be outside
  48. .appendField(this.newQuote_(true))
  49. .appendField(new Blockly.FieldTextInput(
  50. Blockly.Msg.DICTS_CREATE_WITH_ITEM_KEY),
  51. 'ITEM')
  52. .appendField(this.newQuote_(false))
  53. .setCheck('dict')
  54. .appendField(Blockly.Msg.DICT_GET_TO);
  55. this.setInputsInline(false);
  56. this.setOutput(true);
  57. //this.setPreviousStatement(true);
  58. //this.setNextStatement(true);
  59. },
  60. /**
  61. * Create an image of an open or closed quote.
  62. * @param {boolean} open True if open quote, false if closed.
  63. * @return {!Blockly.FieldImage} The field image of the quote.
  64. * @private
  65. */
  66. newQuote_: function(open) {
  67. if (open == this.RTL) {
  68. var file = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAKCAYAAACALL/6AAAA0UlEQVQY023QP0oDURSF8e8MImhlUIiCjWKhrUUK3YCIVkq6bMAF2LkCa8ENWLoNS1sLEQKprMQ/GBDks3kDM+Oc8nfPfTxuANQTYBeYAvdJLL4FnAFfwF2ST9Rz27kp5YH/kwrYp50LdaXHAU4rYNYzWAdeenx7AbgF5sAhcARsAkkyVQ+ACbAKjIGqta4+l78udXxc/LiJG+qvet0pV+q7+tHE+iJzdbGz8FhmOzVcqj/qq7rcKI7Ut1Leq70C1oCrJMMk343HB8ADMEzyVOMff72l48gwfqkAAAAASUVORK5CYII=';
  69. } else {
  70. var file = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAKCAYAAACALL/6AAAAvklEQVQY022PoapCQRRF97lBVDRYhBcEQcP1BwS/QLAqr7xitZn0HzRr8Rts+htmQdCqSbQIwmMZPMIw3lVmZu0zG44UAFSBLdBVBDAFZqFo8eYKtANfBC7AE5h8ZNOHd1FrDnh4VgmDO3ADkujDHPgHfkLZ84bfaLjg/hD6RFLq9z6wBDr+rvuZB1bAEDABY76pA2mGHyWSjvqmIemc4WsCLKOp4nssIj8wD8qS/iSVJK3N7OTeJPV9n72ZbV7iDuSc2BaQBQAAAABJRU5ErkJggg==';
  71. }
  72. return new Blockly.FieldImage(file, 12, 12, '"');
  73. }
  74. };
  75. Blockly.Blocks['dict_keys'] = {
  76. // Set element at index.
  77. init: function() {
  78. this.setColour(Blockly.Blocks.dicts.HUE);
  79. this.appendValueInput('DICT')
  80. .setCheck('dict')
  81. .appendField(Blockly.Msg.DICT_KEYS);
  82. this.setInputsInline(false);
  83. this.setOutput(true, 'Array');
  84. //this.setPreviousStatement(true);
  85. //this.setNextStatement(true);
  86. }
  87. };