Commit e019f6a9 authored by Beka Westberg's avatar Beka Westberg Committed by Evan W. Patton

Fix disabled blocks not working with backpack

parent 75b80b88
......@@ -53,6 +53,8 @@ Blockly.Backpack = function(targetWorkspace, opt_options) {
} else {
opt_options = opt_options || {};
this.options = new Blockly.Options(opt_options);
// Parsing loses this option so we have to reassign.
this.options.disabledPatternId = opt_options.disabledPatternId;
}
this.workspace_ = targetWorkspace;
this.flyout_ = new Blockly.BackpackFlyout(this.options);
......
......@@ -78,19 +78,14 @@ Blockly.BackpackFlyout.prototype.dispose = function() {
};
/**
* Filter the blocks on the flyout to disable the ones that are above the
* capacity limit.
* Returns if the flyout allows a new instance of the given block to be created.
* Always returns true to allow disabled blocks to be dragged out.
* @param {!Blockly.BlockSvg} _block The block to copy from the flyout.
* @return {boolean} True if the flyout allows the block to be instantiated.
*/
Blockly.BackpackFlyout.prototype.filterForCapacity_ = function() {
if (!this.targetWorkspace_) return;
var remainingCapacity = this.targetWorkspace_.remainingCapacity();
var blocks = this.workspace_.getTopBlocks(false);
for (var i = 0, block; block = blocks[i]; i++) {
var allBlocks = block.getDescendants();
var disabled = allBlocks.length > remainingCapacity;
block.setDisabled(disabled);
}
};
Blockly.BackpackFlyout.prototype.isBlockCreatable_ = function(_block) {
return true;
}
/**
* Stop binding to the global mouseup and mousemove events.
......
......@@ -230,7 +230,11 @@ Blockly.WorkspaceSvg.prototype.addWarningIndicator = function() {
*/
Blockly.WorkspaceSvg.prototype.addBackpack = function() {
if (Blockly.Backpack && !this.options.readOnly) {
this.backpack_ = new Blockly.Backpack(this, {scrollbars: true, media: './assets/'});
this.backpack_ = new Blockly.Backpack(this, {
scrollbars: true,
media: './assets/',
disabledPatternId: this.options.disabledPatternId,
});
var svgBackpack = this.backpack_.createDom(this);
this.svgGroup_.appendChild(svgBackpack);
this.backpack_.init();
......
Subproject commit ddb37e2ebf89deec0a4a43d0327c79c453ebf687
Subproject commit db33ee1262697977e9f2b3987f34651d0094f062
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment