UNPKG

jupyterlab-emrys

Version:

A computational environment for Jupyter. Powered by Emrys

92 lines (91 loc) 2.59 kB
// Copyright (c) Jupyter Development Team. // Distributed under the terms of the Modified BSD License. "use strict"; var arrays = require('phosphor-arrays'); var phosphor_menus_1 = require('phosphor-menus'); var phosphor_widget_1 = require('phosphor-widget'); /** * The class name for all main area portrait tab icons. */ var PORTRAIT_ICON_CLASS = 'jp-MainAreaPortraitIcon'; /** * The class name for the jupyter icon from the default theme. */ var JUPYTER_ICON_CLASS = 'jp-JupyterIcon'; /** * The main menu class. It is intended to be used as a singleton. */ var MainMenu = (function () { function MainMenu() { this._items = []; } /** * Add a new menu item to the main menu. */ MainMenu.prototype.addItem = function (item, options) { if (options === void 0) { options = {}; } var rank = 'rank' in options ? options.rank : 100; var rankItem = { item: item, rank: rank }; var index = arrays.upperBound(this._items, rankItem, Private.itemCmp); arrays.insert(this._items, index, rankItem); var items = Private.menuBar.items.slice(); arrays.insert(items, index, item); Private.menuBar.items = items; }; return MainMenu; }()); exports.MainMenu = MainMenu; /** * The main menu extension. * * #### Notes * The main menu extension adds a menu bar to the top area * of the application shell. * */ exports.mainMenuExtension = { id: 'jupyter.extensions.main-menu', activate: activateMainMenu }; /** * A service providing an interface to the main menu. */ exports.mainMenuProvider = { id: 'jupyter.services.main-menu', provides: MainMenu, resolve: function () { return Private.mainMenu; } }; /** * Activate the main menu extension. */ function activateMainMenu(app) { Private.menuBar.id = 'jp-MainMenu'; var logo = new phosphor_widget_1.Widget(); logo.node.className = PORTRAIT_ICON_CLASS + " " + JUPYTER_ICON_CLASS; logo.id = 'jp-MainLogo'; app.shell.addToTopArea(logo); app.shell.addToTopArea(Private.menuBar); } /** * A namespace for private data. */ var Private; (function (Private) { /** * The singleton menu bar instance. */ Private.menuBar = new phosphor_menus_1.MenuBar(); /** * The singleton main menu instance. */ Private.mainMenu = new MainMenu(); /** * A less-than comparison function for menu rank items. */ function itemCmp(first, second) { return first.rank < second.rank; } Private.itemCmp = itemCmp; })(Private || (Private = {}));