From 7d242767213719b83fd457300dbb66c51f920c49 Mon Sep 17 00:00:00 2001 From: Lukas Dachtler Date: Mon, 9 Dec 2019 08:16:48 +0100 Subject: [PATCH] added editable property to workspaceComment (#3480) * added editable property to workspaceComment --- core/workspace_comment.js | 23 +++++++++++++++++++++++ core/workspace_comment_render_svg.js | 1 + core/workspace_comment_svg.js | 11 +++++++++++ 3 files changed, 35 insertions(+) diff --git a/core/workspace_comment.js b/core/workspace_comment.js index 66e494398..5d06eec21 100644 --- a/core/workspace_comment.js +++ b/core/workspace_comment.js @@ -95,6 +95,12 @@ Blockly.WorkspaceComment = function(workspace, content, height, width, opt_id) { */ this.movable_ = true; + /** + * @type {boolean} + * @private + */ + this.editable_ = true; + /** * @protected * @type {string} @@ -229,6 +235,23 @@ Blockly.WorkspaceComment.prototype.setMovable = function(movable) { this.movable_ = movable; }; +/** + * Get whether this comment is editable or not. + * @return {boolean} True if editable. + */ +Blockly.WorkspaceComment.prototype.isEditable = function() { + return this.editable_ && + !(this.workspace && this.workspace.options.readOnly); +}; + +/** + * Set whether this comment is editable or not. + * @param {boolean} editable True if editable. + */ +Blockly.WorkspaceComment.prototype.setEditable = function(editable) { + this.editable_ = editable; +}; + /** * Returns this comment's text. * @return {string} Comment text. diff --git a/core/workspace_comment_render_svg.js b/core/workspace_comment_render_svg.js index 6ba4383c2..c2bc5f047 100644 --- a/core/workspace_comment_render_svg.js +++ b/core/workspace_comment_render_svg.js @@ -160,6 +160,7 @@ Blockly.WorkspaceCommentSvg.prototype.createEditor_ = function() { var textarea = document.createElementNS(Blockly.utils.dom.HTML_NS, 'textarea'); textarea.className = 'blocklyCommentTextarea'; textarea.setAttribute('dir', this.RTL ? 'RTL' : 'LTR'); + textarea.readOnly = !this.isEditable(); body.appendChild(textarea); this.textarea_ = textarea; this.foreignObject_.appendChild(body); diff --git a/core/workspace_comment_svg.js b/core/workspace_comment_svg.js index 80916a837..a2fcef7cc 100644 --- a/core/workspace_comment_svg.js +++ b/core/workspace_comment_svg.js @@ -483,6 +483,17 @@ Blockly.WorkspaceCommentSvg.prototype.setMovable = function(movable) { this.updateMovable(); }; +/** + * Set whether this comment is editable or not. + * @param {boolean} editable True if editable. + */ +Blockly.WorkspaceCommentSvg.prototype.setEditable = function(editable) { + Blockly.WorkspaceCommentSvg.superClass_.setEditable.call(this, editable); + if (this.textarea_) { + this.textarea_.readOnly = !editable; + } +}; + /** * Recursively adds or removes the dragging class to this node and its children. * @param {boolean} adding True if adding, false if removing.