123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- // Copyright (c) Jupyter Development Team.
- // Distributed under the terms of the Modified BSD License.
- 'use strict';
- import {
- Application
- } from 'phosphide/lib/core/application';
- import {
- Widget
- } from 'phosphor-widget';
- import {
- IFrame
- } from './iframe';
- /**
- * The class name added to the help widget.
- */
- const HELP_CLASS = 'jp-Help';
- /**
- * A list of commands to add to the help widget.
- */
- const 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: 'http://docs.scipy.org/doc/numpy/reference/'
- },
- {
- text: 'Scipy Reference',
- id: 'help-doc:scipy-reference',
- url: 'http://docs.scipy.org/doc/scipy/reference/'
- },
- {
- text: 'Notebook Tutorial',
- id: 'help-doc:notebook-tutorial',
- url: 'http://nbviewer.jupyter.org/github/jupyter/notebook/' +
- 'blob/master/docs/source/examples/Notebook/Notebook Basics.ipynb'
- }
- ];
- /**
- * The help handler extension.
- */
- export
- const helpHandlerExtension = {
- id: 'jupyter.extensions.helpHandler',
- 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: Application): Promise<void> {
- let widget = new IFrame();
- widget.addClass(HELP_CLASS);
- widget.title.text = 'Help';
- widget.id = 'help-doc';
- let helpCommandItems = COMMANDS.map(command => {
- return {
- id: command.id,
- handler: () => {
- attachHelp();
- showHelp();
- widget.loadURL(command.url);
- }
- };
- });
- app.commands.add(helpCommandItems);
- app.commands.add([
- {
- id: 'help-doc:activate',
- handler: showHelp
- },
- {
- id: 'help-doc:hide',
- handler: hideHelp
- },
- {
- id: 'help-doc:toggle',
- handler: toggleHelp
- },
- ]);
- let helpPaletteItems = COMMANDS.map(command => {
- return {
- command: command.id,
- text: command.text,
- caption: `Open ${command.text}`,
- category: 'Help'
- };
- });
- app.palette.add(helpPaletteItems);
- return Promise.resolve(void 0);
- function attachHelp(): void {
- if (!widget.isAttached) app.shell.addToRightArea(widget);
- }
- function showHelp(): void {
- app.shell.activateRight(widget.id);
- }
- function hideHelp(): void {
- if (!widget.isHidden) app.shell.collapseRight();
- }
- function toggleHelp(): void {
- if (widget.isHidden) {
- showHelp();
- } else {
- hideHelp();
- }
- }
- }
|