Commit 43a74f92 authored by Evan W. Patton's avatar Evan W. Patton Committed by Jeffrey Schiller

Support disabling events in the REPL (#1849)

parent edf486e4
...@@ -32,6 +32,7 @@ Blockly.Yail.RESERVED_WORDS_ = ''; ...@@ -32,6 +32,7 @@ Blockly.Yail.RESERVED_WORDS_ = '';
Blockly.Yail.ORDER_ATOMIC = 0; // 0 "" ... Blockly.Yail.ORDER_ATOMIC = 0; // 0 "" ...
Blockly.Yail.ORDER_NONE = 99; // (...) Blockly.Yail.ORDER_NONE = 99; // (...)
Blockly.Yail.YAIL_ACTIVE_FORM = "(SimpleForm:getActiveForm)";
Blockly.Yail.YAIL_ADD_COMPONENT = "(add-component "; Blockly.Yail.YAIL_ADD_COMPONENT = "(add-component ";
Blockly.Yail.YAIL_ADD_TO_LIST = "(add-to-list "; Blockly.Yail.YAIL_ADD_TO_LIST = "(add-to-list ";
Blockly.Yail.YAIL_BEGIN = "(begin "; Blockly.Yail.YAIL_BEGIN = "(begin ";
...@@ -86,6 +87,8 @@ Blockly.Yail.YAIL_SET_VARIABLE = "(set-var! "; ...@@ -86,6 +87,8 @@ Blockly.Yail.YAIL_SET_VARIABLE = "(set-var! ";
Blockly.Yail.YAIL_SET_THIS_FORM = "(set-this-form)\n "; Blockly.Yail.YAIL_SET_THIS_FORM = "(set-this-form)\n ";
Blockly.Yail.YAIL_SPACER = " "; Blockly.Yail.YAIL_SPACER = " ";
Blockly.Yail.YAIL_TRUE = "#t"; Blockly.Yail.YAIL_TRUE = "#t";
Blockly.Yail.YAIL_UNREGISTER =
"com.google.appinventor.components.runtime.EventDispatcher:unregisterEventForDelegation";
Blockly.Yail.YAIL_WHILE = "(while "; Blockly.Yail.YAIL_WHILE = "(while ";
Blockly.Yail.YAIL_LIST_CONSTRUCTOR = "*list-for-runtime*"; Blockly.Yail.YAIL_LIST_CONSTRUCTOR = "*list-for-runtime*";
...@@ -664,3 +667,18 @@ Blockly.Yail.blockToCode1 = function(block) { ...@@ -664,3 +667,18 @@ Blockly.Yail.blockToCode1 = function(block) {
return this.scrub_(block, code, true); return this.scrub_(block, code, true);
} }
}; };
/**
* Generates YAIL that will unregister an event if the corresponding block is disabled in the
* workspace.
*
* @param {!Blockly.BlockSvg} block
* @returns {string}
*/
Blockly.Yail.disabledEventBlockToCode = function(block) {
return Blockly.Yail.YAIL_OPEN_BLOCK + Blockly.Yail.YAIL_UNREGISTER + Blockly.Yail.YAIL_SPACER +
Blockly.Yail.YAIL_ACTIVE_FORM + Blockly.Yail.YAIL_SPACER +
Blockly.Yail.YAIL_QUOTE + block.getFieldValue('COMPONENT_SELECTOR') +
Blockly.Yail.YAIL_SPACER + Blockly.Yail.YAIL_QUOTE + block.eventName +
Blockly.Yail.YAIL_CLOSE_BLOCK;
};
...@@ -185,7 +185,16 @@ Blockly.ReplMgr.buildYail = function(workspace) { ...@@ -185,7 +185,16 @@ Blockly.ReplMgr.buildYail = function(workspace) {
if (!block.category || (block.hasError && !block.replError)) { // Don't send blocks with if (!block.category || (block.hasError && !block.replError)) { // Don't send blocks with
continue; // Errors, unless they were errors signaled by the repl continue; // Errors, unless they were errors signaled by the repl
} }
if (block.disabled) { // Don't send disabled blocks if (block.disabled) {
if (block.type == 'component_event') {
// We do need do remove disabled event handlers, though
var code = Blockly.Yail.disabledEventBlockToCode(block);
if (phoneState.blockYail[block.id] != code) {
this.putYail(code, block, success, failure);
phoneState.blockYail[block.id] = code;
}
}
// Skip normal code generation for disabled blocks
continue; continue;
} }
if (block.blockType != "event" && if (block.blockType != "event" &&
......
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