mirror of
https://github.com/scratchfoundation/scratch-blocks.git
synced 2025-07-27 22:29:07 -04:00
Code cleanup addressing PR comments
This commit is contained in:
parent
4843e35894
commit
2c2970df57
7 changed files with 73 additions and 19 deletions
|
@ -111,8 +111,8 @@ Blockly.Events.CommentBase.prototype.fromJson = function(json) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper function for finding the comment this event pertains to.
|
* Helper function for finding the comment this event pertains to.
|
||||||
* @return {Blockly.WorkspaceComment | Blockly.ScratchBlockComment}
|
* @return {?(Blockly.WorkspaceComment | Blockly.ScratchBlockComment)}
|
||||||
* The comment this event pertains to.
|
* The comment this event pertains to, or null if it no longer exists.
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
Blockly.Events.CommentBase.prototype.getComment_ = function() {
|
Blockly.Events.CommentBase.prototype.getComment_ = function() {
|
||||||
|
@ -202,13 +202,12 @@ Blockly.Events.CommentChange.prototype.run = function(forward) {
|
||||||
}
|
}
|
||||||
|
|
||||||
console.warn('Unrecognized comment change: ' + JSON.stringify(contents) + '; cannot undo/redo');
|
console.warn('Unrecognized comment change: ' + JSON.stringify(contents) + '; cannot undo/redo');
|
||||||
return;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class for a comment creation event.
|
* Class for a comment creation event.
|
||||||
* @param {Blockly.WorkspaceComment} comment The created comment.
|
* @param {Blockly.WorkspaceComment | Blockly.ScratchBlockComment} comment
|
||||||
* Null for a blank event.
|
* The created comment. Null for a blank event.
|
||||||
* @param {string=} opt_blockId Optional id for the block this comment belongs
|
* @param {string=} opt_blockId Optional id for the block this comment belongs
|
||||||
* to, if it is a block comment.
|
* to, if it is a block comment.
|
||||||
* @extends {Blockly.Events.CommentBase}
|
* @extends {Blockly.Events.CommentBase}
|
||||||
|
@ -222,13 +221,13 @@ Blockly.Events.CommentCreate = function(comment) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The text content of this comment.
|
* The text content of this comment.
|
||||||
* @type{string}
|
* @type {string}
|
||||||
*/
|
*/
|
||||||
this.text = comment.getText();
|
this.text = comment.getText();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The XY position of this comment on the workspace.
|
* The XY position of this comment on the workspace.
|
||||||
* @type{goog.math.Coordinate}
|
* @type {goog.math.Coordinate}
|
||||||
*/
|
*/
|
||||||
this.xy = comment.getXY();
|
this.xy = comment.getXY();
|
||||||
|
|
||||||
|
@ -236,13 +235,13 @@ Blockly.Events.CommentCreate = function(comment) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The width of this comment when it is full size.
|
* The width of this comment when it is full size.
|
||||||
* @type{number}
|
* @type {number}
|
||||||
*/
|
*/
|
||||||
this.width = hw.width;
|
this.width = hw.width;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The height of this comment when it is full size.
|
* The height of this comment when it is full size.
|
||||||
* @type{number}
|
* @type {number}
|
||||||
*/
|
*/
|
||||||
this.height = hw.height;
|
this.height = hw.height;
|
||||||
|
|
||||||
|
|
|
@ -499,7 +499,9 @@ Blockly.ContextMenu.workspaceCommentOption = function(ws, e) {
|
||||||
comment.render(false);
|
comment.render(false);
|
||||||
comment.select();
|
comment.select();
|
||||||
}
|
}
|
||||||
if (disabled) Blockly.Events.enable();
|
if (disabled) {
|
||||||
|
Blockly.Events.enable();
|
||||||
|
}
|
||||||
Blockly.WorkspaceComment.fireCreateEvent(comment);
|
Blockly.WorkspaceComment.fireCreateEvent(comment);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -361,6 +361,18 @@ Blockly.Events.fromJson = function(json, workspace) {
|
||||||
case Blockly.Events.VAR_RENAME:
|
case Blockly.Events.VAR_RENAME:
|
||||||
event = new Blockly.Events.VarRename(null);
|
event = new Blockly.Events.VarRename(null);
|
||||||
break;
|
break;
|
||||||
|
case Blockly.Events.COMMENT_CREATE:
|
||||||
|
event = new Blockly.Events.CommentCreate(null);
|
||||||
|
break;
|
||||||
|
case Blockly.Events.COMMENT_CHANGE:
|
||||||
|
event = new Blockly.Events.CommentChange(null);
|
||||||
|
break;
|
||||||
|
case Blockly.Events.COMMENT_MOVE:
|
||||||
|
event = new Blockly.Events.CommentMove(null);
|
||||||
|
break;
|
||||||
|
case Blockly.Events.COMMENT_DELETE:
|
||||||
|
event = new Blockly.Events.CommentDelete(null);
|
||||||
|
break;
|
||||||
case Blockly.Events.UI:
|
case Blockly.Events.UI:
|
||||||
event = new Blockly.Events.Ui(null);
|
event = new Blockly.Events.Ui(null);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -51,16 +51,44 @@ goog.require('goog.userAgent');
|
||||||
*/
|
*/
|
||||||
Blockly.ScratchBlockComment = function(block, text, id, x, y, minimized) {
|
Blockly.ScratchBlockComment = function(block, text, id, x, y, minimized) {
|
||||||
Blockly.ScratchBlockComment.superClass_.constructor.call(this, block);
|
Blockly.ScratchBlockComment.superClass_.constructor.call(this, block);
|
||||||
|
/**
|
||||||
|
* The text content of this comment.
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
this.text_ = text;
|
this.text_ = text;
|
||||||
|
/**
|
||||||
|
* The x position of this comment in workspace coordinates.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
this.x_ = x;
|
this.x_ = x;
|
||||||
|
/**
|
||||||
|
* The y position of this comment in workspace coordinates.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
this.y_ = y;
|
this.y_ = y;
|
||||||
|
/**
|
||||||
|
* Whether this comment is minimized.
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
this.isMinimized_ = minimized || false;
|
this.isMinimized_ = minimized || false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The workspace this comment belongs to.
|
||||||
|
* @type {Blockly.Workspace}
|
||||||
|
*/
|
||||||
this.workspace = block.workspace;
|
this.workspace = block.workspace;
|
||||||
|
/**
|
||||||
|
* The unique identifier for this comment.
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
this.id = goog.isString(id) && !this.workspace.getCommentById(id) ?
|
this.id = goog.isString(id) && !this.workspace.getCommentById(id) ?
|
||||||
id : Blockly.utils.genUid();
|
id : Blockly.utils.genUid();
|
||||||
this.workspace.addTopComment(this);
|
this.workspace.addTopComment(this);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The id of the block this comment belongs to.
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
this.blockId = block.id;
|
this.blockId = block.id;
|
||||||
|
|
||||||
if (!block.rendered) {
|
if (!block.rendered) {
|
||||||
|
@ -303,7 +331,9 @@ Blockly.ScratchBlockComment.prototype.setVisible = function(visible) {
|
||||||
// Restore the bubble stats after the visibility switch.
|
// Restore the bubble stats after the visibility switch.
|
||||||
this.setText(text);
|
this.setText(text);
|
||||||
this.setBubbleSize(size.width, size.height);
|
this.setBubbleSize(size.width, size.height);
|
||||||
if (visible) Blockly.ScratchBlockComment.fireCreateEvent(this);
|
if (visible) {
|
||||||
|
Blockly.ScratchBlockComment.fireCreateEvent(this);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -320,7 +350,9 @@ Blockly.ScratchBlockComment.prototype.toggleMinimize_ = function() {
|
||||||
* @package
|
* @package
|
||||||
*/
|
*/
|
||||||
Blockly.ScratchBlockComment.prototype.setMinimized = function(minimize) {
|
Blockly.ScratchBlockComment.prototype.setMinimized = function(minimize) {
|
||||||
if (this.isMinimized_ == minimize) return;
|
if (this.isMinimized_ == minimize) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
Blockly.Events.fire(new Blockly.Events.CommentChange(this,
|
Blockly.Events.fire(new Blockly.Events.CommentChange(this,
|
||||||
{minimized: this.isMinimized_}, {minimized: minimize}));
|
{minimized: this.isMinimized_}, {minimized: minimize}));
|
||||||
this.isMinimized_ = minimize;
|
this.isMinimized_ = minimize;
|
||||||
|
@ -360,6 +392,7 @@ Blockly.ScratchBlockComment.prototype.setBubbleSize = function(width, height) {
|
||||||
* bubble, also set the bubble's size.
|
* bubble, also set the bubble's size.
|
||||||
* @param {number} width Width of the unminimized comment.
|
* @param {number} width Width of the unminimized comment.
|
||||||
* @param {number} height Height of the unminimized comment.
|
* @param {number} height Height of the unminimized comment.
|
||||||
|
* @package
|
||||||
*/
|
*/
|
||||||
Blockly.ScratchBlockComment.prototype.setSize = function(width, height) {
|
Blockly.ScratchBlockComment.prototype.setSize = function(width, height) {
|
||||||
var oldWidth = this.width_;
|
var oldWidth = this.width_;
|
||||||
|
@ -520,7 +553,6 @@ Blockly.ScratchBlockComment.prototype.toXmlWithXY = function() {
|
||||||
return element;
|
return element;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fire a create event for the given workspace comment, if comments are enabled.
|
* Fire a create event for the given workspace comment, if comments are enabled.
|
||||||
* @param {!Blockly.WorkspaceComment} comment The comment that was just created.
|
* @param {!Blockly.WorkspaceComment} comment The comment that was just created.
|
||||||
|
|
|
@ -56,6 +56,11 @@ Blockly.ScratchBubble = function(comment, workspace, content, anchorXY,
|
||||||
bubbleWidth, bubbleHeight, bubbleX, bubbleY, minimized) {
|
bubbleWidth, bubbleHeight, bubbleX, bubbleY, minimized) {
|
||||||
|
|
||||||
// Needed for Events
|
// Needed for Events
|
||||||
|
/**
|
||||||
|
* The comment this bubble belongs to.
|
||||||
|
* @type {Blockly.ScratchBlockComment}
|
||||||
|
* @package
|
||||||
|
*/
|
||||||
this.comment = comment;
|
this.comment = comment;
|
||||||
|
|
||||||
this.workspace_ = workspace;
|
this.workspace_ = workspace;
|
||||||
|
@ -363,8 +368,9 @@ Blockly.ScratchBubble.prototype.resizeMouseDown_ = function(e) {
|
||||||
Blockly.ScratchBubble.prototype.resizeMouseUp_ = function(_e) {
|
Blockly.ScratchBubble.prototype.resizeMouseUp_ = function(_e) {
|
||||||
var oldHW = this.resizeStartSize_;
|
var oldHW = this.resizeStartSize_;
|
||||||
this.resizeStartSize_ = null;
|
this.resizeStartSize_ = null;
|
||||||
if (this.width_ == oldHW.width &&
|
if (this.width_ == oldHW.width && this.height_ == oldHW.height) {
|
||||||
this.height_ == oldHW.height) return;
|
return;
|
||||||
|
}
|
||||||
// Fire a change event for the new width/height after
|
// Fire a change event for the new width/height after
|
||||||
// resize mouse up
|
// resize mouse up
|
||||||
Blockly.Events.fire(new Blockly.Events.CommentChange(
|
Blockly.Events.fire(new Blockly.Events.CommentChange(
|
||||||
|
|
|
@ -337,8 +337,9 @@ Blockly.WorkspaceCommentSvg.prototype.resizeMouseUp_ = function(/*e*/) {
|
||||||
this.unbindDragEvents_();
|
this.unbindDragEvents_();
|
||||||
var oldHW = this.resizeStartSize_;
|
var oldHW = this.resizeStartSize_;
|
||||||
this.resizeStartSize_ = null;
|
this.resizeStartSize_ = null;
|
||||||
if (this.width_ == oldHW.width &&
|
if (this.width_ == oldHW.width && this.height_ == oldHW.height) {
|
||||||
this.height_ == oldHW.height) return;
|
return;
|
||||||
|
}
|
||||||
// Fire a change event for the new width/height after
|
// Fire a change event for the new width/height after
|
||||||
// resize mouse up
|
// resize mouse up
|
||||||
Blockly.Events.fire(new Blockly.Events.CommentChange(
|
Blockly.Events.fire(new Blockly.Events.CommentChange(
|
||||||
|
@ -365,7 +366,9 @@ Blockly.WorkspaceCommentSvg.prototype.resizeMouseMove_ = function(e) {
|
||||||
disabled = true;
|
disabled = true;
|
||||||
}
|
}
|
||||||
this.setSize(this.RTL ? -newXY.x : newXY.x, newXY.y);
|
this.setSize(this.RTL ? -newXY.x : newXY.x, newXY.y);
|
||||||
if (disabled) Blockly.Events.enable();
|
if (disabled) {
|
||||||
|
Blockly.Events.enable();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -706,7 +706,7 @@ Blockly.Xml.domToBlockHeadless_ = function(xmlBlock, workspace) {
|
||||||
if (!isNaN(bubbleW) && !isNaN(bubbleH) &&
|
if (!isNaN(bubbleW) && !isNaN(bubbleH) &&
|
||||||
block.comment && block.comment.setVisible) {
|
block.comment && block.comment.setVisible) {
|
||||||
if (block.comment instanceof Blockly.ScratchBlockComment) {
|
if (block.comment instanceof Blockly.ScratchBlockComment) {
|
||||||
block.commet.setSize(bubbleW, bubbleH);
|
block.comment.setSize(bubbleW, bubbleH);
|
||||||
} else {
|
} else {
|
||||||
block.comment.setBubbleSize(bubbleW, bubbleH);
|
block.comment.setBubbleSize(bubbleW, bubbleH);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue