Browse Source

Bug fix: main menu implementation caused runtime errors.

Afshin Darian 8 years ago
parent
commit
f6d13e451b
2 changed files with 8 additions and 120 deletions
  1. 4 65
      src/mainmenu/index.ts
  2. 4 55
      src/mainmenu/plugin.ts

+ 4 - 65
src/mainmenu/index.ts

@@ -2,7 +2,7 @@
 // Distributed under the terms of the Modified BSD License.
 
 import {
-  indexOf, upperBound
+  find, indexOf, upperBound
 } from 'phosphor/lib/algorithm/searching';
 
 import {
@@ -21,25 +21,6 @@ import {
   MenuBar
 } from 'phosphor/lib/ui/menubar';
 
-import {
-  Widget
-} from 'phosphor/lib/ui/widget';
-
-import {
-  JupyterLab, JupyterLabPlugin
-} from '../application';
-
-
-/**
- * The class name for all main area portrait tab icons.
- */
-const PORTRAIT_ICON_CLASS = 'jp-MainAreaPortraitIcon';
-
-/**
- * The class name for the jupyter icon from the default theme.
- */
-const JUPYTER_ICON_CLASS = 'jp-JupyterIcon';
-
 
 /* tslint:disable */
 /**
@@ -78,12 +59,12 @@ interface IAddMenuOptions {
  * The main menu class.  It is intended to be used as a singleton.
  */
 export
-class MainMenu implements IMainMenu {
+class MainMenu extends MenuBar implements IMainMenu {
   /**
    * Add a new menu to the main menu bar.
    */
   addMenu(menu: Menu, options: IAddMenuOptions = {}): void {
-    if (indexOf(Private.menuBar.menus, menu) > -1) {
+    if (indexOf(this.menus, menu) > -1) {
       return;
     }
 
@@ -95,59 +76,17 @@ class MainMenu implements IMainMenu {
     menu.disposed.connect(() => this._items.remove(rankItem));
 
     this._items.insert(index, rankItem);
-    Private.menuBar.insertMenu(index, menu);
+    this.insertMenu(index, menu);
   }
 
   private _items = new Vector<Private.IRankItem>();
 }
 
 
-/**
- * A service providing an interface to the main menu.
- */
-export
-const mainMenuProvider: JupyterLabPlugin<IMainMenu> = {
-  id: 'jupyter.services.main-menu',
-  provides: IMainMenu,
-  activate: activateMainMenu
-};
-
-
-/**
- * Activate the main menu extension.
- */
-function activateMainMenu(app: JupyterLab): IMainMenu {
-  Private.menuBar = new MenuBar({ keymap: app.keymap });
-  Private.menuBar.id = 'jp-MainMenu';
-
-  let logo = new Widget();
-  logo.node.className = `${PORTRAIT_ICON_CLASS} ${JUPYTER_ICON_CLASS}`;
-  logo.id = 'jp-MainLogo';
-
-  app.shell.addToTopArea(logo);
-  app.shell.addToTopArea(Private.menuBar);
-
-  return Private.mainMenu;
-}
-
-
 /**
  * A namespace for private data.
  */
 namespace Private {
-  /**
-   * The singleton menu bar instance.
-   */
-  export
-  let menuBar: MenuBar;
-
-  /**
-   * The singleton main menu instance.
-   */
-  export
-  const mainMenu = new MainMenu();
-
-
   /**
    * An object which holds a menu and its sort rank.
    */

+ 4 - 55
src/mainmenu/plugin.ts

@@ -1,14 +1,6 @@
 // Copyright (c) Jupyter Development Team.
 // Distributed under the terms of the Modified BSD License.
 
-import {
-  Menu
-} from 'phosphor/lib/ui/menu';
-
-import {
-  MenuBar
-} from 'phosphor/lib/ui/menubar';
-
 import {
   Widget
 } from 'phosphor/lib/ui/widget';
@@ -48,58 +40,15 @@ const mainMenuProvider: JupyterLabPlugin<IMainMenu> = {
  * Activate the main menu extension.
  */
 function activateMainMenu(app: JupyterLab): IMainMenu {
-  Private.menuBar = new MenuBar({ keymap: app.keymap });
-  Private.menuBar.id = 'jp-MainMenu';
+  let menu = new MainMenu({ keymap: app.keymap });
+  menu.id = 'jp-MainMenu';
 
   let logo = new Widget();
   logo.node.className = `${PORTRAIT_ICON_CLASS} ${JUPYTER_ICON_CLASS}`;
   logo.id = 'jp-MainLogo';
 
   app.shell.addToTopArea(logo);
-  app.shell.addToTopArea(Private.menuBar);
-
-  return Private.mainMenu;
-}
-
-
-/**
- * A namespace for private data.
- */
-namespace Private {
-  /**
-   * The singleton menu bar instance.
-   */
-  export
-  let menuBar: MenuBar;
-
-  /**
-   * The singleton main menu instance.
-   */
-  export
-  const mainMenu = new MainMenu();
-
-
-  /**
-   * An object which holds a menu and its sort rank.
-   */
-  export
-  interface IRankItem {
-    /**
-     * The menu for the item.
-     */
-    menu: Menu;
-
-    /**
-     * The sort rank of the menu.
-     */
-    rank: number;
-  }
+  app.shell.addToTopArea(menu);
 
-  /**
-   * A comparator function for menu rank items.
-   */
-  export
-  function itemCmp(first: IRankItem, second: IRankItem): number {
-    return first.rank - second.rank;
-  }
+  return menu;
 }