@@ -37,6 +37,13 @@ import { connect } from "react-redux";
37
37
38
38
import { PositionedMinimap } from "@blockly/workspace-minimap" ;
39
39
40
+ import { TypedVariableModal } from "@blockly/plugin-typed-variable-modal" ;
41
+
42
+ import {
43
+ blocks ,
44
+ unregisterProcedureBlocks ,
45
+ } from "@blockly/block-shareable-procedures" ;
46
+
40
47
import { CategoryBuilder , ToolboxBuilder } from "./toolbox/builder" ;
41
48
import { getColour } from "./helpers/colour" ;
42
49
import sensors from "./toolbox/modules/sensors" ;
@@ -72,6 +79,9 @@ class BlocklyComponent extends React.Component {
72
79
}
73
80
74
81
getToolbox ( board ) {
82
+ if ( ! board ) {
83
+ return new ToolboxBuilder ( ) . buildToolbox ( ) ;
84
+ }
75
85
const senseBoxColor = getColour ( ) . sensebox ;
76
86
77
87
// Create the advanced categories
@@ -118,7 +128,11 @@ class BlocklyComponent extends React.Component {
118
128
. addCategory ( Blockly . Msg . toolbox_time , getColour ( ) . time , time [ board ] )
119
129
. addCategory ( Blockly . Msg . toolbox_math , getColour ( ) . math , math [ board ] )
120
130
. addCategory ( "Audio" , getColour ( ) . audio , audio [ board ] )
121
- // .addCustomCategory(Blockly.Msg.toolbox_variables, getColour().variables, "CREATE_TYPED_VARIABLE") // TODO: This is not working
131
+ . addCustomCategory (
132
+ Blockly . Msg . toolbox_variables ,
133
+ getColour ( ) . variables ,
134
+ "CREATE_TYPED_VARIABLE" ,
135
+ )
122
136
// .addCustomCategory(Blockly.Msg.toolbox_functions, getColour().procedures, "PROCEDURE") // TODO: This is not working
123
137
. addNestedCategory ( Blockly . Msg . toolbox_advanced , getColour ( ) . io , [
124
138
serialCategory ,
@@ -145,6 +159,26 @@ class BlocklyComponent extends React.Component {
145
159
} ,
146
160
...rest ,
147
161
} ) ;
162
+
163
+ unregisterProcedureBlocks ( ) ;
164
+ Blockly . common . defineBlocks ( blocks ) ;
165
+
166
+ workspace . registerToolboxCategoryCallback (
167
+ "CREATE_TYPED_VARIABLE" ,
168
+ this . createFlyout ,
169
+ ) ;
170
+
171
+ const typedVarModal = new TypedVariableModal ( workspace , "callbackName" , [
172
+ [ `${ Blockly . Msg . variable_NUMBER } ` , "int" ] ,
173
+ [ `${ Blockly . Msg . variable_LONG } ` , "long" ] ,
174
+ [ `${ Blockly . Msg . variable_DECIMAL } ` , "float" ] ,
175
+ [ `${ Blockly . Msg . variables_TEXT } ` , "String" ] ,
176
+ [ `${ Blockly . Msg . variables_CHARACTER } ` , "char" ] ,
177
+ [ `${ Blockly . Msg . variables_BOOLEAN } ` , "boolean" ] ,
178
+ ] ) ;
179
+ typedVarModal . init ( ) ;
180
+ // workspace.updateToolbox(this.props.toolbox.current);
181
+
148
182
// Initialize plugin.
149
183
150
184
// Initialize plugin.
@@ -164,6 +198,24 @@ class BlocklyComponent extends React.Component {
164
198
}
165
199
}
166
200
201
+ createFlyout ( workspace ) {
202
+ let xmlList = [ ] ;
203
+
204
+ // Add your button and give it a callback name.
205
+ const button = document . createElement ( "button" ) ;
206
+ button . setAttribute ( "text" , Blockly . Msg . button_createVariable ) ;
207
+ button . setAttribute ( "callbackKey" , "callbackName" ) ;
208
+
209
+ xmlList . push ( button ) ;
210
+
211
+ // This gets all the variables that the user creates and adds them to the
212
+ // flyout.
213
+ const blockList = Blockly . VariablesDynamic . flyoutCategoryBlocks ( workspace ) ;
214
+ console . log ( blockList ) ;
215
+ xmlList = xmlList . concat ( blockList ) ;
216
+ return xmlList ;
217
+ }
218
+
167
219
componentDidUpdate ( prevProps ) {
168
220
if ( prevProps . selectedBoard !== this . props . selectedBoard ) {
169
221
const senseBoxColor = getColour ( ) . sensebox ;
0 commit comments