Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 0 additions & 90 deletions appinventor/blocklyeditor/src/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,100 +17,10 @@ goog.provide('AI.Blockly.Component');
goog.provide('AI.Blockly.ComponentTypes');
goog.provide('AI.Blockly.ComponentInstances');

// App Inventor extensions to Blockly
goog.require('AI.Blockly.TypeBlock');

if (Blockly.Component === undefined) Blockly.Component = {};
if (Blockly.ComponentTypes === undefined) Blockly.ComponentTypes = {};
if (Blockly.ComponentInstances === undefined) Blockly.ComponentInstances = {};

Blockly.Component.add = function(name, uid) {
if (Blockly.ComponentInstances.haveInstance(name, uid)) {
return;
}
AI.Blockly.TypeBlock.needsReload.components = true;
//get type name for instance
var typeName = Blockly.Component.instanceNameToTypeName(name);
Blockly.ComponentInstances.addInstance(name, uid, typeName);
};

/**
* Rename component with given uid and instance name oldname to newname
* @param oldname the Component's current name, e.g., Button1
* @param newname the newname the component will be given, e.g., Button2
* @param uid the component's unique id
*
* Here are the various places that a component's name must be changed, using Button1
* as an example name.
* Blockly.ComponentInstances -- an index containing an entry for each Component used by the app
* keyed on its oldname, needs to change to the new name
* e.g., ComponentInstances['Button1'] --> ComponentInstances['Button2']
*
* Call rename on all component blocks
*/
Blockly.Component.rename = function(oldname, newname, uid) {
console.log("Got call to Blockly.Component.rename(" + oldname + ", " + newname + ", " + uid + ")");
AI.Blockly.TypeBlock.needsReload.components = true;
if (!Blockly.ComponentInstances.haveInstance(oldname, uid)) {
console.log("Renaming, No such Component instance " + oldname + " aborting");
return;
}
// Create an entry in Blockly.ComponentInstances for the block's newname and delete oldname (below)
Blockly.ComponentInstances[newname] = {}
Blockly.ComponentInstances[newname].uid = uid;
Blockly.ComponentInstances[newname].typeName = Blockly.ComponentInstances[oldname].typeName;

// Delete the index entry for the oldname
Blockly.ComponentInstances[oldname] = null;
delete Blockly.ComponentInstances[oldname];

console.log("Revised Blockly.ComponentInstances, Blockly.Language, AI.Yail for " + newname);

// Revise names, types, and block titles for all blocks containing newname in Blockly.common.getMainWorkspace()
var blocks = Blockly.common.getMainWorkspace().getAllBlocks();
for (var x = 0, block; block = blocks[x]; x++) {
if (!block.category) {
continue;
} else if (block.category == 'Component') {
block.rename(oldname, newname); // Changes block's instanceName, typeName, and current title
}
}

console.log("Revised Blockly.common.getMainWorkspace() for " + newname);
};


/**
* Remove component with given type and instance name and unique id uid
* @param type, Component's type -- e.g., Button
* @param name, Component's name == e.g., Buton1
* @param uid, Component's unique id -- not currently used
*
* The component should be listed in the ComponentInstances list.
* - For each instance of the component's block in the Blockly.common.getMainWorkspace()
* -- Call its BlocklyBlock.destroy() method to remove the block
* from the workspace and adjust enclosed or enclosing blocks.
* Remove the block's entry from ComponentInstances
*
*/
Blockly.Component.remove = function(type, name, uid) {
console.log("Got call to Blockly.Component.remove(" + type + ", " + name + ", " + uid + ")");
AI.Blockly.TypeBlock.needsReload.components = true;

// Delete instances of this type of block from the workspace
var allblocks = Blockly.common.getMainWorkspace().getAllBlocks();
for (var x = 0, block; block = allblocks[x]; x++) {
if (!block.category) {
continue;
} else if (block.category == 'Component' && block.instanceName == name) {
block.dispose(true); // Destroy the block gently
}
}

// Remove the component instance
console.log("Deleting " + name + " from Blockly.ComponentInstances");
delete Blockly.ComponentInstances[name];
};

/**
* Builds a map of component name -> top level blocks for that component.
Expand Down
3 changes: 1 addition & 2 deletions appinventor/blocklyeditor/src/demos/yail/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@
}

function defineComponents(componentJsonObj) {
Blockly.Component.add(JSON.stringify(componentTypes[componentJsonObj.$Type]),
componentJsonObj.$Name, componentJsonObj.Uuid);
Blockly.common.getMainWorkspace().addComponent(componentJsonObj.Uuid, componentJsonObj.$Name, componentJsonObj.$Type);
if (componentJsonObj.$Components) {
for (var i = 0, comp; comp = componentJsonObj.$Components[i]; i++) {
defineComponents(comp);
Expand Down
2 changes: 0 additions & 2 deletions appinventor/blocklyeditor/tests/testCommon.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ function getFormComponents(formJson) {

function defineComponents(componentJsonObj) {
Blockly.common.getMainWorkspace().addComponent(componentJsonObj.Uuid, componentJsonObj.$Name, componentJsonObj.$Type);
// Blockly.Component.add(JSON.stringify(componentTypes[componentJsonObj.$Type]),
// componentJsonObj.$Name, componentJsonObj.Uuid);
if (componentJsonObj.$Components) {
for (var i = 0, comp; comp = componentJsonObj.$Components[i]; i++) {
defineComponents(comp);
Expand Down