Skip to content
Permalink
Browse files

Support disabling events in the REPL (#1849)

  • Loading branch information
ewpatton authored and jisqyv committed Sep 24, 2019
1 parent edf486e commit 43a74f926535a5ae4d0309b86ed72a216dc95af1
Showing with 28 additions and 1 deletion.
  1. +18 −0 appinventor/blocklyeditor/src/generators/yail.js
  2. +10 −1 appinventor/blocklyeditor/src/replmgr.js
@@ -32,6 +32,7 @@ Blockly.Yail.RESERVED_WORDS_ = '';
Blockly.Yail.ORDER_ATOMIC = 0; // 0 "" ...
Blockly.Yail.ORDER_NONE = 99; // (...)

Blockly.Yail.YAIL_ACTIVE_FORM = "(SimpleForm:getActiveForm)";
Blockly.Yail.YAIL_ADD_COMPONENT = "(add-component ";
Blockly.Yail.YAIL_ADD_TO_LIST = "(add-to-list ";
Blockly.Yail.YAIL_BEGIN = "(begin ";
@@ -86,6 +87,8 @@ Blockly.Yail.YAIL_SET_VARIABLE = "(set-var! ";
Blockly.Yail.YAIL_SET_THIS_FORM = "(set-this-form)\n ";
Blockly.Yail.YAIL_SPACER = " ";
Blockly.Yail.YAIL_TRUE = "#t";
Blockly.Yail.YAIL_UNREGISTER =
"com.google.appinventor.components.runtime.EventDispatcher:unregisterEventForDelegation";
Blockly.Yail.YAIL_WHILE = "(while ";
Blockly.Yail.YAIL_LIST_CONSTRUCTOR = "*list-for-runtime*";

@@ -664,3 +667,18 @@ Blockly.Yail.blockToCode1 = function(block) {
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) {
if (!block.category || (block.hasError && !block.replError)) { // Don't send blocks with
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;
}
if (block.blockType != "event" &&

0 comments on commit 43a74f9

Please sign in to comment.
You can’t perform that action at this time.