123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- // Copyright (c) Jupyter Development Team.
- // Distributed under the terms of the Modified BSD License.
- import {
- ILabShell,
- ILayoutRestorer,
- JupyterFrontEnd,
- JupyterFrontEndPlugin
- } from '@jupyterlab/application';
- import { TabBarSvg } from '@jupyterlab/ui-components';
- import { each } from '@phosphor/algorithm';
- import { Widget } from '@phosphor/widgets';
- /**
- * The default tab manager extension.
- */
- const plugin: JupyterFrontEndPlugin<void> = {
- id: '@jupyterlab/tabmanager-extension:plugin',
- activate: (
- app: JupyterFrontEnd,
- labShell: ILabShell | null,
- restorer: ILayoutRestorer | null
- ): void => {
- const { shell } = app;
- const tabs = new TabBarSvg<Widget>({
- kind: 'tabManager',
- orientation: 'vertical'
- });
- const header = document.createElement('header');
- if (restorer) {
- restorer.add(tabs, 'tab-manager');
- }
- tabs.id = 'tab-manager';
- tabs.title.iconClass = 'jp-TabIcon jp-SideBar-tabIcon';
- tabs.title.caption = 'Open Tabs';
- header.textContent = 'Open Tabs';
- tabs.node.insertBefore(header, tabs.contentNode);
- shell.add(tabs, 'left', { rank: 600 });
- void app.restored.then(() => {
- const populate = () => {
- tabs.clearTabs();
- each(shell.widgets('main'), widget => {
- tabs.addTab(widget.title);
- });
- };
- // Connect signal handlers.
- tabs.tabActivateRequested.connect((sender, tab) => {
- shell.activateById(tab.title.owner.id);
- });
- tabs.tabCloseRequested.connect((sender, tab) => {
- tab.title.owner.close();
- populate();
- });
- // If available, connect to the shell's layout modified signal.
- if (labShell) {
- labShell.layoutModified.connect(() => {
- populate();
- });
- // when current tab changes, make sure it is activated
- labShell.currentChanged.connect((sender, args) => {
- if (args.newValue) {
- shell.activateById(args.newValue.id);
- }
- });
- }
- // Populate the tab manager.
- populate();
- });
- },
- autoStart: true,
- optional: [ILabShell, ILayoutRestorer]
- };
- /**
- * Export the plugin as default.
- */
- export default plugin;
|