浏览代码

Add new creators for terminals and text files.

Ian Rose 7 年之前
父节点
当前提交
c7baab77e0

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

@@ -35,7 +35,8 @@
     "@jupyterlab/codeeditor": "^0.12.0",
     "@jupyterlab/coreutils": "^0.12.0",
     "@jupyterlab/fileeditor": "^0.12.0",
-    "@jupyterlab/launcher": "^0.12.0"
+    "@jupyterlab/launcher": "^0.12.0",
+    "@jupyterlab/mainmenu": "^0.1.0"
   },
   "devDependencies": {
     "rimraf": "~2.6.2",

+ 40 - 11
packages/fileeditor-extension/src/index.ts

@@ -17,6 +17,10 @@ import {
   ISettingRegistry, MarkdownCodeBlocks, PathExt
 } from '@jupyterlab/coreutils';
 
+import {
+  IFileBrowserFactory
+} from '@jupyterlab/filebrowser';
+
 import {
   FileEditor, FileEditorFactory, IEditorTracker
 } from '@jupyterlab/fileeditor';
@@ -25,6 +29,10 @@ import {
   ILauncher
 } from '@jupyterlab/launcher';
 
+import {
+  IMainMenu
+} from '@jupyterlab/mainmenu';
+
 
 /**
  * The class name for the text editor icon from the default theme.
@@ -41,6 +49,9 @@ const FACTORY = 'Editor';
  * The command IDs used by the fileeditor plugin.
  */
 namespace CommandIDs {
+  export
+  const createNew = 'fileeditor:create-new';
+
   export
   const lineNumbers = 'fileeditor:toggle-line-numbers';
 
@@ -73,7 +84,7 @@ namespace CommandIDs {
 const plugin: JupyterLabPlugin<IEditorTracker> = {
   activate,
   id: '@jupyterlab/fileeditor-extension:plugin',
-  requires: [ILayoutRestorer, IEditorServices, ISettingRegistry],
+  requires: [IEditorServices, IFileBrowserFactory, ILayoutRestorer, IMainMenu, ISettingRegistry],
   optional: [ILauncher],
   provides: IEditorTracker,
   autoStart: true
@@ -89,7 +100,7 @@ export default plugin;
 /**
  * Activate the editor tracker plugin.
  */
-function activate(app: JupyterLab, restorer: ILayoutRestorer, editorServices: IEditorServices, settingRegistry: ISettingRegistry, launcher: ILauncher | null): IEditorTracker {
+function activate(app: JupyterLab, editorServices: IEditorServices, browserFactory: IFileBrowserFactory, restorer: ILayoutRestorer, menu: IMainMenu, settingRegistry: ISettingRegistry, launcher: ILauncher | null): IEditorTracker {
   const id = plugin.id;
   const namespace = 'editor';
   const factory = new FileEditorFactory({
@@ -349,25 +360,43 @@ function activate(app: JupyterLab, restorer: ILayoutRestorer, editorServices: IE
     label: 'Show Markdown Preview'
   });
 
+  // Function to create a new untitled text file, given
+  // the current working directory.
+  const createNew = (cwd: string) => {
+    return commands.execute('docmanager:new-untitled', {
+      path: cwd, type: 'file'
+    }).then(model => {
+      return commands.execute('docmanager:open', {
+        path: model.path, factory: FACTORY
+      });
+    });
+  }
+
   // Add a launcher item if the launcher is available.
+  commands.addCommand(CommandIDs.createNew, {
+    label: 'New File',
+    caption: 'Create a new text file',
+    execute: () => {
+      let cwd = browserFactory.defaultBrowser.model.path;
+      return createNew(cwd);
+    }
+  });
+
   if (launcher) {
     launcher.add({
       displayName: 'Text Editor',
       category: 'Other',
       rank: 1,
       iconClass: EDITOR_ICON_CLASS,
-      callback: cwd => {
-        return commands.execute('docmanager:new-untitled', {
-          path: cwd, type: 'file'
-        }).then(model => {
-          return commands.execute('docmanager:open', {
-            path: model.path, factory: FACTORY
-          });
-        });
-      }
+      callback: createNew
     });
   }
 
+  // Add new text file creation to the file menu.
+  menu.fileMenu.newMenu.addItem({ command: CommandIDs.createNew });
+
+
+
   app.contextMenu.addItem({
     command: CommandIDs.createConsole, selector: '.jp-FileEditor'
   });

+ 1 - 0
packages/mainmenu/src/menus.ts

@@ -18,6 +18,7 @@ class FileMenu extends Menu {
 
     // Create the "New" submenu.
     this.newMenu = new Menu(options);
+    this.newMenu.title.label = 'New';
     this.addItem({
       type: 'submenu',
       submenu: this.newMenu

+ 3 - 0
packages/terminal-extension/src/index.ts

@@ -130,6 +130,9 @@ function activate(app: JupyterLab, mainMenu: IMainMenu, palette: ICommandPalette
   });
   mainMenu.addMenu(menu, {rank: 40});
 
+  // Add terminal creation to the file menu.
+  mainMenu.fileMenu.newMenu.addItem({ command: CommandIDs.createNew });
+
   // Add a launcher item if the launcher is available.
   if (launcher) {
     launcher.add({