Collapse the five 0/1-based index flags into one option.

This commit is contained in:
Neil Fraser
2016-10-06 17:54:43 -07:00
parent e6ec2d6fd9
commit 7928fac3ce
24 changed files with 60 additions and 74 deletions

View File

@@ -86,6 +86,7 @@ function start() {
toolbox: document.getElementById('toolbox'),
zoom: {controls: true, wheel: true}
});
changeIndex();
}
function loadXml() {
@@ -153,23 +154,17 @@ function toXml() {
}
function toJavaScript() {
var oneBasedIndexing = document.getElementById('indexing').checked;
Blockly.JavaScript.ONE_BASED_INDEXING = oneBasedIndexing;
var code = '\'use strict\';\n\n'
code += Blockly.JavaScript.workspaceToCode(workspace);
setOutput(code);
}
function toPython() {
var oneBasedIndexing = document.getElementById('indexing').checked;
Blockly.Python.ONE_BASED_INDEXING = oneBasedIndexing;
var code = Blockly.Python.workspaceToCode(workspace);
setOutput(code);
}
function toPhp() {
var oneBasedIndexing = document.getElementById('indexing').checked;
Blockly.PHP.ONE_BASED_INDEXING = oneBasedIndexing;
var code = Blockly.PHP.workspaceToCode(workspace);
setOutput(code);
}
@@ -180,11 +175,15 @@ function toLua() {
}
function toDart() {
var oneBasedIndexing = document.getElementById('indexing').checked;
Blockly.Dart.ONE_BASED_INDEXING = oneBasedIndexing;
var code = Blockly.Dart.workspaceToCode(workspace);
setOutput(code);
}
function changeIndex() {
var oneBasedIndex = document.getElementById('indexing').checked;
workspace.options.oneBasedIndex = oneBasedIndex;
workspace.toolbox_.flyout_.workspace_.options.oneBasedIndex = oneBasedIndex;
}
</script>
<style>
@@ -326,7 +325,8 @@ h1 {
</p>
<p>
<input id="indexing" type="checkbox" checked> Generate with one-based indexing
<input id="indexing" type="checkbox" onchange="changeIndex()" checked>
<label for="indexing">Generate with one-based indexing</label>
</p>
<p>

View File

@@ -162,7 +162,7 @@ Blockly.Dart['unittest_adjustindex'] = function(block) {
var index = Blockly.Dart.valueToCode(block, 'INDEX',
Blockly.Dart.ORDER_ADDITIVE) || '0';
// Adjust index if using one-based indexing.
if (Blockly.Dart.ONE_BASED_INDEXING) {
if (block.workspace.options.oneBasedIndex) {
if (Blockly.isNumber(index)) {
// If the index is a naked number, adjust it right now.
return [parseFloat(index) + 1, Blockly.Dart.ORDER_ATOMIC];

View File

@@ -166,7 +166,7 @@ Blockly.JavaScript['unittest_adjustindex'] = function(block) {
var index = Blockly.JavaScript.valueToCode(block, 'INDEX',
Blockly.JavaScript.ORDER_ADDITION) || '0';
// Adjust index if using one-based indexing.
if (Blockly.JavaScript.ONE_BASED_INDEXING) {
if (block.workspace.options.oneBasedIndex) {
if (Blockly.isNumber(index)) {
// If the index is a naked number, adjust it right now.
return [parseFloat(index) + 1, Blockly.JavaScript.ORDER_ATOMIC];

View File

@@ -172,7 +172,7 @@ Blockly.PHP['unittest_adjustindex'] = function(block) {
var index = Blockly.PHP.valueToCode(block, 'INDEX',
Blockly.PHP.ORDER_ADDITION) || '0';
// Adjust index if using one-based indexing.
if (Blockly.PHP.ONE_BASED_INDEXING) {
if (block.workspace.options.oneBasedIndex) {
if (Blockly.isNumber(index)) {
// If the index is a naked number, adjust it right now.
return [parseFloat(index) + 1, Blockly.PHP.ORDER_ATOMIC];

View File

@@ -137,7 +137,7 @@ Blockly.Python['unittest_adjustindex'] = function(block) {
var index = Blockly.Python.valueToCode(block, 'INDEX',
Blockly.Python.ORDER_ADDITIVE) || '0';
// Adjust index if using one-based indexing.
if (Blockly.Python.ONE_BASED_INDEXING) {
if (block.workspace.options.oneBasedIndex) {
if (Blockly.isNumber(index)) {
// If the index is a naked number, adjust it right now.
return [parseFloat(index) + 1, Blockly.Python.ORDER_ATOMIC];