Remove maxBlocks (fix #309) (#435)

* Remove `maxBlocks` (fix #309)

* Also remove filterForCapacity_

* More references to remainingCapacity
This commit is contained in:
Tim Mickel 2016-06-21 15:54:03 -04:00 committed by GitHub
parent 5593307e75
commit f1c7cae728
10 changed files with 1 additions and 72 deletions

View file

@ -780,9 +780,6 @@ Blockly.BlockSvg.prototype.showContextMenu_ = function(e) {
Blockly.duplicate_(block);
}
};
if (this.getDescendants().length > this.workspace.remainingCapacity()) {
duplicateOption.enabled = false;
}
menuOptions.push(duplicateOption);
if (this.isEditable() && this.workspace.options.comments) {

View file

@ -224,10 +224,6 @@ Blockly.Flyout.prototype.init = function(targetWorkspace) {
Array.prototype.push.apply(this.eventWrappers_,
Blockly.bindEvent_(this.svgGroup_, 'wheel', this, this.wheel_));
if (!this.autoClose) {
this.filterWrapper_ = this.filterForCapacity_.bind(this);
this.targetWorkspace_.addChangeListener(this.filterWrapper_);
}
// Dragging the flyout up and down (or left and right).
Array.prototype.push.apply(this.eventWrappers_,
Blockly.bindEvent_(this.svgGroup_, 'mousedown', this, this.onMouseDown_));
@ -240,10 +236,6 @@ Blockly.Flyout.prototype.init = function(targetWorkspace) {
Blockly.Flyout.prototype.dispose = function() {
this.hide();
Blockly.unbindEvent_(this.eventWrappers_);
if (this.filterWrapper_) {
this.targetWorkspace_.removeChangeListener(this.filterWrapper_);
this.filterWrapper_ = null;
}
if (this.scrollbar_) {
this.scrollbar_.dispose();
this.scrollbar_ = null;
@ -640,7 +632,6 @@ Blockly.Flyout.prototype.show = function(xmlList) {
this.reflow();
this.offsetHorizontalRtlBlocks(this.workspace_.getTopBlocks(false));
this.filterForCapacity_();
// Fire a resize event to update the flyout's scrollbar.
Blockly.svgResize(this.workspace_);
@ -980,8 +971,6 @@ Blockly.Flyout.prototype.createBlockFunc_ = function(originBlock) {
}
if (flyout.autoClose) {
flyout.hide();
} else {
flyout.filterForCapacity_();
}
// Start a dragging operation on the new block.
block.onMouseDown_(e);
@ -1066,28 +1055,6 @@ Blockly.Flyout.prototype.placeNewBlock_ = function(originBlock) {
return block;
};
/**
* Filter the blocks on the flyout to disable the ones that are above the
* capacity limit.
* @private
*/
Blockly.Flyout.prototype.filterForCapacity_ = function() {
var filtered = false;
var remainingCapacity = this.targetWorkspace_.remainingCapacity();
var blocks = this.workspace_.getTopBlocks(false);
for (var i = 0, block; block = blocks[i]; i++) {
if (this.permanentlyDisabled_.indexOf(block) == -1) {
var allBlocks = block.getDescendants();
block.setDisabled(allBlocks.length > remainingCapacity);
filtered = true;
}
}
if (filtered) {
// Top-most block. Fire an event to allow scrollbars to resize.
Blockly.asyncSvgResize(this.workspace);
}
};
/**
* Return the deletion rectangle for this flyout in viewport coordinates.
* @return {goog.math.Rect} Rectangle in which to delete.

View file

@ -127,7 +127,6 @@ Blockly.Options = function(options) {
this.comments = hasComments;
this.disable = hasDisable;
this.readOnly = readOnly;
this.maxBlocks = options['maxBlocks'] || Infinity;
this.pathToMedia = pathToMedia;
this.hasCategories = hasCategories;
this.hasScrollbars = hasScrollbars;

View file

@ -211,18 +211,6 @@ Blockly.Workspace.prototype.newBlock = function(prototypeName, opt_id) {
return new Blockly.Block(this, prototypeName, opt_id);
};
/**
* The number of blocks that may be added to the workspace before reaching
* the maxBlocks.
* @return {number} Number of blocks left.
*/
Blockly.Workspace.prototype.remainingCapacity = function() {
if (isNaN(this.options.maxBlocks)) {
return Infinity;
}
return this.options.maxBlocks - this.getAllBlocks().length;
};
/**
* Undo or redo the previous action.
* @param {boolean} redo False if undo, true if redo.

View file

@ -515,8 +515,7 @@ Blockly.WorkspaceSvg.prototype.glowStack = function(id, isGlowingStack) {
* @param {!Element} xmlBlock XML block element.
*/
Blockly.WorkspaceSvg.prototype.paste = function(xmlBlock) {
if (!this.rendered || xmlBlock.getElementsByTagName('block').length >=
this.remainingCapacity()) {
if (!this.rendered) {
return;
}
Blockly.terminateDrag_(); // Dragging while pasting? No.

View file

@ -36,7 +36,6 @@
comments: false,
disable: false,
collapse: false,
maxBlocks: Infinity,
media: '../media/',
readOnly: false,
rtl: rtl,

View file

@ -50,23 +50,6 @@ function test_flatWorkspace() {
assertEquals('Cleared workspace (3).', 0, workspace.getAllBlocks().length);
}
function test_maxBlocksWorkspace() {
var workspace = new Blockly.Workspace();
var blockA = workspace.newBlock('');
var blockB = workspace.newBlock('');
assertEquals('Infinite capacity.', Infinity, workspace.remainingCapacity());
workspace.options.maxBlocks = 3;
assertEquals('Three capacity.', 1, workspace.remainingCapacity());
workspace.options.maxBlocks = 2;
assertEquals('Two capacity.', 0, workspace.remainingCapacity());
workspace.options.maxBlocks = 1;
assertEquals('One capacity.', -1, workspace.remainingCapacity());
workspace.options.maxBlocks = 0;
assertEquals('Zero capacity.', -2, workspace.remainingCapacity());
workspace.clear();
assertEquals('Cleared capacity.', 0, workspace.remainingCapacity());
}
function test_getWorkspaceById() {
var workspaceA = new Blockly.Workspace();
var workspaceB = new Blockly.Workspace();

View file

@ -21,7 +21,6 @@
comments: false,
disable: false,
collapse: false,
maxBlocks: Infinity,
media: '../media/',
readOnly: false,
rtl: false,

View file

@ -28,7 +28,6 @@ function start() {
comments: false,
disable: false,
collapse: false,
maxBlocks: Infinity,
media: '../media/',
readOnly: false,
rtl: rtl,

View file

@ -37,7 +37,6 @@
comments: false,
disable: false,
collapse: false,
maxBlocks: Infinity,
media: '../media/',
readOnly: false,
rtl: rtl,