Kaynağa Gözat

Continue breaking menu logic into separate plugin.

Ian Rose 7 yıl önce
ebeveyn
işleme
ba8ad8b0f6

+ 3 - 0
jupyterlab/package.json

@@ -42,6 +42,7 @@
     "@jupyterlab/launcher": "^0.12.0",
     "@jupyterlab/launcher-extension": "^0.12.0",
     "@jupyterlab/mainmenu": "^0.1.0",
+    "@jupyterlab/mainmenu-extension": "^0.1.0",
     "@jupyterlab/markdownviewer-extension": "^0.12.0",
     "@jupyterlab/notebook": "^0.12.0",
     "@jupyterlab/notebook-extension": "^0.12.0",
@@ -99,6 +100,7 @@
       "@jupyterlab/imageviewer-extension": "",
       "@jupyterlab/inspector-extension": "",
       "@jupyterlab/launcher-extension": "",
+      "@jupyterlab/mainmenu-extension": "",
       "@jupyterlab/markdownviewer-extension": "",
       "@jupyterlab/notebook-extension": "",
       "@jupyterlab/running-extension": "",
@@ -171,6 +173,7 @@
       "@jupyterlab/launcher": "../packages/launcher",
       "@jupyterlab/launcher-extension": "../packages/launcher-extension",
       "@jupyterlab/mainmenu": "../packages/mainmenu",
+      "@jupyterlab/mainmenu-extension": "../packages/mainmenu-extension",
       "@jupyterlab/markdownviewer-extension": "../packages/markdownviewer-extension",
       "@jupyterlab/notebook": "../packages/notebook",
       "@jupyterlab/notebook-extension": "../packages/notebook-extension",

+ 1 - 32
packages/apputils-extension/src/index.ts

@@ -16,10 +16,6 @@ import {
   DataConnector, ISettingRegistry, IStateDB, SettingRegistry, StateDB
 } from '@jupyterlab/coreutils';
 
-import {
-  IMainMenu, MainMenu
-} from '@jupyterlab/mainmenu';
-
 import {
   ServiceManager, ServerConnection
 } from '@jupyterlab/services';
@@ -32,10 +28,6 @@ import {
   DisposableDelegate, IDisposable
 } from '@phosphor/disposable';
 
-import {
-  Widget
-} from '@phosphor/widgets';
-
 import {
   activatePalette
 } from './palette';
@@ -106,29 +98,6 @@ class SettingsConnector extends DataConnector<ISettingRegistry.IPlugin, string>
 }
 
 
-/**
- * A service providing an interface to the main menu.
- */
-const menu: JupyterLabPlugin<IMainMenu> = {
-  id: '@jupyterlab/apputils-extension:menu',
-  provides: IMainMenu,
-  activate: (app: JupyterLab): IMainMenu => {
-    let menu = new MainMenu();
-    menu.id = 'jp-MainMenu';
-
-    let logo = new Widget();
-    logo.addClass('jp-MainAreaPortraitIcon');
-    logo.addClass('jp-JupyterIcon');
-    logo.id = 'jp-MainLogo';
-
-    app.shell.addToTopArea(logo);
-    app.shell.addToTopArea(menu);
-
-    return menu;
-  }
-};
-
-
 /**
  * The default commmand palette extension.
  */
@@ -235,7 +204,7 @@ const state: JupyterLabPlugin<IStateDB> = {
  * Export the plugins as default.
  */
 const plugins: JupyterLabPlugin<any>[] = [
-  menu, palette, settings, state, splash, themes
+  palette, settings, state, splash, themes
 ];
 export default plugins;
 

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

@@ -29,10 +29,6 @@ import {
   Launcher
 } from '@jupyterlab/launcher';
 
-import {
-  IMainMenu
-} from '@jupyterlab/mainmenu';
-
 import {
   each
 } from '@phosphor/algorithm';
@@ -111,16 +107,6 @@ const factory: JupyterLabPlugin<IFileBrowserFactory> = {
   requires: [IDocumentManager, IStateDB]
 };
 
-/**
- * The default file browser menu extension.
- */
-const menu: JupyterLabPlugin<void> = {
-  activate: activateMenu,
-  id: '@jupyterlab/filebrowser-extension:menu',
-  requires: [IMainMenu],
-  autoStart: true
-};
-
 /**
  * The file browser namespace token.
  */
@@ -129,7 +115,7 @@ const namespace = 'filebrowser';
 /**
  * Export the plugins as default.
  */
-const plugins: JupyterLabPlugin<any>[] = [factory, browser, menu];
+const plugins: JupyterLabPlugin<any>[] = [factory, browser];
 export default plugins;
 
 
@@ -224,15 +210,6 @@ function activateBrowser(app: JupyterLab, factory: IFileBrowserFactory, restorer
   });
 }
 
-/**
- * Activate the default file browser menu in the main menu.
- */
-function activateMenu(app: JupyterLab, mainMenu: IMainMenu): void {
-  let menu = createMenu(app);
-
-  mainMenu.addMenu(menu, { rank: 1 });
-}
-
 
 /**
  * Add the main file browser commands to the application's command registry.
@@ -396,31 +373,6 @@ function addCommands(app: JupyterLab, tracker: InstanceTracker<FileBrowser>, bro
 }
 
 
-/**
- * Create a top level menu for the file browser.
- */
-function createMenu(app: JupyterLab): Menu {
-  const { commands } = app;
-  const menu = new Menu({ commands });
-
-  menu.title.label = 'File';
-  [
-    CommandIDs.createLauncher,
-    'docmanager:save',
-    'docmanager:save-as',
-    'docmanager:rename',
-    'docmanager:restore-checkpoint',
-    'docmanager:clone',
-    'docmanager:close',
-    'docmanager:close-all-files'
-  ].forEach(command => { menu.addItem({ command }); });
-  menu.addItem({ type: 'separator' });
-  menu.addItem({ command: 'settingeditor:open' });
-
-  return menu;
-}
-
-
 /**
  * Create a context menu for the file browser listing.
  *

+ 3 - 0
packages/mainmenu-extension/README.md

@@ -0,0 +1,3 @@
+# @jupyterlab/mainmenu-extension
+
+An extension for JupyterLab which provides an entry point for the [@jupyterlab/mainmenu](../mainmenu) package.

+ 42 - 0
packages/mainmenu-extension/package.json

@@ -0,0 +1,42 @@
+{
+  "name": "@jupyterlab/mainmenu-extension",
+  "version": "0.1.0",
+  "description": "JupyterLab - Main Menu Extension",
+  "homepage": "https://github.com/jupyterlab/jupyterlab",
+  "bugs": {
+    "url": "https://github.com/jupyterlab/jupyterlab/issues"
+  },
+  "license": "BSD-3-Clause",
+  "author": "Project Jupyter",
+  "files": [
+    "lib/*.d.ts",
+    "lib/*.js.map",
+    "lib/*.js"
+  ],
+  "main": "lib/index.js",
+  "types": "lib/index.d.ts",
+  "directories": {
+    "lib": "lib/"
+  },
+  "repository": {
+    "type": "git",
+    "url": "https://github.com/jupyterlab/jupyterlab.git"
+  },
+  "scripts": {
+    "build": "tsc",
+    "clean": "rimraf lib",
+    "watch": "tsc -w"
+  },
+  "dependencies": {
+    "@jupyterlab/application": "^0.12.0",
+    "@jupyterlab/mainmenu": "^0.1.0",
+    "@phosphor/widgets": "^1.5.0"
+  },
+  "devDependencies": {
+    "rimraf": "~2.6.2",
+    "typescript": "~2.4.2"
+  },
+  "jupyterlab": {
+    "extension": true
+  }
+}

+ 40 - 0
packages/mainmenu-extension/src/index.ts

@@ -0,0 +1,40 @@
+// Copyright (c) Jupyter Development Team.
+// Distributed under the terms of the Modified BSD License.
+
+import {
+  JupyterLab, JupyterLabPlugin
+} from '@jupyterlab/application';
+
+import {
+  Widget
+} from '@phosphor/widgets';
+
+import {
+  IMainMenu, MainMenu
+} from '@jupyterlab/mainmenu';
+
+
+/**
+ * A service providing an interface to the main menu.
+ */
+const menu: JupyterLabPlugin<IMainMenu> = {
+  id: '@jupyterlab/apputils-extension:menu',
+  provides: IMainMenu,
+  activate: (app: JupyterLab): IMainMenu => {
+    const { commands } = app;
+    let menu = new MainMenu(commands);
+    menu.id = 'jp-MainMenu';
+
+    let logo = new Widget();
+    logo.addClass('jp-MainAreaPortraitIcon');
+    logo.addClass('jp-JupyterIcon');
+    logo.id = 'jp-MainLogo';
+
+    app.shell.addToTopArea(logo);
+    app.shell.addToTopArea(menu);
+
+    return menu;
+  }
+};
+
+export default menu;

+ 15 - 0
packages/mainmenu-extension/tsconfig.json

@@ -0,0 +1,15 @@
+{
+  "compilerOptions": {
+    "declaration": true,
+    "noImplicitAny": true,
+    "noEmitOnError": true,
+    "noUnusedLocals": true,
+    "module": "commonjs",
+    "moduleResolution": "node",
+    "target": "ES5",
+    "outDir": "./lib",
+    "lib": ["ES5", "ES2015.Promise", "DOM", "ES2015.Collection"],
+    "types": []
+  },
+  "include": ["src/*"]
+}

+ 2 - 2
packages/mainmenu/README.md

@@ -1,3 +1,3 @@
-# @jupyterlab/mainmenu-extension
+# @jupyterlab/mainmenu
 
-A JupyterLab extension which provides the application menubar and extensions for it.
+A JupyterLab extension which provides the application menubar.

+ 1 - 0
packages/mainmenu/package.json

@@ -32,6 +32,7 @@
     "@jupyterlab/apputils": "^0.12.4",
     "@jupyterlab/coreutils": "^0.12.0",
     "@phosphor/algorithm": "^1.1.2",
+    "@phosphor/commands": "^1.4.0",
     "@phosphor/coreutils": "^1.3.0",
     "@phosphor/disposable": "^1.1.2",
     "@phosphor/widgets": "^1.5.0",

+ 1 - 1
packages/mainmenu/src/index.ts

@@ -1,5 +1,5 @@
 // Copyright (c) Jupyter Development Team.
 // Distributed under the terms of the Modified BSD License.
 
-
 export * from './mainmenu';
+export * from './menus';

+ 23 - 1
packages/mainmenu/src/mainmenu.ts

@@ -5,6 +5,10 @@ import {
   ArrayExt
 } from '@phosphor/algorithm';
 
+import {
+  CommandRegistry
+} from '@phosphor/commands';
+
 import {
   Token
 } from '@phosphor/coreutils';
@@ -13,6 +17,10 @@ import {
   Menu, MenuBar
 } from '@phosphor/widgets';
 
+import {
+  FileMenu
+} from './menus';
+
 
 /* tslint:disable */
 /**
@@ -36,7 +44,7 @@ interface IMainMenu {
   /**
    * The application "File" menu.
    */
-  //readonly fileMenu: Menu;
+  readonly fileMenu: FileMenu;
 
   /**
    * The application "Edit" menu.
@@ -88,6 +96,20 @@ namespace IMainMenu {
  */
 export
 class MainMenu extends MenuBar implements IMainMenu {
+  /**
+   * Construct the main menu bar.
+   */
+  constructor(commands: CommandRegistry) {
+    super();
+    this.fileMenu = new FileMenu({ commands });
+    this.addMenu(this.fileMenu, { rank: 0 });
+  }
+
+  /**
+   * The application "File" menu.
+   */
+  readonly fileMenu: FileMenu;
+
   /**
    * Add a new menu to the main menu bar.
    */

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

@@ -0,0 +1,44 @@
+// Copyright (c) Jupyter Development Team.
+// Distributed under the terms of the Modified BSD License.
+
+import {
+  Menu
+} from '@phosphor/widgets';
+
+
+/**
+ * An extensible FileMenu for the application.
+ */
+export
+class FileMenu extends Menu {
+  constructor(options: Menu.IOptions) {
+    super(options);
+
+    this.title.label = 'File';
+
+    // Create the "New" submenu.
+    this.newMenu = new Menu(options);
+    this.addItem({
+      type: 'submenu',
+      submenu: this.newMenu
+    });
+
+    // Create the rest of the  top-level File menu
+    [
+      'docmanager:save',
+      'docmanager:save-as',
+      'docmanager:rename',
+      'docmanager:restore-checkpoint',
+      'docmanager:clone',
+      'docmanager:close',
+      'docmanager:close-all-files'
+    ].forEach(command => { this.addItem({ command }); });
+    this.addItem({ type: 'separator' });
+    this.addItem({ command: 'settingeditor:open' });
+  }
+
+  /**
+   * The New submenu
+   */
+  readonly newMenu: Menu;
+}

+ 1 - 0
packages/metapackage/package.json

@@ -64,6 +64,7 @@
     "@jupyterlab/launcher": "^0.12.0",
     "@jupyterlab/launcher-extension": "^0.12.0",
     "@jupyterlab/mainmenu": "^0.1.0",
+    "@jupyterlab/mainmenu-extension": "^0.1.0",
     "@jupyterlab/markdownviewer-extension": "^0.12.0",
     "@jupyterlab/notebook": "^0.12.0",
     "@jupyterlab/notebook-extension": "^0.12.0",

+ 1 - 0
packages/metapackage/src/index.ts

@@ -33,6 +33,7 @@ import "@jupyterlab/json-extension";
 import "@jupyterlab/launcher";
 import "@jupyterlab/launcher-extension";
 import "@jupyterlab/mainmenu";
+import "@jupyterlab/mainmenu-extension";
 import "@jupyterlab/markdownviewer-extension";
 import "@jupyterlab/notebook";
 import "@jupyterlab/notebook-extension";

+ 3 - 0
packages/metapackage/tsconfig.json

@@ -19,6 +19,9 @@
     "paths": {
       "@jupyterlab/*": [
         "../*/src"
+      ],
+      "@jupyterlab/mainmenu-extension": [
+        "../mainmenu-extension/src"
       ]
     },
     "jsx": "react",