plugin.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // Copyright (c) Jupyter Development Team.
  2. // Distributed under the terms of the Modified BSD License.
  3. import {
  4. JupyterLab, JupyterLabPlugin
  5. } from '../application';
  6. import {
  7. ICommandPalette
  8. } from '../commandpalette';
  9. import {
  10. InstanceTracker
  11. } from '../common/instancetracker';
  12. import {
  13. ILayoutRestorer
  14. } from '../layoutrestorer';
  15. import {
  16. AboutModel, AboutWidget
  17. } from './';
  18. /**
  19. * The about page extension.
  20. */
  21. export
  22. const plugin: JupyterLabPlugin<void> = {
  23. id: 'jupyter.extensions.about',
  24. activate: activateAbout,
  25. autoStart: true,
  26. requires: [ICommandPalette, ILayoutRestorer]
  27. };
  28. function activateAbout(app: JupyterLab, palette: ICommandPalette, layout: ILayoutRestorer): void {
  29. const namespace = 'about-jupyterlab';
  30. const model = new AboutModel();
  31. const command = `${namespace}:show`;
  32. const category = 'Help';
  33. const tracker = new InstanceTracker<AboutWidget>({ namespace });
  34. layout.restore(tracker, {
  35. command,
  36. args: () => null,
  37. name: () => 'about'
  38. });
  39. let widget: AboutWidget;
  40. function newWidget(): AboutWidget {
  41. let widget = new AboutWidget();
  42. widget.model = model;
  43. widget.id = 'about';
  44. widget.title.label = 'About';
  45. widget.title.closable = true;
  46. tracker.add(widget);
  47. return widget;
  48. }
  49. app.commands.addCommand(command, {
  50. label: 'About JupyterLab',
  51. execute: () => {
  52. if (!widget || widget.isDisposed) {
  53. widget = newWidget();
  54. app.shell.addToMainArea(widget);
  55. }
  56. app.shell.activateMain(widget.id);
  57. }
  58. });
  59. palette.addItem({ command, category });
  60. }