Unverified Commit 68089664 authored by Beka Westberg's avatar Beka Westberg Committed by GitHub

Fix deprecation being inconsistent (#2219)

parent 4a41f72d
...@@ -197,6 +197,19 @@ Blockly.ComponentBlock.addGenericOption = function(block, options) { ...@@ -197,6 +197,19 @@ Blockly.ComponentBlock.addGenericOption = function(block, options) {
options.splice(options.length - 1, 0, item); options.splice(options.length - 1, 0, item);
}; };
/**
* Marks the passed block as a badBlock() and disables it if the data associated
* with the block is not defined, or the data is marked as deprecated.
* @param {Blockly.BlockSvg} block The block to check for deprecation.
* @param {EventDescriptor|MethodDescriptor|PropertyDescriptor} data The data
* associated with the block which is possibly deprecated.
*/
Blockly.ComponentBlock.checkDeprecated = function(block, data) {
if (data && data.deprecated && block.workspace == Blockly.mainWorkspace) {
block.setDisabled(true);
}
}
/** /**
* Create an event block of the given type for a component with the given * Create an event block of the given type for a component with the given
* instance name. eventType is one of the "events" objects in a typeJsonString * instance name. eventType is one of the "events" objects in a typeJsonString
...@@ -301,12 +314,10 @@ Blockly.Blocks.component_event = { ...@@ -301,12 +314,10 @@ Blockly.Blocks.component_event = {
input.init(); input.init();
} }
if (eventType && eventType.deprecated === "true" && this.workspace === Blockly.mainWorkspace) { // Set as badBlock if it doesn't exist.
this.badBlock(); this.verify();
this.setDisabled(true); // Disable it if it does exist and is deprecated.
} Blockly.ComponentBlock.checkDeprecated(this, eventType);
this.verify(); // verify the block and mark it accordingly
this.rendered = oldRendered; this.rendered = oldRendered;
}, },
...@@ -770,15 +781,10 @@ Blockly.Blocks.component_method = { ...@@ -770,15 +781,10 @@ Blockly.Blocks.component_method = {
this.errors = [{name:"checkIfUndefinedBlock"}, {name:"checkIsInDefinition"}, this.errors = [{name:"checkIfUndefinedBlock"}, {name:"checkIsInDefinition"},
{name:"checkComponentNotExistsError"}, {name: "checkGenericComponentSocket"}]; {name:"checkComponentNotExistsError"}, {name: "checkGenericComponentSocket"}];
// mark the block bad if the method isn't defined or is marked deprecated // Set as badBlock if it doesn't exist.
var method = this.getMethodTypeObject(); this.verify();
if ((!method || method.deprecated === true || method.deprecated === 'true') && // Disable it if it does exist and is deprecated.
this.workspace === Blockly.mainWorkspace) { Blockly.ComponentBlock.checkDeprecated(this, this.getMethodTypeObject());
this.badBlock();
this.setDisabled(true);
}
this.verify(); // verify the block and mark it accordingly
this.rendered = oldRendered; this.rendered = oldRendered;
}, },
...@@ -1029,9 +1035,9 @@ Blockly.Blocks.component_set_get = { ...@@ -1029,9 +1035,9 @@ Blockly.Blocks.component_set_get = {
this.setColour(Blockly.ComponentBlock.COLOUR_GET); this.setColour(Blockly.ComponentBlock.COLOUR_GET);
} }
var tooltipDescription; var tooltipDescription;
if (this.propertyName) { if (this.propertyName && this.propertyObject) {
tooltipDescription = componentDb.getInternationalizedPropertyDescription(this.getTypeName(), this.propertyName, tooltipDescription = componentDb.getInternationalizedPropertyDescription(
this.propertyObject.description); this.getTypeName(), this.propertyName, this.propertyObject.description);
} else { } else {
tooltipDescription = Blockly.Msg.UNDEFINED_BLOCK_TOOLTIP; tooltipDescription = Blockly.Msg.UNDEFINED_BLOCK_TOOLTIP;
} }
...@@ -1126,13 +1132,10 @@ Blockly.Blocks.component_set_get = { ...@@ -1126,13 +1132,10 @@ Blockly.Blocks.component_set_get = {
{name:"checkComponentNotExistsError"}, {name: 'checkGenericComponentSocket'}, {name:"checkComponentNotExistsError"}, {name: 'checkGenericComponentSocket'},
{name: 'checkEmptySetterSocket'}]; {name: 'checkEmptySetterSocket'}];
if (thisBlock.propertyObject && this.propertyObject.deprecated === "true" && this.workspace === Blockly.mainWorkspace) { // Set as badBlock if it doesn't exist.
// [lyn, 2015/12/27] mark deprecated properties as bad this.verify();
this.badBlock(); // Disable it if it does exist and is deprecated.
this.setDisabled(true); Blockly.ComponentBlock.checkDeprecated(this, this.propertyObject);
}
this.verify();
for (var i = 0, input; input = this.inputList[i]; i++) { for (var i = 0, input; input = this.inputList[i]; i++) {
input.init(); input.init();
......
...@@ -351,7 +351,6 @@ Blockly.ComponentDatabase.prototype.populateTypes = function(componentInfos) { ...@@ -351,7 +351,6 @@ Blockly.ComponentDatabase.prototype.populateTypes = function(componentInfos) {
info.properties[property.name] = property; info.properties[property.name] = property;
if (typeof property['deprecated'] === 'string') { if (typeof property['deprecated'] === 'string') {
property['deprecated'] = JSON.parse(property['deprecated']); property['deprecated'] = JSON.parse(property['deprecated']);
if (property['deprecated']) continue;
} }
if (property['rw'] == 'read-write') { if (property['rw'] == 'read-write') {
property.mutability = Blockly.PROPERTY_READWRITEABLE; property.mutability = Blockly.PROPERTY_READWRITEABLE;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment