1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- // Copyright (c) Jupyter Development Team.
- // Distributed under the terms of the Modified BSD License.
- import {
- JupyterLab, JupyterLabPlugin
- } from '../application';
- import {
- ICommandLinker
- } from '../commandlinker';
- import {
- ICommandPalette
- } from '../commandpalette';
- import {
- InstanceTracker
- } from '../common/instancetracker';
- import {
- ILayoutRestorer
- } from '../layoutrestorer';
- import {
- FaqModel, FaqWidget
- } from './widget';
- /**
- * The FAQ page extension.
- */
- const plugin: JupyterLabPlugin<void> = {
- id: 'jupyter.extensions.faq',
- requires: [ICommandPalette, ICommandLinker, ILayoutRestorer],
- activate: activateFAQ,
- autoStart: true
- };
- /**
- * Export the plugin as default.
- */
- export default plugin;
- /**
- * Activate the FAQ plugin.
- */
- function activateFAQ(app: JupyterLab, palette: ICommandPalette, linker: ICommandLinker, layout: ILayoutRestorer): void {
- const category = 'Help';
- const command = 'faq-jupyterlab:show';
- const model = new FaqModel();
- const tracker = new InstanceTracker<FaqWidget>({ namespace: 'faq' });
- // Handle state restoration.
- layout.restore(tracker, {
- command,
- args: () => null,
- name: () => 'faq'
- });
- let widget: FaqWidget;
- function newWidget(): FaqWidget {
- let widget = new FaqWidget({ linker });
- widget.model = model;
- widget.id = 'faq';
- widget.title.label = 'FAQ';
- widget.title.closable = true;
- tracker.add(widget);
- return widget;
- }
- app.commands.addCommand(command, {
- label: 'Frequently Asked Questions',
- execute: () => {
- if (!widget || widget.isDisposed) {
- widget = newWidget();
- app.shell.addToMainArea(widget);
- }
- app.shell.activateMain(widget.id);
- }
- });
- palette.addItem({ command, category });
- }
|