index.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Copyright (c) Jupyter Development Team.
  2. // Distributed under the terms of the Modified BSD License.
  3. import {
  4. ILayoutRestorer, JupyterLab, JupyterLabPlugin
  5. } from '@jupyterlab/application';
  6. import {
  7. each
  8. } from '@phosphor/algorithm';
  9. import {
  10. TabBar, Widget
  11. } from '@phosphor/widgets';
  12. import '../style/index.css';
  13. /**
  14. * The default tab manager extension.
  15. */
  16. const plugin: JupyterLabPlugin<void> = {
  17. id: '@jupyterlab/tabmanager-extension:plugin',
  18. activate: (app: JupyterLab, restorer: ILayoutRestorer): void => {
  19. const { shell } = app;
  20. const tabs = new TabBar<Widget>({ orientation: 'vertical' });
  21. const header = document.createElement('header');
  22. restorer.add(tabs, 'tab-manager');
  23. tabs.id = 'tab-manager';
  24. tabs.title.label = 'Tabs';
  25. header.textContent = 'Open Tabs';
  26. tabs.node.insertBefore(header, tabs.contentNode);
  27. shell.addToLeftArea(tabs, { rank: 600 });
  28. app.restored.then(() => {
  29. const populate = () => {
  30. tabs.clearTabs();
  31. each(shell.widgets('main'), widget => { tabs.addTab(widget.title); });
  32. };
  33. // Connect signal handlers.
  34. shell.layoutModified.connect(() => { populate(); });
  35. tabs.tabActivateRequested.connect((sender, tab) => {
  36. shell.activateById(tab.title.owner.id);
  37. });
  38. tabs.tabCloseRequested.connect((sender, tab) => {
  39. tab.title.owner.close();
  40. });
  41. // Populate the tab manager.
  42. populate();
  43. });
  44. },
  45. autoStart: true,
  46. requires: [ILayoutRestorer]
  47. };
  48. /**
  49. * Export the plugin as default.
  50. */
  51. export default plugin;