From ec87ceb2cb87900d45db06f265c8ce7034caa876 Mon Sep 17 00:00:00 2001 From: Jeremy Tuloup Date: Mon, 30 Sep 2024 07:48:01 +0200 Subject: [PATCH] Add to the menu (#57) * Add to the menu * update yarn.lock --- package.json | 3 ++- schema/plugin.json | 17 +++++++++++++++++ src/index.ts | 22 +++++++++++----------- yarn.lock | 1 + 4 files changed, 31 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index c1cd8ca..85ad7af 100644 --- a/package.json +++ b/package.json @@ -62,7 +62,8 @@ "@jupyterlab/docmanager": "^4.2.5", "@jupyterlab/filebrowser": "^4.2.5", "@jupyterlab/services": "^7.2.5", - "@jupyterlab/settingregistry": "^4.2.5" + "@jupyterlab/settingregistry": "^4.2.5", + "@jupyterlab/translation": "^4.2.5" }, "devDependencies": { "@jupyterlab/builder": "^4.0.0", diff --git a/schema/plugin.json b/schema/plugin.json index 5d8d62a..c3b9b2b 100644 --- a/schema/plugin.json +++ b/schema/plugin.json @@ -18,6 +18,23 @@ "default": false } }, + "jupyter.lab.menus": { + "main": [ + { + "id": "jp-mainmenu-view", + "items": [ + { + "command": "quickopen:activate", + "rank": 1 + }, + { + "type": "separator", + "rank": 1 + } + ] + } + ] + }, "jupyter.lab.shortcuts": [ { "command": "quickopen:activate", diff --git a/src/index.ts b/src/index.ts index 7296af0..4ff456d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -8,6 +8,7 @@ import { IDocumentManager } from '@jupyterlab/docmanager'; import { ServerConnection } from '@jupyterlab/services'; import { ISettingRegistry } from '@jupyterlab/settingregistry'; import { FileBrowser, IDefaultFileBrowser } from '@jupyterlab/filebrowser'; +import { ITranslator, nullTranslator } from '@jupyterlab/translation'; import { CommandRegistry } from '@lumino/commands'; import { ReadonlyPartialJSONObject } from '@lumino/coreutils'; import { Message } from '@lumino/messaging'; @@ -128,20 +129,17 @@ class QuickOpenWidget extends CommandPalette { const extension: JupyterFrontEndPlugin = { id: 'jupyterlab-quickopen:plugin', autoStart: true, - requires: [ - ICommandPalette, - IDocumentManager, - ISettingRegistry, - IDefaultFileBrowser - ], + requires: [IDocumentManager, ISettingRegistry, IDefaultFileBrowser], + optional: [ICommandPalette, ITranslator], activate: async ( app: JupyterFrontEnd, - palette: ICommandPalette, docManager: IDocumentManager, settingRegistry: ISettingRegistry, - defaultFileBrowser: IDefaultFileBrowser + defaultFileBrowser: IDefaultFileBrowser, + palette: ICommandPalette | null, + translator: ITranslator | null ) => { - console.log(`Activated extension: ${extension.id}`); + const trans = (translator ?? nullTranslator).load('jupyterlab-quickopen'); const commands: CommandRegistry = new CommandRegistry(); const settings: ISettingRegistry.ISettings = await settingRegistry.load( extension.id @@ -173,12 +171,14 @@ const extension: JupyterFrontEndPlugin = { // palette, assign a hotkey, etc. const command = 'quickopen:activate'; app.commands.addCommand(command, { - label: 'Quick Open', + label: trans.__('Quick Open'), execute: () => { modalPalette.activate(); } }); - palette.addItem({ command, category: 'File Operations' }); + if (palette) { + palette.addItem({ command, category: 'File Operations' }); + } } }; diff --git a/yarn.lock b/yarn.lock index 446cc88..048eb5a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3417,6 +3417,7 @@ __metadata: "@jupyterlab/filebrowser": ^4.2.5 "@jupyterlab/services": ^7.2.5 "@jupyterlab/settingregistry": ^4.2.5 + "@jupyterlab/translation": ^4.2.5 "@types/json-schema": ^7.0.11 "@types/react": ^18.0.26 "@types/react-addons-linked-state-mixin": ^0.14.22