Ver Fonte

Update command palette plugin commands.

Afshin Darian há 8 anos atrás
pai
commit
c0bb74c16f
2 ficheiros alterados com 28 adições e 40 exclusões
  1. 10 5
      src/commandpalette/index.ts
  2. 18 35
      src/commandpalette/plugin.ts

+ 10 - 5
src/commandpalette/index.ts

@@ -17,13 +17,18 @@ import {
 
 
 /**
- * The map of command ids used by the commandpalette plugin.
+ * The command IDs used by the command palette plugin.
  */
 export
-const cmdIds = {
-  activate: 'command-palette:activate',
-  hide: 'command-palette:hide',
-  toggle: 'command-palette:toggle'
+namespace CommandIDs {
+  export
+  const activate = 'command-palette:activate';
+
+  export
+  const hide = 'command-palette:hide';
+
+  export
+  const toggle = 'command-palette:toggle';
 };
 
 

+ 18 - 35
src/commandpalette/plugin.ts

@@ -20,7 +20,7 @@ import {
 } from '../instancerestorer';
 
 import {
-  ICommandPalette, IPaletteItem, cmdIds
+  CommandIDs, ICommandPalette, IPaletteItem
 } from './';
 
 
@@ -102,44 +102,27 @@ function activate(app: JupyterLab, restorer: IInstanceRestorer): ICommandPalette
   palette.id = 'command-palette';
   palette.title.label = 'Commands';
 
-  /**
-   * Activate the command palette within the app shell (used as a command).
-   */
-  function activatePalette(): void {
-    app.shell.activateLeft(palette.id);
-    palette.activate();
-  }
-
-  /**
-   * Hide the command palette within the app shell (used as a command).
-   */
-  function hidePalette(): void {
-    if (!palette.isHidden) {
-      app.shell.collapseLeft();
-    }
-  }
-
-  /**
-   * Toggle the command palette within the app shell (used as a command).
-   */
-  function togglePalette(): void {
-    if (palette.isHidden) {
-      activatePalette();
-    } else {
-      hidePalette();
-    }
-  }
-
-  app.commands.addCommand(cmdIds.activate, {
-    execute: activatePalette,
+  app.commands.addCommand(CommandIDs.activate, {
+    execute: () => { app.shell.activateLeft(palette.id); },
     label: 'Activate Command Palette'
   });
-  app.commands.addCommand(cmdIds.hide, {
-    execute: hidePalette,
+
+  app.commands.addCommand(CommandIDs.hide, {
+    execute: () => {
+      if (!palette.isHidden) {
+        app.shell.collapseLeft();
+      }
+    },
     label: 'Hide Command Palette'
   });
-  app.commands.addCommand(cmdIds.toggle, {
-    execute: togglePalette,
+
+  app.commands.addCommand(CommandIDs.toggle, {
+    execute: () => {
+      if (palette.isHidden) {
+        return app.commands.execute(CommandIDs.activate, void 0);
+      }
+      return app.commands.execute(CommandIDs.hide, void 0);
+    },
     label: 'Toggle Command Palette'
   });