2727goog . provide ( 'Blockly.Blocks.ComponentFieldVariable' ) ;
2828
2929goog . require ( 'Blockly.Blocks' ) ;
30- //goog.require('Blockly.FieldVariable');
3130
3231
3332/**
3433 * Class for a variable's dropdown field.
3534 * @param {?string } varname The default name for the variable. If null,
3635 * a unique variable name will be generated.
36+ * @param {?string } component_type The type of component to show in the dropdown list, eg 'Stepper'
3737 * @param {Function= } opt_validator A function that is executed when a new
3838 * option is selected. Its sole argument is the new option value.
3939 * @extends {Blockly.FieldVariable }
4040 * @constructor
4141 */
4242Blockly . Blocks . ComponentFieldVariable = function ( varname , component_type , opt_validator ) {
43- this . component_type = component_type
44- //override the dropdownCreate to use for this field
45- this . dropdownCreate = Blockly . Blocks . ComponentFieldVariable . dropdownCreateComponents ;
43+ /** @type {string } */
44+ this . component_type = component_type ;
4645 Blockly . Blocks . ComponentFieldVariable . superClass_ . constructor . call ( this ,
4746 varname , opt_validator ) ;
4847 this . setValue ( varname || '' ) ;
4948} ;
5049goog . inherits ( Blockly . Blocks . ComponentFieldVariable , Blockly . FieldVariable ) ;
5150
52- /**
53- * Install this dropdown on a block.
54- * @param {!Blockly.Block } block The block containing this text.
55- */
56- Blockly . Blocks . ComponentFieldVariable . prototype . init = function ( block ) {
57- if ( this . sourceBlock_ ) {
58- // Dropdown has already been initialized once.
59- return ;
60- }
61- Blockly . Blocks . ComponentFieldVariable . superClass_ . init . call ( this , block ) ;
62- } ;
63-
6451Blockly . Blocks . ComponentFieldVariable . ComponentVariables = function ( root , component_type ) {
6552 var blocks ;
6653 if ( root . getDescendants ) {
@@ -100,9 +87,9 @@ Blockly.Blocks.ComponentFieldVariable.ComponentVariables = function(root, compon
10087 * Return a sorted list of variable names for variable dropdown menus.
10188 * Include a special option at the end for creating a new variable name.
10289 * @return {!Array.<string> } Array of variable names.
103- * @this {!Blockly.FieldVariable }
90+ * @this {!ComponentFieldVariable }
10491 */
105- Blockly . Blocks . ComponentFieldVariable . dropdownCreateComponents = function ( ) {
92+ Blockly . Blocks . ComponentFieldVariable . prototype . dropdownCreate = function ( ) {
10693 if ( this . sourceBlock_ && this . sourceBlock_ . workspace ) {
10794 var variableList =
10895 Blockly . Blocks . ComponentFieldVariable . ComponentVariables ( this . sourceBlock_ . workspace ,
@@ -130,9 +117,11 @@ Blockly.Blocks.ComponentFieldVariable.dropdownCreateComponents = function() {
130117
131118/**
132119 * Finds all user-created instances of the ComponentFieldVariable block config.
120+ * @param {!Blockly.Workspace } workspace The block's workspace.
121+ * @param {?string } component_type The type of component setup block to obtain instances from
133122 * @return {!Array.<string> } Array of instance names.
134123 */
135- Blockly . Blocks . ComponentFieldVariable . Instances = function ( component_type ) {
124+ Blockly . Blocks . ComponentFieldVariable . Instances = function ( workspace , component_type ) {
136125 var instList = [ ] ;
137126 var blocks = Blockly . mainWorkspace . getAllBlocks ( ) ;
138127 for ( var x = 0 ; x < blocks . length ; x ++ ) {
@@ -149,8 +138,17 @@ Blockly.Blocks.ComponentFieldVariable.Instances = function(component_type) {
149138 return instList ;
150139} ;
151140
152- Blockly . Blocks . ComponentFieldVariable . CheckSetupPresent = function ( currentDropdown , component_type ) {
153- var instances = Blockly . Blocks . ComponentFieldVariable . Instances ( component_type ) ;
141+ /**
142+ * Check to know of a setup block (which sets pin number) is present for a used
143+ * ComponentFieldVariable.
144+ * @param {!Blockly.Workspace } workspace The block's workspace.
145+ * @param {?string } currentDropdown The selected name in the dropdown for which to check
146+ * if setup block present
147+ * @param {?string } component_type The type of component setup block must be checked
148+ * @return {<boolean> } Wether setup block is present or not
149+ */
150+ Blockly . Blocks . ComponentFieldVariable . CheckSetupPresent = function ( workspace , currentDropdown , component_type ) {
151+ var instances = Blockly . Blocks . ComponentFieldVariable . Instances ( workspace , component_type ) ;
154152
155153 // Check for configuration block presence
156154 if ( ! instances ) {
@@ -163,10 +161,6 @@ Blockly.Blocks.ComponentFieldVariable.CheckSetupPresent = function(currentDropdo
163161 existingConfigSelected = true ;
164162 }
165163 }
166- if ( existingConfigSelected ) {
167- return true ;
168- } else {
169- return false ;
170- }
164+ return existingConfigSelected ;
171165 }
172166}
0 commit comments