@@ -4,6 +4,7 @@ import { installBuiltinHelpInfo, setBuiltinHelpInfo } from "../help";
44import { EXPORTED_VARIABLE_TYPE , IMPORTED_VARIABLE_TYPE } from "../blocksProgram" ;
55
66export const CREATE_VAR_BTN_ID = 'create-variable-btn' ;
7+ export const CREATE_GLOBAL_VAR_BTN_ID = 'create-global-variable-btn' ;
78
89export function initVariables ( ) {
910 let varname = lf ( "{id:var}item" ) ;
@@ -96,7 +97,7 @@ export function initVariables() {
9697 const variablesGetDef = pxt . blocks . getBlockDefinition ( variablesGetId ) ;
9798 msg . VARIABLES_GET_CREATE_SET = variablesGetDef . block [ "VARIABLES_GET_CREATE_SET" ] ;
9899 Blockly . Blocks [ variablesGetId ] = {
99- init : function ( ) {
100+ init : function ( ) {
100101 this . jsonInit (
101102 {
102103 "type" : "variables_get" ,
@@ -106,7 +107,7 @@ export function initVariables() {
106107 "type" : "field_variable" ,
107108 "name" : "VAR" ,
108109 "variable" : "%{BKY_VARIABLES_DEFAULT_NAME}" ,
109- "variableTypes" : [ "" ] ,
110+ "variableTypes" : [ "" , IMPORTED_VARIABLE_TYPE , EXPORTED_VARIABLE_TYPE ] ,
110111 } ,
111112 ] ,
112113 "output" : null ,
@@ -137,22 +138,22 @@ export function initVariables() {
137138 msg . VARIABLES_DEFAULT_NAME = varname ;
138139 msg . VARIABLES_SET_CREATE_GET = lf ( "Create 'get %1'" ) ;
139140 Blockly . Blocks [ variablesSetId ] = {
140- init : function ( ) {
141+ init : function ( ) {
141142 this . jsonInit (
142143 {
143144 "type" : "variables_set" ,
144145 "message0" : "%{BKY_VARIABLES_SET}" ,
145146 "args0" : [
146- {
147- "type" : "field_variable" ,
148- "name" : "VAR" ,
149- "variable" : "%{BKY_VARIABLES_DEFAULT_NAME}" ,
150- "variableTypes" : [ "" ] ,
151- } ,
152- {
153- "type" : "input_value" ,
154- "name" : "VALUE" ,
155- } ,
147+ {
148+ "type" : "field_variable" ,
149+ "name" : "VAR" ,
150+ "variable" : "%{BKY_VARIABLES_DEFAULT_NAME}" ,
151+ "variableTypes" : [ "" , IMPORTED_VARIABLE_TYPE , EXPORTED_VARIABLE_TYPE ] ,
152+ } ,
153+ {
154+ "type" : "input_value" ,
155+ "name" : "VALUE" ,
156+ } ,
156157 ] ,
157158 "previousStatement" : null ,
158159 "nextStatement" : null ,
@@ -179,7 +180,7 @@ export function initVariables() {
179180 "type" : "field_variable" ,
180181 "name" : "VAR" ,
181182 "variable" : varname ,
182- "variableTypes" : [ "" ]
183+ "variableTypes" : [ "" , IMPORTED_VARIABLE_TYPE , EXPORTED_VARIABLE_TYPE ]
183184 } ,
184185 {
185186 "type" : "input_value" ,
@@ -247,11 +248,22 @@ function flyoutCategory(workspace: Blockly.WorkspaceSvg, useXml: boolean): Eleme
247248 // This id is used to re-focus the create variable button after the dialog is closed.
248249 button . setAttribute ( 'id' , CREATE_VAR_BTN_ID ) ;
249250
251+ const globalButton = document . createElement ( 'button' ) as HTMLElement ;
252+ globalButton . setAttribute ( 'text' , lf ( "Make a Global Variable..." ) ) ;
253+ globalButton . setAttribute ( 'callbackKey' , 'CREATE_GLOBAL_VARIABLE' ) ;
254+ // This id is used to re-focus the create variable button after the dialog is closed.
255+ globalButton . setAttribute ( 'id' , CREATE_GLOBAL_VAR_BTN_ID ) ;
256+
250257 workspace . registerButtonCallback ( 'CREATE_VARIABLE' , function ( button ) {
251258 Blockly . Variables . createVariableButtonHandler ( button . getTargetWorkspace ( ) ) ;
252259 } ) ;
253260
261+ workspace . registerButtonCallback ( 'CREATE_GLOBAL_VARIABLE' , function ( button ) {
262+ Blockly . Variables . createVariableButtonHandler ( button . getTargetWorkspace ( ) , null , EXPORTED_VARIABLE_TYPE ) ;
263+ } ) ;
264+
254265 xmlList . push ( button ) ;
266+ xmlList . push ( globalButton ) ;
255267
256268 const blockList = Blockly . Variables . flyoutCategoryBlocks ( workspace ) as HTMLElement [ ] ;
257269 xmlList = xmlList . concat ( blockList ) ;
0 commit comments