Browse Source

remove breakpoints

Borys Palka 5 years ago
parent
commit
d303fcd897
3 changed files with 51 additions and 9 deletions
  1. 4 3
      src/breakpoints/index.ts
  2. 29 6
      src/breakpointsService.ts
  3. 18 0
      src/notebookTracker/index.ts

+ 4 - 3
src/breakpoints/index.ts

@@ -15,8 +15,8 @@ export class Breakpoints extends Panel {
 
     this.service = options.service;
 
-    this.service.testSignal.connect((sender, update) => {
-      console.log('test');
+    this.service.breakpointChanged.connect((sender, update) => {
+      this.model.breakpoint = update;
     });
 
     this.model = new Breakpoints.IModel([]);
@@ -50,6 +50,7 @@ export class Breakpoints extends Panel {
         iconClassName: 'jp-CloseAllIcon',
         onClick: () => {
           this.model.breakpoints = [];
+          this.service.clearSelectedBreakpoints();
         },
         tooltip: 'Remove All Breakpoints'
       })
@@ -106,7 +107,7 @@ export namespace Breakpoints {
 
     set breakpoints(breakpoints: IBreakpoint[]) {
       this._state = breakpoints;
-      this._breakpointsChanged.emit(this._state);
+      this._breakpointsChanged.emit(breakpoints);
     }
 
     set breakpoint(breakpoint: IBreakpoint) {

+ 29 - 6
src/breakpointsService.ts

@@ -1,18 +1,36 @@
-import { Breakpoints } from './breakpoints';
-import { Signal } from '@phosphor/signaling';
 // Copyright (c) Jupyter Development Team.
 // Distributed under the terms of the Modified BSD License.
 
+import { Breakpoints } from './breakpoints';
+import { Signal } from '@phosphor/signaling';
+import { LineInfo } from './notebookTracker';
+
 export class BreakpointsService {
   constructor() {}
 
   state: any = {};
+  selectedBreakpoints: Breakpoints.IBreakpoint[] = [];
 
-  testSignal = new Signal<this, any>(this);
+  selectedBreakpointsChanged = new Signal<this, Breakpoints.IBreakpoint[]>(
+    this
+  );
+  breakpointChanged = new Signal<this, Breakpoints.IBreakpoint>(this);
 
-  addBreakpoint(session_id: any, editor_id: any, lineInfo: any) {
-    console.log('adding');
-    this.testSignal.emit('test');
+  addBreakpoint(session_id: string, editor_id: any, lineInfo: LineInfo) {
+    const breakpoint: Breakpoints.IBreakpoint = {
+      line: lineInfo.line,
+      active: true,
+      verified: true,
+      source: {
+        name: session_id
+      }
+    };
+    this.selectedBreakpoints.push(breakpoint);
+    this.breakpointChanged.emit(breakpoint);
+  }
+
+  get breakpoints() {
+    return this.selectedBreakpoints;
   }
 
   removeBreakpoint(session_id: any, editor_id: any, lineInfo: any) {}
@@ -21,6 +39,11 @@ export class BreakpointsService {
 
   setBreakpointState(session_id: any, editor_id: any, lineInfo: any) {}
 
+  clearSelectedBreakpoints() {
+    this.selectedBreakpoints = [];
+    this.selectedBreakpointsChanged.emit([]);
+  }
+
   newLine(session_id: any, editor_id: any, lineInfo: any) {}
 
   protected changeLines(

+ 18 - 0
src/notebookTracker/index.ts

@@ -29,6 +29,14 @@ export class DebuggerNotebookTracker {
         );
       }
     );
+
+    this.breakpointService.selectedBreakpointsChanged.connect(
+      (sender, update) => {
+        if (update && update.length === 0) {
+          this.clearGutter();
+        }
+      }
+    );
   }
 
   notebookTracker: INotebookTracker;
@@ -46,6 +54,15 @@ export class DebuggerNotebookTracker {
     });
   }
 
+  protected clearGutter() {
+    const editor = this.getCell().editor as CodeMirrorEditor;
+    editor.doc.eachLine(line => {
+      if ((line as LineInfo).gutterMarkers) {
+        editor.editor.setGutterMarker(line, 'breakpoints', null);
+      }
+    });
+  }
+
   protected onActiveCellChanged() {
     const activeCell = this.getCell();
     if (activeCell && activeCell.editor && this.debuggerSession) {
@@ -92,6 +109,7 @@ export class DebuggerNotebookTracker {
   }
 
   protected onGutterClick = (editor: Editor, lineNumber: number) => {
+    console.log(lineNumber);
     const info = editor.lineInfo(lineNumber);
     if (!info) {
       return;