@@ -16,7 +16,7 @@ import { BlocklyRegistry } from './registry';
1616 * user wants to use on a specific document.
1717 */
1818export class BlocklyManager {
19- private _toolbox : JSONObject ;
19+ private _toolbox : string ;
2020 private _generator : Blockly . Generator ;
2121 private _registry : BlocklyRegistry ;
2222 private _selectedKernel : KernelSpec . ISpecModel ;
@@ -36,7 +36,7 @@ export class BlocklyManager {
3636 this . _sessionContext = sessionContext ;
3737 this . _mimetypeService = mimetypeService ;
3838
39- this . _toolbox = this . _registry . toolboxes . get ( 'default' ) ;
39+ this . _toolbox = 'default' ;
4040 this . _generator = this . _registry . generators . get ( 'python' ) ;
4141
4242 this . _changed = new Signal < this, BlocklyManager . Change > ( this ) ;
@@ -47,7 +47,7 @@ export class BlocklyManager {
4747 * Returns the selected toolbox.
4848 */
4949 get toolbox ( ) : JSONObject {
50- return this . _toolbox ;
50+ return this . _registry . toolboxes . get ( this . _toolbox ) ;
5151 }
5252
5353 /**
@@ -94,13 +94,39 @@ export class BlocklyManager {
9494 this . _sessionContext . kernelChanged . disconnect ( this . _onKernelChanged , this ) ;
9595 }
9696
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+
97106 /**
98107 * Set the selected toolbox.
99108 *
100109 * @argument name The name of the toolbox.
101110 */
102111 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 ;
104130 }
105131
106132 /**
@@ -113,7 +139,7 @@ export class BlocklyManager {
113139 }
114140
115141 /**
116- * Set the selected toolbox .
142+ * List the available kernels .
117143 *
118144 * @returns the list of available kernels for Blockly
119145 */
0 commit comments