Skip to content
This repository was archived by the owner on Jul 24, 2019. It is now read-only.

Commit ee83684

Browse files
McSamMcSam
authored andcommitted
search-feature
1 parent 5fd47c7 commit ee83684

35 files changed

+665
-156
lines changed

src/assets/sass/scratch/_toolbox.scss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
@import '../base/mixins';
22

33
$category-colours: (
4+
search : #afffda,
45
trade-definition: #303f9f,
56
before-purchase : #00897b,
67
during-purchase : #78909c,
@@ -114,4 +115,11 @@ $category-colours: (
114115
}
115116
}
116117
}
118+
119+
#search_input {
120+
padding: 10px;
121+
border-radius: 5px;
122+
border: solid $grey 1px;
123+
margin: 3px;
124+
}
117125
}

src/scratch/blocks/Advanced/Functions/procedures_callnoreturn.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,16 @@ Blockly.Blocks.procedures_callnoreturn = {
77
this.argumentVarModels = [];
88
this.previousDisabledState = false;
99

10-
this.jsonInit({
10+
this.jsonInit(this.definition());
11+
},
12+
/**
13+
* Block definitions describe how a block looks and behaves, including the text,
14+
* the colour, the shape, and what other blocks it can connect to. We've separated
15+
* the block definition from the init function so we can search through it.
16+
* https://developers.google.com/blockly/guides/create-custom-blocks/define-blocks
17+
*/
18+
definition() {
19+
return {
1120
message0: '%1 %2',
1221
args0 : [
1322
{
@@ -25,7 +34,20 @@ Blockly.Blocks.procedures_callnoreturn = {
2534
colourTertiary : Blockly.Colours.BinaryProcedures.colourTertiary,
2635
previousStatement: null,
2736
nextStatement : null,
28-
});
37+
tooltip : translate('Function with no return value tooltip'),
38+
category : 'functions',
39+
};
40+
},
41+
/**
42+
* Meta returns an object with with properties that contain human readable strings,
43+
* these strings are used in the flyout help content, as well as used for searching
44+
* for specific blocks.
45+
*/
46+
meta() {
47+
return {
48+
'display_name': translate('Function With no Return name'),
49+
'description' : translate('Function with no return value description'),
50+
};
2951
},
3052
/**
3153
* Procedure calls cannot exist without the corresponding procedure

src/scratch/blocks/Advanced/Functions/procedures_callreturn.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1+
import { translate } from '../../../../utils/lang/i18n';
2+
13
Blockly.Blocks.procedures_callreturn = {
24
init() {
35
this.arguments = [];
46
this.previousDisabledState = false;
57

6-
this.jsonInit({
8+
this.jsonInit(this.definition());
9+
},
10+
definition(){
11+
return {
712
message0: '%1 %2',
813
args0 : [
914
{
@@ -20,7 +25,15 @@ Blockly.Blocks.procedures_callreturn = {
2025
colour : Blockly.Colours.BinaryProcedures.colour,
2126
colourSecondary: Blockly.Colours.BinaryProcedures.colourSecondary,
2227
colourTertiary : Blockly.Colours.BinaryProcedures.colourTertiary,
23-
});
28+
tooltip : translate('Function with return value'),
29+
category : translate('functions'),
30+
};
31+
},
32+
meta(){
33+
return {
34+
'display_name': translate('Function with return value'),
35+
'description' : translate('Function with return value Description'),
36+
};
2437
},
2538
onchange : Blockly.Blocks.procedures_callnoreturn.onchange,
2639
getProcedureDefinition: Blockly.Blocks.procedures_callnoreturn.getProcedureDefinition,

src/scratch/blocks/Advanced/Functions/procedures_defnoreturn.js

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,20 @@ Blockly.Blocks.procedures_defnoreturn = {
77
this.arguments = [];
88
this.argumentVarModels = [];
99

10-
this.jsonInit({
10+
this.jsonInit(this.definition());
11+
12+
// Enforce unique procedure names
13+
const nameField = this.getField('NAME');
14+
nameField.setValidator(Blockly.Procedures.rename);
15+
16+
// Render a ➕-icon for adding parameters
17+
const fieldImage = new Blockly.FieldImage(plusIconLight, 24, 24, '+', () => this.onAddClick());
18+
this.appendDummyInput('ADD_ICON').appendField(fieldImage);
19+
20+
this.setStatements(true);
21+
},
22+
definition() {
23+
return {
1124
message0: translate('function %1 %2'),
1225
args0 : [
1326
{
@@ -24,17 +37,15 @@ Blockly.Blocks.procedures_defnoreturn = {
2437
colour : Blockly.Colours.BinaryProcedures.colour,
2538
colourSecondary: Blockly.Colours.BinaryProcedures.colourSecondary,
2639
colourTertiary : Blockly.Colours.BinaryProcedures.colourTertiary,
27-
});
28-
29-
// Enforce unique procedure names
30-
const nameField = this.getField('NAME');
31-
nameField.setValidator(Blockly.Procedures.rename);
32-
33-
// Render a ➕-icon for adding parameters
34-
const fieldImage = new Blockly.FieldImage(plusIconLight, 24, 24, '+', () => this.onAddClick());
35-
this.appendDummyInput('ADD_ICON').appendField(fieldImage);
36-
37-
this.setStatements(true);
40+
tooltip : translate('function with no return tooltip'),
41+
category : translate('functions'),
42+
};
43+
},
44+
meta() {
45+
return {
46+
'display_name': translate('Function with no return value'),
47+
'description' : translate('Function with no return value description'),
48+
};
3849
},
3950
/**
4051
* Sets the block colour and updates this procedure's caller blocks

src/scratch/blocks/Advanced/Functions/procedures_defreturn.js

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,21 @@ Blockly.Blocks.procedures_defreturn = {
66
this.arguments = [];
77
this.argumentVarModels = [];
88

9-
this.jsonInit({
9+
this.jsonInit(this.definition());
10+
11+
// Enforce unique procedure names
12+
const nameField = this.getField('NAME');
13+
nameField.setValidator(Blockly.Procedures.rename);
14+
15+
// Render a ➕-icon for adding parameters
16+
const fieldImage = new Blockly.FieldImage(plusIconDark, 24, 24, '+', () => this.onAddClick());
17+
this.appendDummyInput('ADD_ICON').appendField(fieldImage);
18+
this.moveInputBefore('ADD_ICON', 'RETURN');
19+
20+
this.setStatements(true);
21+
},
22+
definition(){
23+
return {
1024
message0: translate('function %1 %2 %3'),
1125
message1: 'return %1',
1226
args0 : [
@@ -35,18 +49,15 @@ Blockly.Blocks.procedures_defreturn = {
3549
colour : Blockly.Colours.BinaryProcedures.colour,
3650
colourSecondary: Blockly.Colours.BinaryProcedures.colourSecondary,
3751
colourTertiary : Blockly.Colours.BinaryProcedures.colourTertiary,
38-
});
39-
40-
// Enforce unique procedure names
41-
const nameField = this.getField('NAME');
42-
nameField.setValidator(Blockly.Procedures.rename);
43-
44-
// Render a ➕-icon for adding parameters
45-
const fieldImage = new Blockly.FieldImage(plusIconDark, 24, 24, '+', () => this.onAddClick());
46-
this.appendDummyInput('ADD_ICON').appendField(fieldImage);
47-
this.moveInputBefore('ADD_ICON', 'RETURN');
48-
49-
this.setStatements(true);
52+
tooltip : translate('Function def with return value'),
53+
category : translate('functions'),
54+
};
55+
},
56+
meta(){
57+
return {
58+
'display_name': translate('Function def with return value'),
59+
'description' : translate('Function def with return value Description'),
60+
};
5061
},
5162
onAddClick : Blockly.Blocks.procedures_defnoreturn.onAddClick,
5263
onchange : Blockly.Blocks.procedures_defnoreturn.onchange,

src/scratch/blocks/Advanced/Functions/procedures_ifreturn.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ Blockly.Blocks.procedures_ifreturn = {
99
init() {
1010
this.hasReturnValue = true;
1111

12-
this.jsonInit({
12+
this.jsonInit(this.definition());
13+
},
14+
definition(){
15+
return {
1316
message0: translate('if %1 return %2'),
1417
args0 : [
1518
{
@@ -26,7 +29,15 @@ Blockly.Blocks.procedures_ifreturn = {
2629
colourTertiary : Blockly.Colours.BinaryProcedures.colourTertiary,
2730
previousStatement: null,
2831
nextStatement : null,
29-
});
32+
tooltip : translate('Function If Else'),
33+
category : 'functions',
34+
};
35+
},
36+
meta(){
37+
return {
38+
'display_name': translate('Function If else'),
39+
'description' : translate('Function If else Description'),
40+
};
3041
},
3142
/**
3243
* Create XML to represent whether this block has a return value.

src/scratch/blocks/Advanced/List/lists_create_with.js

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,15 @@ import { translate } from '../../../../utils/lang/i18n';
33

44
Blockly.Blocks.lists_create_with = {
55
init() {
6-
this.jsonInit({
6+
this.jsonInit(this.definition());
7+
8+
// Render a ➕-icon for adding additional `lists_statement` blocks
9+
const fieldImage = new Blockly.FieldImage(plusIconDark, 25, 25, '', () => this.onIconClick());
10+
this.appendDummyInput('ADD_ICON').appendField(fieldImage);
11+
this.moveInputBefore('ADD_ICON', 'STACK');
12+
},
13+
definition(){
14+
return {
715
message0: translate('set %1 to create list with'),
816
message1: '%1',
917
args0 : [
@@ -24,12 +32,15 @@ Blockly.Blocks.lists_create_with = {
2432
colourTertiary : Blockly.Colours.Binary.colourTertiary,
2533
previousStatement: null,
2634
nextStatement : null,
27-
});
28-
29-
// Render a ➕-icon for adding additional `lists_statement` blocks
30-
const fieldImage = new Blockly.FieldImage(plusIconDark, 25, 25, '', () => this.onIconClick());
31-
this.appendDummyInput('ADD_ICON').appendField(fieldImage);
32-
this.moveInputBefore('ADD_ICON', 'STACK');
35+
tooltip : translate('Create List with'),
36+
category : 'list',
37+
};
38+
},
39+
meta(){
40+
return {
41+
'display_name': translate('Create list with'),
42+
'description' : translate('Create list with description'),
43+
};
3344
},
3445
onIconClick() {
3546
if (!this.workspace || this.isInFlyout) {

src/scratch/blocks/Advanced/Variable/variables_get.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ import { translate } from '../../../../utils/lang/i18n';
22

33
Blockly.Blocks.variables_get = {
44
init() {
5-
this.jsonInit({
5+
this.jsonInit(this.definition());
6+
},
7+
definition(){
8+
return {
69
type : 'variables_get',
710
message0: '%1',
811
args0 : [
@@ -17,8 +20,15 @@ Blockly.Blocks.variables_get = {
1720
colour : Blockly.Colours.Binary.colour,
1821
colourSecondary: Blockly.Colours.Binary.colourSecondary,
1922
colourTertiary : Blockly.Colours.Binary.colourTertiary,
20-
tooltip : '',
21-
});
23+
tooltip : translate('Get Variable Tooltip'),
24+
category : translate('variables'),
25+
};
26+
},
27+
meta(){
28+
return {
29+
'display_name': translate('Get Variable Value'),
30+
'description' : translate('Get Variable Value Description'),
31+
};
2232
},
2333
};
2434

src/scratch/blocks/Advanced/Variable/variables_set.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ import { translate } from '../../../../utils/lang/i18n';
22

33
Blockly.Blocks.variables_set = {
44
init() {
5-
this.jsonInit({
5+
this.jsonInit(this.definition());
6+
},
7+
definition(){
8+
return {
69
type : 'field_variable',
710
message0: translate('set %1 to %2'),
811
args0 : [
@@ -21,8 +24,15 @@ Blockly.Blocks.variables_set = {
2124
colourTertiary : Blockly.Colours.Binary.colourTertiary,
2225
previousStatement: null,
2326
nextStatement : null,
24-
tooltip : '',
25-
});
27+
tooltip : translate('Set Variable Tooltip'),
28+
category : 'variables',
29+
};
30+
},
31+
meta(){
32+
return {
33+
'display_name': translate('Set Variable'),
34+
'description' : translate('Set Variable Description'),
35+
};
2636
},
2737
};
2838

src/scratch/blocks/Binary/After Purchase/after_purchase.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ import { translate } from '../../../../utils/lang/i18n';
44

55
Blockly.Blocks.after_purchase = {
66
init() {
7-
this.jsonInit({
7+
this.jsonInit(this.definition());
8+
},
9+
definition(){
10+
return {
811
message0: translate('%1 (4) Get your trade result and trade again %2'),
912
message1: '%1',
1013
args0 : [
@@ -32,7 +35,14 @@ Blockly.Blocks.after_purchase = {
3235
tooltip : translate(
3336
'Get the previous trade information and result, then trade again (Runs on trade finish)'
3437
),
35-
});
38+
category: 'after-purchase',
39+
};
40+
},
41+
meta(){
42+
return {
43+
'display_name': translate('After Purchase'),
44+
'description' : translate('After Purchase Description'),
45+
};
3646
},
3747
onchange(event) {
3848
setBlockTextColor(this);

0 commit comments

Comments
 (0)