Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jolivepetrus committed Jun 4, 2018
1 parent 8b83b43 commit 44b02b8
Show file tree
Hide file tree
Showing 21 changed files with 430 additions and 359 deletions.
4 changes: 2 additions & 2 deletions src/blockly_compressed.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

92 changes: 9 additions & 83 deletions src/blocks/events.js
Expand Up @@ -52,48 +52,11 @@ Blockly.Blocks['when_board_starts'] = {
this.setTooltip(Blockly.Msg.EVENT_WHEN_BOARD_STARTS_TOOLTIP);
},
onchange: function(e) {
if (!this.workspace.isDragging || this.workspace.isDragging()) {
return;
}

if ((typeof e.element != "undefined") && (this.warning != null) && (e.element == "disabled")) {
if (e.blockId == this.id) {
this.setDisabled(true);
return;
}
}

if ((typeof e.element != "undefined") && (e.element == "disabled")) {
if ((e.newValue != e.oldValue) && (e.blockId == this.id)) {
this.disabledByUser = e.newValue;
}
}

var instances = 0;
var blocks = this.workspace.getTopBlocks(true);
for (var x = 0, block; block = blocks[x]; x++) {
if (blocks[x].type == this.type) {
instances++;
}
}

if (instances > 1) {
this.setWarningText(Blockly.Msg.WARNING_ONLY_ONE_INSTANCE_ALLOWED);
if (!this.isInFlyout) {
this.setDisabled(true);
}
} else {
var wasInWarning = (this.warning != null);

this.setWarningText(null);
if (!this.isInFlyout && wasInWarning & (typeof this.disabledByUser == "undefined"?true:(!this.disabledByUser))) {
this.setDisabled(false);
} else {
if (typeof this.disabledByUser != "undefined") {
this.setDisabled(this.disabledByUser);
}
}
}
var self = this;

this.checkUses(e, function(block) {
return true;
}, Blockly.Msg.WARNING_ONLY_ONE_INSTANCE_ALLOWED);
},
section: function() {
return 'start';
Expand Down Expand Up @@ -129,48 +92,11 @@ Blockly.Blocks['when_i_receive'] = {
this.setTooltip(Blockly.Msg.EVENT_WHEN_I_RECEIVE_TOOLTIP);
},
onchange: function(e) {
if (!this.workspace.isDragging || this.workspace.isDragging()) {
return;
}
var self = this;

if ((typeof e.element != "undefined") && (this.warning != null) && (e.element == "disabled")) {
if (e.blockId == this.id) {
this.setDisabled(true);
return;
}
}

if ((typeof e.element != "undefined") && (e.element == "disabled")) {
if ((e.newValue != e.oldValue) && (e.blockId == this.id)) {
this.disabledByUser = e.newValue;
}
}

var uses = 0;
var blocks = this.workspace.getTopBlocks(true);
for (var x = 0, block; block = blocks[x]; x++) {
if ((blocks[x].getFieldValue('WHEN') == this.getFieldValue('WHEN')) && (blocks[x].type == this.type)) {
uses++;
}
}

if (uses > 1) {
this.setWarningText(Blockly.Msg.WARNING_EVENTS_CAN_ONLY_PROCESSED_IN_ONE_EVENT_BLOCK);
if (!this.isInFlyout) {
this.setDisabled(true);
}
} else {
var wasInWarning = (this.warning != null);

this.setWarningText(null);
if (!this.isInFlyout && wasInWarning & (typeof this.disabledByUser == "undefined"?true:(!this.disabledByUser))) {
this.setDisabled(false);
} else {
if (typeof this.disabledByUser != "undefined") {
this.setDisabled(this.disabledByUser);
}
}
}
this.checkUses(e, function(block) {
return (block.getFieldValue('WHEN') == self.getFieldValue('WHEN'));
}, Blockly.Msg.WARNING_EVENTS_CAN_ONLY_PROCESSED_IN_ONE_EVENT_BLOCK);
},
};

Expand Down
31 changes: 8 additions & 23 deletions src/blocks/io.js
Expand Up @@ -577,28 +577,13 @@ Blockly.Blocks['when_digital_pin'] = {
this.setTooltip(Blockly.Msg.EVENT_WHEN_DIGITAL_PIN_TOOLTIP);
},
onchange: function(e) {
if (!this.workspace.isDragging || this.workspace.isDragging()) {
return;
}

var uses = 0;
var blocks = this.workspace.getTopBlocks(true);
for (var x = 0, block; block = blocks[x]; x++) {
if ((blocks[x].getFieldValue('PIN') == this.getFieldValue('PIN')) && (blocks[x].type == this.type)) {
uses++;
}
}

if (uses > 1) {
this.setWarningText(Blockly.Msg.WARNING_EVENTS_CAN_ONLY_PROCESSED_IN_ONE_EVENT_BLOCK);
if (!this.isInFlyout && !this.getInheritedDisabled()) {
this.setDisabled(true);
}
} else {
this.setWarningText(null);
if (!this.isInFlyout) {
this.setDisabled(false);
}
}
var self = this;

this.checkUses(e, function(block) {
return (
(Blockly.Lua.valueToCode(block, 'PIN', Blockly.Lua.ORDER_NONE) == Blockly.Lua.valueToCode(self, 'PIN', Blockly.Lua.ORDER_NONE)) &&
(block.getFieldValue('WHEN') == self.getFieldValue('WHEN'))
);
}, Blockly.Msg.WARNING_EVENTS_CAN_ONLY_PROCESSED_IN_ONE_EVENT_BLOCK);
},
};
28 changes: 5 additions & 23 deletions src/blocks/lora.js
Expand Up @@ -356,29 +356,11 @@ Blockly.Blocks['when_i_receive_a_lora_frame'] = {
this.setTooltip(Blockly.Msg.EVENT_WHEN_I_RECEIVE_A_LORA_FRAME_TOOLTIP);
},
onchange: function(e) {
if (!this.workspace.isDragging || this.workspace.isDragging()) {
return;
}

var instances = 0;
var blocks = this.workspace.getTopBlocks(true);
for (var x = 0, block; block = blocks[x]; x++) {
if (blocks[x].type == this.type) {
instances++;
}
}

if (instances > 1) {
this.setWarningText(Blockly.Msg.WARNING_ONLY_ONE_INSTANCE_ALLOWED);
if (!this.isInFlyout && !this.getInheritedDisabled()) {
this.setDisabled(true);
}
} else {
this.setWarningText(null);
if (!this.isInFlyout) {
this.setDisabled(false);
}
}
var self = this;

this.checkUses(e, function(block) {
return true;
}, Blockly.Msg.WARNING_ONLY_ONE_INSTANCE_ALLOWED);
},
section: function() {
return 'declaration';
Expand Down
30 changes: 6 additions & 24 deletions src/blocks/mqtt.js
Expand Up @@ -126,30 +126,12 @@ Blockly.Blocks['mqtt_subscribe'] = {
this.setColour(Blockly.Blocks.MQTT.HUE);
this.setTooltip('');
},
onchange: function(e) {
if (!this.workspace.isDragging || this.workspace.isDragging()) {
return;
}

var uses = 0;
var blocks = this.workspace.getTopBlocks(true);
for (var x = 0, block; block = blocks[x]; x++) {
if ((Blockly.Lua.valueToCode(blocks[x], 'TOPIC', Blockly.Lua.ORDER_NONE) == Blockly.Lua.valueToCode(this, 'TOPIC', Blockly.Lua.ORDER_NONE)) && (blocks[x].type == this.type)) {
uses++;
}
}

if (uses > 1) {
this.setWarningText(Blockly.Msg.WARNING_EVENTS_CAN_ONLY_PROCESSED_IN_ONE_EVENT_BLOCK);
if (!this.isInFlyout && !this.getInheritedDisabled()) {
this.setDisabled(true);
}
} else {
this.setWarningText(null);
if (!this.isInFlyout) {
this.setDisabled(false);
}
}
onchange: function(e) {
var self = this;

this.checkUses(e, function(block) {
return (Blockly.Lua.valueToCode(block, 'TOPIC', Blockly.Lua.ORDER_NONE) == Blockly.Lua.valueToCode(self, 'TOPIC', Blockly.Lua.ORDER_NONE));
}, Blockly.Msg.WARNING_EVENTS_CAN_ONLY_PROCESSED_IN_ONE_EVENT_BLOCK);
},
section: function() {
return 'default';
Expand Down
94 changes: 10 additions & 84 deletions src/blocks/wifi.js
Expand Up @@ -109,48 +109,11 @@ Blockly.Blocks['when_wifi_is_conneted'] = {
this.setTooltip(Blockly.Msg.EVENT_WHEN_WIFI_IS_CONNECTED_TOOLTIP);
},
onchange: function(e) {
if (!this.workspace.isDragging || this.workspace.isDragging()) {
return;
}

if ((typeof e.element != "undefined") && (this.warning != null) && (e.element == "disabled")) {
if (e.blockId == this.id) {
this.setDisabled(true);
return;
}
}

if ((typeof e.element != "undefined") && (e.element == "disabled")) {
if ((e.newValue != e.oldValue) && (e.blockId == this.id)) {
this.disabledByUser = e.newValue;
}
}

var instances = 0;
var blocks = this.workspace.getTopBlocks(true);
for (var x = 0, block; block = blocks[x]; x++) {
if (blocks[x].type == this.type) {
instances++;
}
}

if (instances > 1) {
this.setWarningText(Blockly.Msg.WARNING_ONLY_ONE_INSTANCE_ALLOWED);
if (!this.isInFlyout) {
this.setDisabled(true);
}
} else {
var wasInWarning = (this.warning != null);

this.setWarningText(null);
if (!this.isInFlyout && wasInWarning & (typeof this.disabledByUser == "undefined"?true:(!this.disabledByUser))) {
this.setDisabled(false);
} else {
if (typeof this.disabledByUser != "undefined") {
this.setDisabled(this.disabledByUser);
}
}
}
var self = this;

this.checkUses(e, function(block) {
return true;
}, Blockly.Msg.WARNING_ONLY_ONE_INSTANCE_ALLOWED);
},
section: function() {
return 'start';
Expand All @@ -172,48 +135,11 @@ Blockly.Blocks['when_wifi_is_disconneted'] = {
this.setTooltip(Blockly.Msg.EVENT_WHEN_WIFI_IS_DISCONNECTED_TOOLTIP);
},
onchange: function(e) {
if (!this.workspace.isDragging || this.workspace.isDragging()) {
return;
}

if ((typeof e.element != "undefined") && (this.warning != null) && (e.element == "disabled")) {
if (e.blockId == this.id) {
this.setDisabled(true);
return;
}
}

if ((typeof e.element != "undefined") && (e.element == "disabled")) {
if ((e.newValue != e.oldValue) && (e.blockId == this.id)) {
this.disabledByUser = e.newValue;
}
}

var instances = 0;
var blocks = this.workspace.getTopBlocks(true);
for (var x = 0, block; block = blocks[x]; x++) {
if (blocks[x].type == this.type) {
instances++;
}
}

if (instances > 1) {
this.setWarningText(Blockly.Msg.WARNING_ONLY_ONE_INSTANCE_ALLOWED);
if (!this.isInFlyout) {
this.setDisabled(true);
}
} else {
var wasInWarning = (this.warning != null);

this.setWarningText(null);
if (!this.isInFlyout && wasInWarning & (typeof this.disabledByUser == "undefined"?true:(!this.disabledByUser))) {
this.setDisabled(false);
} else {
if (typeof this.disabledByUser != "undefined") {
this.setDisabled(this.disabledByUser);
}
}
}
var self = this;

this.checkUses(e, function(block) {
return true;
}, Blockly.Msg.WARNING_ONLY_ONE_INSTANCE_ALLOWED);
},
section: function() {
return 'start';
Expand Down

0 comments on commit 44b02b8

Please sign in to comment.