瀏覽代碼

Common behavior for console creation on file editor

Frederic Collonval 6 年之前
父節點
當前提交
050eb7d58a
共有 1 個文件被更改,包括 23 次插入23 次删除
  1. 23 23
      packages/fileeditor-extension/src/index.ts

+ 23 - 23
packages/fileeditor-extension/src/index.ts

@@ -42,7 +42,7 @@ import {
 
 import { IStatusBar } from '@jupyterlab/statusbar';
 
-import { JSONObject } from '@phosphor/coreutils';
+import { JSONObject, ReadonlyJSONObject } from '@phosphor/coreutils';
 
 import { Menu } from '@phosphor/widgets';
 
@@ -400,6 +400,26 @@ function activate(
     isToggled: () => config.autoClosingBrackets
   });
 
+  async function createConsole(
+    widget: IDocumentWidget<FileEditor>,
+    args?: ReadonlyJSONObject
+  ): Promise<void> {
+    const options = args || {};
+    const console = await commands.execute('console:create', {
+      activate: options['activate'],
+      name: widget.context.contentsModel.name,
+      path: widget.context.path,
+      preferredLanguage: widget.context.model.defaultKernelLanguage,
+      ref: widget.id,
+      insertMode: 'split-bottom'
+    });
+
+    widget.context.pathChanged.connect((sender, value) => {
+      console.session.setPath(value);
+      console.session.setName(widget.context.contentsModel.name);
+    });
+  }
+
   commands.addCommand(CommandIDs.createConsole, {
     execute: args => {
       const widget = tracker.currentWidget;
@@ -408,21 +428,7 @@ function activate(
         return;
       }
 
-      return commands
-        .execute('console:create', {
-          activate: args['activate'],
-          name: widget.context.contentsModel.name,
-          path: widget.context.path,
-          preferredLanguage: widget.context.model.defaultKernelLanguage,
-          ref: widget.id,
-          insertMode: 'split-bottom'
-        })
-        .then(console => {
-          widget.context.pathChanged.connect((sender, value) => {
-            console.session.setPath(value);
-            console.session.setName(widget.context.contentsModel.name);
-          });
-        });
+      return createConsole(widget, args);
     },
     isEnabled,
     label: 'Create Console for Editor'
@@ -722,13 +728,7 @@ function activate(
     menu.fileMenu.consoleCreators.add({
       tracker,
       name: 'Editor',
-      createConsole: current => {
-        const options = {
-          path: current.context.path,
-          preferredLanguage: current.context.model.defaultKernelLanguage
-        };
-        return commands.execute('console:create', options);
-      }
+      createConsole
     } as IFileMenu.IConsoleCreator<IDocumentWidget<FileEditor>>);
 
     // Add a code runner to the Run menu.