Ver Fonte

Merge remote-tracking branch 'upstream/master' into notebook

Jason Grout há 9 anos atrás
pai
commit
a086d58aae

+ 6 - 7
examples/lab/src/plugin.ts

@@ -95,18 +95,17 @@ class DefaultHandler {
     let newFileCommandItem = {
       id: 'jupyter-plugins:new-text-file',
       command: new DelegateCommand(() => {
-        // TODO
-        let editor = new CodeMirrorWidget();
-        editor.title.text = 'untitled.txt'
-        this._shell.addToMainArea(editor);
+        this._browser.newUntitled('file', '.txt').then(
+          contents => this._opener.open(contents.path)
+        );
       })
     }
 /*    let newNotebookCommandItem = {
       id: 'jupyter-plugins:new-notebook',
       command: new DelegateCommand(() => {
-        this._notebook.createNotebook('test.ipynb').then(notebook => {
-          this._shell.addToMainArea(notebook);
-        });
+        this._browser.newUntitled('notebook').then(
+          contents => this._opener.open(contents.path)
+        );
       })
     }
     */

+ 4 - 4
package.json

@@ -6,11 +6,11 @@
   "typings": "lib/index.d.ts",
   "dependencies": {
     "codemirror": "^5.10.0",
-    "jupyter-js-filebrowser": "^0.3.0",
+    "jupyter-js-filebrowser": "^0.3.4",
     "jupyter-js-notebook": "^0.2.1",
-    "jupyter-js-services": "^0.3.0",
-    "jupyter-js-terminal": "^0.1.9",
-    "jupyter-js-utils": "^0.2.4",
+    "jupyter-js-services": "^0.3.3",
+    "jupyter-js-terminal": "^0.1.12",
+    "jupyter-js-utils": "^0.2.6",
     "phosphide": "^0.0.8",
     "phosphor-codemirror": "^0.0.1",
     "phosphor-command": "^0.5.0",

+ 10 - 7
src/filehandler/plugin.ts

@@ -29,14 +29,14 @@ import {
  */
 export
 function resolve(container: Container): Promise<void> {
-  return container.resolve(DefaultFileHandler).then(handler => handler.run());
+  return container.resolve(FileHandlerPlugin).then(plugin => plugin.run());
 }
 
 
 /**
- * An implementation of an IFileHandler.
+ * A plugin that provides the default file handler to the IFileOpener.
  */
-class DefaultFileHandler {
+class FileHandlerPlugin {
 
   /**
    * The dependencies required by the file handler.
@@ -44,20 +44,23 @@ class DefaultFileHandler {
   static requires: Token<any>[] = [IServicesProvider, IFileOpener];
 
   /**
-   * Create a new file handler instance.
+   * Create a new file handler plugin instance.
    */
-  static create(services: IServicesProvider, opener: IFileOpener): DefaultFileHandler {
-    return new DefaultFileHandler(services, opener);
+  static create(services: IServicesProvider, opener: IFileOpener): FileHandlerPlugin {
+    return new FileHandlerPlugin(services, opener);
   }
 
   /**
-   * Construct a new DefaultFileHandler.
+   * Construct a new FileHandlerPlugin.
    */
   constructor(services: IServicesProvider, opener: IFileOpener) {
     this._services = services;
     this._opener = opener;
   }
 
+  /**
+   * Initialize the plugin.
+   */
   run(): void {
     this._handler = new FileHandler(this._services.contentsManager);
     this._opener.register(this._handler, true);

+ 5 - 0
src/fileopener/index.ts

@@ -38,6 +38,11 @@ interface IFileHandler {
  */
 export
 interface IFileOpener {
+  /**
+   * Open the file and add the widget to the application shell.
+   */
+  open(path: string): Promise<void>;
+
   /**
    * Register a file opener.
    * 

+ 18 - 9
src/fileopener/plugin.ts

@@ -75,9 +75,9 @@ class FileOpener implements IFileOpener {
   }
 
   /**
-   * Handle an `openRequested` signal by invoking the appropriate handler.
+   * Open a file and add it to the application shell.
    */
-  private _openRequested(browser: FileBrowserWidget, path: string): void {
+  open(path: string): Promise<void> {
     if (this._handlers.length === 0) {
       return;
     }
@@ -89,8 +89,7 @@ class FileOpener implements IFileOpener {
     }
     // If there was only one match, use it.
     if (handlers.length === 1) {
-      this._open(handlers[0], path);
-      return;
+      return this._open(handlers[0], path);
 
     // If there were no matches, look for default handler(s).
     } else if (handlers.length === 0) {
@@ -101,20 +100,30 @@ class FileOpener implements IFileOpener {
 
     // If there we no matches, do nothing.
     if (handlers.length == 0) {
-      console.warn('Could not open file ')
+      return Promise.reject(new Error(`Could not open file '${path}'`));
 
     // If there was one handler, use it.
     } else if (handlers.length === 1) {
-      this._open(handlers[0], path);
+      return this._open(handlers[0], path);
     } else {
       // There are more than one possible handlers.
       // TODO: Ask the user to choose one.
-      this._open(handlers[0], path);
+      return this._open(handlers[0], path);
     }
   }
 
-  private _open(handler: IFileHandler, path: string): void {
-    handler.open(path).then(widget => {
+  /**
+   * Handle an `openRequested` signal by invoking the appropriate handler.
+   */
+  private _openRequested(browser: FileBrowserWidget, path: string): void {
+    this.open(path);
+  }
+
+  /**
+   * Open a file and add it to the application shell.
+   */
+  private _open(handler: IFileHandler, path: string): Promise<void> {
+    return handler.open(path).then(widget => {
       this._appShell.addToMainArea(widget);
     });
   }