Browse Source

Add scaffolding for transforming shortcuts plugin.

Afshin Darian 6 years ago
parent
commit
8904a4eb84
1 changed files with 27 additions and 10 deletions
  1. 27 10
      packages/shortcuts-extension/src/index.ts

+ 27 - 10
packages/shortcuts-extension/src/index.ts

@@ -43,20 +43,24 @@ import { DisposableSet, IDisposable } from '@phosphor/disposable';
 const plugin: JupyterLabPlugin<void> = {
   id: '@jupyterlab/shortcuts-extension:plugin',
   requires: [ISettingRegistry],
-  activate: (app: JupyterLab, settingRegistry: ISettingRegistry): void => {
+  activate: async (app: JupyterLab, registry: ISettingRegistry) => {
     const { commands } = app;
 
-    settingRegistry
-      .load(plugin.id)
-      .then(settings => {
+    // Transform the settings object to return different annotated defaults
+    // calculated from all the keyboard shortcuts in the registry instead of
+    // using the default values from this plugin's schema.
+    registry.transform(plugin.id, Private.transform(commands, registry));
+
+    try {
+      const settings = await registry.load(plugin.id);
+
+      Private.loadShortcuts(commands, settings.composite);
+      settings.changed.connect(() => {
         Private.loadShortcuts(commands, settings.composite);
-        settings.changed.connect(() => {
-          Private.loadShortcuts(commands, settings.composite);
-        });
-      })
-      .catch((reason: Error) => {
-        console.error('Loading shortcut settings failed.', reason.message);
       });
+    } catch (error) {
+      console.error('Loading shortcut settings failed.', error.message);
+    }
   },
   autoStart: true
 };
@@ -115,4 +119,17 @@ namespace Private {
 
     return valid ? (value as CommandRegistry.IKeyBindingOptions) : undefined;
   }
+
+  /**
+   * Return a transformer that return a settings object annotated defaults.
+   */
+  export function transform(
+    commands: CommandRegistry,
+    registry: ISettingRegistry
+  ): ISettingRegistry.SettingTransform {
+    // Transform the settings object to return different annotated defaults
+    // calculated from all the keyboard shortcuts in the registry instead of
+    // using the default values from this plugin's schema.
+    return settings => settings;
+  }
 }