mirror of
https://github.com/google/blockly.git
synced 2026-01-14 20:37:10 +01:00
Permit single field disabling (https://github.com/google/blockly/issues/4932)
This commit is contained in:
@@ -202,6 +202,13 @@ Blockly.Field.prototype.isDirty_ = true;
|
||||
*/
|
||||
Blockly.Field.prototype.visible_ = true;
|
||||
|
||||
/**
|
||||
* Can the field value be changed using the editor on an editable block?
|
||||
* @type {boolean}
|
||||
* @protected
|
||||
*/
|
||||
Blockly.Field.prototype.enabled_ = true;
|
||||
|
||||
/**
|
||||
* The element the click handler is bound to.
|
||||
* @type {Element}
|
||||
@@ -440,7 +447,7 @@ Blockly.Field.prototype.updateEditable = function() {
|
||||
if (!this.EDITABLE || !group) {
|
||||
return;
|
||||
}
|
||||
if (this.sourceBlock_.isEditable()) {
|
||||
if (this.enabled_ && this.sourceBlock_.isEditable()) {
|
||||
Blockly.utils.dom.addClass(group, 'blocklyEditableText');
|
||||
Blockly.utils.dom.removeClass(group, 'blocklyNonEditableText');
|
||||
group.style.cursor = this.CURSOR;
|
||||
@@ -451,23 +458,44 @@ Blockly.Field.prototype.updateEditable = function() {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Set whether this field's value can be changed using the editor when the
|
||||
* source block is editable.
|
||||
* @param {boolean} enabled True if enabled.
|
||||
*/
|
||||
Blockly.Field.prototype.setEnabled = function(enabled) {
|
||||
this.enabled_ = enabled;
|
||||
this.updateEditable();
|
||||
};
|
||||
|
||||
/**
|
||||
* Check whether this field's value can be changed using the editor when the
|
||||
* source block is editable.
|
||||
* @return {boolean} Whether this field is enabled.
|
||||
*/
|
||||
Blockly.Field.prototype.isEnabled = function() {
|
||||
return this.enabled_;
|
||||
};
|
||||
|
||||
/**
|
||||
* Check whether this field defines the showEditor_ function.
|
||||
* @return {boolean} Whether this field is clickable.
|
||||
*/
|
||||
Blockly.Field.prototype.isClickable = function() {
|
||||
return !!this.sourceBlock_ && this.sourceBlock_.isEditable() &&
|
||||
!!this.showEditor_ && (typeof this.showEditor_ === 'function');
|
||||
return this.enabled_ && !!this.sourceBlock_ && this.sourceBlock_.isEditable()
|
||||
&& !!this.showEditor_ && (typeof this.showEditor_ === 'function');
|
||||
};
|
||||
|
||||
/**
|
||||
* Check whether this field is currently editable. Some fields are never
|
||||
* EDITABLE (e.g. text labels). Other fields may be EDITABLE but may exist on
|
||||
* non-editable blocks.
|
||||
* @return {boolean} Whether this field is editable and on an editable block
|
||||
* non-editable blocks or be currently disabled.
|
||||
* @return {boolean} Whether this field is currently enabled, editable and on
|
||||
* an editable block.
|
||||
*/
|
||||
Blockly.Field.prototype.isCurrentlyEditable = function() {
|
||||
return this.EDITABLE && !!this.sourceBlock_ && this.sourceBlock_.isEditable();
|
||||
return this.enabled_ && this.EDITABLE && !!this.sourceBlock_ &&
|
||||
this.sourceBlock_.isEditable();
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user