Delete events should animate when played (#5919)

Same as PR #5640, except for the addition of a parameter in the JSON to turn this on or off.  While one would normally want animations/sounds on (e.g. undo/redo stack) sometimes they'd be annoying (e.g. events from realtime collaborators).
This commit is contained in:
Neil Fraser
2022-02-11 14:20:10 -08:00
committed by GitHub
parent 60ee40014e
commit bce4c5e2c6
4 changed files with 24 additions and 3 deletions

View File

@@ -399,9 +399,10 @@ Block.COLLAPSED_FIELD_NAME = constants.COLLAPSED_FIELD_NAME;
* @param {boolean} healStack If true, then try to heal any gap by connecting
* the next statement with the previous statement. Otherwise, dispose of
* all children of this block.
* @param {boolean=} _animate If true, show a disposal animation and sound.
* @suppress {checkTypes}
*/
Block.prototype.dispose = function(healStack) {
Block.prototype.dispose = function(healStack, _animate) {
if (!this.workspace) {
// Already deleted.
return;

View File

@@ -54,6 +54,12 @@ class BlockCreate extends BlockBase {
this.xml = Xml.blockToDomWithXY(opt_block);
this.ids = eventUtils.getDescendantIds(opt_block);
/**
* Play UI effects (sound and animation)?
* @type {boolean}
*/
this.ui = true;
/**
* JSON representation of the block that was just created.
* @type {!blocks.State}
@@ -71,6 +77,7 @@ class BlockCreate extends BlockBase {
json['xml'] = Xml.domToText(this.xml);
json['ids'] = this.ids;
json['json'] = this.json;
json['ui'] = this.ui;
if (!this.recordUndo) {
json['recordUndo'] = this.recordUndo;
}
@@ -86,6 +93,7 @@ class BlockCreate extends BlockBase {
this.xml = Xml.textToDom(json['xml']);
this.ids = json['ids'];
this.json = /** @type {!blocks.State} */ (json['json']);
this.ui = !!json['ui'];
if (json['recordUndo'] !== undefined) {
this.recordUndo = json['recordUndo'];
}
@@ -104,7 +112,7 @@ class BlockCreate extends BlockBase {
const id = this.ids[i];
const block = workspace.getBlockById(id);
if (block) {
block.dispose(false);
block.dispose(false, this.ui);
} else if (id === this.blockId) {
// Only complain about root-level block.
console.warn('Can\'t uncreate non-existent block: ' + id);

View File

@@ -63,6 +63,12 @@ class BlockDelete extends BlockBase {
*/
this.wasShadow = opt_block.isShadow();
/**
* Play UI effects (sound and animation)?
* @type {boolean}
*/
this.ui = true;
/**
* JSON representation of the block that was just deleted.
* @type {!blocks.State}
@@ -81,6 +87,7 @@ class BlockDelete extends BlockBase {
json['ids'] = this.ids;
json['wasShadow'] = this.wasShadow;
json['oldJson'] = this.oldJson;
json['ui'] = this.ui;
if (!this.recordUndo) {
json['recordUndo'] = this.recordUndo;
}
@@ -98,6 +105,7 @@ class BlockDelete extends BlockBase {
this.wasShadow =
json['wasShadow'] || this.oldXml.tagName.toLowerCase() === 'shadow';
this.oldJson = /** @type {!blocks.State} */ (json['oldJson']);
this.ui = !!json['ui'];
if (json['recordUndo'] !== undefined) {
this.recordUndo = json['recordUndo'];
}
@@ -114,7 +122,7 @@ class BlockDelete extends BlockBase {
const id = this.ids[i];
const block = workspace.getBlockById(id);
if (block) {
block.dispose(false);
block.dispose(false, this.ui);
} else if (id === this.blockId) {
// Only complain about root-level block.
console.warn('Can\'t delete non-existent block: ' + id);