view.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. // Copyright (c) Jupyter Development Team.
  2. // Distributed under the terms of the Modified BSD License.
  3. import {
  4. Menu, Widget
  5. } from '@phosphor/widgets';
  6. import {
  7. IJupyterLabMenu, IMenuExtender, JupyterLabMenu
  8. } from './labmenu';
  9. /**
  10. * An interface for a View menu.
  11. */
  12. export
  13. interface IViewMenu extends IJupyterLabMenu {
  14. /**
  15. * A map storing IKernelUsers for the Kernel menu.
  16. *
  17. * ### Notes
  18. * The key for the map may be used in menu labels.
  19. */
  20. readonly editorViewers: Map<string, IViewMenu.IEditorViewer<Widget>>;
  21. }
  22. /**
  23. * An extensible View menu for the application.
  24. */
  25. export
  26. class ViewMenu extends JupyterLabMenu implements IViewMenu {
  27. /**
  28. * Construct the view menu.
  29. */
  30. constructor(options: Menu.IOptions) {
  31. super(options);
  32. this.menu.title.label = 'View';
  33. this.editorViewers =
  34. new Map<string, IViewMenu.IEditorViewer<Widget>>();
  35. }
  36. /**
  37. * A map storing IEditorViewers for the View menu.
  38. *
  39. * ### Notes
  40. * The key for the map may be used in menu labels.
  41. */
  42. readonly editorViewers: Map<string, IViewMenu.IEditorViewer<Widget>>;
  43. /**
  44. * Dispose of the resources held by the view menu.
  45. */
  46. dispose(): void {
  47. this.editorViewers.clear();
  48. super.dispose();
  49. }
  50. }
  51. /**
  52. * Namespace for IViewMenu.
  53. */
  54. export
  55. namespace IViewMenu {
  56. /**
  57. * Interface for a text editor viewer to register
  58. * itself with the text editor extension points.
  59. */
  60. export
  61. interface IEditorViewer<T extends Widget> extends IMenuExtender<T> {
  62. /**
  63. * Whether to show line numbers in the editor.
  64. */
  65. toggleLineNumbers?: (widget: T) => void;
  66. /**
  67. * Whether to word-wrap the editor.
  68. */
  69. toggleWordWrap?: (widget: T) => void;
  70. /**
  71. * Whether to match brackets in the editor.
  72. */
  73. toggleMatchBrackets?: (widget: T) => void;
  74. /**
  75. * Whether line numbers are toggled.
  76. */
  77. lineNumbersToggled?: (widget: T) => boolean;
  78. /**
  79. * Whether word wrap is toggled.
  80. */
  81. wordWrapToggled?: (widget: T) => boolean;
  82. /**
  83. * Whether match brackets is toggled.
  84. */
  85. matchBracketsToggled?: (widget: T) => boolean;
  86. }
  87. }