瀏覽代碼

Add translation and keyboard bindings to mode switch.

Jason Grout 4 年之前
父節點
當前提交
920fa96e3f
共有 1 個文件被更改,包括 31 次插入4 次删除
  1. 31 4
      packages/application-extension/src/index.tsx

+ 31 - 4
packages/application-extension/src/index.tsx

@@ -43,6 +43,8 @@ import { buildIcon, Switch } from '@jupyterlab/ui-components';
 
 import { each, iter, toArray } from '@lumino/algorithm';
 
+import { CommandRegistry } from '@lumino/commands';
+
 import { PromiseDelegate } from '@lumino/coreutils';
 
 import { DisposableDelegate, DisposableSet } from '@lumino/disposable';
@@ -945,8 +947,14 @@ const propertyInspector: JupyterFrontEndPlugin<IPropertyInspectorProvider> = {
  */
 const modeSwitch: JupyterFrontEndPlugin<void> = {
   id: '@jupyterlab/application-extension:mode-switch',
-  requires: [ILabShell],
-  activate: (app: JupyterFrontEnd, shell: ILabShell) => {
+  requires: [ILabShell, ITranslator],
+  activate: (
+    app: JupyterFrontEnd,
+    shell: ILabShell,
+    translator: ITranslator
+  ) => {
+    const trans = translator.load('jupyterlab');
+
     const spacer = new Widget();
     spacer.id = 'jp-top-spacer';
     spacer.node.style.flexGrow = '1';
@@ -954,8 +962,7 @@ const modeSwitch: JupyterFrontEndPlugin<void> = {
 
     const modeSwitch = new Switch();
     modeSwitch.id = 'jp-single-document-mode';
-    modeSwitch.label = 'Mode';
-    modeSwitch.caption = 'Single-Document Mode';
+
     modeSwitch.valueChanged.connect((_, args) => {
       shell.mode = args.newValue ? 'single-document' : 'multiple-document';
     });
@@ -963,6 +970,26 @@ const modeSwitch: JupyterFrontEndPlugin<void> = {
       modeSwitch.value = mode === 'single-document';
     });
     modeSwitch.value = shell.mode === 'single-document';
+
+    // Show the current file browser shortcut in its title.
+    const updateModeSwitchTitle = () => {
+      const binding = app.commands.keyBindings.find(
+        b => b.command === CommandIDs.toggleMode
+      );
+      if (binding) {
+        const ks = CommandRegistry.formatKeystroke(binding.keys.join(' '));
+        modeSwitch.caption = trans.__('Single-Document Mode (%1)', ks);
+      } else {
+        modeSwitch.caption = trans.__('Single-Document Mode');
+      }
+    };
+    updateModeSwitchTitle();
+    app.commands.keyBindingChanged.connect(() => {
+      updateModeSwitchTitle();
+    });
+
+    modeSwitch.label = trans.__('Mode');
+
     shell.add(modeSwitch, 'top', { rank: 1010 });
   },
   autoStart: true