Bläddra i källkod

Merge pull request #3660 from ian-r-rose/fix_drag_file_to_main_area

Fix drag-to-main-area behavior.
Jason Grout 7 år sedan
förälder
incheckning
c99a49ff6c

+ 1 - 1
RELEASE.md

@@ -78,7 +78,7 @@ xckd repo
 
 
 ### Extension examples to update
-- https://github.com/jupyterlab/jupyterlab/blob/master/docs/source/developer/notebook.md#adding-a-button-to-the-toolbar
+- https://github.com/jupyterlab/jupyterlab/blob/master/docs/source/developer/notebook.rst#adding-a-button-to-the-toolbar
 
 
 ### Updating the xkcd tutorial

+ 13 - 21
packages/docmanager-extension/src/index.ts

@@ -10,7 +10,7 @@ import {
 } from '@jupyterlab/apputils';
 
 import {
-  IChangedArgs, uuid
+  IChangedArgs
 } from '@jupyterlab/coreutils';
 
 import {
@@ -92,28 +92,20 @@ const plugin: JupyterLabPlugin<IDocumentManager> = {
           'type': 'document-title',
           ...widget.title.dataset
         };
-        if (!widget.isAttached && (widget as any).ready !== undefined) {
+        if (!widget.isAttached) {
+          app.shell.addToMainArea(widget, options || {});
+
           // Add a loading spinner, and remove it when the widget is ready.
-          let spinner = new Spinner();
-          spinner.id = uuid();
-          spinner.title.label = widget.title.label;
-          shell.addToMainArea(spinner, options || {});
-          shell.activateById(spinner.id);
-
-          (widget as any).ready.then(() => {
-            const isCurrent = app.shell.currentWidget === spinner;
-            app.shell.addToMainArea(widget, {...options, ref: spinner.id });
-            spinner.dispose();
-            if (isCurrent) {
-              shell.activateById(widget.id);
-            }
-          });
-        } else if (!widget.isAttached) {
-          shell.addToMainArea(widget, options || {});
-          shell.activateById(widget.id);
-        } else {
-          shell.activateById(widget.id);
+          if (widget.ready !== undefined) {
+            const spinner = new Spinner();
+            widget.node.appendChild(spinner.node);
+            widget.ready.then(() => {
+              widget.node.removeChild(spinner.node);
+              spinner.dispose();
+            });
+          }
         }
+        shell.activateById(widget.id);
 
         // Handle dirty state for open documents.
         let context = docManager.contextForWidget(widget);

+ 2 - 2
packages/docmanager/src/manager.ts

@@ -378,7 +378,7 @@ class DocumentManager implements IDisposable {
    */
   private _createContext(path: string, factory: DocumentRegistry.ModelFactory, kernelPreference: IClientSession.IKernelPreference): Private.IContext {
     // Allow options to be passed when adding a sibling.
-    let adopter = (widget: Widget, options?: DocumentRegistry.IOpenOptions) => {
+    let adopter = (widget: DocumentRegistry.IReadyWidget, options?: DocumentRegistry.IOpenOptions) => {
       this._widgetManager.adoptWidget(context, widget);
       this._opener.open(widget, options);
     };
@@ -519,7 +519,7 @@ namespace DocumentManager {
     /**
      * Open the given widget.
      */
-    open(widget: Widget, options?: DocumentRegistry.IOpenOptions): void;
+    open(widget: DocumentRegistry.IReadyWidget, options?: DocumentRegistry.IOpenOptions): void;
   }
 }
 

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

@@ -125,7 +125,7 @@ class DocumentWidgetManager implements IDisposable {
    *
    * @param widget - The widget to adopt.
    */
-  adoptWidget(context: DocumentRegistry.Context, widget: Widget): void {
+  adoptWidget(context: DocumentRegistry.Context, widget: DocumentRegistry.IReadyWidget): void {
     let widgets = Private.widgetsProperty.get(context);
     widgets.push(widget);
     MessageLoop.installMessageHook(widget, this);
@@ -157,7 +157,7 @@ class DocumentWidgetManager implements IDisposable {
         return false;
       }
       return factory.name === widgetName;
-    }) as DocumentRegistry.IReadyWidget;
+    });
   }
 
   /**
@@ -448,7 +448,7 @@ namespace Private {
    * A private attached property for the widgets associated with a context.
    */
   export
-  const widgetsProperty = new AttachedProperty<DocumentRegistry.Context, Widget[]>({
+  const widgetsProperty = new AttachedProperty<DocumentRegistry.Context, DocumentRegistry.IReadyWidget[]>({
     name: 'widgets',
     create: () => []
   });

+ 7 - 4
packages/notebook-extension/src/index.ts

@@ -1260,7 +1260,7 @@ function addCommands(app: JupyterLab, services: ServiceManager, tracker: Noteboo
     label: 'Create New View for Output',
     execute: args => {
       // Clone the OutputArea
-      const current = getCurrent(args);
+      const current = getCurrent({ ...args, activate: false });
       const nb = current.notebook;
       const outputAreaView = (nb.activeCell as CodeCell).cloneOutputArea();
       // Create an empty toolbar
@@ -1287,9 +1287,9 @@ function addCommands(app: JupyterLab, services: ServiceManager, tracker: Noteboo
     isEnabled: isEnabledAndSingleSelected
   });
   commands.addCommand(CommandIDs.createConsole, {
-    label: 'Create Console for Notebook',
+    label: 'New Console for Notebook',
     execute: args => {
-      const current = getCurrent(args);
+      const current = getCurrent({ ...args, activate: false });
       const widget = tracker.currentWidget;
 
       if (!current || !widget) {
@@ -1653,7 +1653,10 @@ function populateMenus(app: JupyterLab, mainMenu: IMainMenu, tracker: INotebookT
     createConsole: current => {
       const options: ReadonlyJSONObject = {
         path: current.context.path,
-        preferredLanguage: current.context.model.defaultKernelLanguage
+        preferredLanguage: current.context.model.defaultKernelLanguage,
+        activate: true,
+        ref: current.id,
+        insertMode: 'split-bottom'
       };
       return commands.execute('console:create', options);
     }