index.ts 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. // Copyright (c) Jupyter Development Team.
  2. // Distributed under the terms of the Modified BSD License.
  3. import {
  4. ILayoutRestorer, IRouter, JupyterLab, JupyterLabPlugin
  5. } from '@jupyterlab/application';
  6. import {
  7. ISettingRegistry
  8. } from '@jupyterlab/coreutils';
  9. import {
  10. ExtensionView
  11. } from '@jupyterlab/extensionmanager';
  12. /**
  13. * IDs of the commands added by this extension.
  14. */
  15. namespace CommandIDs {
  16. export
  17. const hideExtensionManager = 'extensionmanager:hide-main';
  18. export
  19. const showExtensionManager = 'extensionmanager:activate-main';
  20. export
  21. const toggleExtensionManager = 'extensionmanager:toggle-main';
  22. }
  23. /**
  24. * Initialization data for the extensionmanager plugin.
  25. */
  26. const plugin: JupyterLabPlugin<void> = {
  27. id: '@jupyterlab/extensionmanager-extension:plugin',
  28. autoStart: true,
  29. requires: [ILayoutRestorer, ISettingRegistry, IRouter],
  30. activate: async (app: JupyterLab, restorer: ILayoutRestorer, registry: ISettingRegistry, router: IRouter) => {
  31. const settings = await registry.load(plugin.id);
  32. const enabled = settings.composite['enabled'] as boolean;
  33. // If the extension is enabled or disabled, refresh the page.
  34. settings.changed.connect(() => { router.reload(); });
  35. if (!enabled) {
  36. return;
  37. }
  38. const { shell, serviceManager} = app;
  39. const view = new ExtensionView(serviceManager);
  40. view.id = 'extensionmanager.main-view';
  41. view.title.label = 'Extensions';
  42. restorer.add(view, view.id);
  43. shell.addToLeftArea(view);
  44. addCommands(app, view);
  45. }
  46. };
  47. /**
  48. * Add the main file view commands to the application's command registry.
  49. */
  50. function addCommands(app: JupyterLab, view: ExtensionView): void {
  51. const { commands } = app;
  52. commands.addCommand(CommandIDs.showExtensionManager, {
  53. label: 'Show Extension Manager',
  54. execute: () => { app.shell.activateById(view.id); }
  55. });
  56. commands.addCommand(CommandIDs.hideExtensionManager, {
  57. execute: () => {
  58. if (!view.isHidden) {
  59. app.shell.collapseLeft();
  60. }
  61. }
  62. });
  63. commands.addCommand(CommandIDs.toggleExtensionManager, {
  64. execute: () => {
  65. if (view.isHidden) {
  66. return commands.execute(CommandIDs.showExtensionManager, undefined);
  67. } else {
  68. return commands.execute(CommandIDs.hideExtensionManager, undefined);
  69. }
  70. }
  71. });
  72. // TODO: Also add to command palette
  73. }
  74. export default plugin;