Blockly. Procedures
Utility functions for handling procedures.
Properties
CATEGORY_NAME
string
String for use in the "custom" attribute of a category in toolbox XML. This string indicates that the category should be dynamically populated with procedure blocks. See also Blockly.Variables.CATEGORY_NAME and Blockly.VariablesDynamic.CATEGORY_NAME.
DEFAULT_ARG
string
The default argument for a procedures_mutatorarg block.
Methods
allProcedures
allProcedures(root) returns Array of non-null Array of non-null Array
Find all user-created procedure definitions in a workspace.
Parameter |
|
---|---|
root |
Root workspace. Value must not be null. |
- Returns
-
non-null Array of non-null Array of non-null Array
Pair of arrays, the first contains procedures without return variables, the second with. Each procedure is defined by a three-element list of name, parameter list, and return value boolean.
findLegalName
findLegalName(name, block) returns string
Ensure two identically-named procedures don't exist. Take the proposed procedure name, and return a legal name i.e. one that is not empty and doesn't collide with other procedures.
Parameter |
|
---|---|
name |
string Proposed procedure name. |
block |
Block to disambiguate. Value must not be null. |
- Returns
-
string
Non-colliding name.
flyoutCategory
flyoutCategory(workspace) returns Array of non-null Element
Construct the blocks required by the flyout for the procedure category.
Parameter |
|
---|---|
workspace |
The workspace containing procedures. Value must not be null. |
- Returns
-
non-null Array of non-null Element
Array of XML block elements.
getCallers
getCallers(name, workspace) returns Array of non-null Blockly.Block
Find all the callers of a named procedure.
Parameter |
|
---|---|
name |
string Name of procedure. |
workspace |
The workspace to find callers in. Value must not be null. |
- Returns
-
non-null Array of non-null Blockly.Block
Array of caller blocks.
getDefinition
getDefinition(name, workspace) returns Blockly.Block
Find the definition block for the named procedure.
Parameter |
|
---|---|
name |
string Name of procedure. |
workspace |
The workspace to search. Value must not be null. |
- Returns
-
nullable Blockly.Block
The procedure definition block, or null not found.
isNameUsed
isNameUsed(name, workspace, opt_exclude) returns boolean
Return if the given name is already a procedure name.
Parameter |
|
---|---|
name |
string The questionable name. |
workspace |
The workspace to scan for collisions. Value must not be null. |
opt_exclude |
Optional Optional block to exclude from comparisons (one doesn't want to collide with oneself). |
- Returns
-
boolean
True if the name is used, otherwise return false.
mutateCallers
mutateCallers(defBlock)
When a procedure definition changes its parameters, find and edit all its callers.
Parameter |
|
---|---|
defBlock |
Procedure definition block. Value must not be null. |
mutatorOpenListener
mutatorOpenListener(e)
Listens for when a procedure mutator is opened. Then it triggers a flyout update and adds a mutator change listener to the mutator workspace.
Parameter |
|
---|---|
e |
The event that triggered this listener. Value must not be null. |
rename
rename(name) returns string
Rename a procedure. Called by the editable field.
Parameter |
|
---|---|
name |
string The proposed new name. |
- Returns
-
string
The accepted name.
Abstract type
ProcedureBlock
{getProcedureCall: function() returns string, renameProcedure: function(string, string), getProcedureDef: function() returns non-null Array}
Procedure block type.