Blockly Factory: Clean Up Workspace on Save Block, Import Lowercase Types (#584)

* save only factory base block upon save to library; import block library with lowercase blocktypes

* nit comment
This commit is contained in:
Tina Quach
2016-08-24 10:29:24 -07:00
committed by picklesrus
parent 2995f76ed8
commit 8e44684c81
2 changed files with 11 additions and 2 deletions

View File

@@ -197,7 +197,8 @@ AppController.prototype.formatBlockLibForImport_ = function(xmlText) {
xmlDom.appendChild(blockNode);
var xmlText = Blockly.Xml.domToText(xmlDom);
var blockType = this.getBlockTypeFromXml_(xmlText);
// All block types should be lowercase.
var blockType = this.getBlockTypeFromXml_(xmlText).toLowerCase();
blockXmlTextMap[blockType] = xmlText;
}

View File

@@ -139,11 +139,19 @@ BlockLibraryController.prototype.saveToBlockLibrary = function() {
}
}
// Create block xml.
var xmlElement = goog.dom.createDom('xml');
var block = FactoryUtils.getRootBlock(BlockFactory.mainWorkspace);
xmlElement.appendChild(Blockly.Xml.blockToDomWithXY(block));
// Save block.
var xmlElement = Blockly.Xml.workspaceToDom(BlockFactory.mainWorkspace);
this.storage.addBlock(blockType, xmlElement);
this.storage.saveToLocalStorage();
// Show saved block without other stray blocks sitting in Block Factory's
// main workspace.
this.openBlock(blockType);
// Do not add another option to dropdown if replacing.
if (replace) {
return;