mirror of
https://github.com/google/blockly.git
synced 2026-01-11 02:47:09 +01:00
Added maxTrashcanContents Property to Workspace Options (#2183)
* Added maxTrashcanContents property to workspace options. * Changed default with trashcan to 32.
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user