From 39f7e6660e6bf4ab13a06931f25ff0bc0b197b79 Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Thu, 31 Mar 2016 02:04:23 -0700 Subject: [PATCH] Add category UI event. Issue #306. --- core/events.js | 4 ++-- core/toolbox.js | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) 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; }