plugin.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Copyright (c) Jupyter Development Team.
  2. // Distributed under the terms of the Modified BSD License.
  3. 'use strict';
  4. import {
  5. IAppShell
  6. } from 'phosphide';
  7. import {
  8. Container, Token
  9. } from 'phosphor-di';
  10. import {
  11. ITerminalProvider
  12. } from '../lib';
  13. /**
  14. * Register the plugin contributions.
  15. *
  16. * @param container - The di container for type registration.
  17. *
  18. * #### Notes
  19. * This is called automatically when the plugin is loaded.
  20. */
  21. export
  22. function resolve(container: Container): void {
  23. container.resolve(DefaultHandler).then(handler => { handler.run(); });
  24. }
  25. /**
  26. * The default plugin for the example.
  27. */
  28. class DefaultHandler {
  29. /**
  30. * The dependencies required by the default plugin.
  31. */
  32. static requires: Token<any>[] = [IAppShell, ITerminalProvider];
  33. /**
  34. * Create a default plugin instance..
  35. */
  36. static create(shell: IAppShell, term: ITerminalProvider): DefaultHandler {
  37. return new DefaultHandler(shell, term);
  38. }
  39. /**
  40. * Construct a new default plugin.
  41. */
  42. constructor(shell: IAppShell, term: ITerminalProvider) {
  43. this._shell = shell;
  44. this._term = term;
  45. }
  46. /**
  47. * Create a terminal and add it to the main shell area.
  48. */
  49. run() {
  50. let term = this._term.createTerminal();
  51. this._shell.addToMainArea(term);
  52. }
  53. private _term: ITerminalProvider = null;
  54. private _shell: IAppShell = null;
  55. }