Bug fix for clear (#582)

This commit is contained in:
Emma Dauterman
2016-08-23 13:47:08 -07:00
committed by picklesrus
parent b0432306a1
commit aa9dd9646a
2 changed files with 24 additions and 36 deletions

View File

@@ -399,48 +399,35 @@ WorkspaceFactoryController.prototype.updatePreview = function() {
// through event handlers.
Blockly.Events.disable();
if (this.selectedMode == WorkspaceFactoryController.MODE_TOOLBOX) {
// If currently editing the toolbox.
// Only update the toolbox if not in read only mode.
if (!this.model.options['readOnly']) {
// Get toolbox XML.
var tree = Blockly.Options.parseToolboxTree
(this.generator.generateToolboxXml());
// Only update the toolbox if not in read only mode.
if (!this.model.options['readOnly']) {
// Get toolbox XML.
var tree = Blockly.Options.parseToolboxTree
(this.generator.generateToolboxXml());
// No categories, creates a simple flyout.
if (tree.getElementsByTagName('category').length == 0) {
// No categories, creates a simple flyout.
if (tree.getElementsByTagName('category').length == 0) {
// No categories, creates a simple flyout.
if (this.previewWorkspace.toolbox_) {
this.reinjectPreview(tree); // Switch to simple flyout, expensive.
} else {
this.previewWorkspace.updateToolbox(tree);
}
if (this.previewWorkspace.toolbox_) {
this.reinjectPreview(tree); // Switch to simple flyout, expensive.
} else {
// Uses categories, creates a toolbox.
if (!this.previewWorkspace.toolbox_) {
this.reinjectPreview(tree); // Create a toolbox, expensive.
} else {
this.previewWorkspace.updateToolbox(tree);
}
this.previewWorkspace.updateToolbox(tree);
}
} else {
// Uses categories, creates a toolbox.
if (!this.previewWorkspace.toolbox_) {
this.reinjectPreview(tree); // Create a toolbox, expensive.
} else {
this.previewWorkspace.updateToolbox(tree);
}
}
// Update pre-loaded blocks in the preview workspace to make sure that
// blocks don't get cleared when updating preview from event listeners while
// switching modes.
this.previewWorkspace.clear();
Blockly.Xml.domToWorkspace(this.generator.generateWorkspaceXml(),
this.previewWorkspace);
} else if (this.selectedMode == WorkspaceFactoryController.MODE_PRELOAD){
// If currently editing the pre-loaded workspace.
this.previewWorkspace.clear();
Blockly.Xml.domToWorkspace(this.generator.generateWorkspaceXml(),
this.previewWorkspace);
}
// Update pre-loaded blocks in the preview workspace.
this.previewWorkspace.clear();
Blockly.Xml.domToWorkspace(this.generator.generateWorkspaceXml(),
this.previewWorkspace);
// Reenable events.
Blockly.Events.enable();
};

View File

@@ -301,7 +301,8 @@ WorkspaceFactoryModel.prototype.clearToolboxList = function() {
this.toolboxList = [];
this.hasVariableCategory = false;
this.hasVariableCategory = false;
// TODO(evd2014): When merge changes, also clear shadowList.
this.shadowBlocks = [];
this.selected.xml = Blockly.Xml.textToDom('<xml></xml>');
};
/**