| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
|
|
| |
| |
| |
|
|
| 'use strict';
|
|
|
| goog.provide('Blockly.Events.CommentBase');
|
| goog.provide('Blockly.Events.CommentChange');
|
| goog.provide('Blockly.Events.CommentCreate');
|
| goog.provide('Blockly.Events.CommentDelete');
|
| goog.provide('Blockly.Events.CommentMove');
|
|
|
| goog.require('Blockly.Events');
|
| goog.require('Blockly.Events.Abstract');
|
|
|
| goog.require('goog.math.Coordinate');
|
|
|
|
|
| |
| |
| |
| |
| |
| |
|
|
| Blockly.Events.CommentBase = function(comment) {
|
| |
| |
| |
|
|
| this.commentId = comment.id;
|
|
|
| |
| |
| |
|
|
| this.workspaceId = comment.workspace.id;
|
|
|
| |
| |
| |
| |
|
|
| this.blockId = comment.blockId || null;
|
|
|
| |
| |
| |
| |
| |
|
|
| this.group = Blockly.Events.group_;
|
|
|
| |
| |
| |
|
|
| this.recordUndo = Blockly.Events.recordUndo;
|
| };
|
| goog.inherits(Blockly.Events.CommentBase, Blockly.Events.Abstract);
|
|
|
| |
| |
| |
|
|
| Blockly.Events.CommentBase.prototype.toJson = function() {
|
| var json = {
|
| 'type': this.type
|
| };
|
| if (this.group) {
|
| json['group'] = this.group;
|
| }
|
| if (this.commentId) {
|
| json['commentId'] = this.commentId;
|
| }
|
| if (this.blockId) {
|
| json['blockId'] = this.blockId;
|
| }
|
| return json;
|
| };
|
|
|
| |
| |
| |
|
|
| Blockly.Events.CommentBase.prototype.fromJson = function(json) {
|
| this.commentId = json['commentId'];
|
| this.group = json['group'];
|
| this.blockId = json['blockId'];
|
| };
|
|
|
| |
| |
| |
| |
| |
|
|
| Blockly.Events.CommentBase.prototype.getComment_ = function() {
|
| var workspace = this.getEventWorkspace_();
|
| return workspace.getCommentById(this.commentId);
|
| };
|
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| Blockly.Events.CommentChange = function(comment, oldContents, newContents) {
|
| if (!comment) {
|
| return;
|
| }
|
| Blockly.Events.CommentChange.superClass_.constructor.call(this, comment);
|
| this.oldContents_ = oldContents;
|
| this.newContents_ = newContents;
|
| };
|
| goog.inherits(Blockly.Events.CommentChange, Blockly.Events.CommentBase);
|
|
|
| |
| |
| |
|
|
| Blockly.Events.CommentChange.prototype.type = Blockly.Events.COMMENT_CHANGE;
|
|
|
| |
| |
| |
|
|
| Blockly.Events.CommentChange.prototype.toJson = function() {
|
| var json = Blockly.Events.CommentChange.superClass_.toJson.call(this);
|
| json['newContents'] = this.newContents_;
|
| return json;
|
| };
|
|
|
| |
| |
| |
|
|
| Blockly.Events.CommentChange.prototype.fromJson = function(json) {
|
| Blockly.Events.CommentChange.superClass_.fromJson.call(this, json);
|
| this.newContents_ = json['newValue'];
|
| };
|
|
|
| |
| |
| |
|
|
| Blockly.Events.CommentChange.prototype.isNull = function() {
|
| return this.oldContents_ == this.newContents_;
|
| };
|
|
|
| |
| |
| |
|
|
| Blockly.Events.CommentChange.prototype.run = function(forward) {
|
| var comment = this.getComment_();
|
| if (!comment) {
|
| console.warn('Can\'t change non-existent comment: ' + this.commentId);
|
| return;
|
| }
|
| var contents = forward ? this.newContents_ : this.oldContents_;
|
|
|
| if (contents.hasOwnProperty('minimized')) {
|
| comment.setMinimized(contents.minimized);
|
| }
|
| if (contents.hasOwnProperty('width') && contents.hasOwnProperty('height')) {
|
| comment.setSize(contents.width, contents.height);
|
| }
|
| if (contents.hasOwnProperty('text')) {
|
| comment.setText(contents.text);
|
| }
|
| };
|
|
|
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| Blockly.Events.CommentCreate = function(comment) {
|
| if (!comment) {
|
| return;
|
| }
|
| Blockly.Events.CommentCreate.superClass_.constructor.call(this, comment);
|
|
|
| |
| |
| |
|
|
| this.text = comment.getText();
|
|
|
| |
| |
| |
|
|
| this.xy = comment.getXY();
|
|
|
| var hw = comment.getHeightWidth();
|
|
|
| |
| |
| |
|
|
| this.width = hw.width;
|
|
|
| |
| |
| |
|
|
| this.height = hw.height;
|
|
|
| |
| |
| |
|
|
| this.minimized = comment.isMinimized() || false;
|
|
|
| this.xml = comment.toXmlWithXY();
|
| };
|
| goog.inherits(Blockly.Events.CommentCreate, Blockly.Events.CommentBase);
|
|
|
| |
| |
| |
|
|
| Blockly.Events.CommentCreate.prototype.type = Blockly.Events.COMMENT_CREATE;
|
|
|
| |
| |
| |
| |
| |
|
|
| Blockly.Events.CommentCreate.prototype.toJson = function() {
|
| var json = Blockly.Events.CommentCreate.superClass_.toJson.call(this);
|
| json['xml'] = Blockly.Xml.domToText(this.xml);
|
| return json;
|
| };
|
|
|
| |
| |
| |
|
|
| Blockly.Events.CommentCreate.prototype.fromJson = function(json) {
|
| Blockly.Events.CommentCreate.superClass_.fromJson.call(this, json);
|
| this.xml = Blockly.Xml.textToDom('<xml>' + json['xml'] + '</xml>').firstChild;
|
| };
|
|
|
| |
| |
| |
|
|
| Blockly.Events.CommentCreate.prototype.run = function(forward) {
|
| if (forward) {
|
| var workspace = this.getEventWorkspace_();
|
| if (this.blockId) {
|
| var block = workspace.getBlockById(this.blockId);
|
| if (block) {
|
| block.setCommentText('', this.commentId, this.xy.x, this.xy.y, this.minimized);
|
| }
|
| } else {
|
| var xml = goog.dom.createDom('xml');
|
| xml.appendChild(this.xml);
|
| Blockly.Xml.domToWorkspace(xml, workspace);
|
| }
|
| } else {
|
| var comment = this.getComment_();
|
| if (comment) {
|
| comment.dispose(false, false);
|
| } else {
|
|
|
| console.warn("Can't uncreate non-existent comment: " + this.commentId);
|
| }
|
| }
|
| };
|
|
|
| |
| |
| |
| |
| |
| |
|
|
| Blockly.Events.CommentDelete = function(comment) {
|
| if (!comment) {
|
| return;
|
| }
|
| Blockly.Events.CommentDelete.superClass_.constructor.call(this, comment);
|
| this.xy = comment.getXY();
|
| this.minimized = comment.isMinimized() || false;
|
| this.text = comment.getText();
|
| var hw = comment.getHeightWidth();
|
| this.height = hw.height;
|
| this.width = hw.width;
|
|
|
| this.xml = comment.toXmlWithXY();
|
| };
|
| goog.inherits(Blockly.Events.CommentDelete, Blockly.Events.CommentBase);
|
|
|
| |
| |
| |
|
|
| Blockly.Events.CommentDelete.prototype.type = Blockly.Events.COMMENT_DELETE;
|
|
|
| |
| |
| |
| |
| |
|
|
| Blockly.Events.CommentDelete.prototype.toJson = function() {
|
| var json = Blockly.Events.CommentDelete.superClass_.toJson.call(this);
|
| return json;
|
| };
|
|
|
| |
| |
| |
|
|
| Blockly.Events.CommentDelete.prototype.fromJson = function(json) {
|
| Blockly.Events.CommentDelete.superClass_.fromJson.call(this, json);
|
| };
|
|
|
| |
| |
| |
|
|
| Blockly.Events.CommentDelete.prototype.run = function(forward) {
|
| if (forward) {
|
| var comment = this.getComment_();
|
| if (comment) {
|
| comment.dispose(false, false);
|
| } else {
|
|
|
| console.warn("Can't delete non-existent comment: " + this.commentId);
|
| }
|
| } else {
|
| var workspace = this.getEventWorkspace_();
|
| if (this.blockId) {
|
| var block = workspace.getBlockById(this.blockId);
|
| block.setCommentText(this.text, this.commentId, this.xy.x, this.xy.y, this.minimized);
|
| block.comment.setSize(this.width, this.height);
|
| } else {
|
| var xml = goog.dom.createDom('xml');
|
| xml.appendChild(this.xml);
|
| Blockly.Xml.domToWorkspace(xml, workspace);
|
| }
|
| }
|
| };
|
|
|
| |
| |
| |
| |
| |
| |
|
|
| Blockly.Events.CommentMove = function(comment) {
|
| if (!comment) {
|
| return;
|
| }
|
| Blockly.Events.CommentMove.superClass_.constructor.call(this, comment);
|
|
|
| |
| |
| |
| |
|
|
| this.comment_ = comment;
|
|
|
| this.workspaceWidth_ = comment.workspace.getWidth();
|
| |
| |
| |
|
|
| this.oldCoordinate_ = this.currentLocation_();
|
|
|
| |
| |
| |
|
|
| this.newCoordinate_ = null;
|
| };
|
| goog.inherits(Blockly.Events.CommentMove, Blockly.Events.CommentBase);
|
|
|
| |
| |
| |
| |
| |
|
|
| Blockly.Events.CommentMove.prototype.currentLocation_ = function() {
|
| var xy = this.comment_.getXY();
|
| if (!this.comment_.workspace.RTL) {
|
| return xy;
|
| }
|
|
|
| var rtlAwareX;
|
| if (this.comment_ instanceof Blockly.ScratchBlockComment) {
|
| var commentWidth = this.comment_.getBubbleSize().width;
|
| rtlAwareX = this.workspaceWidth_ - xy.x - commentWidth;
|
| } else {
|
| rtlAwareX = this.workspaceWidth_ - xy.x;
|
| }
|
| return new goog.math.Coordinate(rtlAwareX, xy.y);
|
| };
|
|
|
| |
| |
| |
|
|
| Blockly.Events.CommentMove.prototype.recordNew = function() {
|
| if (!this.comment_) {
|
| throw new Error('Tried to record the new position of a comment on the ' +
|
| 'same event twice.');
|
| }
|
| this.newCoordinate_ = this.currentLocation_();
|
| this.comment_ = null;
|
| };
|
|
|
| |
| |
| |
|
|
| Blockly.Events.CommentMove.prototype.type = Blockly.Events.COMMENT_MOVE;
|
|
|
| |
| |
| |
| |
| |
|
|
| Blockly.Events.CommentMove.prototype.setOldCoordinate = function(xy) {
|
| this.oldCoordinate_ = new goog.math.Coordinate(this.comment_.workspace.RTL ?
|
| this.workspaceWidth_ - xy.x : xy.x, xy.y);
|
| };
|
|
|
| |
| |
| |
| |
| |
|
|
| Blockly.Events.CommentMove.prototype.toJson = function() {
|
| var json = Blockly.Events.CommentMove.superClass_.toJson.call(this);
|
| if (this.newCoordinate_) {
|
| json['newCoordinate'] = Math.round(this.newCoordinate_.x) + ',' +
|
| Math.round(this.newCoordinate_.y);
|
| }
|
| return json;
|
| };
|
|
|
| |
| |
| |
|
|
| Blockly.Events.CommentMove.prototype.fromJson = function(json) {
|
| Blockly.Events.CommentMove.superClass_.fromJson.call(this, json);
|
|
|
| if (json['newCoordinate']) {
|
| var xy = json['newCoordinate'].split(',');
|
| this.newCoordinate_ =
|
| new goog.math.Coordinate(parseFloat(xy[0]), parseFloat(xy[1]));
|
| }
|
| };
|
|
|
| |
| |
| |
|
|
| Blockly.Events.CommentMove.prototype.isNull = function() {
|
| return goog.math.Coordinate.equals(this.oldCoordinate_, this.newCoordinate_);
|
| };
|
|
|
| |
| |
| |
|
|
| Blockly.Events.CommentMove.prototype.run = function(forward) {
|
| var comment = this.getComment_();
|
| if (!comment) {
|
| console.warn('Can\'t move non-existent comment: ' + this.commentId);
|
| return;
|
| }
|
|
|
| var target = forward ? this.newCoordinate_ : this.oldCoordinate_;
|
|
|
| if (comment instanceof Blockly.ScratchBlockComment) {
|
| if (comment.workspace.RTL) {
|
| comment.moveTo(this.workspaceWidth_ - target.x, target.y);
|
| } else {
|
| comment.moveTo(target.x, target.y);
|
| }
|
| } else {
|
|
|
| var current = comment.getXY();
|
| if (comment.workspace.RTL) {
|
| var deltaX = target.x - (this.workspaceWidth_ - current.x);
|
| comment.moveBy(-deltaX, target.y - current.y);
|
| } else {
|
| comment.moveBy(target.x - current.x, target.y - current.y);
|
| }
|
|
|
| }
|
| };
|
|
|