@@ -16,7 +16,7 @@ import { BlocklyRegistry } from './registry';
16
16
* user wants to use on a specific document.
17
17
*/
18
18
export class BlocklyManager {
19
- private _toolbox : JSONObject ;
19
+ private _toolbox : string ;
20
20
private _generator : Blockly . Generator ;
21
21
private _registry : BlocklyRegistry ;
22
22
private _selectedKernel : KernelSpec . ISpecModel ;
@@ -36,7 +36,7 @@ export class BlocklyManager {
36
36
this . _sessionContext = sessionContext ;
37
37
this . _mimetypeService = mimetypeService ;
38
38
39
- this . _toolbox = this . _registry . toolboxes . get ( 'default' ) ;
39
+ this . _toolbox = 'default' ;
40
40
this . _generator = this . _registry . generators . get ( 'python' ) ;
41
41
42
42
this . _changed = new Signal < this, BlocklyManager . Change > ( this ) ;
@@ -47,7 +47,7 @@ export class BlocklyManager {
47
47
* Returns the selected toolbox.
48
48
*/
49
49
get toolbox ( ) : JSONObject {
50
- return this . _toolbox ;
50
+ return this . _registry . toolboxes . get ( this . _toolbox ) ;
51
51
}
52
52
53
53
/**
@@ -94,13 +94,39 @@ export class BlocklyManager {
94
94
this . _sessionContext . kernelChanged . disconnect ( this . _onKernelChanged , this ) ;
95
95
}
96
96
97
+ /**
98
+ * Get the selected toolbox's name.
99
+ *
100
+ * @returns The name of the toolbox.
101
+ */
102
+ getToolbox ( ) {
103
+ return this . _toolbox ;
104
+ }
105
+
97
106
/**
98
107
* Set the selected toolbox.
99
108
*
100
109
* @argument name The name of the toolbox.
101
110
*/
102
111
setToolbox ( name : string ) {
103
- this . _toolbox = this . _registry . toolboxes . get ( name ) ;
112
+ if ( this . _toolbox !== name ) {
113
+ const toolbox = this . _registry . toolboxes . get ( name ) ;
114
+ this . _toolbox = toolbox ? name : 'default' ;
115
+ this . _changed . emit ( 'toolbox' ) ;
116
+ }
117
+ }
118
+
119
+ /**
120
+ * List the available toolboxes.
121
+ *
122
+ * @returns the list of available toolboxes for Blockly
123
+ */
124
+ listToolboxes ( ) : { label : string ; value : string } [ ] {
125
+ const list : { label : string ; value : string } [ ] = [ ] ;
126
+ this . _registry . toolboxes . forEach ( ( toolbox , name ) => {
127
+ list . push ( { label : name , value : name } ) ;
128
+ } ) ;
129
+ return list ;
104
130
}
105
131
106
132
/**
@@ -113,7 +139,7 @@ export class BlocklyManager {
113
139
}
114
140
115
141
/**
116
- * Set the selected toolbox .
142
+ * List the available kernels .
117
143
*
118
144
* @returns the list of available kernels for Blockly
119
145
*/
0 commit comments