view.ts 1.9 KB

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