123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241 |
- 'use strict';
- goog.provide('Blockly.Input');
- goog.require('Blockly.Connection');
- goog.require('Blockly.FieldLabel');
- goog.require('goog.asserts');
- Blockly.Input = function(type, name, block, connection) {
-
- this.type = type;
-
- this.name = name;
-
- this.sourceBlock_ = block;
-
- this.connection = connection;
-
- this.fieldRow = [];
- };
- Blockly.Input.prototype.align = Blockly.ALIGN_LEFT;
- Blockly.Input.prototype.visible_ = true;
- Blockly.Input.prototype.appendField = function(field, opt_name) {
-
- if (!field && !opt_name) {
- return this;
- }
-
- if (goog.isString(field)) {
- field = new Blockly.FieldLabel( (field));
- }
- field.setSourceBlock(this.sourceBlock_);
- if (this.sourceBlock_.rendered) {
- field.init();
- }
- field.name = opt_name;
- if (field.prefixField) {
-
- this.appendField(field.prefixField);
- }
-
- this.fieldRow.push(field);
- if (field.suffixField) {
-
- this.appendField(field.suffixField);
- }
- if (this.sourceBlock_.rendered) {
- this.sourceBlock_.render();
-
- this.sourceBlock_.bumpNeighbours_();
- }
- return this;
- };
- Blockly.Input.prototype.appendTitle = function(field, opt_name) {
- console.warn('Deprecated call to appendTitle, use appendField instead.');
- return this.appendField(field, opt_name);
- };
- Blockly.Input.prototype.removeField = function(name) {
- for (var i = 0, field; field = this.fieldRow[i]; i++) {
- if (field.name === name) {
- field.dispose();
- this.fieldRow.splice(i, 1);
- if (this.sourceBlock_.rendered) {
- this.sourceBlock_.render();
-
- this.sourceBlock_.bumpNeighbours_();
- }
- return;
- }
- }
- goog.asserts.fail('Field "%s" not found.', name);
- };
- Blockly.Input.prototype.isVisible = function() {
- return this.visible_;
- };
- Blockly.Input.prototype.setVisible = function(visible) {
- var renderList = [];
- if (this.visible_ == visible) {
- return renderList;
- }
- this.visible_ = visible;
- var display = visible ? 'block' : 'none';
- for (var y = 0, field; field = this.fieldRow[y]; y++) {
- field.setVisible(visible);
- }
- if (this.connection) {
-
- if (visible) {
- renderList = this.connection.unhideAll();
- } else {
- this.connection.hideAll();
- }
- var child = this.connection.targetBlock();
- if (child) {
- child.getSvgRoot().style.display = display;
- if (!visible) {
- child.rendered = false;
- }
- }
- }
- return renderList;
- };
- Blockly.Input.prototype.setCheck = function(check) {
- if (!this.connection) {
- throw 'This input does not have a connection.';
- }
- this.connection.setCheck(check);
- return this;
- };
- Blockly.Input.prototype.setAlign = function(align) {
- this.align = align;
- if (this.sourceBlock_.rendered) {
- this.sourceBlock_.render();
- }
- return this;
- };
- Blockly.Input.prototype.init = function() {
- if (!this.sourceBlock_.workspace.rendered) {
- return;
- }
- for (var i = 0; i < this.fieldRow.length; i++) {
- this.fieldRow[i].init();
- }
- };
- Blockly.Input.prototype.dispose = function() {
- for (var i = 0, field; field = this.fieldRow[i]; i++) {
- field.dispose();
- }
- if (this.connection) {
- this.connection.dispose();
- }
- this.sourceBlock_ = null;
- };
|