Block(ly) Factory prompts should have defaults. Drop unused copy of colourpicker code.

This commit is contained in:
Neil Fraser
2016-10-11 12:16:17 -07:00
parent c102734ccb
commit 5df55ddea0
19 changed files with 71 additions and 189 deletions

View File

@@ -75,8 +75,8 @@ goog.inherits(Blockly.WorkspaceSvg, Blockly.Workspace);
Blockly.WorkspaceSvg.prototype.resizeHandlerWrapper_ = null;
/**
* The render status of an SVG workspace.
* Returns `true` for visible workspaces and `false` for non-visible, or headless, workspaces.
* The render status of an SVG workspace.
* Returns `true` for visible workspaces and `false` for non-visible, or headless, workspaces.
* @type {boolean}
*/
Blockly.WorkspaceSvg.prototype.rendered = true;
@@ -316,7 +316,7 @@ Blockly.WorkspaceSvg.prototype.dispose = function() {
* @param {?string} prototypeName Name of the language object containing
* type-specific functions for this block.
* @param {string=} opt_id Optional ID. Use this ID if provided, otherwise
* create a new id.
* create a new ID.
* @return {!Blockly.BlockSvg} The created block.
*/
Blockly.WorkspaceSvg.prototype.newBlock = function(prototypeName, opt_id) {

View File

@@ -1,12 +1,12 @@
/**
* @license
* Visual Blocks Editor
* Blockly Demos: Block Factory
*
* Copyright 2016 Google Inc.
* https://developers.google.com/blockly/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* You may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
@@ -134,7 +134,7 @@ AppController.prototype.exportBlockLibraryToFile = function() {
var blockLibText = this.formatBlockLibraryForExport_(blockLib);
// Get file name.
var filename = prompt('Enter the file name under which to save your block ' +
'library.');
'library.', 'library.xml');
// Download file if all necessary parameters are provided.
if (filename) {
FactoryUtils.createAndDownloadFile(blockLibText, filename, 'xml');

View File

@@ -1,12 +1,12 @@
/**
* @license
* Visual Blocks Editor
* Blockly Demos: Block Factory
*
* Copyright 2016 Google Inc.
* https://developers.google.com/blockly/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* You may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0

View File

@@ -1,12 +1,12 @@
/**
* @license
* Visual Blocks Editor
* Blockly Demos: Block Factory
*
* Copyright 2016 Google Inc.
* https://developers.google.com/blockly/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* You may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0

View File

@@ -1,12 +1,12 @@
/**
* @license
* Visual Blocks Editor
* Blockly Demos: Block Factory
*
* Copyright 2016 Google Inc.
* https://developers.google.com/blockly/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* You may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0

View File

@@ -1,12 +1,12 @@
/**
* @license
* Visual Blocks Editor
* Blockly Demos: Block Factory
*
* Copyright 2016 Google Inc.
* https://developers.google.com/blockly/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* You may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0

View File

@@ -1,12 +1,12 @@
/**
* @license
* Visual Blocks Editor
* Blockly Demos: Block Factory
*
* Copyright 2016 Google Inc.
* https://developers.google.com/blockly/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* You may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
@@ -166,5 +166,5 @@ BlockLibraryStorage.prototype.getBlockXmlTextMap = function() {
* @return {boolean} Whether or not blockType is stored in block library.
*/
BlockLibraryStorage.prototype.has = function(blockType) {
return this.blocks[blockType] ? true : false;
return !!this.blocks[blockType];
};

View File

@@ -1,12 +1,12 @@
/**
* @license
* Visual Blocks Editor
* Blockly Demos: Block Factory
*
* Copyright 2016 Google Inc.
* https://developers.google.com/blockly/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* You may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0

View File

@@ -1,12 +1,12 @@
/**
* @license
* Visual Blocks Editor
* Blockly Demos: Block Factory
*
* Copyright 2016 Google Inc.
* https://developers.google.com/blockly/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* You may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0

View File

@@ -1,12 +1,12 @@
/**
* @license
* Visual Blocks Editor
* Blockly Demos: Block Factory
*
* Copyright 2016 Google Inc.
* https://developers.google.com/blockly/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* You may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0

View File

@@ -1,12 +1,12 @@
/**
* @license
* Visual Blocks Editor
* Blockly Demos: Block Factory
*
* Copyright 2016 Google Inc.
* https://developers.google.com/blockly/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* You may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0

View File

@@ -1,12 +1,12 @@
/**
* @license
* Visual Blocks Editor
* Blockly Demos: Block Factory
*
* Copyright 2016 Google Inc.
* https://developers.google.com/blockly/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* You may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0

View File

@@ -1,6 +1,6 @@
/**
* @license
* Visual Blocks Editor
* Blockly Demos: Block Factory
*
* Copyright 2016 Google Inc.
* https://developers.google.com/blockly/

View File

@@ -454,70 +454,6 @@ goog.require('goog.ui.ColorPicker');
<category name="Functions" colour="290" custom="PROCEDURE"></category>
</xml>
<script type="text/javascript">
// Array of Blockly category colors, variety of hues with saturation 45%
// and value 65% as specified in Blockly Developer documentation:
// https://developers.google.com/blockly/guides/create-custom-blocks/define-blocks
var colors = ['#A65C5C',
'#A6635C',
'#A66A5C',
'#A6725C',
'#A6795C',
'#A6815C',
'#A6885C',
'#A6905C',
'#A6975C',
'#A69F5C',
'#A6A65C',
'#9FA65C',
'#97A65C',
'#90A65C',
'#88A65C',
'#81A65C',
'#79A65C',
'#6FA65C',
'#66A65C',
'#5EA65C',
'#5CA661',
'#5CA668',
'#5CA66F',
'#5CA677',
'#5CA67E',
'#5CA686',
'#5CA68D',
'#5CA695',
'#5CA69C',
'#5CA6A4',
'#5CA1A6',
'#5C9AA6',
'#5C92A6',
'#5C8BA6',
'#5C83A6',
'#5C7CA6',
'#5C74A6',
'#5C6AA6',
'#5C61A6',
'#5E5CA6',
'#665CA6',
'#6D5CA6',
'#745CA6',
'#7C5CA6',
'#835CA6',
'#8B5CA6',
'#925CA6',
'#9A5CA6',
'#A15CA6',
'#A65CA4',
'#A65C9C',
'#A65C95',
'#A65C8D',
'#A65C86',
'#A65C7E',
'#A65C77',
'#A65C6F',
'#A65C66',
'#A65C61',
'#A65C5E'];
// Create empty workspace for configuring workspace.
var toolboxWorkspace = Blockly.inject('toolbox_blocks',
{grid:
@@ -726,20 +662,6 @@ goog.require('goog.ui.ColorPicker');
}
});
// Create color picker with specific set of Blockly colors.
var colorPicker = new goog.ui.ColorPicker();
colorPicker.setColors(colors);
// Create and render the popup color picker and attach to button.
var popupPicker = new goog.ui.PopupColorPicker(null, colorPicker);
popupPicker.render();
popupPicker.attach(document.getElementById('dropdown_color'));
popupPicker.setFocusable(true);
goog.events.listen(popupPicker, 'change', function(e) {
controller.changeSelectedCategoryColor(popupPicker.getSelectedColor());
document.getElementById('dropdownDiv_editCategory').classList.remove
("show");
});
// Disable category editing buttons until categories are created.
document.getElementById('button_remove').disabled = true;
document.getElementById('button_up').disabled = true;

View File

@@ -1,6 +1,6 @@
/**
* @license
* Visual Blocks Editor
* Blockly Demos: Block Factory
*
* Copyright 2016 Google Inc.
* https://developers.google.com/blockly/
@@ -108,8 +108,8 @@ WorkspaceFactoryController.prototype.addCategory = function() {
// After possibly creating a category, check again if it's the first category.
var isFirstCategory = !this.model.hasElements();
// Get name from user.
name = this.promptForNewCategoryName('Enter the name of your new category: ');
if (!name) { //Exit if cancelled.
name = this.promptForNewCategoryName('Enter the name of your new category:');
if (!name) { // Exit if cancelled.
return;
}
// Create category.
@@ -117,7 +117,7 @@ WorkspaceFactoryController.prototype.addCategory = function() {
// Switch to category.
this.switchElement(this.model.getCategoryIdByName(name));
// Sets the default options for injecting the workspace
// Sets the default options for injecting the workspace
// when there are categories if adding the first category.
if (isFirstCategory) {
this.view.setCategoryOptions(this.model.hasElements());
@@ -152,7 +152,7 @@ WorkspaceFactoryController.prototype.createCategory = function(name) {
*/
WorkspaceFactoryController.prototype.addClickToSwitch = function(tab, id) {
var self = this;
var clickFunction = function(id) { // Keep this in scope for switchElement
var clickFunction = function(id) { // Keep this in scope for switchElement.
return function() {
self.switchElement(id);
};
@@ -237,15 +237,18 @@ WorkspaceFactoryController.prototype.removeElement = function() {
/**
* Gets a valid name for a new category from the user.
* @param {string} promptString Prompt for the user to enter a name.
* @param {string=} opt_oldName The current name.
* @return {string} Valid name for a new category, or null if cancelled.
*/
WorkspaceFactoryController.prototype.promptForNewCategoryName =
function(promptString) {
function(promptString, opt_oldName) {
var defaultName = opt_oldName;
do {
var name = prompt(promptString);
var name = prompt(promptString, defaultName);
if (!name) { // If cancelled.
return null;
}
defaultName = name;
} while (this.model.hasCategoryByName(name));
return name;
};
@@ -316,9 +319,12 @@ WorkspaceFactoryController.prototype.clearAndLoadElement = function(id) {
*/
WorkspaceFactoryController.prototype.exportXmlFile = function(exportMode) {
// Get file name.
var fileName = prompt('File Name for ' + (exportMode ==
WorkspaceFactoryController.MODE_TOOLBOX ? 'toolbox XML: ' :
'pre-loaded workspace XML: '));
if (exportMode == WorkspaceFactoryController.MODE_TOOLBOX) {
var fileName = prompt('File Name for toolbox XML:', 'toolbox.xml');
} else {
var fileName = prompt('File Name for pre-loaded workspace XML:',
'workspace.xml');
}
if (!fileName) { // If cancelled.
return;
}
@@ -349,7 +355,8 @@ WorkspaceFactoryController.prototype.exportXmlFile = function(exportMode) {
* file name from the user and downloads the options object to that file.
*/
WorkspaceFactoryController.prototype.exportInjectFile = function() {
var fileName = prompt('File Name for starter Blockly workspace code: ');
var fileName = prompt('File Name for starter Blockly workspace code:',
'workspace.js');
if (!fileName) { // If cancelled.
return;
}
@@ -474,18 +481,20 @@ WorkspaceFactoryController.prototype.reinjectPreview = function(tree) {
* currently in use, exits if user presses cancel.
*/
WorkspaceFactoryController.prototype.changeCategoryName = function() {
var selected = this.model.getSelected();
// Return if a category is not selected.
if (this.model.getSelected().type != ListElement.TYPE_CATEGORY) {
if (selected.type != ListElement.TYPE_CATEGORY) {
return;
}
// Get new name from user.
window.foo = selected;
var newName = this.promptForNewCategoryName('What do you want to change this'
+ ' category\'s name to?');
+ ' category\'s name to?', selected.name);
if (!newName) { // If cancelled.
return;
}
// Change category name.
this.model.getSelected().changeName(newName);
selected.changeName(newName);
this.view.updateCategoryName(newName, this.model.getSelectedId());
// Update preview.
this.updatePreview();

View File

@@ -1,6 +1,6 @@
/**
* @license
* Visual Blocks Editor
* Blockly Demos: Block Factory
*
* Copyright 2016 Google Inc.
* https://developers.google.com/blockly/

View File

@@ -1,12 +1,12 @@
/**
* @license
* Visual Blocks Editor
* Blockly Demos: Block Factory
*
* Copyright 2016 Google Inc.
* https://developers.google.com/blockly/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* You may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
@@ -65,68 +65,20 @@ WorkspaceFactoryInit.initWorkspaceFactory = function(controller) {
WorkspaceFactoryInit.initColorPicker_ = function(controller) {
// Array of Blockly category colors, variety of hues with saturation 45%
// and value 65% as specified in Blockly Developer documentation:
// https://developers.google.com/blockly/guides/create-custom-blocks/define-blocks
// developers.google.com/blockly/guides/create-custom-blocks/define-blocks
var colors = [
'#A65C5C',
'#A6635C',
'#A66A5C',
'#A6725C',
'#A6795C',
'#A6815C',
'#A6885C',
'#A6905C',
'#A6975C',
'#A69F5C',
'#A6A65C',
'#9FA65C',
'#97A65C',
'#90A65C',
'#88A65C',
'#81A65C',
'#79A65C',
'#6FA65C',
'#66A65C',
'#5EA65C',
'#5CA661',
'#5CA668',
'#5CA66F',
'#5CA677',
'#5CA67E',
'#5CA686',
'#5CA68D',
'#5CA695',
'#5CA69C',
'#5CA6A4',
'#5CA1A6',
'#5C9AA6',
'#5C92A6',
'#5C8BA6',
'#5C83A6',
'#5C7CA6',
'#5C74A6',
'#5C6AA6',
'#5C61A6',
'#5E5CA6',
'#665CA6',
'#6D5CA6',
'#745CA6',
'#7C5CA6',
'#835CA6',
'#8B5CA6',
'#925CA6',
'#9A5CA6',
'#A15CA6',
'#A65CA4',
'#A65C9C',
'#A65C95',
'#A65C8D',
'#A65C86',
'#A65C7E',
'#A65C77',
'#A65C6F',
'#A65C66',
'#A65C61',
'#A65C5E'
'#A65C5C', '#A6635C', '#A66A5C', '#A6725C', '#A6795C',
'#A6815C', '#A6885C', '#A6905C', '#A6975C', '#A69F5C',
'#A6A65C', '#9FA65C', '#97A65C', '#90A65C', '#88A65C',
'#81A65C', '#79A65C', '#6FA65C', '#66A65C', '#5EA65C',
'#5CA661', '#5CA668', '#5CA66F', '#5CA677', '#5CA67E',
'#5CA686', '#5CA68D', '#5CA695', '#5CA69C', '#5CA6A4',
'#5CA1A6', '#5C9AA6', '#5C92A6', '#5C8BA6', '#5C83A6',
'#5C7CA6', '#5C74A6', '#5C6AA6', '#5C61A6', '#5E5CA6',
'#665CA6', '#6D5CA6', '#745CA6', '#7C5CA6', '#835CA6',
'#8B5CA6', '#925CA6', '#9A5CA6', '#A15CA6', '#A65CA4',
'#A65C9C', '#A65C95', '#A65C8D', '#A65C86', '#A65C7E',
'#A65C77', '#A65C6F', '#A65C66', '#A65C61', '#A65C5E'
];
// Create color picker with specific set of Blockly colors.

View File

@@ -1,6 +1,6 @@
/**
* @license
* Visual Blocks Editor
* Blockly Demos: Block Factory
*
* Copyright 2016 Google Inc.
* https://developers.google.com/blockly/

View File

@@ -1,6 +1,6 @@
/**
* @license
* Visual Blocks Editor
* Blockly Demos: Block Factory
*
* Copyright 2016 Google Inc.
* https://developers.google.com/blockly/
@@ -112,11 +112,10 @@ WorkspaceFactoryView.prototype.updateState = function(selectedIndex, selected) {
document.getElementById('button_editCategory').disabled = selectedIndex < 0 ||
selected.type != ListElement.TYPE_CATEGORY;
document.getElementById('button_remove').disabled = selectedIndex < 0;
document.getElementById('button_up').disabled =
selectedIndex <= 0 ? true : false;
document.getElementById('button_up').disabled = selectedIndex <= 0;
var table = document.getElementById('categoryTable');
document.getElementById('button_down').disabled = selectedIndex >=
table.rows.length - 1 || selectedIndex < 0 ? true : false;
table.rows.length - 1 || selectedIndex < 0;
// Disable/enable the workspace as necessary.
this.disableWorkspace(this.shouldDisableWorkspace(selected));
};