Prechádzať zdrojové kódy

First pass at command palette extension

Afshin Darian 8 rokov pred
rodič
commit
251bd04e47
1 zmenil súbory, kde vykonal 96 pridanie a 0 odobranie
  1. 96 0
      src/commandpalette/plugin.ts

+ 96 - 0
src/commandpalette/plugin.ts

@@ -0,0 +1,96 @@
+/*-----------------------------------------------------------------------------
+| Copyright (c) Jupyter Development Team.
+| Distributed under the terms of the Modified BSD License.
+|----------------------------------------------------------------------------*/
+
+import {
+  Token
+} from 'phosphor/lib/core/token';
+
+import {
+  CommandPalette
+} from 'phosphor/lib/ui/commandpalette';
+
+import {
+  JupyterLab, JupyterLabPlugin
+} from '../application';
+
+
+/* tslint:disable */
+/**
+ * The command palette token.
+ */
+export
+const ICommandPalette = new Token<ICommandPalette>('jupyter.services.commandpalette');
+/* tslint:enable */
+
+
+/**
+ * The default commmand palette extension.
+ */
+export
+const commandPaletteExtension: JupyterLabPlugin<ICommandPalette> = {
+  id: 'jupyter.services.commandpalette',
+  activate: activateCommandPalette
+};
+
+export
+interface ICommandPalette extends CommandPalette {}
+
+
+/**
+ *
+ */
+function activateCommandPalette(app: JupyterLab): ICommandPalette {
+  const { commands, keymap } = app;
+  const palette = new CommandPalette({ commands, keymap });
+
+  /**
+   * Activate the command palette (used as a command).
+   */
+  function activatePalette(): void {
+    app.shell.activateLeft(palette.id);
+    palette.inputNode.focus();
+    palette.inputNode.select();
+  }
+
+  /**
+   * Hide the command palette (used as a command).
+   */
+  function hidePalette(): void {
+    if (!palette.isHidden) {
+      app.shell.collapseLeft();
+    }
+  }
+
+  /**
+   * Toggle the command palette (used as a command).
+   */
+  function togglePalette(): void {
+    if (palette.isHidden) {
+      activatePalette();
+    } else {
+      hidePalette();
+    }
+  }
+
+  palette.id = 'command-palette';
+  palette.title.label = 'Commands';
+
+  app.commands.addCommand('command-palette:activate', {
+    execute: activatePalette,
+    label: 'Activate Command Palette'
+  });
+  app.commands.addCommand('command-palette:hide', {
+    execute: hidePalette,
+    label: 'Hide Command Palette'
+  });
+  app.commands.addCommand('command-palette:toggle', {
+    execute: togglePalette,
+    label: 'Toggle Command Palette'
+  });
+
+  app.shell.addToLeftArea(palette);
+
+  return palette;
+}