Skip to content

Commit ea9c6ba

Browse files
committed
Added writeLine to simple framework
1 parent 3d9c56c commit ea9c6ba

File tree

5 files changed

+44
-1
lines changed

5 files changed

+44
-1
lines changed

src/blocks/simple/blocks.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,24 @@ Blockly.Blocks['simple_text_write'] = {
3838
};
3939

4040

41+
/**
42+
* Write line.
43+
*/
44+
Blockly.Blocks['simple_text_writeLine'] = {
45+
init: function() {
46+
this.setHelpUrl('');
47+
this.setColour(290);
48+
this.appendValueInput('text')
49+
.setCheck('String')
50+
.appendField(i18t('writeLine('));
51+
this.appendDummyInput()
52+
.appendField(')');
53+
this.setPreviousStatement(true, ['Number', 'String']);
54+
this.setNextStatement(true, ['Number', 'String']);
55+
this.setTooltip(i18t('Writes the text on its own line the screen.'));
56+
},
57+
};
58+
4159
/**
4260
* Draw circle.
4361
*/

src/blocks/simple/javascript.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@ Blockly.JavaScript['simple_text_write'] = function(block) {
3030
return 'command.write(' + text + ');\n';
3131
};
3232

33+
/**
34+
* Write line.
35+
* @param {!Blockly.block} block
36+
* @return {string}
37+
*/
38+
Blockly.JavaScript['simple_text_writeLine'] = function(block) {
39+
let text = Blockly.JavaScript.valueToCode(block, 'text',
40+
Blockly.JavaScript.ORDER_ATOMIC);
41+
return 'command.writeLine(' + text + ');\n';
42+
};
3343

3444
/**
3545
* Draw circle.

src/blocks/simple/toolbox.soy

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@
3232
<block type="text"><field name="TEXT"></field></block>
3333
</value>
3434
</block>
35+
<block type="simple_text_writeLine">
36+
<value name="text">
37+
<block type="text"><field name="TEXT"></field></block>
38+
</value>
39+
</block>
3540
</category>
3641

3742
<category name="Draw" colour="260">

src/config/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,4 @@ cwc.config.Sample = {
119119
/**
120120
* @return {string}
121121
*/
122-
cwc.config.Version = '5.7.28';
122+
cwc.config.Version = '5.7.29';

src/frameworks/simple/command.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@ cwc.framework.simple.Command.prototype.write = function(text) {
5959
this.addNode_(goog.dom.createTextNode(text));
6060
};
6161

62+
/**
63+
* Writes a text and line break on screen.
64+
* @param {string} text
65+
* @export
66+
*/
67+
cwc.framework.simple.Command.prototype.writeLine = function(text) {
68+
this.addNode_(goog.dom.createTextNode(text));
69+
this.addNode_(goog.dom.createElement('br'));
70+
};
6271

6372
/**
6473
* @param {string} title
@@ -105,6 +114,7 @@ cwc.framework.simple.Command.prototype.mapGlobal = function() {
105114
}
106115
window['command'] = {
107116
'write': this.write.bind(this),
117+
'writeLine': this.writeLine.bind(this),
108118
'showAlert': this.showAlert.bind(this),
109119
'showPrompt': this.showPrompt.bind(this),
110120
'showActionCancel': this.showActionCancel.bind(this),

0 commit comments

Comments
 (0)