JupyterLab 4.0 will include toc:show-panel
command, and in earlier versions you can activate ToC using activateById()
method from JupyterFrontEnd.IShell
interface using table-of-contents
identifier.
You can try it out on jupyterlab-plugin-playground with the following code:
import { JupyterFrontEnd, JupyterFrontEndPlugin } from '@jupyterlab/application';
import { NotebookPanel, INotebookTracker } from '@jupyterlab/notebook';
const plugin: JupyterFrontEndPlugin<void> = {
id: 'toc-show:plugin',
autoStart: true,
requires: [INotebookTracker],
activate: (app: JupyterFrontEnd, notebookTracker: INotebookTracker) => {
alert('TOC-show extension activated!'); // you can remove this
notebookTracker.currentChanged.connect((_: any, notebookPanel: NotebookPanel | null) => {
if (notebookPanel) {
// JupyterLab 3.x:
app.shell.activateById('table-of-contents');
// JupyterLab 4.0+:
// app.commands.execute('toc:show-panel');
}
});
},
};
export default plugin;
For packaging/installing it as a permanent extension you can follow the JupyterLab extension tutorial.
In future it might be possible to recreate this functionality from ipylab but currently it does not implement signal handlind.