Blockly Factory: Generate Block Library Category in Workspace Factory (#568)

* Added block library category to toolbox workspace in workspace factory and update it each time user switches to workspace factory

* Added whitespace to end of index.html

* Bug fixes for convertShadowBlocks and updateState

* Last part of bug fix for adding separators
This commit is contained in:
Emma Dauterman
2016-08-19 09:48:51 -07:00
committed by picklesrus
parent 88eac2480b
commit 61af94314e
4 changed files with 39 additions and 19 deletions

View File

@@ -304,6 +304,9 @@ AppController.prototype.onTab = function() {
FactoryUtils.hide('workspaceFactoryContent');
} else if (this.selectedTab == 'WORKSPACE_FACTORY') {
// Update block library category.
var categoryXml = this.exporter.getBlockLibCategory();
this.workspaceFactoryController.setBlockLibCategory(categoryXml);
// Hide container of exporter.
FactoryUtils.hide('blockLibraryExporter');
// Show workspace factory container.

View File

@@ -715,7 +715,8 @@
<category name="Variables" colour="330" custom="VARIABLE"></category>
<category name="Functions" colour="290" custom="PROCEDURE"></category>
<sep></sep>
<category name="Block Library" colour="260" id="blockLibCategory"></category>
</xml>
</body>
</html>
</html>

View File

@@ -232,7 +232,6 @@ WorkspaceFactoryController.prototype.removeElement = function() {
// when there are no categories.
this.allowToSetDefaultOptions();
}
// Update preview.
this.updatePreview();
};
@@ -288,12 +287,6 @@ WorkspaceFactoryController.prototype.clearAndLoadElement = function(id) {
this.view.setCategoryTabSelection(this.model.getSelectedId(), false);
}
// If switching from a separator, enable workspace in view.
if (this.model.getSelectedId() != null && this.model.getSelected().type ==
ListElement.TYPE_SEPARATOR) {
this.view.disableWorkspace(false);
}
// If switching to another category, set category selection in the model and
// view.
if (id != null) {
@@ -305,16 +298,19 @@ WorkspaceFactoryController.prototype.clearAndLoadElement = function(id) {
// Selects the next tab.
this.view.setCategoryTabSelection(id, true);
// Mark all shadow blocks laoded and order blocks as if shown in a flyout.
this.view.markShadowBlocks(this.model.getShadowBlocksInWorkspace
(this.toolboxWorkspace.getAllBlocks()));
this.toolboxWorkspace.cleanUp();
// Update category editing buttons.
this.view.updateState(this.model.getIndexByElementId
(this.model.getSelectedId()), this.model.getSelected());
} else {
// Update category editing buttons for no categories.
this.view.updateState(-1, null);
}
// Mark all shadow blocks laoded and order blocks as if shown in a flyout.
this.view.markShadowBlocks(this.model.getShadowBlocksInWorkspace
(this.toolboxWorkspace.getAllBlocks()));
this.toolboxWorkspace.cleanUp();
// Update category editing buttons.
this.view.updateState(this.model.getIndexByElementId
(this.model.getSelectedId()), this.model.getSelected());
};
/**
@@ -608,7 +604,7 @@ WorkspaceFactoryController.prototype.loadCategory = function() {
// Switch to loaded category.
this.switchElement(copy.id);
// Convert actual shadow blocks to user-generated shadow blocks.
this.convertShadowBlocks_();
this.convertShadowBlocks();
// Save state from workspace before updating preview.
this.saveStateFromWorkspace();
if (isFirstCategory) {
@@ -1177,3 +1173,22 @@ WorkspaceFactoryController.prototype.importBlocks =
reader.readAsText(file);
};
/*
* Updates the block library category in the toolbox workspace toolbox.
*
* @param {!Element} categoryXml XML for the block library category.
*/
WorkspaceFactoryController.prototype.setBlockLibCategory =
function(categoryXml) {
var blockLibCategory = document.getElementById('blockLibCategory');
// Set category id so that it can be easily replaced, and set a standard,
// arbitrary block library color.
categoryXml.setAttribute('id', 'blockLibCategory');
categoryXml.setAttribute('colour', 260);
// Update the toolbox and toolboxWorkspace.
this.toolbox.replaceChild(categoryXml, blockLibCategory);
this.toolboxWorkspace.updateToolbox(this.toolbox);
};

View File

@@ -282,7 +282,8 @@ WorkspaceFactoryView.prototype.disableWorkspace = function(disable) {
* @return {boolean} True if the workspace should be disabled, false otherwise.
*/
WorkspaceFactoryView.prototype.shouldDisableWorkspace = function(category) {
return category != null && (category.type == ListElement.TYPE_SEPARATOR ||
return category != null && category.type != ListElement.TYPE_FLYOUT &&
(category.type == ListElement.TYPE_SEPARATOR ||
category.custom == 'VARIABLE' || category.custom == 'PROCEDURE');
};