Browse Source

Merge pull request #22 from blink1073/simplify-resolvers

Simplify resolvers
A. Darian 9 years ago
parent
commit
f00e487ce4

+ 21 - 14
examples/lab/index.css

@@ -15,6 +15,7 @@ body {
   left: 0;
   right: 0;
   bottom: 0;
+  font-size: 13px;
 }
 
 
@@ -300,7 +301,7 @@ body {
 }
 
 
-.p-CommandPalette .p-header {
+.p-CommandPalette-header {
   color: #757575;
   font-size: 11px;
   font-weight: 500;
@@ -308,55 +309,61 @@ body {
 }
 
 
-.p-CommandPalette .p-header hr {
+.p-CommandPalette-header hr {
   height: 1px;
   border-width: 0;
   background-color: #e0e0e0;
 }
 
 
-.p-CommandPalette .p-search {
+.p-CommandPalette-search {
   margin-bottom: 4px;
 }
 
 
-.p-CommandPalette .p-search .p-input-wrapper {
+.p-CommandPalette-inputWrapper {
   border: 1px solid #e0e0e0;
   padding: 4px;
 }
 
 
-.p-CommandPalette .p-search input {
+.p-CommandPalette-search input {
   width: 100%;
   border: none;
   outline: none;
 }
 
 
-.p-CommandPalette .p-command {
+.p-CommandPalette-command {
   color: #757575;
+  cursor: pointer;
   font-weight: 500;
   font-size: 13px;
-  padding: 3px 0px;
+  padding: 3px 0 3px 2px;
 }
 
+.p-CommandPalette-command.p-mod-disabled {
+  color: #d5d5d5;
+  cursor: not-allowed;
+}
 
-.p-CommandPalette .p-command .p-description {
+.p-CommandPalette-description {
   color: #9e9e9e;
   font-weight: 400;
   font-size: 10px;
 }
 
+.p-CommandPalette-command.p-mod-disabled .p-CommandPalette-description {
+  color: #d5d5d5;
+}
 
-.p-CommandPalette .p-command .p-shortcut {
+.p-CommandPalette-shortcut {
   margin-right: 15px;
 }
 
-
-.p-CommandPalette .p-command:focus,
-.p-CommandPalette .p-command:focus .p-description,
-.p-CommandPalette .p-command:focus .p-shortcut {
-  outline: 0;
+.p-CommandPalette-command.p-mod-focus,
+.p-CommandPalette-command.p-mod-focus .p-CommandPalette-description,
+.p-CommandPalette-command.p-mod-focus .p-CommandPalette-shortcut {
   background: #2196f3;
   color: #fff;
 }

+ 11 - 38
examples/lab/src/plugin.ts

@@ -41,42 +41,15 @@ import {
  */
 export
 function resolve(container: Container): void {
-  container.resolve(DefaultHandler).then(handler => { handler.run(); });
-}
-
-
-/**
- * The default plugin for the example.
- */
-class DefaultHandler {
-
-  /**
-   * The dependencies required by the default plugin.
-   */
-  static requires: Token<any>[] = [IAppShell, ICommandPalette, IFileBrowserWidget];
-
-  /**
-   * Create a default plugin instance..
-   */
-  static create(shell: IAppShell, palette: ICommandPalette, browser: IFileBrowserWidget): DefaultHandler {
-    return new DefaultHandler(shell, palette, browser);
-  }
-
-  /**
-   * Construct a new default plugin.
-   */
-  constructor(shell: IAppShell, palette: ICommandPalette, browser: IFileBrowserWidget) {
-    this._shell = shell;
-    this._palette = palette;
-    this._browser = browser;
-  }
-
-  run() {
-    this._browser.title.text = 'Files';
-    this._shell.addToLeftArea(this._browser, { rank: 40 });
-  }
-
-  private _shell: IAppShell = null;
-  private _palette: ICommandPalette = null;
-  private _browser: FileBrowserWidget = null;
+  container.resolve({
+    requires: [IAppShell, ICommandPalette, IFileBrowserWidget],
+    create: (shell, palette, browser) => {
+      palette.title.text = 'Commands';
+      shell.addToLeftArea(palette, { rank: 40 });
+      shell.attach(document.body);
+      window.addEventListener('resize', () => { shell.update(); });
+      browser.title.text = 'Files';
+      shell.addToLeftArea(browser, { rank: 40 });
+    }
+  });
 }

+ 0 - 0
examples/lab/untitled.txt


+ 1 - 1
package.json

@@ -11,7 +11,7 @@
     "jupyter-js-services": "^0.3.3",
     "jupyter-js-terminal": "^0.1.12",
     "jupyter-js-utils": "^0.2.6",
-    "phosphide": "^0.0.8",
+    "phosphide": "^0.1.0",
     "phosphor-codemirror": "^0.0.1",
     "phosphor-command": "^0.5.0",
     "phosphor-di": "^0.9.0",

+ 1 - 1
src/filebrowser/plugin.css

@@ -5,7 +5,7 @@
 .jp-FileBrowser {
   background-color: #F5F5F5;
   color: #757575;
-  font: 13px Helvetica, Arial, sans-serif;
+  font-family: "Helvetica Neue", Helvetica;
   min-width: 300px;
 }
 

+ 2 - 3
src/filebrowser/plugin.ts

@@ -7,7 +7,7 @@ import {
 } from 'jupyter-js-filebrowser';
 
 import {
-  Container, Lifetime, Token
+  Container, Token
 } from 'phosphor-di';
 
 import {
@@ -32,9 +32,8 @@ import './plugin.css';
 export
 function register(container: Container): void {
   container.register(IFileBrowserWidget, {
-    lifetime: Lifetime.Singleton,
     requires: [IServicesProvider],
-    create: (provider: IServicesProvider): IFileBrowserWidget => {
+    create: (provider) => {
       let contents = provider.contentsManager;
       let sessions = provider.notebookSessionManager;
       let model = new FileBrowserModel(contents, sessions);

+ 8 - 41
src/filehandler/plugin.ts

@@ -28,45 +28,12 @@ import {
  * This is called automatically when the plugin is loaded.
  */
 export
-function resolve(container: Container): Promise<void> {
-  return container.resolve(FileHandlerPlugin).then(plugin => plugin.run());
-}
-
-
-/**
- * A plugin that provides the default file handler to the IFileOpener.
- */
-class FileHandlerPlugin {
-
-  /**
-   * The dependencies required by the file handler.
-   */
-  static requires: Token<any>[] = [IServicesProvider, IFileOpener];
-
-  /**
-   * Create a new file handler plugin instance.
-   */
-  static create(services: IServicesProvider, opener: IFileOpener): FileHandlerPlugin {
-    return new FileHandlerPlugin(services, opener);
-  }
-
-  /**
-   * 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.registerDefault(this._handler);
-  }
-
-  private _handler: IFileHandler = null;
-  private _services: IServicesProvider = null;
-  private _opener: IFileOpener = null;
+function resolve(container: Container): void {
+  container.resolve({
+    requires: [IServicesProvider, IFileOpener],
+    create: (services, opener) => {
+      let handler = new FileHandler(services.contentsManager);
+      opener.registerDefault(handler);
+    }
+  });
 }

+ 7 - 40
src/imagehandler/plugin.ts

@@ -33,46 +33,13 @@ import {
  */
 export
 function resolve(container: Container): Promise<void> {
-  return container.resolve(ImageHandlerPlugin).then(plugin => plugin.run());
-}
-
-
-/**
- * A plugin that provides the default file handler to the IFileOpener.
- */
-class ImageHandlerPlugin {
-
-  /**
-   * The dependencies required by the file handler.
-   */
-  static requires: Token<any>[] = [IServicesProvider, IFileOpener];
-
-  /**
-   * Create a new file handler plugin instance.
-   */
-  static create(services: IServicesProvider, opener: IFileOpener): ImageHandlerPlugin {
-    return new ImageHandlerPlugin(services, opener);
-  }
-
-  /**
-   * Construct a new FileHandlerPlugin.
-   */
-  constructor(services: IServicesProvider, opener: IFileOpener) {
-    this._services = services;
-    this._opener = opener;
-  }
-
-  /**
-   * Initialize the plugin.
-   */
-  run(): void {
-    this._handler = new ImageHandler(this._services.contentsManager);
-    this._opener.register(this._handler);
-  }
-
-  private _handler: ImageHandler = null;
-  private _services: IServicesProvider = null;
-  private _opener: IFileOpener = null;
+  return container.resolve({
+    requires: [IServicesProvider, IFileOpener],
+    create: (services, opener) => {
+      let handler = new ImageHandler(services.contentsManager);
+      opener.register(handler);
+    }
+  });
 }
 
 

+ 10 - 7
src/notebook/plugin.ts

@@ -37,10 +37,13 @@ import './plugin.css';
  * This is called automatically when the plugin is loaded.
  */
 export
-function resolve(container: Container) {
-  Promise.all([container.resolve(IServicesProvider),
-               container.resolve(IFileOpener)]).then(([services, opener]) => {
-    opener.register(new NotebookFileHandler(services.contentsManager))
+function resolve(container: Container): void {
+  container.resolve({
+    requires: [IServicesProvider, IFileOpener],
+    create: (services, opener) => {
+      let handler = new NotebookFileHandler(services.contentsManager);
+      opener.register(handler);
+    }
   });
 }
 
@@ -57,7 +60,7 @@ class NotebookFileHandler extends AbstractFileHandler {
   get fileExtensions(): string[] {
     return ['.ipynb']
   }
-  
+
   /**
    * Get file contents given a path.
    */
@@ -75,7 +78,7 @@ class NotebookFileHandler extends AbstractFileHandler {
     return widget;
   }
 
-  
+
   protected populateWidget(widget: NotebookWidget, model: IContentsModel): Promise<void> {
     let nbdata: NBData = makedata(model);
     populateNotebookModel(widget.model, nbdata);
@@ -89,4 +92,4 @@ function makedata(a: IContentsModel): NBData {
     name: a.name,
     path: a.path
   }
-}
+}

+ 27 - 46
src/terminal/plugin.ts

@@ -22,51 +22,32 @@ import './plugin.css';
 
 
 export
-function resolve(container: Container): Promise<void> {
-  return container.resolve(TerminalPlugin).then(() => {});
-}
-
-
-class TerminalPlugin {
-
-  /**
-   * The dependencies required by the editor factory.
-   */
-  static requires: Token<any>[] = [IAppShell, ICommandPalette, ICommandRegistry];
-
-  /**
-   * Create a new terminal plugin instance.
-   */
-  static create(shell: IAppShell, palette: ICommandPalette, registry: ICommandRegistry): TerminalPlugin {
-    return new TerminalPlugin(shell, palette, registry);
-  }
-
-  /**
-   * Construct a terminal plugin.
-   */
-  constructor(shell: IAppShell, palette: ICommandPalette, registry: ICommandRegistry) {
-    let termCommandItem = {
-      // Move this to the terminal.
-      id: 'jupyter-plugins:new-terminal',
-      command: new DelegateCommand(() => {
-        let term = new TerminalWidget();
-        term.color = 'black';
-        term.background = 'white';
-        term.title.closable = true;
-        shell.addToMainArea(term);
-      })
+function resolve(container: Container): void {
+  container.resolve({
+    requires: [IAppShell, ICommandPalette, ICommandRegistry],
+    create: (shell, palette, registry) => {
+      let termCommandItem = {
+        // Move this to the terminal.
+        id: 'jupyter-plugins:new-terminal',
+        command: new DelegateCommand(() => {
+          let term = new TerminalWidget();
+          term.color = 'black';
+          term.background = 'white';
+          term.title.closable = true;
+          shell.addToMainArea(term);
+        })
+      }
+      registry.add([termCommandItem]);
+      let paletteItem = {
+        id: 'jupyter-plugins:new-terminal',
+        title: 'Terminal',
+        caption: ''
+      };
+      let section = {
+        text: 'New...',
+        items: [paletteItem]
+      }
+      palette.add([section]);
     }
-    registry.add([termCommandItem]);
-    let paletteItem = {
-      id: 'jupyter-plugins:new-terminal',
-      title: 'Terminal',
-      caption: ''
-    };
-    let section = {
-      text: 'New...',
-      items: [paletteItem]
-    }
-    palette.add([section]);
-  }
-
+  });
 }