瀏覽代碼

Clean up.

Afshin Darian 8 年之前
父節點
當前提交
f1f5ee20e1
共有 1 個文件被更改,包括 74 次插入77 次删除
  1. 74 77
      packages/docmanager/src/manager.ts

+ 74 - 77
packages/docmanager/src/manager.ts

@@ -135,48 +135,53 @@ class DocumentManager implements IDisposable {
   }
 
   /**
-   * Open a file and return the widget used to view it.
-   * Reveals an already existing editor.
-   *
-   * @param path - The file path to open.
-   *
-   * @param widgetName - The name of the widget factory to use. 'default' will use the default widget.
+   * Clone a widget.
    *
-   * @param kernel - An optional kernel name/id to override the default.
+   * @param widget - The source widget.
    *
-   * @returns The created widget, or `undefined`.
+   * @returns A new widget or `undefined`.
    *
    * #### Notes
-   * This function will return `undefined` if a valid widget factory
-   * cannot be found.
+   *  Uses the same widget factory and context as the source, or returns
+   *  `undefined` if the source widget is not managed by this manager.
    */
-  openOrReveal(path: string, widgetName='default', kernel?: Kernel.IModel): Widget {
-    let widget = this.findWidget(path, widgetName);
-    if (!widget) {
-      widget = this.open(path, widgetName, kernel);
-    } else {
-      this._opener.open(widget);
-    }
-    return widget;
+  cloneWidget(widget: Widget): Widget {
+    return this._widgetManager.cloneWidget(widget);
   }
 
   /**
-   * Open a file and return the widget used to view it.
-   *
-   * @param path - The file path to open.
-   *
-   * @param widgetName - The name of the widget factory to use. 'default' will use the default widget.
+   * Close all of the open documents.
+   */
+  closeAll(): Promise<void> {
+    return Promise.all(
+      toArray(map(this._contexts, context => {
+        return this._widgetManager.closeWidgets(context);
+      }))
+    ).then(() => undefined);
+  }
+
+  /**
+   * Close the widgets associated with a given path.
    *
-   * @param kernel - An optional kernel name/id to override the default.
+   * @param path - The target path.
+   */
+  closeFile(path: string): Promise<void> {
+    let context = this._contextForPath(path);
+    if (context) {
+      return this._widgetManager.closeWidgets(context);
+    }
+    return Promise.resolve(void 0);
+  }
+
+  /**
+   * Get the document context for a widget.
    *
-   * @returns The created widget, or `undefined`.
+   * @param widget - The widget of interest.
    *
-   * #### Notes
-   * This function will return `undefined` if a valid widget factory
-   * cannot be found.
+   * @returns The context associated with the widget, or `undefined`.
    */
-  open(path: string, widgetName='default', kernel?: Kernel.IModel): Widget {
-    return this._createOrOpenDocument('open', path, widgetName, kernel);
+  contextForWidget(widget: Widget): DocumentRegistry.Context {
+    return this._widgetManager.contextForWidget(widget);
   }
 
   /**
@@ -247,65 +252,60 @@ class DocumentManager implements IDisposable {
   }
 
   /**
-   * Get the document context for a widget.
-   *
-   * @param widget - The widget of interest.
+   * Create a new untitled file.
    *
-   * @returns The context associated with the widget, or `undefined`.
+   * @param options - The file content creation options.
    */
-  contextForWidget(widget: Widget): DocumentRegistry.Context {
-    return this._widgetManager.contextForWidget(widget);
+  newUntitled(options: Contents.ICreateOptions): Promise<Contents.IModel> {
+    if (options.type === 'file') {
+      options.ext = options.ext || '.txt';
+    }
+    return this.services.contents.newUntitled(options);
   }
 
   /**
-   * Clone a widget.
+   * Open a file and return the widget used to view it.
    *
-   * @param widget - The source widget.
+   * @param path - The file path to open.
    *
-   * @returns A new widget or `undefined`.
+   * @param widgetName - The name of the widget factory to use. 'default' will use the default widget.
+   *
+   * @param kernel - An optional kernel name/id to override the default.
+   *
+   * @returns The created widget, or `undefined`.
    *
    * #### Notes
-   *  Uses the same widget factory and context as the source, or returns
-   *  `undefined` if the source widget is not managed by this manager.
+   * This function will return `undefined` if a valid widget factory
+   * cannot be found.
    */
-  cloneWidget(widget: Widget): Widget {
-    return this._widgetManager.cloneWidget(widget);
+  open(path: string, widgetName='default', kernel?: Kernel.IModel): Widget {
+    return this._createOrOpenDocument('open', path, widgetName, kernel);
   }
 
   /**
-   * Close the widgets associated with a given path.
+   * Open a file and return the widget used to view it.
+   * Reveals an already existing editor.
    *
-   * @param path - The target path.
-   */
-  closeFile(path: string): Promise<void> {
-    let context = this._contextForPath(path);
-    if (context) {
-      return this._widgetManager.closeWidgets(context);
-    }
-    return Promise.resolve(void 0);
-  }
-
-  /**
-   * Close all of the open documents.
-   */
-  closeAll(): Promise<void> {
-    return Promise.all(
-      toArray(map(this._contexts, context => {
-        return this._widgetManager.closeWidgets(context);
-      }))
-    ).then(() => undefined);
-  }
-
-  /**
-   * Create a new untitled file.
+   * @param path - The file path to open.
    *
-   * @param options - The file content creation options.
+   * @param widgetName - The name of the widget factory to use. 'default' will use the default widget.
+   *
+   * @param kernel - An optional kernel name/id to override the default.
+   *
+   * @returns The created widget, or `undefined`.
+   *
+   * #### Notes
+   * This function will return `undefined` if a valid widget factory
+   * cannot be found.
    */
-  newUntitled(options: Contents.ICreateOptions): Promise<Contents.IModel> {
-    if (options.type === 'file') {
-      options.ext = options.ext || '.txt';
+  openOrReveal(path: string, widgetName='default', kernel?: Kernel.IModel): Widget {
+    let widget = this.findWidget(path, widgetName);
+    if (!widget) {
+      widget = this.open(path, widgetName, kernel);
+    } else {
+      this._opener.open(widget);
     }
-    return this.services.contents.newUntitled(options);
+    return widget;
   }
 
   /**
@@ -353,8 +353,7 @@ class DocumentManager implements IDisposable {
    */
   private _findContext(path: string, factoryName: string): Private.IContext {
     return find(this._contexts, context => {
-      return (context.factoryName === factoryName &&
-              context.path === path);
+      return context.factoryName === factoryName && context.path === path;
     });
   }
 
@@ -362,9 +361,7 @@ class DocumentManager implements IDisposable {
    * Get a context for a given path.
    */
   private _contextForPath(path: string): Private.IContext {
-    return find(this._contexts, context => {
-      return context.path === path;
-    });
+    return find(this._contexts, context => context.path === path);
   }
 
   /**