|
@@ -17,6 +17,10 @@ import {
|
|
IMainMenu
|
|
IMainMenu
|
|
} from '@jupyterlab/mainmenu';
|
|
} from '@jupyterlab/mainmenu';
|
|
|
|
|
|
|
|
+import {
|
|
|
|
+ KernelMessage
|
|
|
|
+} from '@jupyterlab/services';
|
|
|
|
+
|
|
import {
|
|
import {
|
|
Message
|
|
Message
|
|
} from '@phosphor/messaging';
|
|
} from '@phosphor/messaging';
|
|
@@ -26,7 +30,7 @@ import {
|
|
} from '@phosphor/virtualdom';
|
|
} from '@phosphor/virtualdom';
|
|
|
|
|
|
import {
|
|
import {
|
|
- PanelLayout, Widget
|
|
|
|
|
|
+ Menu, PanelLayout, Widget
|
|
} from '@phosphor/widgets';
|
|
} from '@phosphor/widgets';
|
|
|
|
|
|
import '../style/index.css';
|
|
import '../style/index.css';
|
|
@@ -84,34 +88,6 @@ const RESOURCES = [
|
|
text: 'Notebook Reference',
|
|
text: 'Notebook Reference',
|
|
url: 'https://jupyter-notebook.readthedocs.io/en/latest/'
|
|
url: 'https://jupyter-notebook.readthedocs.io/en/latest/'
|
|
},
|
|
},
|
|
- {
|
|
|
|
- text: 'IPython Reference',
|
|
|
|
- url: 'https://ipython.readthedocs.io/en/stable/'
|
|
|
|
- },
|
|
|
|
- {
|
|
|
|
- text: 'Numpy Reference',
|
|
|
|
- url: 'https://docs.scipy.org/doc/numpy/reference/'
|
|
|
|
- },
|
|
|
|
- {
|
|
|
|
- text: 'Scipy Reference',
|
|
|
|
- url: 'https://docs.scipy.org/doc/scipy/reference/'
|
|
|
|
- },
|
|
|
|
- {
|
|
|
|
- text: 'Python Reference',
|
|
|
|
- url: 'https://docs.python.org/3.5/'
|
|
|
|
- },
|
|
|
|
- {
|
|
|
|
- text: 'Matplotlib Reference',
|
|
|
|
- url: 'https://matplotlib.org/contents.html?v=20160707164940'
|
|
|
|
- },
|
|
|
|
- {
|
|
|
|
- text: 'SymPy Reference',
|
|
|
|
- url: 'http://docs.sympy.org/latest/index.html?v=20160707164940'
|
|
|
|
- },
|
|
|
|
- {
|
|
|
|
- text: 'Pandas Reference',
|
|
|
|
- url: 'https://pandas.pydata.org/pandas-docs/stable/?v=20160707164940'
|
|
|
|
- },
|
|
|
|
{
|
|
{
|
|
text: 'Markdown Reference',
|
|
text: 'Markdown Reference',
|
|
url: 'https://help.github.com/articles/' +
|
|
url: 'https://help.github.com/articles/' +
|
|
@@ -190,7 +166,7 @@ function activate(app: JupyterLab, mainMenu: IMainMenu, palette: ICommandPalette
|
|
let counter = 0;
|
|
let counter = 0;
|
|
const category = 'Help';
|
|
const category = 'Help';
|
|
const namespace = 'help-doc';
|
|
const namespace = 'help-doc';
|
|
- const { commands, shell, info} = app;
|
|
|
|
|
|
+ const { commands, shell, info, serviceManager } = app;
|
|
const tracker = new InstanceTracker<HelpWidget>({ namespace });
|
|
const tracker = new InstanceTracker<HelpWidget>({ namespace });
|
|
|
|
|
|
// Handle state restoration.
|
|
// Handle state restoration.
|
|
@@ -225,6 +201,55 @@ function activate(app: JupyterLab, mainMenu: IMainMenu, palette: ICommandPalette
|
|
RESOURCES.map(args => { return { args, command: CommandIDs.open }; });
|
|
RESOURCES.map(args => { return { args, command: CommandIDs.open }; });
|
|
helpMenu.addGroup(resourcesGroup, 10);
|
|
helpMenu.addGroup(resourcesGroup, 10);
|
|
|
|
|
|
|
|
+ // Generate a cache of the kernel help links.
|
|
|
|
+ const kernelInfoCache = new Map<string, KernelMessage.IInfoReply>();
|
|
|
|
+ serviceManager.sessions.runningChanged.connect((m, sessions) => {
|
|
|
|
+ // If a new session has been added, it is at the back
|
|
|
|
+ // of the session list. If one has changed or stopped,
|
|
|
|
+ // it does not hurt to check it.
|
|
|
|
+ const sessionModel = sessions[sessions.length-1];
|
|
|
|
+ if (kernelInfoCache.has(sessionModel.kernel.name)) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ serviceManager.sessions.connectTo(sessionModel.id).then((session) => {
|
|
|
|
+ session.kernel.ready.then(() => {
|
|
|
|
+ // Set the Kernel Info cache.
|
|
|
|
+ const name = session.kernel.name;
|
|
|
|
+ kernelInfoCache.set(name, session.kernel.info);
|
|
|
|
+
|
|
|
|
+ // Utility function to check if the current widget
|
|
|
|
+ // has registered itself with the help menu.
|
|
|
|
+ const usesKernel = () => {
|
|
|
|
+ let result = false;
|
|
|
|
+ const widget = app.shell.currentWidget;
|
|
|
|
+ if (!widget) {
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
+ helpMenu.kernelUsers.forEach(u => {
|
|
|
|
+ if (u.tracker.has(widget) && u.getKernel(widget).name === name) {
|
|
|
|
+ result = true;
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // Add the kernel info help_links to the Help menu.
|
|
|
|
+ const kernelGroup: Menu.IItemOptions[] = [];
|
|
|
|
+ session.kernel.info.help_links.forEach((link) => {
|
|
|
|
+ const commandId = `help-menu-${name}:${link.text}`;
|
|
|
|
+ commands.addCommand(commandId, {
|
|
|
|
+ label: link.text,
|
|
|
|
+ isVisible: usesKernel,
|
|
|
|
+ isEnabled: usesKernel,
|
|
|
|
+ execute: () => { commands.execute(CommandIDs.open, link) }
|
|
|
|
+ });
|
|
|
|
+ kernelGroup.push({ command: commandId });
|
|
|
|
+ });
|
|
|
|
+ helpMenu.addGroup(kernelGroup, 20);
|
|
|
|
+ });
|
|
|
|
+ });
|
|
|
|
+ });
|
|
|
|
+
|
|
commands.addCommand(CommandIDs.about, {
|
|
commands.addCommand(CommandIDs.about, {
|
|
label: `About ${info.name}`,
|
|
label: `About ${info.name}`,
|
|
execute: () => {
|
|
execute: () => {
|