2013-10-30 14:46:03 -07:00
|
|
|
/**
|
2014-01-28 03:00:09 -08:00
|
|
|
* @license
|
2013-10-30 14:46:03 -07:00
|
|
|
* Visual Blocks Editor
|
|
|
|
*
|
|
|
|
* Copyright 2012 Google Inc.
|
2014-10-07 13:09:55 -07:00
|
|
|
* https://developers.google.com/blockly/
|
2013-10-30 14:46:03 -07:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (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
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @fileoverview Object representing a workspace.
|
|
|
|
* @author fraser@google.com (Neil Fraser)
|
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
goog.provide('Blockly.Workspace');
|
|
|
|
|
2016-10-04 21:20:07 -07:00
|
|
|
goog.require('goog.array');
|
2015-02-06 15:27:25 -08:00
|
|
|
goog.require('goog.math');
|
|
|
|
|
2013-10-30 14:46:03 -07:00
|
|
|
|
|
|
|
/**
|
2014-12-23 11:22:02 -08:00
|
|
|
* Class for a workspace. This is a data structure that contains blocks.
|
|
|
|
* There is no UI, and can be created headlessly.
|
2016-03-29 14:26:56 -07:00
|
|
|
* @param {Blockly.Options} opt_options Dictionary of options.
|
2013-10-30 14:46:03 -07:00
|
|
|
* @constructor
|
|
|
|
*/
|
2015-04-28 13:51:25 -07:00
|
|
|
Blockly.Workspace = function(opt_options) {
|
2015-12-09 10:17:40 +01:00
|
|
|
/** @type {string} */
|
2017-02-02 14:17:43 -05:00
|
|
|
this.id = Blockly.utils.genUid();
|
2015-12-09 10:17:40 +01:00
|
|
|
Blockly.Workspace.WorkspaceDB_[this.id] = this;
|
2016-03-29 14:26:56 -07:00
|
|
|
/** @type {!Blockly.Options} */
|
2015-04-28 13:51:25 -07:00
|
|
|
this.options = opt_options || {};
|
2015-08-19 17:21:05 -07:00
|
|
|
/** @type {boolean} */
|
2015-04-28 13:51:25 -07:00
|
|
|
this.RTL = !!this.options.RTL;
|
2016-02-11 14:46:51 -08:00
|
|
|
/** @type {boolean} */
|
|
|
|
this.horizontalLayout = !!this.options.horizontalLayout;
|
2016-05-11 11:44:38 -07:00
|
|
|
/** @type {number} */
|
2016-04-13 15:30:11 -07:00
|
|
|
this.toolboxPosition = this.options.toolboxPosition;
|
2016-05-12 18:30:42 -07:00
|
|
|
|
2016-05-04 15:05:45 -07:00
|
|
|
/**
|
|
|
|
* @type {!Array.<!Blockly.Block>}
|
|
|
|
* @private
|
|
|
|
*/
|
2015-08-19 17:21:05 -07:00
|
|
|
this.topBlocks_ = [];
|
2016-05-04 15:05:45 -07:00
|
|
|
/**
|
|
|
|
* @type {!Array.<!Function>}
|
|
|
|
* @private
|
|
|
|
*/
|
2016-02-11 21:40:33 -08:00
|
|
|
this.listeners_ = [];
|
2016-05-12 18:30:42 -07:00
|
|
|
|
2016-02-24 13:57:14 -05:00
|
|
|
/** @type {!Array.<!Function>} */
|
|
|
|
this.tapListeners_ = [];
|
2016-05-12 18:30:42 -07:00
|
|
|
|
2016-05-04 15:05:45 -07:00
|
|
|
/**
|
|
|
|
* @type {!Array.<!Blockly.Events.Abstract>}
|
|
|
|
* @private
|
|
|
|
*/
|
2016-03-03 17:48:54 -08:00
|
|
|
this.undoStack_ = [];
|
2016-05-12 18:30:42 -07:00
|
|
|
|
2016-05-04 15:05:45 -07:00
|
|
|
/**
|
|
|
|
* @type {!Array.<!Blockly.Events.Abstract>}
|
|
|
|
* @private
|
|
|
|
*/
|
2016-03-03 17:48:54 -08:00
|
|
|
this.redoStack_ = [];
|
2016-05-12 18:30:42 -07:00
|
|
|
|
2016-05-04 15:05:45 -07:00
|
|
|
/**
|
|
|
|
* @type {!Object}
|
|
|
|
* @private
|
|
|
|
*/
|
2016-04-05 18:43:39 -07:00
|
|
|
this.blockDB_ = Object.create(null);
|
2016-06-22 16:16:31 -07:00
|
|
|
/*
|
2016-10-21 17:38:57 -07:00
|
|
|
* @type {!Array.<string>}
|
2016-06-22 16:16:31 -07:00
|
|
|
* A list of all of the named variables in the workspace, including variables
|
|
|
|
* that are not currently in use.
|
|
|
|
*/
|
|
|
|
this.variableList = [];
|
2013-10-30 14:46:03 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2016-09-27 17:47:36 -04:00
|
|
|
* Returns `true` if the workspace is visible and `false` if it's headless.
|
|
|
|
* @type {boolean}
|
2013-10-30 14:46:03 -07:00
|
|
|
*/
|
2014-12-23 11:22:02 -08:00
|
|
|
Blockly.Workspace.prototype.rendered = false;
|
2013-10-30 14:46:03 -07:00
|
|
|
|
2016-03-03 17:48:54 -08:00
|
|
|
/**
|
2016-09-27 17:47:36 -04:00
|
|
|
* Maximum number of undo events in stack. `0` turns off undo, `Infinity` sets it to unlimited.
|
|
|
|
* @type {number}
|
2016-03-03 17:48:54 -08:00
|
|
|
*/
|
|
|
|
Blockly.Workspace.prototype.MAX_UNDO = 1024;
|
|
|
|
|
2013-10-30 14:46:03 -07:00
|
|
|
/**
|
|
|
|
* Dispose of this workspace.
|
|
|
|
* Unlink from all DOM elements to prevent memory leaks.
|
|
|
|
*/
|
|
|
|
Blockly.Workspace.prototype.dispose = function() {
|
2016-02-11 21:40:33 -08:00
|
|
|
this.listeners_.length = 0;
|
2014-12-23 11:22:02 -08:00
|
|
|
this.clear();
|
2015-12-09 10:17:40 +01:00
|
|
|
// Remove from workspace database.
|
|
|
|
delete Blockly.Workspace.WorkspaceDB_[this.id];
|
2013-10-30 14:46:03 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2014-12-23 11:22:02 -08:00
|
|
|
* Angle away from the horizontal to sweep for blocks. Order of execution is
|
|
|
|
* generally top to bottom, but a small angle changes the scan to give a bit of
|
|
|
|
* a left to right bias (reversed in RTL). Units are in degrees.
|
|
|
|
* See: http://tvtropes.org/pmwiki/pmwiki.php/Main/DiagonalBilling.
|
2013-10-30 14:46:03 -07:00
|
|
|
*/
|
2014-12-23 11:22:02 -08:00
|
|
|
Blockly.Workspace.SCAN_ANGLE = 3;
|
2013-10-30 14:46:03 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a block to the list of top blocks.
|
|
|
|
* @param {!Blockly.Block} block Block to remove.
|
|
|
|
*/
|
|
|
|
Blockly.Workspace.prototype.addTopBlock = function(block) {
|
|
|
|
this.topBlocks_.push(block);
|
2016-06-22 16:16:31 -07:00
|
|
|
if (this.isFlyout) {
|
2016-08-17 16:07:50 -07:00
|
|
|
// This is for the (unlikely) case where you have a variable in a block in
|
|
|
|
// an always-open flyout. It needs to be possible to edit the block in the
|
|
|
|
// flyout, so the contents of the dropdown need to be correct.
|
2016-07-07 15:28:23 -07:00
|
|
|
var variables = Blockly.Variables.allUsedVariables(block);
|
2016-06-22 16:16:31 -07:00
|
|
|
for (var i = 0; i < variables.length; i++) {
|
|
|
|
if (this.variableList.indexOf(variables[i]) == -1) {
|
|
|
|
this.variableList.push(variables[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-10-30 14:46:03 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove a block from the list of top blocks.
|
|
|
|
* @param {!Blockly.Block} block Block to remove.
|
|
|
|
*/
|
|
|
|
Blockly.Workspace.prototype.removeTopBlock = function(block) {
|
2016-10-04 21:20:07 -07:00
|
|
|
if (!goog.array.remove(this.topBlocks_, block)) {
|
2013-10-30 14:46:03 -07:00
|
|
|
throw 'Block not present in workspace\'s list of top-most blocks.';
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Finds the top-level blocks and returns them. Blocks are optionally sorted
|
|
|
|
* by position; top to bottom (with slight LTR or RTL bias).
|
|
|
|
* @param {boolean} ordered Sort the list if true.
|
|
|
|
* @return {!Array.<!Blockly.Block>} The top-level block objects.
|
|
|
|
*/
|
|
|
|
Blockly.Workspace.prototype.getTopBlocks = function(ordered) {
|
|
|
|
// Copy the topBlocks_ list.
|
|
|
|
var blocks = [].concat(this.topBlocks_);
|
|
|
|
if (ordered && blocks.length > 1) {
|
2014-11-24 15:08:19 -08:00
|
|
|
var offset = Math.sin(goog.math.toRadians(Blockly.Workspace.SCAN_ANGLE));
|
2015-04-28 13:51:25 -07:00
|
|
|
if (this.RTL) {
|
2013-10-30 14:46:03 -07:00
|
|
|
offset *= -1;
|
|
|
|
}
|
|
|
|
blocks.sort(function(a, b) {
|
|
|
|
var aXY = a.getRelativeToSurfaceXY();
|
|
|
|
var bXY = b.getRelativeToSurfaceXY();
|
|
|
|
return (aXY.y + offset * aXY.x) - (bXY.y + offset * bXY.x);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return blocks;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Find all blocks in workspace. No particular order.
|
|
|
|
* @return {!Array.<!Blockly.Block>} Array of blocks.
|
|
|
|
*/
|
|
|
|
Blockly.Workspace.prototype.getAllBlocks = function() {
|
|
|
|
var blocks = this.getTopBlocks(false);
|
2014-12-23 11:22:02 -08:00
|
|
|
for (var i = 0; i < blocks.length; i++) {
|
|
|
|
blocks.push.apply(blocks, blocks[i].getChildren());
|
2013-10-30 14:46:03 -07:00
|
|
|
}
|
|
|
|
return blocks;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Dispose of all blocks in workspace.
|
|
|
|
*/
|
|
|
|
Blockly.Workspace.prototype.clear = function() {
|
2016-03-17 14:44:26 -07:00
|
|
|
var existingGroup = Blockly.Events.getGroup();
|
|
|
|
if (!existingGroup) {
|
|
|
|
Blockly.Events.setGroup(true);
|
|
|
|
}
|
2013-10-30 14:46:03 -07:00
|
|
|
while (this.topBlocks_.length) {
|
|
|
|
this.topBlocks_[0].dispose();
|
|
|
|
}
|
2016-03-17 14:44:26 -07:00
|
|
|
if (!existingGroup) {
|
|
|
|
Blockly.Events.setGroup(false);
|
|
|
|
}
|
2016-06-22 16:16:31 -07:00
|
|
|
this.variableList.length = 0;
|
2016-09-28 16:41:35 -04:00
|
|
|
// Any block with a drop-down or WidgetDiv was disposed.
|
|
|
|
if (Blockly.DropDownDiv) {
|
|
|
|
Blockly.DropDownDiv.hideWithoutAnimation();
|
|
|
|
}
|
|
|
|
if (Blockly.WidgetDiv) {
|
|
|
|
Blockly.WidgetDiv.hide(true);
|
|
|
|
}
|
2016-06-22 16:16:31 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2016-07-13 16:46:27 -07:00
|
|
|
* Walk the workspace and update the list of variables to include all variables
|
|
|
|
* in use on the workspace. Use when loading new workspaces from disk.
|
|
|
|
* @param {boolean} clearList True if the old variable list should be cleared.
|
2016-06-22 16:16:31 -07:00
|
|
|
*/
|
2016-07-13 16:46:27 -07:00
|
|
|
Blockly.Workspace.prototype.updateVariableList = function(clearList) {
|
2016-06-22 16:16:31 -07:00
|
|
|
// TODO: Sort
|
|
|
|
if (!this.isFlyout) {
|
|
|
|
// Update the list in place so that the flyout's references stay correct.
|
2016-07-13 16:46:27 -07:00
|
|
|
if (clearList) {
|
|
|
|
this.variableList.length = 0;
|
|
|
|
}
|
|
|
|
var allVariables = Blockly.Variables.allUsedVariables(this);
|
2016-06-22 16:16:31 -07:00
|
|
|
for (var i = 0; i < allVariables.length; i++) {
|
2016-07-13 16:46:27 -07:00
|
|
|
this.createVariable(allVariables[i]);
|
2016-06-22 16:16:31 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Rename a variable by updating its name in the variable list.
|
2016-07-01 15:51:59 -07:00
|
|
|
* TODO: #468
|
2016-06-22 16:16:31 -07:00
|
|
|
* @param {string} oldName Variable to rename.
|
|
|
|
* @param {string} newName New variable name.
|
|
|
|
*/
|
|
|
|
Blockly.Workspace.prototype.renameVariable = function(oldName, newName) {
|
2016-08-17 16:07:50 -07:00
|
|
|
// Find the old name in the list.
|
|
|
|
var variableIndex = this.variableIndexOf(oldName);
|
|
|
|
var newVariableIndex = this.variableIndexOf(newName);
|
|
|
|
|
|
|
|
// We might be renaming to an existing name but with different case. If so,
|
|
|
|
// we will also update all of the blocks using the new name to have the
|
|
|
|
// correct case.
|
|
|
|
if (newVariableIndex != -1 &&
|
|
|
|
this.variableList[newVariableIndex] != newName) {
|
|
|
|
var oldCase = this.variableList[newVariableIndex];
|
|
|
|
}
|
|
|
|
|
|
|
|
Blockly.Events.setGroup(true);
|
|
|
|
var blocks = this.getAllBlocks();
|
|
|
|
// Iterate through every block.
|
|
|
|
for (var i = 0; i < blocks.length; i++) {
|
|
|
|
blocks[i].renameVar(oldName, newName);
|
|
|
|
if (oldCase) {
|
|
|
|
blocks[i].renameVar(oldCase, newName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Blockly.Events.setGroup(false);
|
|
|
|
|
|
|
|
|
|
|
|
if (variableIndex == newVariableIndex ||
|
|
|
|
variableIndex != -1 && newVariableIndex == -1) {
|
|
|
|
// Only changing case, or renaming to a completely novel name.
|
2016-06-22 16:16:31 -07:00
|
|
|
this.variableList[variableIndex] = newName;
|
2016-07-01 15:51:59 -07:00
|
|
|
} else if (variableIndex != -1 && newVariableIndex != -1) {
|
2016-08-17 16:07:50 -07:00
|
|
|
// Renaming one existing variable to another existing variable.
|
2016-10-09 13:11:21 -05:00
|
|
|
// The case might have changed, so we update the destination ID.
|
2016-08-17 16:07:50 -07:00
|
|
|
this.variableList[newVariableIndex] = newName;
|
2016-10-09 13:11:21 -05:00
|
|
|
this.variableList.splice(variableIndex, 1);
|
2016-06-22 16:16:31 -07:00
|
|
|
} else {
|
|
|
|
this.variableList.push(newName);
|
|
|
|
console.log('Tried to rename an non-existent variable.');
|
|
|
|
}
|
2013-10-30 14:46:03 -07:00
|
|
|
};
|
|
|
|
|
2016-07-01 15:51:59 -07:00
|
|
|
/**
|
2016-08-17 16:07:50 -07:00
|
|
|
* Create a variable with the given name.
|
2016-07-01 15:51:59 -07:00
|
|
|
* TODO: #468
|
|
|
|
* @param {string} name The new variable's name.
|
|
|
|
*/
|
|
|
|
Blockly.Workspace.prototype.createVariable = function(name) {
|
2016-08-17 16:07:50 -07:00
|
|
|
var index = this.variableIndexOf(name);
|
2016-07-13 16:46:27 -07:00
|
|
|
if (index == -1) {
|
|
|
|
this.variableList.push(name);
|
|
|
|
}
|
2013-10-30 14:46:03 -07:00
|
|
|
};
|
|
|
|
|
2016-08-17 16:07:50 -07:00
|
|
|
/**
|
|
|
|
* Find all the uses of a named variable.
|
|
|
|
* @param {string} name Name of variable.
|
|
|
|
* @return {!Array.<!Blockly.Block>} Array of block usages.
|
|
|
|
*/
|
|
|
|
Blockly.Workspace.prototype.getVariableUses = function(name) {
|
|
|
|
var uses = [];
|
|
|
|
var blocks = this.getAllBlocks();
|
|
|
|
// Iterate through every block and check the name.
|
|
|
|
for (var i = 0; i < blocks.length; i++) {
|
|
|
|
var blockVariables = blocks[i].getVars();
|
|
|
|
if (blockVariables) {
|
|
|
|
for (var j = 0; j < blockVariables.length; j++) {
|
|
|
|
var varName = blockVariables[j];
|
|
|
|
// Variable name may be null if the block is only half-built.
|
|
|
|
if (varName && Blockly.Names.equals(varName, name)) {
|
|
|
|
uses.push(blocks[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return uses;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete a variables and all of its uses from this workspace.
|
|
|
|
* @param {string} name Name of variable to delete.
|
|
|
|
*/
|
|
|
|
Blockly.Workspace.prototype.deleteVariable = function(name) {
|
2017-02-02 14:17:43 -05:00
|
|
|
var variableIndex = this.variableIndexOf(name);
|
|
|
|
if (variableIndex == -1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Check whether this variable is a function parameter before deleting.
|
|
|
|
var uses = this.getVariableUses(name);
|
|
|
|
for (var i = 0, block; block = uses[i]; i++) {
|
|
|
|
if (block.type == 'procedures_defnoreturn' ||
|
|
|
|
block.type == 'procedures_defreturn') {
|
|
|
|
var procedureName = block.getFieldValue('NAME');
|
|
|
|
Blockly.alert(
|
|
|
|
Blockly.Msg.CANNOT_DELETE_VARIABLE_PROCEDURE.
|
|
|
|
replace('%1', name).
|
|
|
|
replace('%2', procedureName));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-01 16:32:10 -07:00
|
|
|
var workspace = this;
|
2017-02-02 14:17:43 -05:00
|
|
|
function doDeletion() {
|
2016-11-02 13:56:27 -07:00
|
|
|
Blockly.Events.setGroup(true);
|
2017-02-02 14:17:43 -05:00
|
|
|
for (var i = 0; i < uses.length; i++) {
|
|
|
|
uses[i].dispose(true, false);
|
2016-11-02 13:56:27 -07:00
|
|
|
}
|
|
|
|
Blockly.Events.setGroup(false);
|
2017-02-02 14:17:43 -05:00
|
|
|
workspace.variableList.splice(variableIndex, 1);
|
2016-11-02 13:56:27 -07:00
|
|
|
}
|
2017-02-02 14:17:43 -05:00
|
|
|
if (uses.length > 1) {
|
|
|
|
// Confirm before deleting multiple blocks.
|
|
|
|
Blockly.confirm(
|
|
|
|
Blockly.Msg.DELETE_VARIABLE_CONFIRMATION.replace('%1', uses.length).
|
|
|
|
replace('%2', name),
|
|
|
|
function(ok) {
|
|
|
|
if (ok) {
|
|
|
|
doDeletion();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
// No confirmation necessary for a single block.
|
|
|
|
doDeletion();
|
2016-08-17 16:07:50 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check whether a variable exists with the given name. The check is
|
|
|
|
* case-insensitive.
|
|
|
|
* @param {string} name The name to check for.
|
|
|
|
* @return {number} The index of the name in the variable list, or -1 if it is
|
|
|
|
* not present.
|
|
|
|
*/
|
|
|
|
Blockly.Workspace.prototype.variableIndexOf = function(name) {
|
|
|
|
for (var i = 0, varname; varname = this.variableList[i]; i++) {
|
|
|
|
if (Blockly.Names.equals(varname, name)) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
};
|
|
|
|
|
2013-10-30 14:46:03 -07:00
|
|
|
/**
|
2014-12-23 11:22:02 -08:00
|
|
|
* Returns the horizontal offset of the workspace.
|
|
|
|
* Intended for LTR/RTL compatibility in XML.
|
|
|
|
* Not relevant for a headless workspace.
|
|
|
|
* @return {number} Width.
|
2013-10-30 14:46:03 -07:00
|
|
|
*/
|
2014-12-23 11:22:02 -08:00
|
|
|
Blockly.Workspace.prototype.getWidth = function() {
|
|
|
|
return 0;
|
2013-10-30 14:46:03 -07:00
|
|
|
};
|
|
|
|
|
2015-12-07 16:40:45 +01:00
|
|
|
/**
|
|
|
|
* Obtain a newly created block.
|
|
|
|
* @param {?string} prototypeName Name of the language object containing
|
|
|
|
* type-specific functions for this block.
|
2016-08-30 15:50:59 -04:00
|
|
|
* @param {string=} opt_id Optional ID. Use this ID if provided, otherwise
|
2015-12-09 10:02:42 +01:00
|
|
|
* create a new id.
|
2015-12-07 16:40:45 +01:00
|
|
|
* @return {!Blockly.Block} The created block.
|
|
|
|
*/
|
2015-12-09 10:02:42 +01:00
|
|
|
Blockly.Workspace.prototype.newBlock = function(prototypeName, opt_id) {
|
|
|
|
return new Blockly.Block(this, prototypeName, opt_id);
|
2015-12-07 16:40:45 +01:00
|
|
|
};
|
|
|
|
|
2016-03-03 17:48:54 -08:00
|
|
|
/**
|
|
|
|
* Undo or redo the previous action.
|
|
|
|
* @param {boolean} redo False if undo, true if redo.
|
|
|
|
*/
|
|
|
|
Blockly.Workspace.prototype.undo = function(redo) {
|
2016-03-14 23:14:05 -07:00
|
|
|
var inputStack = redo ? this.redoStack_ : this.undoStack_;
|
|
|
|
var outputStack = redo ? this.undoStack_ : this.redoStack_;
|
2016-05-04 15:05:45 -07:00
|
|
|
var inputEvent = inputStack.pop();
|
|
|
|
if (!inputEvent) {
|
2016-03-03 17:48:54 -08:00
|
|
|
return;
|
|
|
|
}
|
2016-05-04 15:05:45 -07:00
|
|
|
var events = [inputEvent];
|
2016-03-03 17:48:54 -08:00
|
|
|
// Do another undo/redo if the next one is of the same group.
|
2016-05-04 15:05:45 -07:00
|
|
|
while (inputStack.length && inputEvent.group &&
|
|
|
|
inputEvent.group == inputStack[inputStack.length - 1].group) {
|
2016-03-14 23:14:05 -07:00
|
|
|
events.push(inputStack.pop());
|
2016-03-03 17:48:54 -08:00
|
|
|
}
|
2016-03-14 23:14:05 -07:00
|
|
|
// Push these popped events on the opposite stack.
|
|
|
|
for (var i = 0, event; event = events[i]; i++) {
|
|
|
|
outputStack.push(event);
|
|
|
|
}
|
|
|
|
events = Blockly.Events.filter(events, redo);
|
2016-03-06 18:32:20 -08:00
|
|
|
Blockly.Events.recordUndo = false;
|
|
|
|
for (var i = 0, event; event = events[i]; i++) {
|
|
|
|
event.run(redo);
|
|
|
|
}
|
|
|
|
Blockly.Events.recordUndo = true;
|
2016-03-03 17:48:54 -08:00
|
|
|
};
|
|
|
|
|
2016-03-25 19:03:18 -07:00
|
|
|
/**
|
|
|
|
* Clear the undo/redo stacks.
|
|
|
|
*/
|
|
|
|
Blockly.Workspace.prototype.clearUndo = function() {
|
|
|
|
this.undoStack_.length = 0;
|
|
|
|
this.redoStack_.length = 0;
|
|
|
|
// Stop any events already in the firing queue from being undoable.
|
|
|
|
Blockly.Events.clearPendingUndo();
|
|
|
|
};
|
|
|
|
|
2014-11-28 21:43:39 -08:00
|
|
|
/**
|
2016-02-11 21:40:33 -08:00
|
|
|
* When something in this workspace changes, call a function.
|
|
|
|
* @param {!Function} func Function to call.
|
|
|
|
* @return {!Function} Function that can be passed to
|
|
|
|
* removeChangeListener.
|
2014-11-28 21:43:39 -08:00
|
|
|
*/
|
2016-02-11 21:40:33 -08:00
|
|
|
Blockly.Workspace.prototype.addChangeListener = function(func) {
|
|
|
|
this.listeners_.push(func);
|
|
|
|
return func;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stop listening for this workspace's changes.
|
|
|
|
* @param {Function} func Function to stop calling.
|
|
|
|
*/
|
|
|
|
Blockly.Workspace.prototype.removeChangeListener = function(func) {
|
2016-10-04 21:20:07 -07:00
|
|
|
goog.array.remove(this.listeners_, func);
|
2016-02-11 21:40:33 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fire a change event.
|
|
|
|
* @param {!Blockly.Events.Abstract} event Event to fire.
|
|
|
|
*/
|
|
|
|
Blockly.Workspace.prototype.fireChangeListener = function(event) {
|
2016-03-03 17:48:54 -08:00
|
|
|
if (event.recordUndo) {
|
|
|
|
this.undoStack_.push(event);
|
|
|
|
this.redoStack_.length = 0;
|
|
|
|
if (this.undoStack_.length > this.MAX_UNDO) {
|
|
|
|
this.undoStack_.unshift();
|
|
|
|
}
|
|
|
|
}
|
2016-10-13 17:09:41 -04:00
|
|
|
// Copy listeners in case a listener attaches/detaches itself.
|
|
|
|
var currentListeners = this.listeners_.slice();
|
|
|
|
for (var i = 0, func; func = currentListeners[i]; i++) {
|
2016-02-11 21:40:33 -08:00
|
|
|
func(event);
|
|
|
|
}
|
2014-11-28 21:43:39 -08:00
|
|
|
};
|
2015-04-28 13:51:25 -07:00
|
|
|
|
2016-04-05 18:43:39 -07:00
|
|
|
/**
|
|
|
|
* Find the block on this workspace with the specified ID.
|
|
|
|
* @param {string} id ID of block to find.
|
|
|
|
* @return {Blockly.Block} The sought after block or null if not found.
|
|
|
|
*/
|
|
|
|
Blockly.Workspace.prototype.getBlockById = function(id) {
|
2016-10-13 17:09:41 -04:00
|
|
|
var block = this.blockDB_[id];
|
|
|
|
if (!block && this.getFlyout() && this.getFlyout().getWorkspace()) {
|
|
|
|
block = this.getFlyout().getWorkspace().blockDB_[id];
|
|
|
|
}
|
|
|
|
return block || null;
|
2016-04-05 18:43:39 -07:00
|
|
|
};
|
|
|
|
|
Feature/merge feb 2017 (#791)
* Revert "Rebuild nov 3 16"
* Move injected css to start of head
* simplification
* lint
* Remove copy/paste buttons.
* Localisation updates from https://translatewiki.net.
* Don't split dropdown text if there is an image.
* Unblock push to master.
* Revert "Revert "Rebuild nov 3 16""
This reverts commit c8ca24a0007b70e137417e843459c87185141a55.
* rebuild
* Remove ifelse block and messages'
* Remove obsolete Gecko image hack. Apparently this has been fixed in Gecko.
* Add correct focus behavior for the modal. Update boundary sounds.
* Disallow clicks on disabled buttons.
* add back metadata tag to qqq
* revert qqq.json
* Improve performance of block dragging. This is a backport of the blo… (#732)
Improve performance of block dragging. This is a backport of the block drag surface from scratch-blocks. At the beginning of a block drag, blocks get moved to a drag surface which then translates using translate3d to avoid repainting the entire svg on every mouse move. At the end of the drag, the blocks are dropped back in the svg in their new position.
* API-breaking cleanup. But doubtful anyone will be affected. (#748)
* Make add/removeClass return whether they did anything.
* Move more functions onto utils.
* Move bind functions to Blockly.
* Routine recompile.
* String reference in JSON string messages (#741)
* Adds message references to message string interpolation, in the form of %{BKY_STRING}.
* Re-adding CONTROLS_IFELSE block using the new syntax, referencing to CONTROL_IF equivalents.
* Fix compiler errors.
* Break the sidebar out into its own individual component.
* Hide notification messages after a short time interval.
* Fix selection border on blocks that have been highlighted.
* controls_ifelse: Remove right-align. Remove Boolean check on statements. (#749)
* Move away from using a common modal service, since the block options and the toolbox modals are going to end up behaving fairly differently.
* Fix conflict between 'utils' and 'image dropdown' merges.
* Add a contextual modal for the toolbox.
* Fix some bugs arising in the toolbox modal for the no-categories case.
* Allow attaching blocks to a marked spot from the toolbox modal. This is the last prerequisite for removal of the existing on-screen toolbox.
* Delete the on-screen toolbox.
* Add warning sounds when the user reaches a boundary of the workspace.
* Stop some blocks from throwing errors in headless workspaces.
* Lint
* Fix speling.
* Fix broken highlighting when highlighted block is deleted. Issue 752.
* When the workspace is empty, make it easy for the user to add a new group of blocks to it.
* Handle the finer points for setting focus correctly after deleting blocks from the workspace.
* When user edits text in a field, set text, not value.
Existing text-editable fields don’t care (dropdown care, but are not
text-editable). But a note picker needs to set its value to 60 if text
is set to ‘C4’.
* Set the text not the value when closing a text editor.
Also rename variables for clarity.
* Localisation updates from https://translatewiki.net.
* Streamline the logic for block selection callbacks in the toolbox modal.
* Do not show disabled actions in the block options modal.
* Set focus correctly when toolbox modal is dismissed.
* Add information regarding target screen reader and browser.
* Rebuild Blockly.
* Remove unavailable blocks from toolbox modal. Hide unnecessary category name in a toolbox without categories.
* Do some refactoring and tidy-up. Pull some hardcoded strings out for i18n purposes; remove unused strings.
* Update config options for sidebar buttons.
* Minor refactoring. Remove unused dependencies.
* Improve styling of sidebar buttons.
* Remove clipboard functionality.
* Refactor and simplify marked spot logic.
* Change dropdowns to select fields instead of lists of buttons.
* Add ability to specify a css class for labels and buttons
* Don't make labels clickable
* console.log -> console.warn
* change 'class' to 'web-style'
* createSvgElement is now in utils. fix two calls.
* Improve comments.
* lint
* fix missing semicolon
* When adding a new block group from the toolbox modal, only show blocks with no output connections.
* Clean up the sidebar file and remove unneeded code.
* Remove some functions from utilsService and consolidate code in workspace-tree.component.js.
* Standardize indentation.
* Remove premature focus on buttons in modal dialogs, since this prevents readout of the dialog text.
* Localisation updates from https://translatewiki.net.
* Don't get Toolbox element unless needed.
* Associate flyout button callbacks directly with workspaces
* Add colour block to the block factory base block initial state
* Start getting helpurl and tooltip in
* Generate helpURL and tooltip for Javascript block definition
* Use Tab keys instead of arrow keys for dialog boxes. Set role=alertdialog and read out the header/text automatically. Ensure that Esc key actually closes dialogs and that all keystrokes are captured.
* Add an aria-describedby to the 'create new block group...' button in the workspace to give more context.
* Fix issue with aria-liveregion not speaking. Allow sufficient time for alert noise to play before speaking the notification.
* Make zoom speed independent of event granularity
Before, touchpads would give "smoother" scrolling by delivering lots of
mousewheel events with small distance changes. Because the code only
looked at the sign of deltaY, ten 5px scrolls would zoom 10x more than
one 50px scroll.
This change makes zooming with a touchpad more like zooming with a
mousewheel. On my laptop, a full-scale zoom (fully out to fully in) was
about a 5mm finger movement before, and is now about 3cm.
Fixes #758.
* Split the scrollbar and flyout out into their own SVG elements. They (#771)
* Split the scrollbar and flyout out into their own SVG elements. They
are siblings of the workpsace SVG. This paves the way to make performance
improvements to workspace dragging.
* remove overflow-y on the block exporter labels so scroll bars do not show upin firefox. Also fix up the styles on the labels so that they display better in firefox. (#699)
* Fix #698 by adjusting the regex to not have \. Still not 100% sure w… (#700)
* Fix #698 by adjusting the regex to not have \. Still not 100% sure why that was there.
Also replaces bad names on input. There are probably more invalid names but this is
a start.
* update generator comments
* Move the call to disable resize before placeNewBlock so that it is of… (#777)
* Move the call to disable resize before placeNewBlock so that it is off when workspace resizeContents
gets triggered by placeNewBlock. This fixes a bug in rtl mode where the workspace was being resized
between when the block was added to the workspace and when it was moved to the proper location.
* Disable workspace resizing while loading the flyout from XML
* Localisation updates from https://translatewiki.net.
* Add a workspace drag surface that blocks and bubble get moved to duri… (#778)
* Add a workspace drag surface that blocks and bubble get moved to during a workspace drag.
The surface is translated using translate3d instead of svg's translate attribute so that
the browser does not have to repaint the entire workspace on every mouse move.
This is very similar to the block drag surface.
* Address code review comments
* add back hasClass_ utility removed in #748 and stop using contains since it is not supported in IE
* Fixes #786 by checking if getComputedStyle is null in is3dSupported. We do not cache the value in this case and try again later. is3dSupported is only called while users are interacting with blockly which they cannot do while hidden so the performance implications of running the check again are minimal. (#787)
* Localisation updates from https://translatewiki.net.
* Change the Python codegen for string quoting to match the behaviour of `repr` on a string in CPython.
* Localisation updates from https://translatewiki.net.
* Add an `allInputsConnected` method to `Block` and `Workspace` to test whether all trees in the block forest have their inputs filled. An optional argument controls whether or not shadow blocks are counted as being filled. Recommitting changes off `develop` instead of `master` as per discussion in PR #791.
* Localisation updates from https://translatewiki.net.
* Localisation updates from https://translatewiki.net.
* Use the drag surface when scrolling using the scrollbars. #783 (#789)
* End event groups when you finish editing a field
* Fix #794 and make the workspace grid drag along with the workspace. (#801)
There was some IE specific code that also applies to Edge so just updated
a conditional to include Edge.
* Now that text input's setText skips setValue, it needs to explicitly create a change event
* Check if the text has changed before firing an event
* Init procedure blocks with empty name, and set default name in xml in Blockly.Procedures.flyoutCategory
* Routine rebuild
* Move createDom call into the constructor of block drag surface. (#790)
* Make cursor stay as a closed hand when dragging blocks around in the drag surface. Do this by applying the same style to text elements in the drag surface that we do in the main svg. (#805)
* Don't connect to blocks under the flyout.
* recompile again. (#806)
* Fix german translation
* Fix german translation of 'delete x blocks'
* Adding unit tests for ifelse block.
* Improvements to the generator test framework.
* <field>, <value> reorder due to load/save.
* Use the npm closure library instead of the same library installed at a parallel directory
* Fix undo/redo for FieldCheckbox
Thanks to PR #813 by ademenev
* PR #818: Adding support for string table lookups in dropdown field labels
Adding support for string table lookups in dropdown field labels specified in JSON.
Adds Blockly.utils.replaceMessageReferences() method to handle string replacement without interpolation tokens. Effectively uses the same old code, now moved into tokenizeInterpolation_(), which takes a parseInterpolationTokens option.
Replaces the direct JavaScript references (not pure JSON, and thus not portable).
Demonstrating this behavior in the logic_boolean dropdown.
* Integrating qqq.json changes into messages.json. (#820)
From commits b77f8cbebc5cef247116d3df6a428df8addbe53d and 4ecdedec9f8a69f78abf246e7a5db1e1a0be6b85
* Naming changes in mirror demo
* Adding support for untranslated messages. (#819)
This will be used to define constants accessible in JSON block definitions. Messages with descriptions that include `{{Notranslate}}` will not be included in the translation files sent to TranslateWiki. Instead, they are written to `msg/json/constants.json`, and later merged back into the `.js` files, similar to synonyms.
Template details: https://translatewiki.net/wiki/Template:Notranslate
* JSON support for message lookup in colour, tooltip, and help URL. (#825)
String replacement for the colour, tooltip text and help URL attributes of JSON defined blocks.
Demonstrated in logic_boolean.
* Fixes as per code review on PR.
* Reduce number of Closure files in App Engine upload.
* Python false is False. Issue #828.
* Replace 'const' with 'var'.
This unbreaks IE10 and advanced compiled apps such as Blockly Games.
* Fix bug in audioService where attached event callbacks were not being cleared properly.
* Rename workspace-tree to workspace-block.
* Minor refactoring of the modal code (add comments, guard against invalid keystrokes, etc.).
* FieldNumber & FieldAngle: Default value "0" (#832)
FieldNumber and FieldAngle previously accepted "undefined" as values, if not defined in JSON. This catches these and uses "0" for any NaN value. The constructor value parameter is now optional. Includes tests.
* Remove unnecessary check when attaching a new block to a marked connection.
* Remove debug info.
* Refactor and simplify field-segment.component.js.
* Replace single quotes with double. (#836)
Fixes commits in #832.
* Adding extensions for JSON support of dynamic blocks. (#834)
Adding support for extensions, functions that can assist with loading blocks, much like init functions, but that can be referenced from JSON definitions. This allows JSON definitions to define dynamic blocks such as onchange handlers and mutators.
Rewrote math_number as an example pure JSON block.
* Add ability to add a class to a scrollbar so that different types of … (#837)
* Add ability to add a class to a scrollbar so that different types of scrollbars can
be distinguished from each other. You used to be able to do this by looking at the parent
element but now all the scrollbars are siblings in the dom.
Also, use this new class to fix #816 so that layering of the flyout and workspace scrollbars
are done correctly.
* JSON definitions for colour blocks (#838)
Replaces old colour block definitions with a Blockly.defineBlocksWithJsonArray(..) call. Generator unit tests continue to load and pass, signifying compatibility with prior block definitions.
Replaces extension 'math_number_tooltip' with the reusable 'parent_tooltip_when_inline' extension, also used by colour_picker. Includes tests.
* Rewrite tree.service.js.
- Remove unnecessary code and functions.
- Add documentation where needed.
- Fix a bug arising when a block on the workspace is attached to an existing link.
* Use setValue in fieldTextInput so that procedure renaming works
* Further cleanup and removal of unnecessary functions. Pull some strings out for i18n.
* Use bindEvent_ instead of bindEventWithChecks_ for longStop
* Clean up workspace.component.js. When moving a block from one place to another, move all blocks after it too, and adjust the active descs accordingly.
* Unit tests for JSON block definitions (just the start) (#850)
* Beginnings of a JSON block definition unit test set.
* Dispose of unit test workspaces and blocks in finally blocks.
* Clarify JSON error message by echoing arg notation.
* New blocks text_count, text_replace, and text_reverse (#830)
Includes generators for all languages and units tests on those generators.
* Fixing combo boxes getting out-of-sync with NVDA.
Combo boxes need to be special cased like text input. Also, Escape is
a reserved button in NVDA, so I added Enter as a way to "submit and
move up a level" in addition to escape, so these boxes can be edited
while NVDA is on.
* Add a block to reverse a list (#844)
* Porting math.js blocks to JSON (#846)
Moving all `math.js` definitions into a single JSON array, complete with i18n syntax for all messages, dropdowns, and tooltips.
Adding Blockly.Extensions.buildTooltipForDropdown(..) to facilitate the creation and error-checking of tooltips that update based on the value of a dropdown.
Now warn on raw string in JSON 'extensions'.
* Fixing JSON support for images in dropdowns. Adding tests. (#851)
Fixes #848.
* Update README.md
Add a link to our forum.
* Correcting math_change color
* Enable custom flyout categories.
* Add some safety
* Update the set of reserved words in Python to reflect the current state of Python (2.7 and 3.6). (#861)
* .getOptions_() to .getOptions() (#869)
Fixes #867.
* Blockly.Extensions.buildTooltipForDropdown(..): Deferred validation. (#870)
Defer tooltip message string check until after load, when all Blockly.Msg should be loaded.
Avoids validation in headless mode, due to lack of document.readyState.
* annotation updates
* jsdoc corrections (#874)
* Remove use of Array.prototype.includes which is not implemented in IE or Edge < 14. Fixes google/blockly#876.
* Attempt to work around the IE/Edge bug where `getComputedTextLength()` throws an exception when the SVG node is not visible. This workaround forces a re-render, which in turn, forces a re-calculation of the node width once a block is inserted into the workspace SVG. This workaround is only executed on IE and Edge. See https://groups.google.com/forum/#!topic/blockly/T8IR4t4xAIY for the initial discussion of this issue.
* Change CSS transforms to work with older browsers (#879)
* Change the setting of the CSS transform properties on SVG nodes to set both the unprefixed version and the `-webkit-` prefixed version so that Blockly correctly renders in order browsers, such as Safari < 9 and iOS Safari < 9.2. For discussion of this issue, see https://groups.google.com/forum/#!topic/blockly/o3pERaRQhSg
* Correct the separation between the CSS transform property and the rest of the CSS that was in the variable misleadingly called "transform".
* Don't try to get block position in a headless workspace
* Stop bumping neighbours in headless blockly
* Place context menu correctly on touch
* Clear all active desc ids when the 'Erase Workspace' button is pressed.
* Fix a bug where splicing a block between two linked blocks disconnects the group and messes up the focus.
* Deleting a top-level block does not cause blocks after it to be deleted. Properly handle the active desc for this case.
* Use the empty field placeholder for dropdowns that do not have a value selected.
* Bugfix for #892. I incorrectly converted one CSS transform setting to use the cross-browser setting function in 40a063763c74b3f712c3057565966c25d5cfdb10. (#895)
* Adding @namespace annotations for JSDoc. (#900)
* Fix typo causing TypeError (#901)
* Pinning the angular2 dependency, and including licenses. (#893)
* Add skeleton for tests on rendered workspaces
* Fix some lint errors
* Correct changedState in setWarningText() (#908)
When clearing warnings on blocks with IDs, the changedState variable should be true if the text changed. This will trigger the block being reshaped and remove the space for the notification icon (this.bumpNeighbours_).
* Adds Block.prototype.mixin() and Blockly.Extensions.registerMixin(). (#907)
Adds Block.prototype.mixin() and Blockly.Extensions.registerMixin().
This adds support for a common use pattern in extensions, and adds
error checking to avoid future incompatibilities.
* Porting Logic blocks to JSON (#913)
Extensions, mixins, mutators and constants now grouped under the new namespace Blockly.Constants.Logic.
* Improving errors/warnings with Block.toDevString() and Connection.toString(). (#911)
* Add isEditable to field, and add tests
* Separate tests
* Blockly.Constants.Math and Blockly.Constants.Colour extension constants (#916)
Also, correcting quotes in logic.js.
* Correction to logic_ternary type check (#920)
* Porting Loop blocks to JSON (#919)
* Improved documentation on `Blockly.Extensions.buildTooltipForDropdown`
* Replaced incorrect uses of `@mixes` JSDoc annotation (on mixin extensions) with `@augments Blockly.Block`.
* Added Blockly.Extensions.buildTooltipWithFieldValue() extension helper.
* Workspace isDraggable
* JSONify simple list blocks
* JSONify variable blocks
* Initial text block, with a mixin to generate quote image fields. (#923)
Text block now uses the extension "text_quotes", supported by Blockly.Constants.Text.QUOTE_IMAGE_MIXIN.quoteField_(fieldName), so that each platform can use the best platform appropriate image (size, density, etc.) for the quotes.
* Add no-op stub .neighbors() for headless Connection.
* Adding tests for logic_ternary block in a new jsunit test framework.
* Correcting output of the logic_null block.
* extension controls_if => controls_if_mutator.
* Renamed extension function constant, and moved variables into the mixin.
* Dereference string table references when loading variable fields from JSON.
* Moving FieldImage string dereferencing back into Block.interpolate_() (part of jsonInit()). This sets a clear boundary of where dereferencing should happen.
Towards this, I've added message dereferencing for other field types here, as well. I've used a pattern of field-type specific helper functions.
* Addressing comments.
* .utils.replaceMessageReferences(..) now gracefully returns non-string arguments.
* Fix a few small errors and rebuild
* Call dynamic toolbox generators correctly
* cleanup
* Fix unit tests, and delete a few that relied on completely undefined behaviour
* Fix RTL text inputs
* eslintignore more tests
* Fix insertion marker highlighting, I think
* Make getFlyout public
2017-02-21 12:09:23 -08:00
|
|
|
/**
|
|
|
|
* Checks whether all value and statement inputs in the workspace are filled
|
|
|
|
* with blocks.
|
|
|
|
* @param {boolean=} opt_shadowBlocksAreFilled An optional argument controlling
|
|
|
|
* whether shadow blocks are counted as filled. Defaults to true.
|
|
|
|
* @return {boolean} True if all inputs are filled, false otherwise.
|
|
|
|
*/
|
|
|
|
Blockly.Workspace.prototype.allInputsFilled = function(opt_shadowBlocksAreFilled) {
|
|
|
|
var blocks = this.getTopBlocks(false);
|
|
|
|
for (var i = 0, block; block = blocks[i]; i++) {
|
|
|
|
if (!block.allInputsFilled(opt_shadowBlocksAreFilled)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Getter for the flyout associated with this workspace. This is null in a
|
|
|
|
* non-rendered workspace, but may be overriden by subclasses.
|
|
|
|
* @return {Blockly.Flyout} The flyout on this workspace.
|
|
|
|
*/
|
|
|
|
Blockly.Workspace.prototype.getFlyout = function() {
|
|
|
|
return null;
|
|
|
|
};
|
|
|
|
|
2015-12-09 10:17:40 +01:00
|
|
|
/**
|
|
|
|
* Database of all workspaces.
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
Blockly.Workspace.WorkspaceDB_ = Object.create(null);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Find the workspace with the specified ID.
|
|
|
|
* @param {string} id ID of workspace to find.
|
|
|
|
* @return {Blockly.Workspace} The sought after workspace or null if not found.
|
|
|
|
*/
|
|
|
|
Blockly.Workspace.getById = function(id) {
|
|
|
|
return Blockly.Workspace.WorkspaceDB_[id] || null;
|
|
|
|
};
|
|
|
|
|
2015-05-22 17:08:59 -07:00
|
|
|
// Export symbols that would otherwise be renamed by Closure compiler.
|
|
|
|
Blockly.Workspace.prototype['clear'] = Blockly.Workspace.prototype.clear;
|
2016-03-25 19:03:18 -07:00
|
|
|
Blockly.Workspace.prototype['clearUndo'] =
|
|
|
|
Blockly.Workspace.prototype.clearUndo;
|
2016-02-11 21:40:33 -08:00
|
|
|
Blockly.Workspace.prototype['addChangeListener'] =
|
|
|
|
Blockly.Workspace.prototype.addChangeListener;
|
|
|
|
Blockly.Workspace.prototype['removeChangeListener'] =
|
|
|
|
Blockly.Workspace.prototype.removeChangeListener;
|