From b5295c23e245fff38bd074e5e705fd5df8b72772 Mon Sep 17 00:00:00 2001 From: Meriem-BenIsmail Date: Tue, 26 Mar 2024 13:55:32 +0100 Subject: [PATCH] fixed issue with console conflicts --- src/index.ts | 47 +++++++++-------------------------------------- 1 file changed, 9 insertions(+), 38 deletions(-) diff --git a/src/index.ts b/src/index.ts index fde4452..e88e904 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,8 +4,6 @@ import { Menu } from '@lumino/widgets'; import { ISettingRegistry } from '@jupyterlab/settingregistry'; import { IMainMenu } from '@jupyterlab/mainmenu'; import { EditorLanguageRegistry } from '@jupyterlab/codemirror'; -import { ConsolePanel } from '@jupyterlab/console'; -import { SessionContext } from '@jupyterlab/apputils'; function addKernelMenuItems( app: any, @@ -13,12 +11,14 @@ function addKernelMenuItems( palette: any, mainMenu: IMainMenu ) { - const { commands, shell } = app; + const { commands } = app; const menu = new Menu({ commands: app.commands }); menu.title.label = 'Available Kernels Menu'; mainMenu.addMenu(menu); + Object.entries(serviceManager.kernelspecs.specs.kernelspecs).forEach( ([key, value]: [string, any]) => { + let count: number = 0; const kernelMenu = new Menu({ commands: app.commands }); kernelMenu.title.label = value.display_name; const language = @@ -33,6 +33,7 @@ function addKernelMenuItems( }); const startNotebookCommand = `widgets:start-notebook-${key}`; + commands.addCommand(startNotebookCommand, { label: `New ${key} notebook`, execute: async () => { @@ -49,47 +50,17 @@ function addKernelMenuItems( }); } }); - let contentFactory: ConsolePanel.IContentFactory; - const startConsoleCommand = `widgets:start-console-${key}`; + commands.addCommand(startConsoleCommand, { label: `New ${key} console`, execute: async () => { + count++; try { - const sessionManager = app.serviceManager.sessions; - const specsManager = app.serviceManager.kernelspecs; - - const rendermime = app.rendermime; - const manager = app.shell.widgets; - const mimeTypeService = app.docRegistry.mimeTypeService; - - const kernelName = key; - console.log(kernelName); - - const sessionContext = new SessionContext({ - sessionManager: sessionManager, - specsManager: specsManager, - kernelPreference: await sessionManager.startNew({ - name: `${kernelName} console`, - kernel: { name: kernelName }, - type: 'console', - path: '.' - }) - }); - sessionContext.changeKernel(); - - console.log(sessionContext.kernelPreference); - - await sessionContext.ready; - const panel = new ConsolePanel({ - rendermime: rendermime, - contentFactory: contentFactory, - manager: manager, - mimeTypeService: mimeTypeService, - sessionContext: sessionContext + await commands.execute('console:create', { + name: `Console ${count}`, + kernelPreference: { name: key } }); - shell.add(panel, 'main'); - shell.activateById(panel.id); } catch (error) { console.error('Error starting console:', error); }