Bläddra i källkod

Merge pull request #2829 from blink1073/multiple-views-file

Allow cloning an open document
Afshin Darian 7 år sedan
förälder
incheckning
bd1f88d393

+ 35 - 2
packages/docmanager-extension/src/index.ts

@@ -52,6 +52,9 @@ namespace CommandIDs {
   export
   const open = 'docmanager:open';
 
+  export
+  const clone = 'docmanager:clone';
+
   export
   const restoreCheckpoint = 'docmanager:restore-checkpoint';
 
@@ -102,7 +105,7 @@ const plugin: JupyterLabPlugin<IDocumentManager> = {
     const docManager = new DocumentManager({ registry, manager, opener });
 
     // Register the file operations commands.
-    addCommands(app, docManager, palette);
+    addCommands(app, docManager, palette, opener);
 
     return docManager;
   }
@@ -118,7 +121,7 @@ export default plugin;
 /**
  * Add the file operations commands to the application's command registry.
  */
-function addCommands(app: JupyterLab, docManager: IDocumentManager, palette: ICommandPalette): void {
+function addCommands(app: JupyterLab, docManager: IDocumentManager, palette: ICommandPalette, opener: DocumentManager.IWidgetOpener): void {
   const { commands } = app;
   const category = 'File Operations';
   const isEnabled = () => {
@@ -257,16 +260,46 @@ function addCommands(app: JupyterLab, docManager: IDocumentManager, palette: ICo
     label: 'Rename'
   });
 
+  commands.addCommand(CommandIDs.clone, {
+    isVisible: () => {
+      const widget = app.shell.currentWidget;
+      if (!widget) {
+        return;
+      }
+      // Find the context for the widget.
+      let context = docManager.contextForWidget(widget);
+      return context !== null;
+    },
+    execute: () => {
+      const widget = app.shell.currentWidget;
+      if (!widget) {
+        return;
+      }
+      // Clone the widget.
+      let child = docManager.cloneWidget(widget);
+      if (child) {
+        opener.open(child);
+      }
+    },
+    label: 'New View into File'
+  });
+
   app.contextMenu.addItem({
     command: CommandIDs.rename,
     selector: '[data-type="document-title"]',
     rank: 1
   });
+  app.contextMenu.addItem({
+    command: CommandIDs.clone,
+    selector: '[data-type="document-title"]',
+    rank: 2
+  });
 
   [
     CommandIDs.save,
     CommandIDs.restoreCheckpoint,
     CommandIDs.saveAs,
+    CommandIDs.clone,
     CommandIDs.close,
     CommandIDs.closeAllFiles
   ].forEach(command => { palette.addItem({ command, category }); });

+ 1 - 1
packages/docmanager/src/widgetmanager.ts

@@ -193,7 +193,7 @@ class DocumentWidgetManager implements IDisposable {
     }
     let newWidget = this.createWidget(factory, context);
     this.adoptWidget(context, newWidget);
-    return widget;
+    return newWidget;
   }
 
   /**

+ 1 - 0
packages/filebrowser-extension/src/index.ts

@@ -392,6 +392,7 @@ function createMenu(app: JupyterLab): Menu {
     'docmanager:save-as',
     'docmanager:rename',
     'docmanager:restore-checkpoint',
+    'docmanager:clone',
     'docmanager:close',
     'docmanager:close-all-files'
   ].forEach(command => { menu.addItem({ command }); });