Skip to content

Commit 6d4eeed

Browse files
RRosiojtpio
andauthored
Help-extension split into multiple plugins (#6700)
* help-extension split into multiple plugins * Update packages/help-extension/src/index.tsx Co-authored-by: Jeremy Tuloup <[email protected]> * rename schema json file Co-authored-by: Jeremy Tuloup <[email protected]>
1 parent 4e6282c commit 6d4eeed

File tree

2 files changed

+102
-60
lines changed

2 files changed

+102
-60
lines changed

packages/help-extension/src/index.tsx

+102-60
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
JupyterFrontEndPlugin
77
} from '@jupyterlab/application';
88

9-
import { showDialog, Dialog } from '@jupyterlab/apputils';
9+
import { showDialog, Dialog, ICommandPalette } from '@jupyterlab/apputils';
1010

1111
import { IMainMenu } from '@jupyterlab/mainmenu';
1212

@@ -42,20 +42,13 @@ namespace CommandIDs {
4242
}
4343

4444
/**
45-
* The help plugin.
45+
* A plugin to open the about section with resources.
4646
*/
47-
const plugin: JupyterFrontEndPlugin<void> = {
48-
id: '@jupyter-notebook/help-extension:plugin',
47+
const open: JupyterFrontEndPlugin<void> = {
48+
id: '@jupyter-notebook/help-extension:open',
4949
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 => {
5751
const { commands } = app;
58-
const trans = translator.load('notebook');
5952

6053
commands.addCommand(CommandIDs.open, {
6154
label: args => args['text'] as string,
@@ -64,54 +57,26 @@ const plugin: JupyterFrontEndPlugin<void> = {
6457
window.open(url);
6558
}
6659
});
60+
}
61+
};
6762

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');
11580

11681
commands.addCommand(CommandIDs.about, {
11782
label: trans.__('About %1', app.name),
@@ -176,6 +141,10 @@ const plugin: JupyterFrontEndPlugin<void> = {
176141
}
177142
});
178143

144+
if (palette) {
145+
palette.addItem({ command: CommandIDs.about, category });
146+
}
147+
179148
const resourcesGroup = RESOURCES.map(args => ({
180149
args,
181150
command: CommandIDs.open
@@ -187,4 +156,77 @@ const plugin: JupyterFrontEndPlugin<void> = {
187156
}
188157
};
189158

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

Comments
 (0)