Commit d1f6bdb1 authored by Neil Fraser's avatar Neil Fraser

Make Block.getField public.

parent fe34c268
......@@ -1047,8 +1047,8 @@ Blockly.Block.prototype.setParent=function(a){if(this.parentBlock_){for(var b=th
a)?a.childBlocks_.push(this):this.workspace.addTopBlock(this)};Blockly.Block.prototype.getDescendants=function(){for(var a=[this],b,c=0;b=this.childBlocks_[c];c++)a.push.apply(a,b.getDescendants());return a};Blockly.Block.prototype.isDeletable=function(){return this.deletable_&&!(this.workspace&&this.workspace.options.readOnly)};Blockly.Block.prototype.setDeletable=function(a){this.deletable_=a};Blockly.Block.prototype.isMovable=function(){return this.movable_&&!(this.workspace&&this.workspace.options.readOnly)};
Blockly.Block.prototype.setMovable=function(a){this.movable_=a};Blockly.Block.prototype.isEditable=function(){return this.editable_&&!(this.workspace&&this.workspace.options.readOnly)};Blockly.Block.prototype.setEditable=function(a){this.editable_=a;a=0;for(var b;b=this.inputList[a];a++)for(var c=0,d;d=b.fieldRow[c];c++)d.updateEditable();if(this.rendered)for(b=this.getIcons(),a=0;a<b.length;a++)b[a].updateEditable()};
Blockly.Block.prototype.setConnectionsHidden=function(a){if(!a&&this.isCollapsed()){if(this.outputConnection&&this.outputConnection.setHidden(a),this.previousConnection&&this.previousConnection.setHidden(a),this.nextConnection){this.nextConnection.setHidden(a);var b=this.nextConnection.targetBlock();b&&b.setConnectionsHidden(a)}}else for(var c=this.getConnections_(!0),d=0;b=c[d];d++)b.setHidden(a),b.isSuperior()&&(b=b.targetBlock())&&b.setConnectionsHidden(a)};
Blockly.Block.prototype.setHelpUrl=function(a){this.helpUrl=a};Blockly.Block.prototype.setTooltip=function(a){this.tooltip=a};Blockly.Block.prototype.getColour=function(){return this.colourHue_};Blockly.Block.prototype.setColour=function(a){this.colourHue_=a;this.rendered&&this.updateColour()};Blockly.Block.prototype.getField_=function(a){for(var b=0,c;c=this.inputList[b];b++)for(var d=0,e;e=c.fieldRow[d];d++)if(e.name===a)return e;return null};
Blockly.Block.prototype.getFieldValue=function(a){return(a=this.getField_(a))?a.getValue():null};Blockly.Block.prototype.getTitleValue=function(a){console.warn("Deprecated call to getTitleValue, use getFieldValue instead.");return this.getFieldValue(a)};Blockly.Block.prototype.setFieldValue=function(a,b){var c=this.getField_(b);goog.asserts.assertObject(c,'Field "%s" not found.',b);c.setValue(a)};
Blockly.Block.prototype.setHelpUrl=function(a){this.helpUrl=a};Blockly.Block.prototype.setTooltip=function(a){this.tooltip=a};Blockly.Block.prototype.getColour=function(){return this.colourHue_};Blockly.Block.prototype.setColour=function(a){this.colourHue_=a;this.rendered&&this.updateColour()};Blockly.Block.prototype.getField=function(a){for(var b=0,c;c=this.inputList[b];b++)for(var d=0,e;e=c.fieldRow[d];d++)if(e.name===a)return e;return null};
Blockly.Block.prototype.getFieldValue=function(a){return(a=this.getField(a))?a.getValue():null};Blockly.Block.prototype.getTitleValue=function(a){console.warn("Deprecated call to getTitleValue, use getFieldValue instead.");return this.getFieldValue(a)};Blockly.Block.prototype.setFieldValue=function(a,b){var c=this.getField(b);goog.asserts.assertObject(c,'Field "%s" not found.',b);c.setValue(a)};
Blockly.Block.prototype.setTitleValue=function(a,b){console.warn("Deprecated call to setTitleValue, use setFieldValue instead.");this.setFieldValue(a,b)};
Blockly.Block.prototype.setPreviousStatement=function(a,b){this.previousConnection&&(goog.asserts.assert(!this.previousConnection.targetConnection,"Must disconnect previous statement before removing connection."),this.previousConnection.dispose(),this.previousConnection=null);a&&(goog.asserts.assert(!this.outputConnection,"Remove output connection prior to adding previous connection."),void 0===b&&(b=null),this.previousConnection=new Blockly.Connection(this,Blockly.PREVIOUS_STATEMENT),this.previousConnection.setCheck(b));
this.rendered&&(this.render(),this.bumpNeighbours_())};Blockly.Block.prototype.setNextStatement=function(a,b){this.nextConnection&&(goog.asserts.assert(!this.nextConnection.targetConnection,"Must disconnect next statement before removing connection."),this.nextConnection.dispose(),this.nextConnection=null);a&&(void 0===b&&(b=null),this.nextConnection=new Blockly.Connection(this,Blockly.NEXT_STATEMENT),this.nextConnection.setCheck(b));this.rendered&&(this.render(),this.bumpNeighbours_())};
......
......@@ -57,7 +57,7 @@ Blockly.Blocks['controls_repeat'] = {
});
this.appendStatementInput('DO')
.appendField(Blockly.Msg.CONTROLS_REPEAT_INPUT_DO);
this.getField_('TIMES').setChangeHandler(
this.getField('TIMES').setChangeHandler(
Blockly.FieldTextInput.nonnegativeIntegerValidator);
}
};
......
......@@ -570,12 +570,12 @@ Blockly.Blocks['procedures_callnoreturn'] = {
var input = this.getInput('TOPROW');
if (input) {
if (this.arguments_.length) {
if (!this.getField_('WITH')) {
if (!this.getField('WITH')) {
input.appendField(Blockly.Msg.PROCEDURES_CALL_BEFORE_PARAMS, 'WITH');
input.init();
}
} else {
if (this.getField_('WITH')) {
if (this.getField('WITH')) {
input.removeField('WITH');
}
}
......
......@@ -56,7 +56,7 @@ Blockly.Blocks.logic_null={init:function(){this.setHelpUrl(Blockly.Msg.LOGIC_NUL
Blockly.Blocks.logic_ternary={init:function(){this.setHelpUrl(Blockly.Msg.LOGIC_TERNARY_HELPURL);this.setColour(Blockly.Blocks.logic.HUE);this.appendValueInput("IF").setCheck("Boolean").appendField(Blockly.Msg.LOGIC_TERNARY_CONDITION);this.appendValueInput("THEN").appendField(Blockly.Msg.LOGIC_TERNARY_IF_TRUE);this.appendValueInput("ELSE").appendField(Blockly.Msg.LOGIC_TERNARY_IF_FALSE);this.setOutput(!0);this.setTooltip(Blockly.Msg.LOGIC_TERNARY_TOOLTIP);this.prevParentConnection_=null},onchange:function(){if(this.workspace){var a=
this.getInputTargetBlock("THEN"),b=this.getInputTargetBlock("ELSE"),c=this.outputConnection.targetConnection;if((a||b)&&c)for(var d=0;2>d;d++){var e=1==d?a:b;e&&!e.outputConnection.checkType_(c)&&(c===this.prevParentConnection_?(this.setParent(null),c.sourceBlock_.bumpNeighbours_()):(e.setParent(null),e.bumpNeighbours_()))}this.prevParentConnection_=c}}};
// Copyright 2012 Google Inc. Apache License 2.0
Blockly.Blocks.loops={};Blockly.Blocks.loops.HUE=120;Blockly.Blocks.controls_repeat={init:function(){this.jsonInit({message0:Blockly.Msg.CONTROLS_REPEAT_TITLE,args0:[{type:"field_input",name:"TIMES",text:"10"}],previousStatement:null,nextStatement:null,colour:Blockly.Blocks.loops.HUE,tooltip:Blockly.Msg.CONTROLS_REPEAT_TOOLTIP,helpUrl:Blockly.Msg.CONTROLS_REPEAT_HELPURL});this.appendStatementInput("DO").appendField(Blockly.Msg.CONTROLS_REPEAT_INPUT_DO);this.getField_("TIMES").setChangeHandler(Blockly.FieldTextInput.nonnegativeIntegerValidator)}};
Blockly.Blocks.loops={};Blockly.Blocks.loops.HUE=120;Blockly.Blocks.controls_repeat={init:function(){this.jsonInit({message0:Blockly.Msg.CONTROLS_REPEAT_TITLE,args0:[{type:"field_input",name:"TIMES",text:"10"}],previousStatement:null,nextStatement:null,colour:Blockly.Blocks.loops.HUE,tooltip:Blockly.Msg.CONTROLS_REPEAT_TOOLTIP,helpUrl:Blockly.Msg.CONTROLS_REPEAT_HELPURL});this.appendStatementInput("DO").appendField(Blockly.Msg.CONTROLS_REPEAT_INPUT_DO);this.getField("TIMES").setChangeHandler(Blockly.FieldTextInput.nonnegativeIntegerValidator)}};
Blockly.Blocks.controls_repeat_ext={init:function(){this.jsonInit({message0:Blockly.Msg.CONTROLS_REPEAT_TITLE,args0:[{type:"input_value",name:"TIMES",check:"Number"}],previousStatement:null,nextStatement:null,colour:Blockly.Blocks.loops.HUE,tooltip:Blockly.Msg.CONTROLS_REPEAT_TOOLTIP,helpUrl:Blockly.Msg.CONTROLS_REPEAT_HELPURL});this.appendStatementInput("DO").appendField(Blockly.Msg.CONTROLS_REPEAT_INPUT_DO)}};
Blockly.Blocks.controls_whileUntil={init:function(){var a=[[Blockly.Msg.CONTROLS_WHILEUNTIL_OPERATOR_WHILE,"WHILE"],[Blockly.Msg.CONTROLS_WHILEUNTIL_OPERATOR_UNTIL,"UNTIL"]];this.setHelpUrl(Blockly.Msg.CONTROLS_WHILEUNTIL_HELPURL);this.setColour(Blockly.Blocks.loops.HUE);this.appendValueInput("BOOL").setCheck("Boolean").appendField(new Blockly.FieldDropdown(a),"MODE");this.appendStatementInput("DO").appendField(Blockly.Msg.CONTROLS_WHILEUNTIL_INPUT_DO);this.setPreviousStatement(!0);this.setNextStatement(!0);
var b=this;this.setTooltip(function(){var a=b.getFieldValue("MODE");return{WHILE:Blockly.Msg.CONTROLS_WHILEUNTIL_TOOLTIP_WHILE,UNTIL:Blockly.Msg.CONTROLS_WHILEUNTIL_TOOLTIP_UNTIL}[a]})}};
......@@ -108,8 +108,8 @@ Blockly.Blocks.procedures_mutatorarg={init:function(){this.setColour(Blockly.Blo
Blockly.Blocks.procedures_callnoreturn={init:function(){this.setHelpUrl(Blockly.Msg.PROCEDURES_CALLNORETURN_HELPURL);this.setColour(Blockly.Blocks.procedures.HUE);this.appendDummyInput("TOPROW").appendField(Blockly.Msg.PROCEDURES_CALLNORETURN_CALL).appendField("","NAME");this.setPreviousStatement(!0);this.setNextStatement(!0);this.arguments_=[];this.quarkConnections_={};this.quarkArguments_=null},getProcedureCall:function(){return this.getFieldValue("NAME")},renameProcedure:function(a,b){Blockly.Names.equals(a,
this.getProcedureCall())&&(this.setFieldValue(b,"NAME"),this.setTooltip((this.outputConnection?Blockly.Msg.PROCEDURES_CALLRETURN_TOOLTIP:Blockly.Msg.PROCEDURES_CALLNORETURN_TOOLTIP).replace("%1",b)))},setProcedureParameters:function(a,b){if(b)if(goog.array.equals(this.arguments_,a))this.quarkArguments_=b;else{this.setCollapsed(!1);if(b.length!=a.length)throw"Error: paramNames and paramIds must be the same length.";this.quarkArguments_||(this.quarkConnections_={},a.join("\n")==this.arguments_.join("\n")?
this.quarkArguments_=b:this.quarkArguments_=[]);var c=this.rendered;this.rendered=!1;for(var d=this.arguments_.length-1;0<=d;d--){var e=this.getInput("ARG"+d);if(e){var f=e.connection.targetConnection;this.quarkConnections_[this.quarkArguments_[d]]=f;this.removeInput("ARG"+d)}}this.arguments_=[].concat(a);this.renderArgs_();if(this.quarkArguments_=b)for(d=0;d<this.arguments_.length;d++){var e=this.getInput("ARG"+d),g=this.quarkArguments_[d];g in this.quarkConnections_&&(f=this.quarkConnections_[g],
!f||f.targetConnection||f.sourceBlock_.workspace!=this.workspace?delete this.quarkConnections_[g]:e.connection.connect(f))}(this.rendered=c)&&this.render()}else this.quarkConnections_={},this.quarkArguments_=null},renderArgs_:function(){for(var a=0;a<this.arguments_.length;a++){var b=this.appendValueInput("ARG"+a).setAlign(Blockly.ALIGN_RIGHT).appendField(this.arguments_[a]);b.init()}if(b=this.getInput("TOPROW"))this.arguments_.length?this.getField_("WITH")||(b.appendField(Blockly.Msg.PROCEDURES_CALL_BEFORE_PARAMS,
"WITH"),b.init()):this.getField_("WITH")&&b.removeField("WITH")},mutationToDom:function(){var a=document.createElement("mutation");a.setAttribute("name",this.getProcedureCall());for(var b=0;b<this.arguments_.length;b++){var c=document.createElement("arg");c.setAttribute("name",this.arguments_[b]);a.appendChild(c)}return a},domToMutation:function(a){var b=a.getAttribute("name");this.setFieldValue(b,"NAME");this.setTooltip((this.outputConnection?Blockly.Msg.PROCEDURES_CALLRETURN_TOOLTIP:Blockly.Msg.PROCEDURES_CALLNORETURN_TOOLTIP).replace("%1",
!f||f.targetConnection||f.sourceBlock_.workspace!=this.workspace?delete this.quarkConnections_[g]:e.connection.connect(f))}(this.rendered=c)&&this.render()}else this.quarkConnections_={},this.quarkArguments_=null},renderArgs_:function(){for(var a=0;a<this.arguments_.length;a++){var b=this.appendValueInput("ARG"+a).setAlign(Blockly.ALIGN_RIGHT).appendField(this.arguments_[a]);b.init()}if(b=this.getInput("TOPROW"))this.arguments_.length?this.getField("WITH")||(b.appendField(Blockly.Msg.PROCEDURES_CALL_BEFORE_PARAMS,
"WITH"),b.init()):this.getField("WITH")&&b.removeField("WITH")},mutationToDom:function(){var a=document.createElement("mutation");a.setAttribute("name",this.getProcedureCall());for(var b=0;b<this.arguments_.length;b++){var c=document.createElement("arg");c.setAttribute("name",this.arguments_[b]);a.appendChild(c)}return a},domToMutation:function(a){var b=a.getAttribute("name");this.setFieldValue(b,"NAME");this.setTooltip((this.outputConnection?Blockly.Msg.PROCEDURES_CALLRETURN_TOOLTIP:Blockly.Msg.PROCEDURES_CALLNORETURN_TOOLTIP).replace("%1",
b));if((b=Blockly.Procedures.getDefinition(b,this.workspace))&&b.mutator&&b.mutator.isVisible())this.setProcedureParameters(b.arguments_,b.paramIds_);else{for(var b=[],c=0,d;d=a.childNodes[c];c++)"arg"==d.nodeName.toLowerCase()&&b.push(d.getAttribute("name"));this.setProcedureParameters(b,b)}},renameVar:function(a,b){for(var c=0;c<this.arguments_.length;c++)Blockly.Names.equals(a,this.arguments_[c])&&(this.arguments_[c]=b,this.getInput("ARG"+c).fieldRow[0].setText(b))},customContextMenu:function(a){var b=
{enabled:!0};b.text=Blockly.Msg.PROCEDURES_HIGHLIGHT_DEF;var c=this.getProcedureCall(),d=this.workspace;b.callback=function(){var a=Blockly.Procedures.getDefinition(c,d);a&&a.select()};a.push(b)}};
Blockly.Blocks.procedures_callreturn={init:function(){this.setHelpUrl(Blockly.Msg.PROCEDURES_CALLRETURN_HELPURL);this.setColour(Blockly.Blocks.procedures.HUE);this.appendDummyInput("TOPROW").appendField(Blockly.Msg.PROCEDURES_CALLRETURN_CALL).appendField("","NAME");this.setOutput(!0);this.arguments_=[];this.quarkConnections_={};this.quarkArguments_=null},getProcedureCall:Blockly.Blocks.procedures_callnoreturn.getProcedureCall,renameProcedure:Blockly.Blocks.procedures_callnoreturn.renameProcedure,
......
......@@ -592,9 +592,8 @@ Blockly.Block.prototype.setColour = function(colourHue) {
* Returns the named field from a block.
* @param {string} name The name of the field.
* @return {Blockly.Field} Named field, or null if field does not exist.
* @private
*/
Blockly.Block.prototype.getField_ = function(name) {
Blockly.Block.prototype.getField = function(name) {
for (var i = 0, input; input = this.inputList[i]; i++) {
for (var j = 0, field; field = input.fieldRow[j]; j++) {
if (field.name === name) {
......@@ -611,7 +610,7 @@ Blockly.Block.prototype.getField_ = function(name) {
* @return {?string} Value from the field or null if field does not exist.
*/
Blockly.Block.prototype.getFieldValue = function(name) {
var field = this.getField_(name);
var field = this.getField(name);
if (field) {
return field.getValue();
}
......@@ -635,7 +634,7 @@ Blockly.Block.prototype.getTitleValue = function(name) {
* @param {string} name The name of the field.
*/
Blockly.Block.prototype.setFieldValue = function(newValue, name) {
var field = this.getField_(name);
var field = this.getField(name);
goog.asserts.assertObject(field, 'Field "%s" not found.', name);
field.setValue(newValue);
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment