Browse Source

Update terminal plugin

Steven Silvester 9 years ago
parent
commit
bba1008c9b
2 changed files with 42 additions and 83 deletions
  1. 0 32
      src/terminal/index.ts
  2. 42 51
      src/terminal/plugin.ts

+ 0 - 32
src/terminal/index.ts

@@ -1,32 +0,0 @@
-// Copyright (c) Jupyter Development Team.
-// Distributed under the terms of the Modified BSD License.
-'use strict';
-
-import {
-  TerminalWidget, ITerminalOptions
-} from 'jupyter-js-terminal';
-
-import {
-  Token
-} from 'phosphor-di';
-
-
-
-/**
- * A factory for creating a Jupyter editor.
- */
-export
-interface ITerminalProvider {
-
-  /**
-   * Create a new Terminal instance.
-   */
-  createTerminal(options?: ITerminalOptions): TerminalWidget;
-}
-
-
-/**
- * The dependency token for the `ITerminalProvider` interface.
- */
-export
-const ITerminalProvider = new Token<ITerminalProvider>('jupyter-js-plugins.ITerminalProvider');

+ 42 - 51
src/terminal/plugin.ts

@@ -7,63 +7,54 @@ import {
 } from 'jupyter-js-terminal';
 
 import {
-  IAppShell, ICommandPalette, ICommandRegistry, IShortcutManager
-} from 'phosphide';
-
-import {
-  Container, Token
-} from 'phosphor-di';
+  Application
+} from 'phosphide/lib/core/application';
 
 import {
   TabPanel
 } from 'phosphor-tabs';
 
 
+/**
+ * The default terminal extension. 
+ */
 export
-function resolve(container: Container): Promise<void> {
-  return container.resolve({
-    requires: [IAppShell, ICommandPalette, ICommandRegistry, IShortcutManager],
-    create: (shell: IAppShell, palette: ICommandPalette, registry: ICommandRegistry, shortcuts: IShortcutManager) => {
-
-      let newTerminalId = 'terminal:new';
-
-      registry.add([
-        {
-          id: newTerminalId,
-          handler: () => {
-            let term = new TerminalWidget();
-            term.color = 'black';
-            term.background = 'white';
-            term.title.closable = true;
-            shell.addToMainArea(term);
-            let stack = term.parent;
-            if (!stack) {
-              return;
-            }
-            let tabs = stack.parent;
-            if (tabs instanceof TabPanel) {
-              tabs.currentWidget = term;
-            }
-          }
-        }
-      ]);
-      shortcuts.add([
-        {
-          sequence: ['Ctrl T'],
-          selector: '*',
-          command: newTerminalId,
-          args: void 0
-        }
-      ]);
-      palette.add([
-        {
-          id: newTerminalId,
-          args: void 0,
-          category: 'Terminal',
-          text: 'New Terminal',
-          caption: 'Start a new terminal session'
-        }
-      ]);
+const terminalExtension = {
+  id: 'jupyter.extensions.terminal',
+  activate: activateTerminal
+};
+
+
+function activateTerminal(app: Application): Promise<void> {
+
+  let newTerminalId = 'terminal:new';
+
+  app.commands.add([{
+    id: newTerminalId,
+    handler: () => {
+      let term = new TerminalWidget();
+      term.color = 'black';
+      term.background = 'white';
+      term.title.closable = true;
+      app.shell.addToMainArea(term);
+      let stack = term.parent;
+      if (!stack) {
+        return;
+      }
+      let tabs = stack.parent;
+      if (tabs instanceof TabPanel) {
+        tabs.currentWidget = term;
+      }
+    }
+  }]);
+  app.palette.add([
+    {
+      command: newTerminalId,
+      category: 'Terminal',
+      text: 'New Terminal',
+      caption: 'Start a new terminal session'
     }
-  });
+  ]);
+
+  return Promise.resolve(void 0);
 }