renciso218 / blockly

Automatically exported from code.google.com/p/blockly
0 stars 0 forks source link

Field Drop downs storing human readable names #72

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
The drop downs are currently storing human readable names as opposed to the 
language neutral names. Also, while the language neutral names are stored, the 
human readable ones should appear on the block.

Attached are the changed field.js and field_dropdown.js that I'm now using. The 
changes I've made are below:

field_dropdown.js

Line 122 
text == this.text_ -> value == this.text_

Line 135 
Blockly.bindEvent_(gElement, 'mouseup', this, callbackFactory(text)); -> 
Blockly.bindEvent_(gElement, 'mouseup', this, callbackFactory(value));

Line 210 
if (options[x][0] == selectedText) { -> if (options[x][1] == selectedText) {

Line 226 
this.setText(options[x][0]); -> this.setText(options[x][1]);

Line 235
/**
 * Get the human-readable value for this dropdown menu.
 * @return {string} Human readable text.
 */
Blockly.FieldDropdown.prototype.getHumanReadableValue = function(){
    var selectedText = this.text_;
    var options = this.getOptions_();
    for (var x = 0; x < options.length; x++) {
        // Options are tuples of human-readable text and language-neutral values.
        if (options[x][1] == selectedText) {
          return options[x][0];
        }
    }

    return selectedText;
}

field.js

Line 168
text = this.getHumanReadableValue();

Line 186
/**
 * By default there is no difference between the human-readable text and
 * the language-neutral values.  Subclasses (such as dropdown) may define this.
 * @return {string} Current text.
 */
Blockly.Field.prototype.getHumanReadableValue = function(){
    return this.text_;
}

Original issue reported on code.google.com by paulmed...@gmail.com on 10 Sep 2012 at 1:09

GoogleCodeExporter commented 8 years ago
Hello, could you provide clarification on the nature of this bug.  Here are my 
steps in an attempt to reproduce the problem:

Go to the playground:
http://blockly-demo.appspot.com/blockly/tests/playground.html
Create a "repeat while" block and place on the otherwise empty canvas.
Execute the following lines on the JavaScript console:

var block = Blockly.mainWorkspace.getTopBlocks()[0];
block.getTitleText('MODE');
block.getTitleValue('MODE');

The getTitleText call returns 'while' (lowercase, which is English) and the 
getTitleValue call returns 'WHILE' (uppercase, which is language neutral).  
This appears to be correct.

Furthermore, when the block is exported to XML (using the export button on the 
left), the result includes:
<title name="MODE">WHILE</title>
Which is the language neutral version.

Deleting the block and importing the block from the same XML (using the import 
button on the left), results in a repeat block which has its dropdown showing 
"while" in the UI.

All of this appears to be correct.  Please clarify steps to demonstrate an 
error.  Thank you.

Original comment by neil.fra...@gmail.com on 28 Sep 2012 at 9:40

GoogleCodeExporter commented 8 years ago
Sorry about that Neil. A mistake on my end.

Original comment by paulmed...@gmail.com on 8 Oct 2012 at 12:33