Add category UI event. Issue #306.

This commit is contained in:
Neil Fraser
2016-03-31 02:04:23 -07:00
parent 83925b2fe7
commit 39f7e6660e
2 changed files with 9 additions and 2 deletions

View File

@@ -651,8 +651,8 @@ Blockly.Events.Ui.prototype.type = Blockly.Events.UI;
* Encode the event as JSON.
* @return {!Object} JSON representation.
*/
Blockly.Events.Change.prototype.toJson = function() {
var json = Blockly.Events.Change.superClass_.toJson.call(this);
Blockly.Events.Ui.prototype.toJson = function() {
var json = Blockly.Events.Ui.superClass_.toJson.call(this);
json['element'] = this.element;
if (this.newValue !== undefined) {
json['newValue'] = this.newValue;

View File

@@ -404,6 +404,7 @@ Blockly.Toolbox.TreeControl.prototype.setSelectedItem = function(node) {
// not rendered.
toolbox.addColour_(node);
}
var oldNode = this.getSelectedItem();
goog.ui.tree.TreeControl.prototype.setSelectedItem.call(this, node);
if (node && node.blocks && node.blocks.length) {
toolbox.flyout_.show(node.blocks);
@@ -415,6 +416,12 @@ Blockly.Toolbox.TreeControl.prototype.setSelectedItem = function(node) {
// Hide the flyout.
toolbox.flyout_.hide();
}
if (oldNode != node && oldNode != this) {
var event = new Blockly.Events.Ui(null, 'category',
oldNode && oldNode.getHtml(), node && node.getHtml());
event.workspaceId = toolbox.workspace_.id;
Blockly.Events.fire(event);
}
if (node) {
toolbox.lastCategory_ = node;
}