Ver Fonte

Make imageviewer consistent with other InstanceTrackers.

Ian Rose há 7 anos atrás
pai
commit
c9c4f87888

+ 1 - 2
packages/imageviewer-extension/package.json

@@ -31,8 +31,7 @@
   "dependencies": {
     "@jupyterlab/application": "^0.12.0",
     "@jupyterlab/apputils": "^0.12.4",
-    "@jupyterlab/imageviewer": "^0.12.0",
-    "@phosphor/commands": "^1.4.0"
+    "@jupyterlab/imageviewer": "^0.12.0"
   },
   "devDependencies": {
     "rimraf": "~2.6.2",

+ 10 - 13
packages/imageviewer-extension/src/index.ts

@@ -13,11 +13,6 @@ import {
   ImageViewer, ImageViewerFactory, IImageTracker
 } from '@jupyterlab/imageviewer';
 
-import {
-  CommandRegistry
-} from '@phosphor/commands';
-
-
 /**
  * The command IDs used by the image widget plugin.
  */
@@ -99,7 +94,7 @@ function activate(app: JupyterLab, palette: ICommandPalette, restorer: ILayoutRe
     }
   });
 
-  addCommands(tracker, app.commands);
+  addCommands(app, tracker);
 
   const category = 'Image Viewer';
 
@@ -114,31 +109,33 @@ function activate(app: JupyterLab, palette: ICommandPalette, restorer: ILayoutRe
  * Add the commands for the image widget.
  */
 export
-function addCommands(tracker: IImageTracker, commands: CommandRegistry) {
+function addCommands(app: JupyterLab, tracker: IImageTracker) {
+  const { commands } = app;
 
   /**
-   * Whether there is an active notebook.
+   * Whether there is an active image viewer.
    */
-  function hasWidget(): boolean {
-    return tracker.currentWidget !== null;
+  function isEnabled(): boolean {
+    return tracker.currentWidget !== null &&
+           tracker.currentWidget === app.shell.currentWidget;
   }
 
   commands.addCommand('imageviewer:zoom-in', {
     execute: zoomIn,
     label: 'Zoom In',
-    isEnabled: hasWidget
+    isEnabled
   });
 
   commands.addCommand('imageviewer:zoom-out', {
     execute: zoomOut,
     label: 'Zoom Out',
-    isEnabled: hasWidget
+    isEnabled
   });
 
   commands.addCommand('imageviewer:reset-zoom', {
     execute: resetZoom,
     label: 'Reset Zoom',
-    isEnabled: hasWidget
+    isEnabled
   });
 
   function zoomIn(): void {