model.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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 { VariablesModel } from './panels/variables/model';
  9. /**
  10. * A model for a debugger.
  11. */
  12. export class DebuggerModel {
  13. /**
  14. * Instantiate a new DebuggerModel
  15. */
  16. constructor() {
  17. this.breakpoints = new BreakpointsModel();
  18. this.callstack = new CallstackModel();
  19. this.variables = new VariablesModel();
  20. this.sources = new SourcesModel({
  21. currentFrameChanged: this.callstack.currentFrameChanged
  22. });
  23. }
  24. /**
  25. * The breakpoints model.
  26. */
  27. readonly breakpoints: BreakpointsModel;
  28. /**
  29. * The callstack model.
  30. */
  31. readonly callstack: CallstackModel;
  32. /**
  33. * The variables model.
  34. */
  35. readonly variables: VariablesModel;
  36. /**
  37. * The sources model.
  38. */
  39. readonly sources: SourcesModel;
  40. /**
  41. * A signal emitted when the debugger widget is disposed.
  42. */
  43. get disposed(): ISignal<this, void> {
  44. return this._disposed;
  45. }
  46. /**
  47. * Whether the model is disposed.
  48. */
  49. get isDisposed(): boolean {
  50. return this._isDisposed;
  51. }
  52. /**
  53. * The set of threads in stopped state.
  54. */
  55. get stoppedThreads(): Set<number> {
  56. return this._stoppedThreads;
  57. }
  58. /**
  59. * Assigns the parameters to the set of threads in stopped state.
  60. */
  61. set stoppedThreads(threads: Set<number>) {
  62. this._stoppedThreads = threads;
  63. }
  64. /**
  65. * The current debugger title.
  66. */
  67. get title(): string {
  68. return this._title;
  69. }
  70. /**
  71. * Set the current debugger title.
  72. */
  73. set title(title: string) {
  74. if (title === this._title) {
  75. return;
  76. }
  77. this._title = title ?? '-';
  78. this._titleChanged.emit(title);
  79. }
  80. /**
  81. * A signal emitted when the title changes.
  82. */
  83. get titleChanged(): ISignal<this, string> {
  84. return this._titleChanged;
  85. }
  86. /**
  87. * Dispose the model.
  88. */
  89. dispose(): void {
  90. if (this._isDisposed) {
  91. return;
  92. }
  93. this._isDisposed = true;
  94. this._disposed.emit();
  95. }
  96. /**
  97. * Clear the model.
  98. */
  99. clear(): void {
  100. this._stoppedThreads.clear();
  101. const breakpoints = new Map<string, IDebugger.IBreakpoint[]>();
  102. this.breakpoints.restoreBreakpoints(breakpoints);
  103. this.callstack.frames = [];
  104. this.variables.scopes = [];
  105. this.sources.currentSource = null;
  106. this.title = '-';
  107. }
  108. private _disposed = new Signal<this, void>(this);
  109. private _isDisposed = false;
  110. private _stoppedThreads = new Set<number>();
  111. private _title = '-';
  112. private _titleChanged = new Signal<this, string>(this);
  113. }