Explorar o código

Add command enable/disable to imageviewer

Steven Silvester %!s(int64=8) %!d(string=hai) anos
pai
achega
c8d6ba9e27
Modificáronse 1 ficheiros con 20 adicións e 2 borrados
  1. 20 2
      packages/imageviewer-extension/src/index.ts

+ 20 - 2
packages/imageviewer-extension/src/index.ts

@@ -111,19 +111,37 @@ function activate(app: JupyterLab, registry: IDocumentRegistry, palette: IComman
  */
 export
 function addCommands(tracker: IImageTracker, commands: CommandRegistry) {
+
+  /**
+   * Whether there is an active notebook.
+   */
+  function hasWidget(): boolean {
+    return tracker.currentWidget !== null;
+  }
+
+  // Update the command registry when the image viewer state changes.
+  tracker.currentChanged.connect(() => {
+    if (tracker.size <= 1) {
+      commands.notifyCommandChanged(CommandIDs.zoomIn);
+    }
+  });
+
   commands.addCommand('imageviewer:zoom-in', {
     execute: zoomIn,
     label: 'Zoom In'
+    isEnabled: hasWidget
   });
 
   commands.addCommand('imageviewer:zoom-out', {
     execute: zoomOut,
-    label: 'Zoom Out'
+    label: 'Zoom Out',
+    isEnabled: hasWidget
   });
 
   commands.addCommand('imageviewer:reset-zoom', {
     execute: resetZoom,
-    label: 'Reset Zoom'
+    label: 'Reset Zoom',
+    isEnabled: hasWidget
   });
 
   function zoomIn(): void {