Dave Willmer il y a 9 ans
Parent
commit
dad5f95c5e
4 fichiers modifiés avec 139 ajouts et 159 suppressions
  1. 2 2
      package.json
  2. 62 78
      src/documentmanager/plugin.ts
  3. 54 52
      src/notebook/plugin.ts
  4. 21 27
      src/terminal/plugin.ts

+ 2 - 2
package.json

@@ -15,9 +15,9 @@
     "jupyter-js-terminal": "^0.1.15",
     "jupyter-js-utils": "^0.3.0",
     "jupyter-js-widgets": "^0.0.6",
-    "phosphide": "^0.4.0",
+    "phosphide": "^0.5.0",
     "phosphor-codemirror": "^0.0.1",
-    "phosphor-command": "^0.8.0",
+    "phosphor-commandpalette": "^0.1.0",
     "phosphor-di": "^0.9.0",
     "phosphor-panel": "^1.0.0-rc.1",
     "phosphor-properties": "^2.0.0",

+ 62 - 78
src/documentmanager/plugin.ts

@@ -21,10 +21,6 @@ import {
 import * as arrays
  from 'phosphor-arrays';
 
-import {
-  SimpleCommand
-} from 'phosphor-command';
-
 import {
   Container, Token
 } from 'phosphor-di';
@@ -75,197 +71,185 @@ function resolve(container: Container): Promise<void> {
       // Create a command to add a new empty text file.
       // This requires an id and an instance of a command object.
       let newTextFileId = 'file-operations:new-text-file';
-      let newTextFileCommand = new SimpleCommand({
-        category: 'File Operations',
-        text: 'New Text File',
-        caption: 'Create a new text file',
-        handler: () => {
-          browser.newUntitled('file', '.txt').then(
-            contents => manager.open(contents)
-          );
-        }
-      });
 
       // Add the command to the command registry, shortcut manager
       // and command palette plugins.
       registry.add([
         {
           id: newTextFileId,
-          command: newTextFileCommand
+          handler: () => {
+            browser.newUntitled('file', '.txt').then(
+              contents => manager.open(contents)
+            );
+          }
         }
       ]);
       shortcuts.add([
         {
           sequence: ['Ctrl O'],
           selector: '*',
-          command: newTextFileId
+          command: newTextFileId,
+          args: void 0
         }
       ]);
       palette.add([
         {
           id: newTextFileId,
-          args: void 0
+          args: void 0,
+          category: 'File Operations',
+          text: 'New Text File',
+          caption: 'Create a new text file'
         }
       ]);
 
       // Add the command for a new notebook.
       let newNotebookId = 'file-operations:new-notebook';
-      let newNotebookCommand = new SimpleCommand({
-        category: 'File Operations',
-        text: 'New Notebook',
-        caption: 'Create a new Jupyter Notebook',
-        handler: () => {
-          browser.newUntitled('notebook').then(
-            contents => manager.open(contents)
-          );
-        }
-      });
 
       registry.add([
         {
           id: newNotebookId,
-          command: newNotebookCommand
+          handler: () => {
+            browser.newUntitled('notebook').then(
+              contents => manager.open(contents)
+            );
+          }
         }
       ]);
       shortcuts.add([
         {
           sequence: ['Ctrl Shift N'],
           selector: '*',
-          command: newNotebookId
+          command: newNotebookId,
+          args: void 0
         }
       ]);
       palette.add([
         {
           id: newNotebookId,
-          args: void 0
+          args: void 0,
+          category: 'File Operations',
+          text: 'New Notebook',
+          caption: 'Create a new Jupyter Notebook'
         }
       ]);
 
       // Add the command for saving a document.
       let saveDocumentId = 'file-operations:save';
-      let saveDocumentCommand = new SimpleCommand({
-        category: 'File Operations',
-        text: 'Save Document',
-        caption: 'Save the current document',
-        handler: () => {
-          manager.save();
-          return true;
-        }
-      });
 
       registry.add([
         {
           id: saveDocumentId,
-          command: saveDocumentCommand
+          handler: () => {
+            manager.save();
+            return true;
+          }
         }
       ]);
       shortcuts.add([
         {
           sequence: ['Accel S'],
           selector: `.${DOCUMENT_CLASS}.${FOCUS_CLASS}`,
-          command: saveDocumentId
+          command: saveDocumentId,
+          args: void 0
         }
       ]);
       palette.add([
         {
           id: saveDocumentId,
-          args: void 0
+          args: void 0,
+          category: 'File Operations',
+          text: 'Save Document',
+          caption: 'Save the current document'
         }
       ]);
 
       // Add the command for reverting a document.
       let revertDocumentId = 'file-operations:revert';
-      let revertDocumentCommand = new SimpleCommand({
-        category: 'File Operations',
-        text: 'Revert Document',
-        caption: 'Revert the current document',
-        handler: () => {
-          manager.revert();
-          return true;
-        }
-      });
 
       registry.add([
         {
           id: revertDocumentId,
-          command: revertDocumentCommand
+          handler: () => {
+            manager.revert();
+            return true;
+          }
         }
       ]);
       shortcuts.add([
         {
           sequence: ['Accel R'],
           selector: `.${DOCUMENT_CLASS}.${FOCUS_CLASS}`,
-          command: revertDocumentId
+          command: revertDocumentId,
+          args: void 0
         }
       ]);
       palette.add([
         {
           id: revertDocumentId,
-          args: void 0
+          args: void 0,
+          category: 'File Operations',
+          text: 'Revert Document',
+          caption: 'Revert the current document'
         }
       ]);
 
       // Add the command for closing a document.
       let closeDocumentId = 'file-operations:close';
-      let closeDocumentCommand = new SimpleCommand({
-        category: 'File Operations',
-        text: 'Close Document',
-        caption: 'Close the current document',
-        handler: () => {
-          manager.close();
-          return true;
-        }
-      });
 
       registry.add([
         {
           id: closeDocumentId,
-          command: closeDocumentCommand
+          handler: () => {
+            manager.close();
+            return true;
+          }
         }
       ]);
       shortcuts.add([
         {
           sequence: ['Ctrl Q'],
           selector: `.${DOCUMENT_CLASS}.${FOCUS_CLASS}`,
-          command: closeDocumentId
+          command: closeDocumentId,
+          args: void 0
         }
       ]);
       palette.add([
         {
           id: closeDocumentId,
-          args: void 0
+          args: void 0,
+          category: 'File Operations',
+          text: 'Close Document',
+          caption: 'Close the current document'
         }
       ]);
 
       // Add the command for closing all documents.
       let closeAllId = 'file-operations:close-all';
-      let closeAllCommand = new SimpleCommand({
-        category: 'File Operations',
-        text: 'Close All',
-        caption: 'Close all open documents',
-        handler: () => {
-          manager.closeAll();
-          return true;
-        }
-      });
 
       registry.add([
         {
           id: closeAllId,
-          command: closeAllCommand
+          handler: () => {
+            manager.closeAll();
+            return true;
+          }
         }
       ]);
       shortcuts.add([
         {
           sequence: ['Ctrl Shift Q'],
           selector: `.${DOCUMENT_CLASS}`,
-          command: closeAllId
+          command: closeAllId,
+          args: void 0
         }
       ]);
       palette.add([
         {
           id: closeAllId,
-          args: void 0
+          args: void 0,
+          category: 'File Operations',
+          text: 'Close All',
+          caption: 'Close all open documents'
         }
       ]);
 

+ 54 - 52
src/notebook/plugin.ts

@@ -21,13 +21,9 @@ import {
 } from 'jupyter-js-services';
 
 import {
-  ICommandRegistry, IShortcutManager
+  ICommandRegistry, IShortcutManager, ICommandPalette
 } from 'phosphide';
 
-import {
-  SimpleCommand
-} from 'phosphor-command';
-
 import {
   Container
 } from 'phosphor-di';
@@ -50,46 +46,9 @@ import {
 
 
 let executeCellCommandId = 'notebook:execute-selected-cell';
-let executeCommand = new SimpleCommand({
-  category: 'Notebook Operations',
-  text: 'Execute current cell',
-  caption: 'Execute the current cell',
-  handler: (args) => {
-    executeSelectedCell(args.model, args.session);
-  }
-})
-
 let renderCellCommandId = 'notebook:render-selected-cell';
-let renderCommand = new SimpleCommand({
-  category: 'Notebook Operations',
-  text: 'Render current markdown cell',
-  caption: 'Render the current markdown cell',
-  handler: (args) => {
-    renderSelectedCell(args.model);
-  }
-})
-
-
 let selectNextCellCommandId = 'notebook:select-next-cell';
-let selectNextCell = new SimpleCommand({
-  category: 'Notebook Operations',
-  text: 'Select next cell',
-  caption: 'Select next cell',
-  handler: (args) => {
-    args.model.selectNextCell();
-  }
-})
-
 let selectPreviousCellCommandId = 'notebook:select-previous-cell';
-let selectPreviousCell = new SimpleCommand({
-  category: 'Notebook Operations',
-  text: 'Select previous cell',
-  caption: 'Select previous cell',
-  handler: (args) => {
-    args.model.selectPreviousCell();
-  }
-})
-
 
 let notebookContainerClass = 'jp-NotebookContainer';
 
@@ -104,24 +63,39 @@ let notebookContainerClass = 'jp-NotebookContainer';
 export
 function resolve(container: Container): Promise<AbstractFileHandler> {
   return container.resolve({
-    requires: [IServicesProvider, IDocumentManager, ICommandRegistry, IShortcutManager],
+    requires: [IServicesProvider, IDocumentManager, ICommandRegistry, IShortcutManager, ICommandPalette],
     create: (services: IServicesProvider, manager: IDocumentManager,
-             registry: ICommandRegistry, shortcuts: IShortcutManager) => {
-      let handler = new NotebookFileHandler(services.contentsManager, services.notebookSessionManager, shortcuts);
+             registry: ICommandRegistry, shortcuts: IShortcutManager,
+             palette: ICommandPalette) => {
+      let handler = new NotebookFileHandler(
+        services.contentsManager,
+        services.notebookSessionManager,
+        shortcuts,
+        palette
+      );
       manager.register(handler);
       registry.add([{
         id: executeCellCommandId,
-        command: executeCommand
+        handler: (args) => {
+          executeSelectedCell(args.model, args.session);
+        }
       }, {
         id: renderCellCommandId,
-        command: renderCommand
+        handler: (args) => {
+          renderSelectedCell(args.model);
+        }
       }, {
         id: selectNextCellCommandId,
-        command: selectNextCell
+        handler: (args) => {
+          args.model.selectNextCell();
+        }
       }, {
         id: selectPreviousCellCommandId,
-        command: selectPreviousCell
-      }])
+        handler: (args) => {
+          args.model.selectPreviousCell();
+        }
+      }]);
+
       return handler;
     }
   });
@@ -191,10 +165,11 @@ export
 class NotebookFileHandler extends AbstractFileHandler {
 
   constructor(contents: IContentsManager, session: INotebookSessionManager,
-  shortcuts: IShortcutManager) {
+  shortcuts: IShortcutManager, palette: ICommandPalette) {
     super(contents);
     this.session = session;
     this.shortcuts = shortcuts;
+    this.palette = palette;
   }
 
   /**
@@ -253,7 +228,33 @@ class NotebookFileHandler extends AbstractFileHandler {
         selector: `${prefix} .jp-Cell`,
         command: selectPreviousCellCommandId,
         args: {model: model}
-      }])
+      }]);
+
+      this.palette.add([{
+        id: executeCellCommandId,
+        args: {model: model, session: s},
+        category: 'Notebook Operations',
+        text: 'Execute current cell',
+        caption: 'Execute the current cell'
+      }, {
+        id: renderCellCommandId,
+        args: {model: model},
+        category: 'Notebook Operations',
+        text: 'Render current markdown cell',
+        caption: 'Render the current markdown cell'
+      }, {
+        id: selectNextCellCommandId,
+        args: {model: model},
+        category: 'Notebook Operations',
+        text: 'Select next cell',
+        caption: 'Select next cell'
+      }, {
+        id: selectPreviousCellCommandId,
+        args: {model: model},
+        category: 'Notebook Operations',
+        text: 'Select previous cell',
+        caption: 'Select previous cell'
+      }]);
 
       s.kernel.registerCommTarget('jupyter.widget', (comm, msg) => {
         console.log('comm message', msg);
@@ -293,6 +294,7 @@ class NotebookFileHandler extends AbstractFileHandler {
     return Promise.resolve(void 0);
   }
 
+  palette: ICommandPalette;
   session: INotebookSessionManager;
   shortcuts: IShortcutManager;
   notebookId: number = 0;

+ 21 - 27
src/terminal/plugin.ts

@@ -10,10 +10,6 @@ import {
   IAppShell, ICommandPalette, ICommandRegistry, IShortcutManager
 } from 'phosphide';
 
-import {
-  SimpleCommand
-} from 'phosphor-command';
-
 import {
   Container, Token
 } from 'phosphor-di';
@@ -30,44 +26,42 @@ function resolve(container: Container): Promise<void> {
     create: (shell: IAppShell, palette: ICommandPalette, registry: ICommandRegistry, shortcuts: IShortcutManager) => {
 
       let newTerminalId = 'terminal:new';
-      let newTerminalCommand = new SimpleCommand({
-        category: 'Terminal',
-        text: 'New Terminal',
-        caption: 'Start a new terminal session',
-        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;
-          }
-        }
-      });
 
       registry.add([
         {
           id: newTerminalId,
-          command: newTerminalCommand
+          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
+          command: newTerminalId,
+          args: void 0
         }
       ]);
       palette.add([
         {
           id: newTerminalId,
-          args: void 0
+          args: void 0,
+          category: 'Terminal',
+          text: 'New Terminal',
+          caption: 'Start a new terminal session'
         }
       ]);
     }