plugin.ts 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. // Copyright (c) Jupyter Development Team.
  2. // Distributed under the terms of the Modified BSD License.
  3. import {
  4. ServiceManager
  5. } from 'jupyter-js-services';
  6. import {
  7. Application
  8. } from 'phosphide/lib/core/application';
  9. import {
  10. Widget
  11. } from 'phosphor-widget';
  12. /**
  13. * The landing page extension.
  14. */
  15. export
  16. const landingExtension = {
  17. id: 'jupyter.extensions.landing',
  18. requires: [ServiceManager],
  19. activate: activateLanding
  20. };
  21. function activateLanding(app: Application, services: ServiceManager): void {
  22. let widget = new Widget();
  23. widget.id = 'landing-jupyterlab';
  24. widget.title.text = 'Launcher';
  25. widget.title.closable = true;
  26. widget.addClass('jp-Landing');
  27. let dialog = document.createElement('div');
  28. dialog.className = 'jp-Landing-dialog';
  29. widget.node.appendChild(dialog);
  30. let title = document.createElement('span');
  31. title.textContent = 'Welcome to';
  32. title.className = 'jp-Landing-title';
  33. dialog.appendChild(title);
  34. let logo = document.createElement('span');
  35. logo.className = 'jp-ImageJupyterLab jp-Landing-logo';
  36. dialog.appendChild(logo);
  37. let subtitle = document.createElement('span');
  38. subtitle.textContent = 'alpha';
  39. subtitle.className = 'jp-Landing-subtitle';
  40. dialog.appendChild(subtitle);
  41. let subtext = document.createElement('span');
  42. subtext.textContent = 'This is not ready for general usage yet.';
  43. subtext.className = 'jp-Landing-subtext';
  44. dialog.appendChild(subtext);
  45. let header = document.createElement('span');
  46. header.textContent = 'Start a new activity:';
  47. header.className = 'jp-Landing-header';
  48. dialog.appendChild(header);
  49. let body = document.createElement('div');
  50. body.className = 'jp-Landing-body';
  51. dialog.appendChild(body);
  52. for (let name of ['Notebook', 'Console', 'Terminal', 'Text Editor']) {
  53. let column = document.createElement('div');
  54. body.appendChild(column);
  55. column.className = 'jp-Landing-column';
  56. let img = document.createElement('span');
  57. let imgName = name.replace(' ', '');
  58. img.className = `jp-Image${imgName} jp-Landing-image`;
  59. column.appendChild(img);
  60. let text = document.createElement('span');
  61. text.textContent = name;
  62. text.className = 'jp-Landing-text';
  63. column.appendChild(text);
  64. }
  65. let img = body.getElementsByClassName('jp-ImageNotebook')[0];
  66. img.addEventListener('click', () => {
  67. app.commands.execute('file-operations:new-notebook');
  68. });
  69. let tour = document.createElement('span')
  70. tour.textContent = 'Take a tour';
  71. tour.className = 'jp-Landing-tour';
  72. dialog.appendChild(tour);
  73. tour.addEventListener('click', () => {
  74. app.commands.execute('about-jupyterlab:show');
  75. });
  76. img = body.getElementsByClassName('jp-ImageConsole')[0];
  77. img.addEventListener('click', () => {
  78. app.commands.execute(`console:create-${services.kernelspecs.default}`);
  79. });
  80. img = body.getElementsByClassName('jp-ImageTextEditor')[0];
  81. img.addEventListener('click', () => {
  82. app.commands.execute('file-operations:new-text-file');
  83. });
  84. img = body.getElementsByClassName('jp-ImageTerminal')[0];
  85. img.addEventListener('click', () => {
  86. app.commands.execute('terminal:create-new');
  87. });
  88. app.commands.add([{
  89. id: 'jupyterlab-launcher:show',
  90. handler: () => {
  91. if (!widget.isAttached) {
  92. app.shell.addToMainArea(widget);
  93. }
  94. app.shell.activateMain(widget.id);
  95. }
  96. }]);
  97. app.palette.add([{
  98. command: 'jupyterlab-launcher:show',
  99. text: 'JupyterLab Launcher',
  100. category: 'Help'
  101. }]);
  102. app.shell.addToMainArea(widget);
  103. }