Emitting event on trashcan close. (#4056)

* Emitting event on trashcan close.
This commit is contained in:
Monica Kozbial
2020-07-21 13:14:29 -07:00
committed by GitHub
parent e88ec53425
commit 26993a120f
2 changed files with 35 additions and 15 deletions

View File

@@ -323,7 +323,7 @@ Blockly.hideChaff = function(opt_allowToolbox) {
// trashcan UI (no trashcan to click to close it).
if (workspace.trashcan &&
workspace.trashcan.flyout) {
workspace.trashcan.flyout.hide();
workspace.trashcan.closeFlyout();
}
var toolbox = workspace.getToolbox();
if (toolbox &&

View File

@@ -372,6 +372,34 @@ Blockly.Trashcan.prototype.contentsIsOpen = function() {
return this.flyout.isVisible();
};
/**
* Opens the trashcan flyout.
*/
Blockly.Trashcan.prototype.openFlyout = function() {
if (this.contentsIsOpen()) {
return;
}
var xml = [];
for (var i = 0, text; (text = this.contents_[i]); i++) {
xml[i] = Blockly.Xml.textToDom(text);
}
this.flyout.show(xml);
this.fireUiEvent_(true);
};
/**
* Closes the trashcan flyout.
*/
Blockly.Trashcan.prototype.closeFlyout = function() {
if (!this.contentsIsOpen()) {
return;
}
this.flyout.hide();
this.fireUiEvent_(false);
};
/**
* Empties the trashcan's contents. If the contents-flyout is currently open
* it will be closed.
@@ -382,9 +410,7 @@ Blockly.Trashcan.prototype.emptyContents = function() {
}
this.contents_.length = 0;
this.setMinOpenness_(0);
if (this.contentsIsOpen()) {
this.flyout.hide();
}
this.closeFlyout();
};
/**
@@ -523,22 +549,16 @@ Blockly.Trashcan.prototype.click = function() {
if (!this.hasContents_()) {
return;
}
var xml = [];
for (var i = 0, text; (text = this.contents_[i]); i++) {
xml[i] = Blockly.Xml.textToDom(text);
}
this.flyout.show(xml);
this.fireUiEvent_();
this.openFlyout();
};
/**
* Fires a ui event for trashcan flyout opening.
* Fires a ui event for trashcan flyout open or close.
* @param {boolean} trashcanOpen Whether the flyout is opening.
* @private
*/
Blockly.Trashcan.prototype.fireUiEvent_ = function() {
var uiEvent = new Blockly.Events.Ui(null, 'trashcanOpen', null, true);
Blockly.Trashcan.prototype.fireUiEvent_ = function(trashcanOpen) {
var uiEvent = new Blockly.Events.Ui(null, 'trashcanOpen', null, trashcanOpen);
uiEvent.workspaceId = this.workspace_.id;
Blockly.Events.fire(uiEvent);
};