Explorar o código

add tool in breakpoints remove all

Borys Palka %!s(int64=5) %!d(string=hai) anos
pai
achega
da24c2e521
Modificáronse 4 ficheiros con 30 adicións e 1 borrados
  1. 11 1
      src/breakpoints/body.tsx
  2. 11 0
      src/breakpoints/index.ts
  3. 4 0
      style/icons.css
  4. 4 0
      style/icons/close-all.svg

+ 11 - 1
src/breakpoints/body.tsx

@@ -4,6 +4,7 @@
 import React, { useState } from 'react';
 import React, { useState } from 'react';
 import { Breakpoints } from '.';
 import { Breakpoints } from '.';
 import { ReactWidget } from '@jupyterlab/apputils';
 import { ReactWidget } from '@jupyterlab/apputils';
+import { ArrayExt } from '@phosphor/algorithm';
 
 
 export class Body extends ReactWidget {
 export class Body extends ReactWidget {
   constructor(model: Breakpoints.IModel) {
   constructor(model: Breakpoints.IModel) {
@@ -20,7 +21,7 @@ export class Body extends ReactWidget {
 }
 }
 
 
 const BreakpointsComponent = ({ model }: { model: Breakpoints.IModel }) => {
 const BreakpointsComponent = ({ model }: { model: Breakpoints.IModel }) => {
-  const [breakpoints] = useState(model.breakpoints);
+  const [breakpoints, setBreakpoints] = useState(model.breakpoints);
   const [active, setActive] = useState(model.isActive);
   const [active, setActive] = useState(model.isActive);
 
 
   model.activesChange.connect((_: Breakpoints.IModel, update: boolean) => {
   model.activesChange.connect((_: Breakpoints.IModel, update: boolean) => {
@@ -28,6 +29,15 @@ const BreakpointsComponent = ({ model }: { model: Breakpoints.IModel }) => {
     setActive(update);
     setActive(update);
   });
   });
 
 
+  model.breakpointsChanged.connect(
+    (_: Breakpoints.IModel, updates: Breakpoints.IBreakpoint[]) => {
+      if (ArrayExt.shallowEqual(breakpoints, updates)) {
+        return;
+      }
+      setBreakpoints(updates);
+    }
+  );
+
   return (
   return (
     <div>
     <div>
       {breakpoints.map((breakpoint: any) => (
       {breakpoints.map((breakpoint: any) => (

+ 11 - 0
src/breakpoints/index.ts

@@ -32,6 +32,17 @@ export class Breakpoints extends Panel {
         tooltip: 'Deactivate Breakpoints'
         tooltip: 'Deactivate Breakpoints'
       })
       })
     );
     );
+
+    header.toolbar.addItem(
+      'closeAll',
+      new ToolbarButton({
+        iconClassName: 'jp-CloseAllIcon',
+        onClick: () => {
+          this.model.breakpoints = [];
+        },
+        tooltip: 'Remove All Breakpoints'
+      })
+    );
   }
   }
 
 
   readonly body: Widget;
   readonly body: Widget;

+ 4 - 0
style/icons.css

@@ -54,3 +54,7 @@
 .jp-VariableIcon {
 .jp-VariableIcon {
   background-image: url('icons/variable.svg');
   background-image: url('icons/variable.svg');
 }
 }
+
+.jp-CloseAllIcon {
+  background-image: url('icons/close-all.svg');
+}

+ 4 - 0
style/icons/close-all.svg

@@ -0,0 +1,4 @@
+<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
+<path fill-rule="evenodd" clip-rule="evenodd" d="M8.62132 8.0858L7.91421 7.37869L6.5 8.7929L5.08579 7.37869L4.37868 8.0858L5.79289 9.50001L4.37868 10.9142L5.08579 11.6213L6.5 10.2071L7.91421 11.6213L8.62132 10.9142L7.20711 9.50001L8.62132 8.0858Z" fill="#424242"/>
+<path fill-rule="evenodd" clip-rule="evenodd" d="M5 3L6 2H13L14 3V10L13 11H11V13L10 14H3L2 13V6L3 5H5V3ZM6 5H10L11 6V10H13V3H6V5ZM10 6H3V13H10V6Z" fill="#424242"/>
+</svg>