view.ts 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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.title.label = 'View';
  33. this.editorViewers =
  34. new Map<string, IViewMenu.IEditorViewer<Widget>>();
  35. }
  36. /**
  37. * A map storing IKernelUsers for the Kernel 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. /**
  45. * Namespace for IViewMenu.
  46. */
  47. export
  48. namespace IViewMenu {
  49. /**
  50. * Interface for a text editor viewer to register
  51. * itself with the text editor extension points.
  52. */
  53. export
  54. interface IEditorViewer<T extends Widget> extends IMenuExtender<T> {
  55. /**
  56. * Whether to show line numbers in the editor.
  57. */
  58. toggleLineNumbers?: (widget: T) => void;
  59. /**
  60. * Whether to word-wrap the editor.
  61. */
  62. toggleWordWrap?: (widget: T) => void;
  63. /**
  64. * Whether to match brackets in the editor.
  65. */
  66. toggleMatchBrackets?: (widget: T) => void;
  67. /**
  68. * Whether line numbers are toggled.
  69. */
  70. lineNumbersToggled?: (widget: T) => boolean;
  71. /**
  72. * Whether word wrap is toggled.
  73. */
  74. wordWrapToggled?: (widget: T) => boolean;
  75. /**
  76. * Whether match brackets is toggled.
  77. */
  78. matchBracketsToggled?: (widget: T) => boolean;
  79. }
  80. }