Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help-extension split into multiple plugins #6700

Merged
merged 3 commits into from
Jan 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
162 changes: 102 additions & 60 deletions packages/help-extension/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
JupyterFrontEndPlugin
} from '@jupyterlab/application';

import { showDialog, Dialog } from '@jupyterlab/apputils';
import { showDialog, Dialog, ICommandPalette } from '@jupyterlab/apputils';

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

Expand Down Expand Up @@ -42,20 +42,13 @@ namespace CommandIDs {
}

/**
* The help plugin.
* A plugin to open the about section with resources.
*/
const plugin: JupyterFrontEndPlugin<void> = {
id: '@jupyter-notebook/help-extension:plugin',
const open: JupyterFrontEndPlugin<void> = {
id: '@jupyter-notebook/help-extension:open',
autoStart: true,
requires: [ITranslator],
optional: [IMainMenu],
activate: (
app: JupyterFrontEnd,
translator: ITranslator,
menu: IMainMenu | null
): void => {
activate: (app: JupyterFrontEnd): void => {
const { commands } = app;
const trans = translator.load('notebook');

commands.addCommand(CommandIDs.open, {
label: args => args['text'] as string,
Expand All @@ -64,54 +57,26 @@ const plugin: JupyterFrontEndPlugin<void> = {
window.open(url);
}
});
}
};

commands.addCommand(CommandIDs.shortcuts, {
label: trans.__('Keyboard Shortcuts'),
execute: () => {
const title = (
<span className="jp-AboutNotebook-about-header">
<div className="jp-AboutNotebook-about-header-info">
{trans.__('Keyboard Shortcuts')}
</div>
</span>
);

const body = (
<table className="jp-AboutNotebook-shortcuts">
<thead>
<tr>
<th>{trans.__('Name')}</th>
<th>{trans.__('Shortcut')}</th>
</tr>
</thead>
<tbody>
{commands.keyBindings
.filter(binding => commands.isEnabled(binding.command))
.map((binding, i) => (
<tr key={i}>
<td>{commands.label(binding.command)}</td>
<td>
<pre>{binding.keys.join(', ')}</pre>
</td>
</tr>
))}
</tbody>
</table>
);

return showDialog({
title,
body,
buttons: [
Dialog.createButton({
label: trans.__('Dismiss'),
className:
'jp-AboutNotebook-about-button jp-mod-reject jp-mod-styled'
})
]
});
}
});
/**
* Plugin to add a command to show an About Jupyter Notebook and Markdown Reference.
*/
const about: JupyterFrontEndPlugin<void> = {
id: '@jupyter-notebook/help-extension:about',
autoStart: true,
requires: [ITranslator],
optional: [IMainMenu, ICommandPalette],
activate: (
app: JupyterFrontEnd,
translator: ITranslator,
menu: IMainMenu | null,
palette: ICommandPalette | null
): void => {
const { commands } = app;
const trans = translator.load('notebook');
const category = trans.__('Help');

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

if (palette) {
palette.addItem({ command: CommandIDs.about, category });
}

const resourcesGroup = RESOURCES.map(args => ({
args,
command: CommandIDs.open
Expand All @@ -187,4 +156,77 @@ const plugin: JupyterFrontEndPlugin<void> = {
}
};

export default plugin;
/**
* A plugin to add a command to display Keyboard Shortcuts.
*/
const shortcuts: JupyterFrontEndPlugin<void> = {
id: '@jupyter-notebook/help-extension:shortcuts',
autoStart: true,
requires: [ITranslator],
optional: [ICommandPalette],
activate: (
app: JupyterFrontEnd,
translator: ITranslator,
palette: ICommandPalette | null
): void => {
const { commands } = app;
const trans = translator.load('notebook');
const category = trans.__('Help');

commands.addCommand(CommandIDs.shortcuts, {
label: trans.__('Keyboard Shortcuts'),
execute: () => {
const title = (
<span className="jp-AboutNotebook-about-header">
<div className="jp-AboutNotebook-about-header-info">
{trans.__('Keyboard Shortcuts')}
</div>
</span>
);

const body = (
<table className="jp-AboutNotebook-shortcuts">
<thead>
<tr>
<th>{trans.__('Name')}</th>
<th>{trans.__('Shortcut')}</th>
</tr>
</thead>
<tbody>
{commands.keyBindings
.filter(binding => commands.isEnabled(binding.command))
.map((binding, i) => (
<tr key={i}>
<td>{commands.label(binding.command)}</td>
<td>
<pre>{binding.keys.join(', ')}</pre>
</td>
</tr>
))}
</tbody>
</table>
);

return showDialog({
title,
body,
buttons: [
Dialog.createButton({
label: trans.__('Dismiss'),
className:
'jp-AboutNotebook-about-button jp-mod-reject jp-mod-styled'
})
]
});
}
});

if (palette) {
palette.addItem({ command: CommandIDs.shortcuts, category });
}
}
};

const plugins: JupyterFrontEndPlugin<any>[] = [open, shortcuts, about];

export default plugins;