6
6
JupyterFrontEndPlugin
7
7
} from '@jupyterlab/application' ;
8
8
9
- import { showDialog , Dialog } from '@jupyterlab/apputils' ;
9
+ import { showDialog , Dialog , ICommandPalette } from '@jupyterlab/apputils' ;
10
10
11
11
import { IMainMenu } from '@jupyterlab/mainmenu' ;
12
12
@@ -42,20 +42,13 @@ namespace CommandIDs {
42
42
}
43
43
44
44
/**
45
- * The help plugin.
45
+ * A plugin to open the about section with resources .
46
46
*/
47
- const plugin : JupyterFrontEndPlugin < void > = {
48
- id : '@jupyter-notebook/help-extension:plugin ' ,
47
+ const open : JupyterFrontEndPlugin < void > = {
48
+ id : '@jupyter-notebook/help-extension:open ' ,
49
49
autoStart : true ,
50
- requires : [ ITranslator ] ,
51
- optional : [ IMainMenu ] ,
52
- activate : (
53
- app : JupyterFrontEnd ,
54
- translator : ITranslator ,
55
- menu : IMainMenu | null
56
- ) : void => {
50
+ activate : ( app : JupyterFrontEnd ) : void => {
57
51
const { commands } = app ;
58
- const trans = translator . load ( 'notebook' ) ;
59
52
60
53
commands . addCommand ( CommandIDs . open , {
61
54
label : args => args [ 'text' ] as string ,
@@ -64,54 +57,26 @@ const plugin: JupyterFrontEndPlugin<void> = {
64
57
window . open ( url ) ;
65
58
}
66
59
} ) ;
60
+ }
61
+ } ;
67
62
68
- commands . addCommand ( CommandIDs . shortcuts , {
69
- label : trans . __ ( 'Keyboard Shortcuts' ) ,
70
- execute : ( ) => {
71
- const title = (
72
- < span className = "jp-AboutNotebook-about-header" >
73
- < div className = "jp-AboutNotebook-about-header-info" >
74
- { trans . __ ( 'Keyboard Shortcuts' ) }
75
- </ div >
76
- </ span >
77
- ) ;
78
-
79
- const body = (
80
- < table className = "jp-AboutNotebook-shortcuts" >
81
- < thead >
82
- < tr >
83
- < th > { trans . __ ( 'Name' ) } </ th >
84
- < th > { trans . __ ( 'Shortcut' ) } </ th >
85
- </ tr >
86
- </ thead >
87
- < tbody >
88
- { commands . keyBindings
89
- . filter ( binding => commands . isEnabled ( binding . command ) )
90
- . map ( ( binding , i ) => (
91
- < tr key = { i } >
92
- < td > { commands . label ( binding . command ) } </ td >
93
- < td >
94
- < pre > { binding . keys . join ( ', ' ) } </ pre >
95
- </ td >
96
- </ tr >
97
- ) ) }
98
- </ tbody >
99
- </ table >
100
- ) ;
101
-
102
- return showDialog ( {
103
- title,
104
- body,
105
- buttons : [
106
- Dialog . createButton ( {
107
- label : trans . __ ( 'Dismiss' ) ,
108
- className :
109
- 'jp-AboutNotebook-about-button jp-mod-reject jp-mod-styled'
110
- } )
111
- ]
112
- } ) ;
113
- }
114
- } ) ;
63
+ /**
64
+ * Plugin to add a command to show an About Jupyter Notebook and Markdown Reference.
65
+ */
66
+ const about : JupyterFrontEndPlugin < void > = {
67
+ id : '@jupyter-notebook/help-extension:about' ,
68
+ autoStart : true ,
69
+ requires : [ ITranslator ] ,
70
+ optional : [ IMainMenu , ICommandPalette ] ,
71
+ activate : (
72
+ app : JupyterFrontEnd ,
73
+ translator : ITranslator ,
74
+ menu : IMainMenu | null ,
75
+ palette : ICommandPalette | null
76
+ ) : void => {
77
+ const { commands } = app ;
78
+ const trans = translator . load ( 'notebook' ) ;
79
+ const category = trans . __ ( 'Help' ) ;
115
80
116
81
commands . addCommand ( CommandIDs . about , {
117
82
label : trans . __ ( 'About %1' , app . name ) ,
@@ -176,6 +141,10 @@ const plugin: JupyterFrontEndPlugin<void> = {
176
141
}
177
142
} ) ;
178
143
144
+ if ( palette ) {
145
+ palette . addItem ( { command : CommandIDs . about , category } ) ;
146
+ }
147
+
179
148
const resourcesGroup = RESOURCES . map ( args => ( {
180
149
args,
181
150
command : CommandIDs . open
@@ -187,4 +156,77 @@ const plugin: JupyterFrontEndPlugin<void> = {
187
156
}
188
157
} ;
189
158
190
- export default plugin ;
159
+ /**
160
+ * A plugin to add a command to display Keyboard Shortcuts.
161
+ */
162
+ const shortcuts : JupyterFrontEndPlugin < void > = {
163
+ id : '@jupyter-notebook/help-extension:shortcuts' ,
164
+ autoStart : true ,
165
+ requires : [ ITranslator ] ,
166
+ optional : [ ICommandPalette ] ,
167
+ activate : (
168
+ app : JupyterFrontEnd ,
169
+ translator : ITranslator ,
170
+ palette : ICommandPalette | null
171
+ ) : void => {
172
+ const { commands } = app ;
173
+ const trans = translator . load ( 'notebook' ) ;
174
+ const category = trans . __ ( 'Help' ) ;
175
+
176
+ commands . addCommand ( CommandIDs . shortcuts , {
177
+ label : trans . __ ( 'Keyboard Shortcuts' ) ,
178
+ execute : ( ) => {
179
+ const title = (
180
+ < span className = "jp-AboutNotebook-about-header" >
181
+ < div className = "jp-AboutNotebook-about-header-info" >
182
+ { trans . __ ( 'Keyboard Shortcuts' ) }
183
+ </ div >
184
+ </ span >
185
+ ) ;
186
+
187
+ const body = (
188
+ < table className = "jp-AboutNotebook-shortcuts" >
189
+ < thead >
190
+ < tr >
191
+ < th > { trans . __ ( 'Name' ) } </ th >
192
+ < th > { trans . __ ( 'Shortcut' ) } </ th >
193
+ </ tr >
194
+ </ thead >
195
+ < tbody >
196
+ { commands . keyBindings
197
+ . filter ( binding => commands . isEnabled ( binding . command ) )
198
+ . map ( ( binding , i ) => (
199
+ < tr key = { i } >
200
+ < td > { commands . label ( binding . command ) } </ td >
201
+ < td >
202
+ < pre > { binding . keys . join ( ', ' ) } </ pre >
203
+ </ td >
204
+ </ tr >
205
+ ) ) }
206
+ </ tbody >
207
+ </ table >
208
+ ) ;
209
+
210
+ return showDialog ( {
211
+ title,
212
+ body,
213
+ buttons : [
214
+ Dialog . createButton ( {
215
+ label : trans . __ ( 'Dismiss' ) ,
216
+ className :
217
+ 'jp-AboutNotebook-about-button jp-mod-reject jp-mod-styled'
218
+ } )
219
+ ]
220
+ } ) ;
221
+ }
222
+ } ) ;
223
+
224
+ if ( palette ) {
225
+ palette . addItem ( { command : CommandIDs . shortcuts , category } ) ;
226
+ }
227
+ }
228
+ } ;
229
+
230
+ const plugins : JupyterFrontEndPlugin < any > [ ] = [ open , shortcuts , about ] ;
231
+
232
+ export default plugins ;
0 commit comments