diff --git a/core/events.js b/core/events.js index 8e90f6583..7570fb8e9 100644 --- a/core/events.js +++ b/core/events.js @@ -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; diff --git a/core/toolbox.js b/core/toolbox.js index c8818be1c..3951c107d 100644 --- a/core/toolbox.js +++ b/core/toolbox.js @@ -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; }