mirror of
https://github.com/google/blockly.git
synced 2026-01-08 09:30:06 +01:00
fix: serializing disabled interactions (#6847)
* feat: add own property getters for disabled interactions * feat: add serialization of disabled attributes
This commit is contained in:
@@ -795,6 +795,15 @@ export class Block implements IASTNodeLocation, IDeletable {
|
||||
!this.workspace.options.readOnly;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether this block's own deletable property is true or false.
|
||||
*
|
||||
* @returns True if the block's deletable property is true, false otherwise.
|
||||
*/
|
||||
isOwnDeletable(): boolean {
|
||||
return this.deletable_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether this block is deletable or not.
|
||||
*
|
||||
@@ -808,12 +817,23 @@ export class Block implements IASTNodeLocation, IDeletable {
|
||||
* Get whether this block is movable or not.
|
||||
*
|
||||
* @returns True if movable.
|
||||
* @internal
|
||||
*/
|
||||
isMovable(): boolean {
|
||||
return this.movable_ && !this.isShadow_ && !this.isDeadOrDying() &&
|
||||
!this.workspace.options.readOnly;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether this block's own movable property is true or false.
|
||||
*
|
||||
* @returns True if the block's movable property is true, false otherwise.
|
||||
* @internal
|
||||
*/
|
||||
isOwnMovable(): boolean {
|
||||
return this.movable_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether this block is movable or not.
|
||||
*
|
||||
@@ -882,12 +902,22 @@ export class Block implements IASTNodeLocation, IDeletable {
|
||||
* Get whether this block is editable or not.
|
||||
*
|
||||
* @returns True if editable.
|
||||
* @internal
|
||||
*/
|
||||
isEditable(): boolean {
|
||||
return this.editable_ && !this.isDeadOrDying() &&
|
||||
!this.workspace.options.readOnly;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether this block's own editable property is true or false.
|
||||
*
|
||||
* @returns True if the block's editable property is true, false otherwise.
|
||||
*/
|
||||
isOwnEditable(): boolean {
|
||||
return this.editable_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether this block is editable or not.
|
||||
*
|
||||
|
||||
@@ -48,6 +48,9 @@ export interface State {
|
||||
x?: number;
|
||||
y?: number;
|
||||
collapsed?: boolean;
|
||||
deletable?: boolean;
|
||||
movable?: boolean;
|
||||
editable?: boolean;
|
||||
enabled?: boolean;
|
||||
inline?: boolean;
|
||||
data?: string;
|
||||
@@ -142,6 +145,15 @@ function saveAttributes(block: Block, state: State) {
|
||||
if (!block.isEnabled()) {
|
||||
state['enabled'] = false;
|
||||
}
|
||||
if (!block.isOwnDeletable()) {
|
||||
state['deletable'] = false;
|
||||
}
|
||||
if (!block.isOwnMovable()) {
|
||||
state['movable'] = false;
|
||||
}
|
||||
if (!block.isOwnEditable()) {
|
||||
state['editable'] = false;
|
||||
}
|
||||
if (block.inputsInline !== undefined &&
|
||||
block.inputsInline !== block.inputsInlineDefault) {
|
||||
state['inline'] = block.inputsInline;
|
||||
@@ -437,6 +449,15 @@ function loadAttributes(block: Block, state: State) {
|
||||
if (state['collapsed']) {
|
||||
block.setCollapsed(true);
|
||||
}
|
||||
if (state['deletable'] === false) {
|
||||
block.setDeletable(false);
|
||||
}
|
||||
if (state['movable'] === false) {
|
||||
block.setMovable(false);
|
||||
}
|
||||
if (state['editable'] === false) {
|
||||
block.setEditable(false);
|
||||
}
|
||||
if (state['enabled'] === false) {
|
||||
block.setEnabled(false);
|
||||
}
|
||||
|
||||
@@ -73,10 +73,25 @@ Serializer.Attributes.Disabled = new SerializerTestCase('Disabled',
|
||||
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
||||
'<block type="logic_negate" id="id******************" disabled="true" x="42" y="42"></block>' +
|
||||
'</xml>');
|
||||
Serializer.Attributes.NotDeletable = new SerializerTestCase('Deletable',
|
||||
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
||||
'<block type="logic_negate" id="id******************" deletable="false" x="42" y="42"></block>' +
|
||||
'</xml>');
|
||||
Serializer.Attributes.NotMovable = new SerializerTestCase('Movable',
|
||||
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
||||
'<block type="logic_negate" id="id******************" movable="false" x="42" y="42"></block>' +
|
||||
'</xml>');
|
||||
Serializer.Attributes.NotEditable = new SerializerTestCase('Editable',
|
||||
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
||||
'<block type="logic_negate" id="id******************" editable="false" x="42" y="42"></block>' +
|
||||
'</xml>');
|
||||
Serializer.Attributes.testCases = [
|
||||
Serializer.Attributes.Basic,
|
||||
Serializer.Attributes.Collapsed,
|
||||
Serializer.Attributes.Disabled,
|
||||
Serializer.Attributes.NotDeletable,
|
||||
Serializer.Attributes.NotMovable,
|
||||
Serializer.Attributes.NotEditable,
|
||||
];
|
||||
|
||||
Serializer.Attributes.Inline = new SerializerTestSuite('Inline');
|
||||
|
||||
Reference in New Issue
Block a user