mirror of
https://github.com/scratchfoundation/scratch-blocks.git
synced 2025-08-28 22:10:31 -04:00
* Remove `maxBlocks` (fix #309) * Also remove filterForCapacity_ * More references to remainingCapacity
This commit is contained in:
parent
5593307e75
commit
f1c7cae728
10 changed files with 1 additions and 72 deletions
|
@ -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) {
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -36,7 +36,6 @@
|
|||
comments: false,
|
||||
disable: false,
|
||||
collapse: false,
|
||||
maxBlocks: Infinity,
|
||||
media: '../media/',
|
||||
readOnly: false,
|
||||
rtl: rtl,
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
comments: false,
|
||||
disable: false,
|
||||
collapse: false,
|
||||
maxBlocks: Infinity,
|
||||
media: '../media/',
|
||||
readOnly: false,
|
||||
rtl: false,
|
||||
|
|
|
@ -28,7 +28,6 @@ function start() {
|
|||
comments: false,
|
||||
disable: false,
|
||||
collapse: false,
|
||||
maxBlocks: Infinity,
|
||||
media: '../media/',
|
||||
readOnly: false,
|
||||
rtl: rtl,
|
||||
|
|
|
@ -37,7 +37,6 @@
|
|||
comments: false,
|
||||
disable: false,
|
||||
collapse: false,
|
||||
maxBlocks: Infinity,
|
||||
media: '../media/',
|
||||
readOnly: false,
|
||||
rtl: rtl,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue