瀏覽代碼

Merge pull request #138 from JohanMabille/panel_closed

Fixed cell manager when debugger panel is closed and reopened
Jeremy Tuloup 5 年之前
父節點
當前提交
a9c639824d
共有 4 個文件被更改,包括 42 次插入6 次删除
  1. 15 2
      src/breakpoints/index.ts
  2. 16 4
      src/handlers/cell.ts
  3. 6 0
      src/service.ts
  4. 5 0
      src/tokens.ts

+ 15 - 2
src/breakpoints/index.ts

@@ -2,7 +2,7 @@
 // Distributed under the terms of the Modified BSD License.
 
 import { Toolbar, ToolbarButton } from '@jupyterlab/apputils';
-
+import { IDisposable } from '@phosphor/disposable';
 import { Signal } from '@phosphor/signaling';
 import { Panel, PanelLayout, Widget } from '@phosphor/widgets';
 import { DebugProtocol } from 'vscode-debugprotocol';
@@ -77,7 +77,7 @@ export namespace Breakpoints {
     active: boolean;
   }
 
-  export class Model {
+  export class Model implements IDisposable {
     constructor(model: IBreakpoint[]) {
       this._breakpoints = model;
     }
@@ -134,6 +134,18 @@ export namespace Breakpoints {
       }
     }
 
+    get isDisposed(): boolean {
+      return this._isDisposed;
+    }
+
+    dispose(): void {
+      if (this._isDisposed) {
+        return;
+      }
+      this._isDisposed = true;
+      Signal.clearData(this);
+    }
+
     private _selectedType: SessionTypes;
     private _breakpointChanged = new Signal<this, IBreakpoint>(this);
     private _breakpoints: IBreakpoint[];
@@ -141,6 +153,7 @@ export namespace Breakpoints {
       console: [] as Breakpoints.IBreakpoint[],
       notebook: [] as Breakpoints.IBreakpoint[]
     };
+    private _isDisposed: boolean = false;
   }
 
   /**

+ 16 - 4
src/handlers/cell.ts

@@ -21,11 +21,21 @@ const LINE_HIGHLIGHT_CLASS = 'jp-breakpoint-line-highlight';
 
 export class CellManager implements IDisposable {
   constructor(options: CellManager.IOptions) {
-    this._debuggerModel = options.debuggerModel;
     this._debuggerService = options.debuggerService;
-    this.breakpointsModel = options.breakpointsModel;
+    this.onModelChanged();
+    this._debuggerService.modelChanged.connect(() => this.onModelChanged());
     this.activeCell = options.activeCell;
     this.onActiveCellChanged();
+  }
+
+  isDisposed: boolean;
+
+  private onModelChanged() {
+    this._debuggerModel = this._debuggerService.model;
+    if (!this._debuggerModel) {
+      return;
+    }
+    this.breakpointsModel = this._debuggerModel.breakpointsModel;
 
     this._debuggerModel.variablesModel.changed.connect(() => {
       this.cleanupHighlight();
@@ -42,9 +52,11 @@ export class CellManager implements IDisposable {
       }
       this.addBreakpointsToEditor(this.activeCell);
     });
-  }
 
-  isDisposed: boolean;
+    if (this.activeCell) {
+      this._debuggerModel.codeValue = this.activeCell.model.value;
+    }
+  }
 
   private showCurrentLine(lineNumber: number) {
     if (!this.activeCell) {

+ 6 - 0
src/service.ts

@@ -56,6 +56,7 @@ export class DebugService implements IDebugger {
 
   set model(model: Debugger.Model) {
     this._model = model;
+    this._modelChanged.emit(model);
   }
 
   get session(): IDebugger.ISession {
@@ -154,6 +155,10 @@ export class DebugService implements IDebugger {
     return this._sessionChanged;
   }
 
+  get modelChanged(): ISignal<IDebugger, Debugger.Model> {
+    return this._modelChanged;
+  }
+
   get eventMessage(): ISignal<IDebugger, IDebugger.ISession.Event> {
     return this._eventMessage;
   }
@@ -299,6 +304,7 @@ export class DebugService implements IDebugger {
   private _isDisposed: boolean = false;
   private _session: IDebugger.ISession;
   private _sessionChanged = new Signal<IDebugger, IDebugger.ISession>(this);
+  private _modelChanged = new Signal<IDebugger, Debugger.Model>(this);
   private _eventMessage = new Signal<IDebugger, IDebugger.ISession.Event>(this);
   private _model: Debugger.Model;
 

+ 5 - 0
src/tokens.ts

@@ -100,6 +100,11 @@ export interface IDebugger {
    */
   sessionChanged: ISignal<IDebugger, IDebugger.ISession>;
 
+  /**
+   * Signal emitted upon model changed.
+   */
+  modelChanged: ISignal<IDebugger, Debugger.Model>;
+
   /**
    * Signal emitted for debug event messages.
    */