Skip to content

Commit 5d1ec20

Browse files
committed
Adds a dropdown to select a toolbox
1 parent a6b5f4f commit 5d1ec20

File tree

9 files changed

+2054
-11
lines changed

9 files changed

+2054
-11
lines changed

src/index.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,4 +208,19 @@ const plugin: JupyterFrontEndPlugin<IBlocklyRegisty> = {
208208
}
209209
};
210210

211-
export default plugin;
211+
import BlocklyNiryo from './niryo/niryo_one_python_generators';
212+
213+
/**
214+
* Initialization data for the jupyterlab-blocky extension.
215+
*/
216+
const niryo: JupyterFrontEndPlugin<void> = {
217+
id: 'jupyterlab-blocky:niryo',
218+
autoStart: true,
219+
requires: [IBlocklyRegisty],
220+
activate: (app: JupyterFrontEnd, blockly: IBlocklyRegisty): void => {
221+
console.log('JupyterLab extension jupyterlab-blocky-niryo is activated!');
222+
blockly.registerToolbox('niryo', BlocklyNiryo.Toolbox);
223+
}
224+
};
225+
226+
export default [plugin, niryo];

src/layout.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,5 +186,8 @@ export class BlocklyLayout extends PanelLayout {
186186
this._cell.model.sharedModel.setSource(code);
187187
this._cell.model.mimeType = this._manager.mimeType;
188188
}
189+
if (change === 'toolbox') {
190+
this._workspace.updateToolbox(this._manager.toolbox as any);
191+
}
189192
}
190193
}

src/manager.ts

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { BlocklyRegistry } from './registry';
1616
* user wants to use on a specific document.
1717
*/
1818
export 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

Comments
 (0)