model.ts 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. // Copyright (c) Jupyter Development Team.
  2. // Distributed under the terms of the Modified BSD License.
  3. import { IDebugger } from './tokens';
  4. import { ISignal, Signal } from '@lumino/signaling';
  5. import { BreakpointsModel } from './panels/breakpoints/model';
  6. import { CallstackModel } from './panels/callstack/model';
  7. import { SourcesModel } from './panels/sources/model';
  8. import { KernelSourcesModel } from './panels/kernelSources/model';
  9. import { VariablesModel } from './panels/variables/model';
  10. /**
  11. * A model for a debugger.
  12. */
  13. export class DebuggerModel implements IDebugger.Model.IService {
  14. /**
  15. * Instantiate a new DebuggerModel
  16. */
  17. constructor() {
  18. this.breakpoints = new BreakpointsModel();
  19. this.callstack = new CallstackModel();
  20. this.variables = new VariablesModel();
  21. this.sources = new SourcesModel({
  22. currentFrameChanged: this.callstack.currentFrameChanged
  23. });
  24. this.kernelSources = new KernelSourcesModel();
  25. }
  26. /**
  27. * The breakpoints model.
  28. */
  29. readonly breakpoints: BreakpointsModel;
  30. /**
  31. * The callstack model.
  32. */
  33. readonly callstack: CallstackModel;
  34. /**
  35. * The variables model.
  36. */
  37. readonly variables: VariablesModel;
  38. /**
  39. * The sources model.
  40. */
  41. readonly sources: SourcesModel;
  42. /**
  43. * The kernel sources model.
  44. */
  45. readonly kernelSources: KernelSourcesModel;
  46. /**
  47. * A signal emitted when the debugger widget is disposed.
  48. */
  49. get disposed(): ISignal<this, void> {
  50. return this._disposed;
  51. }
  52. /**
  53. * Whether the kernel support rich variable rendering based on mime type.
  54. */
  55. get hasRichVariableRendering(): boolean {
  56. return this._hasRichVariableRendering;
  57. }
  58. set hasRichVariableRendering(v: boolean) {
  59. this._hasRichVariableRendering = v;
  60. }
  61. /**
  62. * Whether the model is disposed.
  63. */
  64. get isDisposed(): boolean {
  65. return this._isDisposed;
  66. }
  67. /**
  68. * The set of threads in stopped state.
  69. */
  70. get stoppedThreads(): Set<number> {
  71. return this._stoppedThreads;
  72. }
  73. /**
  74. * Assigns the parameters to the set of threads in stopped state.
  75. */
  76. set stoppedThreads(threads: Set<number>) {
  77. this._stoppedThreads = threads;
  78. }
  79. /**
  80. * The current debugger title.
  81. */
  82. get title(): string {
  83. return this._title;
  84. }
  85. /**
  86. * Set the current debugger title.
  87. */
  88. set title(title: string) {
  89. if (title === this._title) {
  90. return;
  91. }
  92. this._title = title ?? '-';
  93. this._titleChanged.emit(title);
  94. }
  95. /**
  96. * A signal emitted when the title changes.
  97. */
  98. get titleChanged(): ISignal<this, string> {
  99. return this._titleChanged;
  100. }
  101. /**
  102. * Dispose the model.
  103. */
  104. dispose(): void {
  105. if (this._isDisposed) {
  106. return;
  107. }
  108. this._isDisposed = true;
  109. this._disposed.emit();
  110. }
  111. /**
  112. * Clear the model.
  113. */
  114. clear(): void {
  115. this._stoppedThreads.clear();
  116. const breakpoints = new Map<string, IDebugger.IBreakpoint[]>();
  117. this.breakpoints.restoreBreakpoints(breakpoints);
  118. this.callstack.frames = [];
  119. this.variables.scopes = [];
  120. this.sources.currentSource = null;
  121. this.kernelSources.kernelSources = null;
  122. this.title = '-';
  123. }
  124. private _disposed = new Signal<this, void>(this);
  125. private _isDisposed = false;
  126. private _hasRichVariableRendering = false;
  127. private _stoppedThreads = new Set<number>();
  128. private _title = '-';
  129. private _titleChanged = new Signal<this, string>(this);
  130. }