浏览代码

Backport PR #10645: Context menu plugin schema (#10698)

Co-authored-by: Jeremy Tuloup <jeremy.tuloup@gmail.com>
MeeseeksMachine 3 年之前
父节点
当前提交
0fa10bed46

+ 47 - 0
packages/application-extension/schema/commands.json

@@ -1,6 +1,53 @@
 {
   "title": "Application Commands",
   "description": "Application commands settings.",
+  "jupyter.lab.shortcuts": [
+    {
+      "command": "application:activate-next-tab",
+      "keys": ["Ctrl Shift ]"],
+      "selector": "body"
+    },
+    {
+      "command": "application:activate-previous-tab",
+      "keys": ["Ctrl Shift ["],
+      "selector": "body"
+    },
+    {
+      "command": "application:activate-next-tab-bar",
+      "keys": ["Ctrl Shift ."],
+      "selector": "body"
+    },
+    {
+      "command": "application:activate-previous-tab-bar",
+      "keys": ["Ctrl Shift ,"],
+      "selector": "body"
+    },
+    {
+      "command": "application:close",
+      "keys": ["Alt W"],
+      "selector": ".jp-Activity"
+    },
+    {
+      "command": "application:toggle-mode",
+      "keys": ["Accel Shift D"],
+      "selector": "body"
+    },
+    {
+      "command": "application:toggle-left-area",
+      "keys": ["Accel B"],
+      "selector": "body"
+    },
+    {
+      "command": "application:toggle-right-area",
+      "keys": [""],
+      "selector": "body"
+    },
+    {
+      "command": "application:toggle-presentation-mode",
+      "keys": [""],
+      "selector": "body"
+    }
+  ],
   "jupyter.lab.menus": {
     "main": [
       {

+ 4 - 50
packages/application-extension/schema/main.json → packages/application-extension/schema/context-menu.json

@@ -1,54 +1,8 @@
 {
-  "title": "Application",
-  "description": "Main JupyterLab application settings.",
-  "jupyter.lab.setting-icon-label": "Application",
-  "jupyter.lab.shortcuts": [
-    {
-      "command": "application:activate-next-tab",
-      "keys": ["Ctrl Shift ]"],
-      "selector": "body"
-    },
-    {
-      "command": "application:activate-previous-tab",
-      "keys": ["Ctrl Shift ["],
-      "selector": "body"
-    },
-    {
-      "command": "application:activate-next-tab-bar",
-      "keys": ["Ctrl Shift ."],
-      "selector": "body"
-    },
-    {
-      "command": "application:activate-previous-tab-bar",
-      "keys": ["Ctrl Shift ,"],
-      "selector": "body"
-    },
-    {
-      "command": "application:close",
-      "keys": ["Alt W"],
-      "selector": ".jp-Activity"
-    },
-    {
-      "command": "application:toggle-mode",
-      "keys": ["Accel Shift D"],
-      "selector": "body"
-    },
-    {
-      "command": "application:toggle-left-area",
-      "keys": ["Accel B"],
-      "selector": "body"
-    },
-    {
-      "command": "application:toggle-right-area",
-      "keys": [""],
-      "selector": "body"
-    },
-    {
-      "command": "application:toggle-presentation-mode",
-      "keys": [""],
-      "selector": "body"
-    }
-  ],
+  "title": "Application Context Menu",
+  "description": "JupyterLab context menu settings.",
+  "jupyter.lab.setting-icon-label": "Application Context Menu",
+  "jupyter.lab.shortcuts": [],
   "jupyter.lab.transform": true,
   "properties": {
     "contextMenu": {

+ 7 - 11
packages/application-extension/src/index.tsx

@@ -363,16 +363,11 @@ const mainCommands: JupyterFrontEndPlugin<void> = {
   }
 };
 
-/**
- * Main plugin id
- */
-const MAIN_PLUGIN_ID = '@jupyterlab/application-extension:main';
-
 /**
  * The main extension.
  */
 const main: JupyterFrontEndPlugin<ITreePathUpdater> = {
-  id: MAIN_PLUGIN_ID,
+  id: '@jupyterlab/application-extension:main',
   requires: [IRouter, IWindowResolver, ITranslator],
   optional: [IConnectionLost],
   provides: ITreePathUpdater,
@@ -540,7 +535,7 @@ const main: JupyterFrontEndPlugin<ITreePathUpdater> = {
 /**
  * Plugin to build the context menu from the settings.
  */
-const contextMenu: JupyterFrontEndPlugin<void> = {
+const contextMenuPlugin: JupyterFrontEndPlugin<void> = {
   id: '@jupyterlab/application-extension:context-menu',
   autoStart: true,
   requires: [ISettingRegistry, ITranslator],
@@ -925,7 +920,7 @@ const JupyterLogo: JupyterFrontEndPlugin<void> = {
  * Export the plugins as default.
  */
 const plugins: JupyterFrontEndPlugin<any>[] = [
-  contextMenu,
+  contextMenuPlugin,
   dirty,
   main,
   mainCommands,
@@ -971,6 +966,7 @@ namespace Private {
     translator: ITranslator
   ): Promise<void> {
     const trans = translator.load('jupyterlab');
+    const pluginId = contextMenuPlugin.id;
     let canonical: ISettingRegistry.ISchema | null;
     let loaded: { [name: string]: ISettingRegistry.IContextMenuItem[] } = {};
 
@@ -1005,7 +1001,7 @@ namespace Private {
     }
 
     // Transform the plugin object to return different schema than the default.
-    registry.transform(MAIN_PLUGIN_ID, {
+    registry.transform(pluginId, {
       compose: plugin => {
         // Only override the canonical schema the first time.
         if (!canonical) {
@@ -1050,7 +1046,7 @@ namespace Private {
     // preloaded all initial plugins.
     canonical = null;
 
-    const settings = await registry.load(MAIN_PLUGIN_ID);
+    const settings = await registry.load(pluginId);
 
     const contextItems: ISettingRegistry.IContextMenuItem[] =
       JSONExt.deepCopy(settings.composite.contextMenu as any) ?? [];
@@ -1070,7 +1066,7 @@ namespace Private {
     });
 
     registry.pluginChanged.connect(async (sender, plugin) => {
-      if (plugin !== MAIN_PLUGIN_ID) {
+      if (plugin !== pluginId) {
         // If the plugin changed its menu.
         const oldItems = loaded[plugin] ?? [];
         const newItems =