jupyterlab-emrys
Version:
A computational environment for Jupyter. Powered by Emrys
245 lines (244 loc) • 7.42 kB
JavaScript
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
;
var phosphor_menus_1 = require('phosphor-menus');
var iframe_1 = require('../iframe');
var plugin_1 = require('../mainmenu/plugin');
/**
* The class name added to the help widget.
*/
var HELP_CLASS = 'jp-Help';
/**
* A list of commands to add to the help widget.
*/
var COMMANDS = [
{
text: 'Scipy Lecture Notes',
id: 'help-doc:scipy-lecture-notes',
url: 'http://www.scipy-lectures.org/'
},
{
text: 'Numpy Reference',
id: 'help-doc:numpy-reference',
url: '//docs.scipy.org/doc/numpy/reference/'
},
{
text: 'Scipy Reference',
id: 'help-doc:scipy-reference',
url: '//docs.scipy.org/doc/scipy/reference/'
},
{
text: 'Notebook Tutorial',
id: 'help-doc:notebook-tutorial',
url: '//nbviewer.jupyter.org/github/jupyter/notebook/' +
'blob/master/docs/source/examples/Notebook/Notebook Basics.ipynb'
},
{
text: 'Python Reference',
id: 'help-doc:python-reference',
url: '//docs.python.org/3.5/'
},
{
text: 'IPython Reference',
id: 'help-doc:ipython-reference',
url: '//ipython.org/documentation.html?v=20160707164940'
},
{
text: 'Matplotlib Reference',
id: 'help-doc:mathplotlib-reference',
url: 'http://matplotlib.org/contents.html?v=20160707164940'
},
{
text: 'SymPy Reference',
id: 'help-doc:sympy-reference',
url: 'http://docs.sympy.org/latest/index.html?v=20160707164940'
},
{
text: 'Pandas Reference',
id: 'help-doc:pandas-reference',
url: 'http://pandas.pydata.org/pandas-docs/stable/?v=20160707164940'
},
{
text: 'Markdown Reference',
id: 'help-doc:markdown-reference',
url: '//help.github.com/articles/getting-started-with-writing-and-formatting-on-github/'
}
];
/**
* The help handler extension.
*/
exports.helpHandlerExtension = {
id: 'jupyter.extensions.help-handler',
requires: [plugin_1.MainMenu],
activate: activateHelpHandler
};
/**
* Activate the help handler extension.
*
* @param app - The phosphide application object.
*
* returns A promise that resolves when the extension is activated.
*/
function activateHelpHandler(app, mainMenu) {
var iframe = new iframe_1.IFrame();
iframe.addClass(HELP_CLASS);
iframe.title.text = 'Help';
iframe.id = 'help-doc';
var helpCommandItems = COMMANDS.map(function (command) {
return {
id: command.id,
handler: function () {
Private.attachHelp(app, iframe);
Private.showHelp(app, iframe);
iframe.loadURL(command.url);
}
};
});
app.commands.add(helpCommandItems);
app.commands.add([
{
id: 'help-doc:activate',
handler: function () { Private.showHelp(app, iframe); }
},
{
id: 'help-doc:hide',
handler: function () { Private.hideHelp(app, iframe); }
},
{
id: 'help-doc:toggle',
handler: function () { Private.toggleHelp(app, iframe); }
}
]);
var helpPaletteItems = COMMANDS.map(function (command) {
return {
command: command.id,
text: command.text,
caption: "Open " + command.text,
category: 'Help'
};
});
app.palette.add(helpPaletteItems);
var menu = new phosphor_menus_1.Menu([
new phosphor_menus_1.MenuItem({
text: 'About JupyterLab',
handler: function () {
app.commands.execute('about-jupyterlab:show');
}
}),
new phosphor_menus_1.MenuItem({
text: 'Frequently Asked Questions',
handler: function () {
app.commands.execute('faq-jupyterlab:show');
}
}),
new phosphor_menus_1.MenuItem({
text: 'Notebook Tutorial',
handler: function () {
app.commands.execute('help-doc:notebook-tutorial');
}
}),
new phosphor_menus_1.MenuItem({
type: phosphor_menus_1.MenuItem.Separator
}),
new phosphor_menus_1.MenuItem({
text: 'IPython Reference',
handler: function () {
app.commands.execute('help-doc:ipython-reference');
}
}),
new phosphor_menus_1.MenuItem({
text: 'Markdown Reference',
handler: function () {
app.commands.execute('help-doc:markdown-reference');
}
}),
new phosphor_menus_1.MenuItem({
text: 'Matplotlib Reference',
handler: function () {
app.commands.execute('help-doc:mathplotlib-reference');
}
}),
new phosphor_menus_1.MenuItem({
text: 'Numpy Reference',
handler: function () {
app.commands.execute('help-doc:numpy-reference');
}
}),
new phosphor_menus_1.MenuItem({
text: 'Pandas Reference',
handler: function () {
app.commands.execute('help-doc:pandas-reference');
}
}),
new phosphor_menus_1.MenuItem({
text: 'Python Reference',
handler: function () {
app.commands.execute('help-doc:python-reference');
}
}),
new phosphor_menus_1.MenuItem({
text: 'Scipy Lecture Notes',
handler: function () {
app.commands.execute('help-doc:scipy-lecture-notes');
}
}),
new phosphor_menus_1.MenuItem({
text: 'Scipy Reference',
handler: function () {
app.commands.execute('help-doc:scipy-reference');
}
}),
new phosphor_menus_1.MenuItem({
text: 'SymPy Reference',
handler: function () {
app.commands.execute('help-doc:sympy-reference');
}
})
]);
var helpMenu = new phosphor_menus_1.MenuItem({ text: 'Help', submenu: menu });
mainMenu.addItem(helpMenu);
return Promise.resolve(void 0);
}
/**
* A namespace for help plugin private functions.
*/
var Private;
(function (Private) {
/**
* Attach the help iframe widget to the application shell.
*/
function attachHelp(app, iframe) {
if (!iframe.isAttached) {
app.shell.addToRightArea(iframe);
}
}
Private.attachHelp = attachHelp;
/**
* Show the help widget.
*/
function showHelp(app, iframe) {
app.shell.activateRight(iframe.id);
}
Private.showHelp = showHelp;
/**
* Hide the help widget.
*/
function hideHelp(app, iframe) {
if (!iframe.isHidden) {
app.shell.collapseRight();
}
}
Private.hideHelp = hideHelp;
/**
* Toggle whether the help widget is shown or hidden.
*/
function toggleHelp(app, iframe) {
if (iframe.isHidden) {
showHelp(app, iframe);
}
else {
hideHelp(app, iframe);
}
}
Private.toggleHelp = toggleHelp;
})(Private || (Private = {}));