added editable property to workspaceComment (#3480)

* added editable property to workspaceComment
This commit is contained in:
Lukas Dachtler
2019-12-09 08:16:48 +01:00
committed by Sam El-Husseini
parent f5bb5b6143
commit 7d24276721
3 changed files with 35 additions and 0 deletions

View File

@@ -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.

View File

@@ -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);

View File

@@ -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.