mirror of
https://github.com/google/blockly.git
synced 2026-01-15 12:57:12 +01:00
Add category UI event. Issue #306.
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user