From dcae85dd4f12ed96ea993d7324a945da6349751a Mon Sep 17 00:00:00 2001 From: Beka Westberg Date: Tue, 18 Dec 2018 13:22:43 -0800 Subject: [PATCH] Added maxTrashcanContents Property to Workspace Options (#2183) * Added maxTrashcanContents property to workspace options. * Changed default with trashcan to 32. --- core/options.js | 9 +++++++++ core/trashcan.js | 31 ++++++++++++++++--------------- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/core/options.js b/core/options.js index 0b91d9d64..0bbf36889 100644 --- a/core/options.js +++ b/core/options.js @@ -54,6 +54,14 @@ Blockly.Options = function(options) { if (hasTrashcan === undefined) { hasTrashcan = hasCategories; } + var maxTrashcanContents = options['maxTrashcanContents']; + if (hasTrashcan) { + if (maxTrashcanContents === undefined) { + maxTrashcanContents = 32; + } + } else { + maxTrashcanContents = 0; + } var hasCollapse = options['collapse']; if (hasCollapse === undefined) { hasCollapse = hasCategories; @@ -124,6 +132,7 @@ Blockly.Options = function(options) { this.hasCategories = hasCategories; this.hasScrollbars = hasScrollbars; this.hasTrashcan = hasTrashcan; + this.maxTrashcanContents = maxTrashcanContents; this.hasSounds = hasSounds; this.hasCss = hasCss; this.horizontalLayout = horizontalLayout; diff --git a/core/trashcan.js b/core/trashcan.js index 8c2c47f70..7d3f22355 100644 --- a/core/trashcan.js +++ b/core/trashcan.js @@ -38,6 +38,10 @@ goog.require('goog.math.Rect'); */ Blockly.Trashcan = function(workspace) { this.workspace_ = workspace; + if (this.workspace_.options.maxTrashcanContents <= 0) { + return; + } + var flyoutWorkspaceOptions = { scrollbars: true, disabledPatternId: this.workspace_.options.disabledPatternId, @@ -117,14 +121,6 @@ Blockly.Trashcan.prototype.SPRITE_TOP_ = 32; */ Blockly.Trashcan.prototype.HAS_BLOCKS_LID_ANGLE = 0.1; -/** - * The maximum number of blocks that can go in the trashcan's flyout. '0' turns - * turns off trashcan contents, 'Infinity' sets it to unlimited. - * @type {number} - * @private - */ -Blockly.Trashcan.prototype.MAX_CONTENTS = 32; - /** * Current open/close state of the lid. * @type {boolean} @@ -273,9 +269,11 @@ Blockly.Trashcan.prototype.createDom = function() { * @return {number} Distance from workspace bottom to the top of trashcan. */ Blockly.Trashcan.prototype.init = function(bottom) { - Blockly.utils.insertAfter(this.flyout_.createDom('svg'), - this.workspace_.getParentSvg()); - this.flyout_.init(this.workspace_); + if (this.workspace_.options.maxTrashcanContents > 0) { + Blockly.utils.insertAfter(this.flyout_.createDom('svg'), + this.workspace_.getParentSvg()); + this.flyout_.init(this.workspace_); + } this.bottom_ = this.MARGIN_BOTTOM_ + bottom; this.setOpen_(false); @@ -448,7 +446,7 @@ Blockly.Trashcan.prototype.mouseOut_ = function() { Blockly.Trashcan.prototype.onDelete_ = function() { var trashcan = this; return function(event) { - if (!trashcan.MAX_CONTENTS) { + if (trashcan.workspace_.options.maxTrashcanContents <= 0) { return; } if (event.type == Blockly.Events.BLOCK_DELETE) { @@ -457,9 +455,12 @@ Blockly.Trashcan.prototype.onDelete_ = function() { return; } trashcan.contents_.unshift(cleanedXML); - if (trashcan.contents_.length > trashcan.MAX_CONTENTS) { - trashcan.contents_.splice(trashcan.MAX_CONTENTS, - trashcan.contents_.length - trashcan.MAX_CONTENTS); + if (trashcan.contents_.length > + trashcan.workspace_.options.maxTrashcanContents) { + trashcan.contents_.splice( + trashcan.workspace_.options.maxTrashcanContents, + trashcan.contents_.length - + trashcan.workspace_.options.maxTrashcanContents); } trashcan.hasBlocks_ = true;