From 49644b8cc309954d523bb7e644e91f0f6d5d7323 Mon Sep 17 00:00:00 2001 From: Nicolas Brichet <32258950+brichet@users.noreply.github.com> Date: Tue, 14 Jan 2025 12:17:35 +0100 Subject: [PATCH] Use Toolbar registry for the notebok button and move it to the right (#24) --- js/jupyterlab-slideshow/schema/plugin.json | 9 +++++++++ .../src/notebook/extension.ts | 20 +------------------ js/jupyterlab-slideshow/src/plugin.ts | 2 +- 3 files changed, 11 insertions(+), 20 deletions(-) diff --git a/js/jupyterlab-slideshow/schema/plugin.json b/js/jupyterlab-slideshow/schema/plugin.json index 719b875..bc47b7c 100644 --- a/js/jupyterlab-slideshow/schema/plugin.json +++ b/js/jupyterlab-slideshow/schema/plugin.json @@ -30,6 +30,15 @@ "description": "Configure Deck Settings", "jupyter.lab.setting-icon": "deck:start", "jupyter.lab.setting-icon-label": "Decks", + "jupyter.lab.toolbars": { + "Notebook": [ + { + "name": "deck", + "command": "deck:toggle", + "rank": 900 + } + ] + }, "properties": { "active": { "title": "Activate Deck", diff --git a/js/jupyterlab-slideshow/src/notebook/extension.ts b/js/jupyterlab-slideshow/src/notebook/extension.ts index 3406d5f..4a04cc0 100644 --- a/js/jupyterlab-slideshow/src/notebook/extension.ts +++ b/js/jupyterlab-slideshow/src/notebook/extension.ts @@ -1,45 +1,27 @@ -import { CommandToolbarButton } from '@jupyterlab/apputils'; import { DocumentRegistry } from '@jupyterlab/docregistry'; import { NotebookPanel, INotebookModel } from '@jupyterlab/notebook'; -import { CommandRegistry } from '@lumino/commands'; -import { IDisposable, DisposableDelegate } from '@lumino/disposable'; - -import { CommandIds } from '../tokens'; import { NotebookPresenter } from './presenter'; export class NotebookDeckExtension implements DocumentRegistry.IWidgetExtension { - private _commands: CommandRegistry; private _presenter: NotebookPresenter; constructor(options: DeckExtension.IOptions) { - this._commands = options.commands; this._presenter = options.presenter; } createNew( panel: NotebookPanel, context: DocumentRegistry.IContext, - ): IDisposable { - const button = new CommandToolbarButton({ - commands: this._commands, - label: '', - id: CommandIds.toggle, - }); - - panel.toolbar.insertItem(5, 'deck', button); - + ): void { this._presenter.preparePanel(panel); - - return new DisposableDelegate(() => button.dispose()); } } export namespace DeckExtension { export interface IOptions { - commands: CommandRegistry; presenter: NotebookPresenter; } } diff --git a/js/jupyterlab-slideshow/src/plugin.ts b/js/jupyterlab-slideshow/src/plugin.ts index 7bd63af..927765c 100644 --- a/js/jupyterlab-slideshow/src/plugin.ts +++ b/js/jupyterlab-slideshow/src/plugin.ts @@ -100,7 +100,7 @@ const notebookPlugin: JupyterFrontEndPlugin = { app.docRegistry.addWidgetExtension( NOTEBOOK_FACTORY, - new NotebookDeckExtension({ commands, presenter }), + new NotebookDeckExtension({ presenter }), ); }, };