mirror of
https://github.com/google/blockly.git
synced 2026-01-08 09:30:06 +01:00
Fix compiler warnings related to events. (#3151)
* Fix 23 warnings in event related code.
This commit is contained in:
@@ -177,16 +177,16 @@ Blockly.Events.Change.prototype.run = function(forward) {
|
||||
}
|
||||
break;
|
||||
case 'comment':
|
||||
block.setCommentText(value || null);
|
||||
block.setCommentText(/** @type {string} */ (value) || null);
|
||||
break;
|
||||
case 'collapsed':
|
||||
block.setCollapsed(value);
|
||||
block.setCollapsed(!!value);
|
||||
break;
|
||||
case 'disabled':
|
||||
block.setEnabled(!value);
|
||||
break;
|
||||
case 'inline':
|
||||
block.setInputsInline(value);
|
||||
block.setInputsInline(!!value);
|
||||
break;
|
||||
case 'mutation':
|
||||
var oldMutation = '';
|
||||
@@ -195,7 +195,7 @@ Blockly.Events.Change.prototype.run = function(forward) {
|
||||
oldMutation = oldMutationDom && Blockly.Xml.domToText(oldMutationDom);
|
||||
}
|
||||
if (block.domToMutation) {
|
||||
var dom = Blockly.Xml.textToDom(value || '<mutation/>');
|
||||
var dom = Blockly.Xml.textToDom(/** @type {string} */ (value) || '<mutation/>');
|
||||
block.domToMutation(dom);
|
||||
}
|
||||
Blockly.Events.fire(new Blockly.Events.Change(
|
||||
@@ -223,7 +223,7 @@ Blockly.Events.Create = function(block) {
|
||||
} else {
|
||||
this.xml = Blockly.Xml.blockToDom(block);
|
||||
}
|
||||
this.ids = Blockly.Events.getDescendantIds_(block);
|
||||
this.ids = Blockly.Events.getDescendantIds(block);
|
||||
};
|
||||
Blockly.utils.object.inherits(Blockly.Events.Create, Blockly.Events.BlockBase);
|
||||
|
||||
@@ -276,7 +276,7 @@ Blockly.Events.Create.prototype.run = function(forward) {
|
||||
for (var i = 0, id; id = this.ids[i]; i++) {
|
||||
var block = workspace.getBlockById(id);
|
||||
if (block) {
|
||||
block.dispose(false, false);
|
||||
block.dispose(false);
|
||||
} else if (id == this.blockId) {
|
||||
// Only complain about root-level block.
|
||||
console.warn("Can't uncreate non-existent block: " + id);
|
||||
@@ -305,7 +305,7 @@ Blockly.Events.Delete = function(block) {
|
||||
} else {
|
||||
this.oldXml = Blockly.Xml.blockToDom(block);
|
||||
}
|
||||
this.ids = Blockly.Events.getDescendantIds_(block);
|
||||
this.ids = Blockly.Events.getDescendantIds(block);
|
||||
};
|
||||
Blockly.utils.object.inherits(Blockly.Events.Delete, Blockly.Events.BlockBase);
|
||||
|
||||
@@ -352,7 +352,7 @@ Blockly.Events.Delete.prototype.run = function(forward) {
|
||||
for (var i = 0, id; id = this.ids[i]; i++) {
|
||||
var block = workspace.getBlockById(id);
|
||||
if (block) {
|
||||
block.dispose(false, false);
|
||||
block.dispose(false);
|
||||
} else if (id == this.blockId) {
|
||||
// Only complain about root-level block.
|
||||
console.warn("Can't delete non-existent block: " + id);
|
||||
@@ -448,7 +448,7 @@ Blockly.Events.Move.prototype.recordNew = function() {
|
||||
* @private
|
||||
*/
|
||||
Blockly.Events.Move.prototype.currentLocation_ = function() {
|
||||
var workspace = Blockly.Workspace.getById(this.workspaceId);
|
||||
var workspace = this.getEventWorkspace_();
|
||||
var block = workspace.getBlockById(this.blockId);
|
||||
var location = {};
|
||||
var parent = block.getParent();
|
||||
|
||||
@@ -195,6 +195,9 @@ Blockly.Events.fireNow_ = function() {
|
||||
var queue = Blockly.Events.filter(Blockly.Events.FIRE_QUEUE_, true);
|
||||
Blockly.Events.FIRE_QUEUE_.length = 0;
|
||||
for (var i = 0, event; event = queue[i]; i++) {
|
||||
if (!event.workspaceId) {
|
||||
continue;
|
||||
}
|
||||
var workspace = Blockly.Workspace.getById(event.workspaceId);
|
||||
if (workspace) {
|
||||
workspace.fireChangeListener(event);
|
||||
@@ -330,9 +333,9 @@ Blockly.Events.setGroup = function(state) {
|
||||
* Compute a list of the IDs of the specified block and all its descendants.
|
||||
* @param {!Blockly.Block} block The root block.
|
||||
* @return {!Array.<string>} List of block IDs.
|
||||
* @private
|
||||
* @package
|
||||
*/
|
||||
Blockly.Events.getDescendantIds_ = function(block) {
|
||||
Blockly.Events.getDescendantIds = function(block) {
|
||||
var ids = [];
|
||||
var descendants = block.getDescendants(false);
|
||||
for (var i = 0, descendant; descendant = descendants[i]; i++) {
|
||||
@@ -373,13 +376,13 @@ Blockly.Events.fromJson = function(json, workspace) {
|
||||
event = new Blockly.Events.VarRename(null, '');
|
||||
break;
|
||||
case Blockly.Events.UI:
|
||||
event = new Blockly.Events.Ui(null);
|
||||
event = new Blockly.Events.Ui(null, '', '', '');
|
||||
break;
|
||||
case Blockly.Events.COMMENT_CREATE:
|
||||
event = new Blockly.Events.CommentCreate(null);
|
||||
break;
|
||||
case Blockly.Events.COMMENT_CHANGE:
|
||||
event = new Blockly.Events.CommentChange(null);
|
||||
event = new Blockly.Events.CommentChange(null, '', '');
|
||||
break;
|
||||
case Blockly.Events.COMMENT_MOVE:
|
||||
event = new Blockly.Events.CommentMove(null);
|
||||
@@ -405,6 +408,9 @@ Blockly.Events.fromJson = function(json, workspace) {
|
||||
Blockly.Events.disableOrphans = function(event) {
|
||||
if (event.type == Blockly.Events.MOVE ||
|
||||
event.type == Blockly.Events.CREATE) {
|
||||
if (!event.workspaceId) {
|
||||
return;
|
||||
}
|
||||
var workspace = Blockly.Workspace.getById(event.workspaceId);
|
||||
var block = workspace.getBlockById(event.blockId);
|
||||
if (block) {
|
||||
|
||||
@@ -44,7 +44,7 @@ Blockly.Events.Abstract = function() {
|
||||
* perspective, and should be undone together.
|
||||
* @type {string}
|
||||
*/
|
||||
this.group = Blockly.Events.group_;
|
||||
this.group = Blockly.Events.getGroup();
|
||||
|
||||
/**
|
||||
* Sets whether the event should be added to the undo stack.
|
||||
@@ -93,12 +93,14 @@ Blockly.Events.Abstract.prototype.run = function(_forward) {
|
||||
|
||||
/**
|
||||
* Get workspace the event belongs to.
|
||||
* @return {Blockly.Workspace} The workspace the event belongs to.
|
||||
* @return {!Blockly.Workspace} The workspace the event belongs to.
|
||||
* @throws {Error} if workspace is null.
|
||||
* @protected
|
||||
*/
|
||||
Blockly.Events.Abstract.prototype.getEventWorkspace_ = function() {
|
||||
var workspace = Blockly.Workspace.getById(this.workspaceId);
|
||||
if (this.workspaceId) {
|
||||
var workspace = Blockly.Workspace.getById(this.workspaceId);
|
||||
}
|
||||
if (!workspace) {
|
||||
throw Error('Workspace is null. Event must have been generated from real' +
|
||||
' Blockly events.');
|
||||
|
||||
@@ -365,7 +365,9 @@ Blockly.createMainWorkspace_ = function(svg, options, blockDragSurface,
|
||||
console.log('WARNING: Moved object in bounds but there was no' +
|
||||
' event group. This may break undo.');
|
||||
}
|
||||
Blockly.Events.setGroup(oldGroup);
|
||||
if (oldGroup !== null) {
|
||||
Blockly.Events.setGroup(oldGroup);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ goog.require('Blockly.utils.object');
|
||||
Blockly.Events.Ui = function(block, element, oldValue, newValue) {
|
||||
Blockly.Events.Ui.superClass_.constructor.call(this);
|
||||
this.blockId = block ? block.id : null;
|
||||
this.workspaceId = block ? block.workspace.id : null;
|
||||
this.workspaceId = block ? block.workspace.id : undefined;
|
||||
this.element = element;
|
||||
this.oldValue = oldValue;
|
||||
this.newValue = newValue;
|
||||
|
||||
@@ -51,7 +51,7 @@ Blockly.Events.FinishedLoading = function(workspace) {
|
||||
* perspective, and should be undone together.
|
||||
* @type {string}
|
||||
*/
|
||||
this.group = Blockly.Events.group_;
|
||||
this.group = Blockly.Events.getGroup();
|
||||
|
||||
// Workspace events do not undo or redo.
|
||||
this.recordUndo = false;
|
||||
|
||||
@@ -62,7 +62,7 @@ Blockly.Events.CommentBase = function(comment) {
|
||||
* perspective, and should be undone together.
|
||||
* @type {string}
|
||||
*/
|
||||
this.group = Blockly.Events.group_;
|
||||
this.group = Blockly.Events.getGroup();
|
||||
|
||||
/**
|
||||
* Sets whether the event should be added to the undo stack.
|
||||
@@ -315,7 +315,7 @@ Blockly.Events.CommentMove = function(comment) {
|
||||
|
||||
/**
|
||||
* The location after the move, in workspace coordinates.
|
||||
* @type {!Blockly.utils.Coordinate}
|
||||
* @type {Blockly.utils.Coordinate}
|
||||
*/
|
||||
this.newCoordinate_ = null;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user