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

Commit 42366b6

Browse files
McSamMcSam
authored andcommitted
modified algorithm
1 parent b0acb94 commit 42366b6

File tree

9 files changed

+150
-111
lines changed

9 files changed

+150
-111
lines changed

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 : translate('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/Math/math_single.js

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

33
Blockly.Blocks.math_single = {
44
init() {
5-
this.jsonInit({
5+
this.jsonInit(this.definition());
6+
},
7+
definition(){
8+
return {
69
message0: translate('%1 %2'),
710
args0 : [
811
{
@@ -28,7 +31,15 @@ Blockly.Blocks.math_single = {
2831
colour : Blockly.Colours.Binary.colour,
2932
colourSecondary: Blockly.Colours.Binary.colourSecondary,
3033
colourTertiary : Blockly.Colours.Binary.colourTertiary,
31-
});
34+
tooltip : translate('Mathematical Single Tooltip'),
35+
category : translate('mathematical'),
36+
};
37+
},
38+
meta(){
39+
return {
40+
'display_name': translate('Mathematical Single'),
41+
'description' : translate('Mathematical Single Description'),
42+
};
3243
},
3344
};
3445

src/scratch/blocks/Math/math_trig.js

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

33
Blockly.Blocks.math_trig = {
44
init() {
5-
this.jsonInit({
5+
this.jsonInit(this.definition());
6+
},
7+
definition(){
8+
return {
69
message0: translate('%1 %2'),
710
args0 : [
811
{
@@ -28,7 +31,15 @@ Blockly.Blocks.math_trig = {
2831
colour : Blockly.Colours.Binary.colour,
2932
colourSecondary: Blockly.Colours.Binary.colourSecondary,
3033
colourTertiary : Blockly.Colours.Binary.colourTertiary,
31-
});
34+
tooltip : translate('Mathematical Trig Tooltip'),
35+
category : translate('mathematical'),
36+
};
37+
},
38+
meta(){
39+
return {
40+
'display_name': translate('Mathematical Trig'),
41+
'description' : translate('Mathematical Trig Description'),
42+
};
3243
},
3344
};
3445

src/scratch/hooks/data_category.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,18 @@ import { translate } from '../../utils/lang/i18n';
88
*/
99
Blockly.DataCategory = function(workspace) {
1010
const variableModelList = workspace.getVariablesOfType('');
11-
const xmlList = [];
11+
let xmlList = [];
1212

1313
// `Create Variable`-button
1414
Blockly.DataCategory.addCreateButton(xmlList, workspace);
1515

16+
xmlList = Blockly.DataCategory.search(variableModelList);
17+
18+
return xmlList;
19+
};
20+
21+
Blockly.DataCategory.search = function(variableModelList){
22+
const xmlList = [];
1623
if (variableModelList.length > 0) {
1724
const generateVariableFieldXmlString = variableModel => {
1825
// The variable name may be user input, so it may contain characters that

src/scratch/hooks/flyout_base.js

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
2+
import { translate } from '../../utils/lang/i18n';
3+
14
/* eslint-disable func-names, no-underscore-dangle */
25

36
/**
@@ -38,7 +41,7 @@ Blockly.Flyout.prototype.scrollAnimationFraction = 1.0;
3841
* @param {number} y The computed y origin of the flyout's SVG group.
3942
* @protected
4043
*/
41-
Blockly.Flyout.prototype.positionAt_ = function(width, height, x, y) {
44+
Blockly.Flyout.prototype.positionAt_ = function (width, height, x, y) {
4245
this.svgGroup_.setAttribute('width', width);
4346
this.svgGroup_.setAttribute('height', height);
4447

@@ -73,26 +76,52 @@ Blockly.Flyout.prototype.positionAt_ = function(width, height, x, y) {
7376
* @return {number} The width of the flyout.
7477
* deriv-bot: Return actual width rather than this.DEFAULT_WIDTH.
7578
*/
76-
Blockly.Flyout.prototype.getWidth = function() {
79+
Blockly.Flyout.prototype.getWidth = function () {
7780
return this.width_;
7881
};
7982

8083
const addSearchFlyout = (callback, xmlList, flyout) => {
8184
let xmlSearchList = xmlList;
82-
if (xmlList.type === Blockly.Search.NAME_TYPE) {
83-
const blocksLength = Object.keys(xmlList.blocks).length;
84-
const nodesLength = Object.keys(xmlList.nodes).length;
85-
const noResult = !blocksLength && !nodesLength;
86-
87-
xmlSearchList =
88-
Blockly.Search.flyoutCategory(xmlList.blocks, flyout.workspace_, noResult);
89-
xmlSearchList = xmlSearchList.concat(xmlList.nodes);
85+
if (xmlList.type === 'search') {
86+
const blocks = xmlList.blocks;
87+
const fn_blocks = xmlList.fnBlocks;
88+
const var_blocks = xmlList.varBlocks;
89+
const noResult = !blocks.length
90+
&& !Object.keys(fn_blocks).length
91+
&& !var_blocks.length;
92+
93+
xmlSearchList = [];
94+
95+
if (noResult) {
96+
const label = document.createElement('label');
97+
label.setAttribute('text', translate('No Blocks Found'));
98+
xmlSearchList.push(label);
99+
} else {
100+
const label = document.createElement('label');
101+
label.setAttribute('text', translate('Result(s)'));
102+
103+
xmlSearchList.push(label);
104+
}
105+
106+
if (Object.keys(fn_blocks).length) {
107+
const func_xml_list = Blockly.Procedures.flyoutCategory(flyout.workspace_);
108+
109+
xmlSearchList = xmlSearchList.concat(func_xml_list);
110+
}
111+
112+
if (var_blocks.length) {
113+
const var_xml_list = Blockly.DataCategory.search(var_blocks);
114+
115+
xmlSearchList = xmlSearchList.concat(var_xml_list);
116+
}
117+
118+
xmlSearchList = xmlSearchList.concat(blocks);
90119
}
91120

92121
callback(xmlSearchList);
93122
};
94123

95124
const originalFlyoutShowFn = Blockly.Flyout.prototype.show;
96-
Blockly.Flyout.prototype.show = function(xmlList){
125+
Blockly.Flyout.prototype.show = function (xmlList) {
97126
addSearchFlyout(originalFlyoutShowFn.bind(this), xmlList, this);
98127
};

src/scratch/hooks/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,3 @@ import './icon';
1111
import './procedures';
1212
import './toolbox';
1313
import './variables';
14-
import './search';

src/scratch/hooks/search.js

Lines changed: 0 additions & 40 deletions
This file was deleted.

0 commit comments

Comments
 (0)