mirror of
https://github.com/google/blockly.git
synced 2026-01-10 02:17:09 +01:00
Disable/enable function calls along with their definitions (#2019)
Fixes #1344 Extends the event listener on procedure caller blocks to also check for their definition being enabled/disabled and update their own state in response.
This commit is contained in:
@@ -569,7 +569,9 @@ Blockly.Blocks['procedures_callnoreturn'] = {
|
||||
this.argumentVarModels_ = [];
|
||||
this.quarkConnections_ = {};
|
||||
this.quarkIds_ = null;
|
||||
this.previousDisabledState_ = false;
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns the name of the procedure this block calls.
|
||||
* @return {string} Procedure name.
|
||||
@@ -789,6 +791,10 @@ Blockly.Blocks['procedures_callnoreturn'] = {
|
||||
// Block is deleted or is in a flyout.
|
||||
return;
|
||||
}
|
||||
if (!event.recordUndo) {
|
||||
// Events not generated by user. Skip handling.
|
||||
return;
|
||||
}
|
||||
if (event.type == Blockly.Events.BLOCK_CREATE &&
|
||||
event.ids.indexOf(this.id) != -1) {
|
||||
// Look for the case where a procedure call was created (usually through
|
||||
@@ -843,6 +849,27 @@ Blockly.Blocks['procedures_callnoreturn'] = {
|
||||
this.dispose(true, false);
|
||||
Blockly.Events.setGroup(false);
|
||||
}
|
||||
} else if (event.type == Blockly.Events.CHANGE && event.element == 'disabled') {
|
||||
var name = this.getProcedureCall();
|
||||
var def = Blockly.Procedures.getDefinition(name, this.workspace);
|
||||
if (def && def.id == event.blockId) {
|
||||
// in most cases the old group should be ''
|
||||
var oldGroup = Blockly.Events.getGroup();
|
||||
if (oldGroup) {
|
||||
// This should only be possible programatically and may indicate a problem
|
||||
// with event grouping. If you see this message please investigate. If the
|
||||
// use ends up being valid we may need to reorder events in the undo stack.
|
||||
console.log('Saw an existing group while responding to a definition change');
|
||||
}
|
||||
Blockly.Events.setGroup(event.group);
|
||||
if (event.newValue) {
|
||||
this.previousDisabledState_ = this.disabled;
|
||||
this.setDisabled(true);
|
||||
} else {
|
||||
this.setDisabled(this.previousDisabledState_);
|
||||
}
|
||||
Blockly.Events.setGroup(oldGroup);
|
||||
}
|
||||
}
|
||||
},
|
||||
/**
|
||||
@@ -882,7 +909,9 @@ Blockly.Blocks['procedures_callreturn'] = {
|
||||
this.arguments_ = [];
|
||||
this.quarkConnections_ = {};
|
||||
this.quarkIds_ = null;
|
||||
this.previousDisabledState_ = false;
|
||||
},
|
||||
|
||||
getProcedureCall: Blockly.Blocks['procedures_callnoreturn'].getProcedureCall,
|
||||
renameProcedure: Blockly.Blocks['procedures_callnoreturn'].renameProcedure,
|
||||
setProcedureParameters_:
|
||||
|
||||
Reference in New Issue
Block a user