Add click UI event.

This commit is contained in:
Neil Fraser 2016-03-29 08:10:44 -07:00
parent 741491347b
commit 5f1cb3b92c
2 changed files with 30 additions and 20 deletions

View file

@ -123,11 +123,20 @@ Blockly.BlockSvg.prototype.initSvg = function() {
* Select this block. Highlight it visually.
*/
Blockly.BlockSvg.prototype.select = function() {
if (Blockly.selected) {
// Unselect any previously selected block.
Blockly.selected.unselect();
if (Blockly.selected == this) {
return;
}
Blockly.Events.fire(new Blockly.Events.Ui(this, 'selected', false, true));
var oldId = null;
if (Blockly.selected) {
oldId = Blockly.selected.id;
// Unselect any previously selected block.
Blockly.Events.disable();
Blockly.selected.unselect();
Blockly.Events.enable();
}
var event = new Blockly.Events.Ui(null, 'selected', oldId, this.id);
event.workspaceId = this.workspace.id;
Blockly.Events.fire(event);
Blockly.selected = this;
this.addSelect();
Blockly.fireUiEvent(this.workspace.getCanvas(), 'blocklySelectChange');
@ -140,7 +149,9 @@ Blockly.BlockSvg.prototype.unselect = function() {
if (Blockly.selected != this) {
return;
}
Blockly.Events.fire(new Blockly.Events.Ui(this, 'selected', true, false));
var event = new Blockly.Events.Ui(null, 'selected', this.id, null);
event.workspaceId = this.workspace.id;
Blockly.Events.fire(event);
Blockly.selected = null;
this.removeSelect();
Blockly.fireUiEvent(this.workspace.getCanvas(), 'blocklySelectChange');
@ -548,6 +559,10 @@ Blockly.BlockSvg.prototype.onMouseDown_ = function(e) {
* @private
*/
Blockly.BlockSvg.prototype.onMouseUp_ = function(e) {
if (Blockly.dragMode_ != 2) {
Blockly.Events.fire(
new Blockly.Events.Ui(this, 'click', undefined, undefined));
}
Blockly.setPageSelectable(true);
Blockly.terminateDrag_();
if (Blockly.selected && Blockly.highlightedConnection_) {

View file

@ -241,12 +241,14 @@ Blockly.Events.getDescendantIds_ = function(block) {
/**
* Abstract class for an event.
* @param {!Blockly.Block} block The block.
* @param {Blockly.Block} block The block.
* @constructor
*/
Blockly.Events.Abstract = function(block) {
this.blockId = block.id;
this.workspaceId = block.workspace.id;
if (block) {
this.blockId = block.id;
this.workspaceId = block.workspace.id;
}
this.group = Blockly.Events.group_;
this.recordUndo = Blockly.Events.recordUndo;
};
@ -269,7 +271,7 @@ Blockly.Events.Abstract.prototype.toJson = function() {
/**
* Does this event record any change of state?
* @return {boolean} True if something changed.
* @return {boolean} True if null, false if something changed.
*/
Blockly.Events.Abstract.prototype.isNull = function() {
return false;
@ -623,7 +625,7 @@ Blockly.Events.Move.prototype.run = function(forward) {
/**
* Class for a UI event.
* @param {!Blockly.Block} block The affected block.
* @param {Blockly.Block} block The affected block.
* @param {string} element One of 'selected', 'comment', 'mutator', etc.
* @param {string} oldValue Previous value of element.
* @param {string} newValue New value of element.
@ -652,15 +654,8 @@ Blockly.Events.Ui.prototype.type = Blockly.Events.UI;
Blockly.Events.Change.prototype.toJson = function() {
var json = Blockly.Events.Change.superClass_.toJson.call(this);
json['element'] = this.element;
json['newValue'] = this.newValue;
if (this.newValue !== undefined) {
json['newValue'] = this.newValue;
}
return json;
};
/**
* Does this event record any change of state?
* @return {boolean} True if something changed.
*/
Blockly.Events.Ui.prototype.isNull = function() {
return this.oldValue == this.newValue;
};