From 194341f2e501c1a6d481c7bd0a4d4afbf7f042d6 Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Wed, 6 Apr 2016 16:27:25 -0700 Subject: [PATCH] Allow use of setOutput (and friends) to change checks. Issue #315. --- core/block.js | 65 ++++++++++++++++++++++++++++--------------------- core/options.js | 5 ---- 2 files changed, 37 insertions(+), 33 deletions(-) diff --git a/core/block.js b/core/block.js index 604c5a0d6..8cdcdf7df 100644 --- a/core/block.js +++ b/core/block.js @@ -709,21 +709,24 @@ Blockly.Block.prototype.setTitleValue = function(newValue, name) { * list of statement types. Null/undefined if any type could be connected. */ Blockly.Block.prototype.setPreviousStatement = function(newBoolean, opt_check) { - if (this.previousConnection) { - goog.asserts.assert(!this.previousConnection.isConnected(), - 'Must disconnect previous statement before removing connection.'); - this.previousConnection.dispose(); - this.previousConnection = null; - } if (newBoolean) { - goog.asserts.assert(!this.outputConnection, - 'Remove output connection prior to adding previous connection.'); if (opt_check === undefined) { opt_check = null; } - this.previousConnection = - new Blockly.Connection(this, Blockly.PREVIOUS_STATEMENT); + if (!this.previousConnection) { + goog.asserts.assert(!this.outputConnection, + 'Remove output connection prior to adding previous connection.'); + this.previousConnection = + new Blockly.Connection(this, Blockly.PREVIOUS_STATEMENT); + } this.previousConnection.setCheck(opt_check); + } else { + if (this.previousConnection) { + goog.asserts.assert(!this.previousConnection.isConnected(), + 'Must disconnect previous statement before removing connection.'); + this.previousConnection.dispose(); + this.previousConnection = null; + } } }; @@ -734,19 +737,22 @@ Blockly.Block.prototype.setPreviousStatement = function(newBoolean, opt_check) { * list of statement types. Null/undefined if any type could be connected. */ Blockly.Block.prototype.setNextStatement = function(newBoolean, opt_check) { - if (this.nextConnection) { - goog.asserts.assert(!this.nextConnection.isConnected(), - 'Must disconnect next statement before removing connection.'); - this.nextConnection.dispose(); - this.nextConnection = null; - } if (newBoolean) { if (opt_check === undefined) { opt_check = null; } - this.nextConnection = - new Blockly.Connection(this, Blockly.NEXT_STATEMENT); + if (!this.nextConnection) { + this.nextConnection = + new Blockly.Connection(this, Blockly.NEXT_STATEMENT); + } this.nextConnection.setCheck(opt_check); + } else { + if (this.nextConnection) { + goog.asserts.assert(!this.nextConnection.isConnected(), + 'Must disconnect next statement before removing connection.'); + this.nextConnection.dispose(); + this.nextConnection = null; + } } }; @@ -758,21 +764,24 @@ Blockly.Block.prototype.setNextStatement = function(newBoolean, opt_check) { * (e.g. variable get). */ Blockly.Block.prototype.setOutput = function(newBoolean, opt_check) { - if (this.outputConnection) { - goog.asserts.assert(!this.outputConnection.isConnected(), - 'Must disconnect output value before removing connection.'); - this.outputConnection.dispose(); - this.outputConnection = null; - } if (newBoolean) { - goog.asserts.assert(!this.previousConnection, - 'Remove previous connection prior to adding output connection.'); if (opt_check === undefined) { opt_check = null; } - this.outputConnection = - new Blockly.Connection(this, Blockly.OUTPUT_VALUE); + if (!this.outputConnection) { + goog.asserts.assert(!this.previousConnection, + 'Remove previous connection prior to adding output connection.'); + this.outputConnection = + new Blockly.Connection(this, Blockly.OUTPUT_VALUE); + } this.outputConnection.setCheck(opt_check); + } else { + if (this.outputConnection) { + goog.asserts.assert(!this.outputConnection.isConnected(), + 'Must disconnect output value before removing connection.'); + this.outputConnection.dispose(); + this.outputConnection = null; + } } }; diff --git a/core/options.js b/core/options.js index 83c084511..91a927497 100644 --- a/core/options.js +++ b/core/options.js @@ -85,9 +85,6 @@ Blockly.Options = function(options) { pathToMedia = options['path'] + 'media/'; } - var enableRealtime = !!options['realtime']; - var realtimeOptions = enableRealtime ? options['realtimeOptions'] : undefined; - this.RTL = !!options['rtl']; this.collapse = hasCollapse; this.comments = hasComments; @@ -103,8 +100,6 @@ Blockly.Options = function(options) { this.languageTree = languageTree; this.gridOptions = Blockly.Options.parseGridOptions_(options); this.zoomOptions = Blockly.Options.parseZoomOptions_(options); - this.enableRealtime = enableRealtime; - this.realtimeOptions = realtimeOptions; }; /**