Commit 0341af0c authored by Evan W. Patton's avatar Evan W. Patton

Allow component blocks and property getters in global declarations

It is often the case that people will want to construct a list of
components or store some information about a copmonent so that it can
be restored later. this currently requires putting all of the
initialization into the Screen's Initialize event handler. However,
many people intuitively expect that they can construct a list of
components as part of the global declaration. This changes allows for
component blocks and property getters to be used in a blocks tree with
a global declaration root node.

Change-Id: I69d26716ebf4bfcdd52465f15eaf75af1c4170cf
parent 4ccbeea4
......@@ -1284,7 +1284,7 @@ Blockly.Blocks.component_component_block = {
this.appendDummyInput().appendField(this.componentDropDown, Blockly.ComponentBlock.COMPONENT_SELECTOR);
//this.componentDropDown.setValue(this.instanceName);
this.setOutput(true, [this.typeName,"COMPONENT"]);
this.errors = [{name:"checkIfUndefinedBlock"},{name:"checkIsInDefinition"},{name:"checkComponentNotExistsError"}];
this.errors = [{name:"checkIfUndefinedBlock"},{name:"checkComponentNotExistsError"}];
},
// Renames the block's instanceName, type, and reset its title
rename : function(oldname, newname) {
......
......@@ -293,6 +293,10 @@ Blockly.WarningHandler.prototype.checkErrors = function(block) {
//Check if the block is inside of a variable declaration block, if so, create an error
Blockly.WarningHandler.prototype["checkIsInDefinition"] = function(block){
// Allow property getters as they should be pure.
if (block.type === 'component_set_get' && block.setOrGet === 'get') {
return false;
}
var rootBlock = block.getRootBlock();
if(rootBlock.type == "global_declaration"){
var errorMessage = Blockly.Msg.ERROR_BLOCK_CANNOT_BE_IN_DEFINTION;
......
......@@ -551,7 +551,7 @@
var-val-pairs))
;; Create each component and set its corresponding field
(define (init-components component-descriptors)
(define (create-components component-descriptors)
(for-each (lambda (component-info)
(let ((component-name (caddr component-info))
(init-thunk (cadddr component-info))
......@@ -566,14 +566,10 @@
;; Add the mapping from component name -> component object to the
;; form-environment
(add-to-form-environment component-name component-object))))
component-descriptors)
;; Now that all the components are constructed we can call
;; their init-thunk and their Initialize methods. We need
;; to do this after all the construction steps because the
;; init-thunk (i.e. design-time initializations) and
;; Initialize methods may contain references to other
;; components.
;;
component-descriptors))
;; Initialize all of the components
(define (init-components component-descriptors)
;; First all the init-thunks
(for-each (lambda (component-info)
(let ((component-name (caddr component-info))
......@@ -618,12 +614,13 @@
(register-events events-to-register)
(try-catch
(begin
(let ((components (reverse components-to-create)))
;; We need this binding because the block parser sends this symbol
;; to represent an uninitialized value
;; We have to explicity write #!null here, rather than
;; *the-null-value* because that external defintion hasn't happened yet
(add-to-global-vars '*the-null-value* (lambda () #!null))
(create-components components)
;; These next three clauses need to be in this order:
;; Properties can't be set until after the global variables are
;; assigned. And some properties can't be set after the components are
......@@ -631,7 +628,13 @@
;; components have been installed. (This gives an error.)
(init-global-variables (reverse global-vars-to-create))
(for-each force (reverse form-do-after-creation))
(init-components (reverse components-to-create)))
;; Now that all the components are constructed we can call
;; their init-thunk and their Initialize methods. We need
;; to do this after all the construction steps because the
;; init-thunk (i.e. design-time initializations) and
;; Initialize methods may contain references to other
;; components.
(init-components components))
(exception com.google.appinventor.components.runtime.errors.YailRuntimeError
;;(android-log-form "Caught exception in define-form ")
(process-exception exception))))))))
......
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