@@ -4,94 +4,159 @@ import {
4
4
ILayoutRestorer
5
5
} from '@jupyterlab/application' ;
6
6
7
- import {
8
- ICommandPalette ,
9
- MainAreaWidget ,
10
- WidgetTracker
11
- } from '@jupyterlab/apputils' ;
12
-
13
- import { Widget } from '@lumino/widgets' ;
14
-
15
- import * as Blockly from 'blockly' ;
16
-
17
- namespace CommandIDs {
18
- export const open = 'jupyterlab-blocky:open-editor' ;
19
- }
20
-
21
- const TOOLBOX = {
22
- kind : 'flyoutToolbox' ,
23
- contents : [
24
- {
25
- kind : 'block' ,
26
- type : 'controls_if'
27
- } ,
28
- {
29
- kind : 'block' ,
30
- type : 'controls_whileUntil'
31
- }
32
- ]
33
- } ;
7
+ // import {
8
+ // ICommandPalette,
9
+ // MainAreaWidget,
10
+ // WidgetTracker
11
+ // } from '@jupyterlab/apputils';
12
+
13
+ // import { Widget } from '@lumino/widgets';
14
+
15
+ import { WidgetTracker } from '@jupyterlab/apputils' ;
16
+
17
+ // import * as Blockly from 'blockly';
18
+
19
+ import { BlocklyEditorFactory } from './factory' ;
20
+
21
+ // namespace CommandIDs {
22
+ // export const open = 'jupyterlab-blocky:open-editor';
23
+ // }
24
+
25
+ import { BlocklyEditor } from './widget' ;
26
+
27
+ // const TOOLBOX = {
28
+ // kind: 'flyoutToolbox',
29
+ // contents : [
30
+ // {
31
+ // kind : 'block',
32
+ // type : 'controls_if'
33
+ // },
34
+ // {
35
+ // kind : 'block',
36
+ // type : 'controls_ifelse'
37
+ // },
38
+ // {
39
+ // kind : 'block',
40
+ // type : 'logic_compare'
41
+ // },
42
+ // {
43
+ // kind : 'block',
44
+ // type : 'logic_operation'
45
+ // },
46
+ // {
47
+ // kind : 'block',
48
+ // type : 'logic_boolean'
49
+ // },
50
+ // {
51
+ // kind : 'block',
52
+ // type : 'controls_whileUntil'
53
+ // },
54
+ // {
55
+ // kind : 'block',
56
+ // type : 'controls_repeat_ext'
57
+ // },
58
+ // {
59
+ // kind : 'block',
60
+ // type : 'controls_for'
61
+ // },
62
+ // {
63
+ // kind : 'block',
64
+ // type : 'math_number'
65
+ // },
66
+ // {
67
+ // kind : 'block',
68
+ // type : 'math_arithmetic'
69
+ // }
70
+ // ]
71
+ // };
72
+
73
+ /**
74
+ * The name of the factory that creates the editor widgets.
75
+ */
76
+ const FACTORY = 'Blockly editor' ;
34
77
35
78
/**
36
79
* Initialization data for the jupyterlab-blocky extension.
37
80
*/
38
81
const plugin : JupyterFrontEndPlugin < void > = {
39
82
id : 'jupyterlab-blocky:plugin' ,
40
83
autoStart : true ,
41
- requires : [ ICommandPalette , ILayoutRestorer ] ,
42
- activate : (
43
- app : JupyterFrontEnd ,
44
- palette : ICommandPalette ,
45
- restorer : ILayoutRestorer
46
- ) => {
84
+ // requires: [ICommandPalette, ILayoutRestorer],
85
+ // activate: (
86
+ // app: JupyterFrontEnd,
87
+ // palette: ICommandPalette,
88
+ // restorer: ILayoutRestorer
89
+ // ) => {
90
+ requires : [ ILayoutRestorer ] ,
91
+ activate : ( app : JupyterFrontEnd , restorer : ILayoutRestorer ) => {
47
92
console . log ( 'JupyterLab extension jupyterlab-blocky is activated!' ) ;
48
93
49
- let editorPanel : MainAreaWidget | null = null ;
94
+ // let editorPanel: MainAreaWidget | null = null;
50
95
51
- // Namespace for the tracker
52
- const namespace = 'documents-example' ;
96
+ // // Namespace for the tracker
97
+ // const namespace = 'documents-example';
98
+ const namespace = 'jupyterlab-blocky' ;
53
99
// Creating the tracker for the document
54
- const tracker = new WidgetTracker < MainAreaWidget > ( { namespace } ) ;
100
+ // const tracker = new WidgetTracker<MainAreaWidget>({ namespace });
101
+ const tracker = new WidgetTracker < BlocklyEditor > ( { namespace } ) ;
55
102
56
103
// Handle state restoration.
57
104
if ( restorer ) {
58
105
// When restoring the app, if the document was open, reopen it
59
106
restorer . restore ( tracker , {
60
- command : CommandIDs . open ,
61
- name : widget => ''
107
+ // command: CommandIDs.open,
108
+ // name: widget => ''
109
+ command : 'docmanager:open' ,
110
+ args : widget => ( { path : widget . context . path , factory : FACTORY } ) ,
111
+ name : widget => widget . context . path
62
112
} ) ;
63
113
}
64
114
65
- app . commands . addCommand ( CommandIDs . open , {
66
- label : 'Open Blockly Editor' ,
67
- caption : 'Open Blockly Editor' ,
68
- isEnabled : ( ) => true ,
69
- execute : ( ) => {
70
- const content = new Widget ( ) ;
71
- content . id = 'jp-Blockly-container' ;
72
- editorPanel = new MainAreaWidget ( { content } ) ;
73
- editorPanel . title . label = 'Blockly Editor' ;
74
-
75
- editorPanel . disposed . connect ( ( ) => {
76
- editorPanel = null ;
77
- workspace . dispose ( ) ;
78
- } ) ;
79
-
80
- app . shell . add ( editorPanel , 'main' ) ;
81
-
82
- const workspace = Blockly . inject ( content . node , {
83
- toolbox : TOOLBOX
84
- } ) ;
85
- console . debug ( 'Blockly:' , workspace ) ;
86
- }
115
+ // app.commands.addCommand(CommandIDs.open, {
116
+ // label: 'Open Blockly Editor',
117
+ // caption: 'Open Blockly Editor',
118
+ // isEnabled: () => true,
119
+ // execute: () => {
120
+ // const content = new Widget();
121
+ // content.id = 'jp-Blockly-container';
122
+ // editorPanel = new MainAreaWidget({ content });
123
+ // editorPanel.title.label = 'Blockly Editor';
124
+
125
+ // editorPanel.disposed.connect(() => {
126
+ // editorPanel = null;
127
+ // workspace.dispose();
128
+ // });
129
+
130
+ // app.shell.add(editorPanel, 'main');
131
+
132
+ // const workspace = Blockly.inject(content.node, {
133
+ // toolbox: TOOLBOX
134
+ // });
135
+ // console.debug('Blockly:', workspace);
136
+ // }
137
+ // Creating the widget factory to register it so the document manager knows about
138
+ // our new DocumentWidget
139
+ const widgetFactory = new BlocklyEditorFactory ( {
140
+ name : FACTORY ,
141
+ modelName : 'text' ,
142
+ fileTypes : [ 'json' ]
87
143
} ) ;
88
144
89
- if ( palette ) {
90
- palette . addItem ( {
91
- command : CommandIDs . open ,
92
- category : 'Blockly Editor'
145
+ // if (palette) {
146
+ // palette.addItem({
147
+ // command: CommandIDs.open,
148
+ // category: 'Blockly Editor'
149
+ // Add the widget to the tracker when it's created
150
+ widgetFactory . widgetCreated . connect ( ( sender , widget ) => {
151
+ // Notify the instance tracker if restore data needs to update.
152
+ widget . context . pathChanged . connect ( ( ) => {
153
+ tracker . save ( widget ) ;
93
154
} ) ;
94
- }
155
+ // }
156
+ tracker . add ( widget ) ;
157
+ } ) ;
158
+ // Registering the widget factory
159
+ app . docRegistry . addWidgetFactory ( widgetFactory ) ;
95
160
}
96
161
} ;
97
162
0 commit comments