diff --git a/packages/application/src/shell.ts b/packages/application/src/shell.ts index 3ece75171c..c6a230e96c 100644 --- a/packages/application/src/shell.ts +++ b/packages/application/src/shell.ts @@ -13,7 +13,7 @@ import { Message, MessageLoop, IMessageHandler } from '@lumino/messaging'; import { ISignal, Signal } from '@lumino/signaling'; -import { Panel, Widget, BoxLayout } from '@lumino/widgets'; +import { Panel, Widget, BoxLayout, TabPanel } from '@lumino/widgets'; /** * The Jupyter Notebook application shell token. @@ -73,6 +73,7 @@ export class NotebookShell extends Widget implements JupyterFrontEnd.IShell { rootLayout.addWidget(this._main); this.layout = rootLayout; + this._mainIsTabPanel = false; } /** @@ -103,12 +104,29 @@ export class NotebookShell extends Widget implements JupyterFrontEnd.IShell { return this._menuWrapper; } + /** + * Get the status of main area. + */ + get mainIsTabPanel(): Boolean { + return this._mainIsTabPanel; + } + + /** + * Set the status of main area. + */ + set mainIsTabPanel(value: Boolean) { + this._mainIsTabPanel = value; + } + /** * Activate a widget in its area. */ activateById(id: string): void { const widget = find(this.widgets('main'), w => w.id === id); if (widget) { + if (this._mainIsTabPanel) { + (this._main.widgets[0] as TabPanel).tabBar.currentTitle = widget.title; + } widget.activate(); } } @@ -137,11 +155,16 @@ export class NotebookShell extends Widget implements JupyterFrontEnd.IShell { return this._menuHandler.addWidget(widget, rank); } if (area === 'main' || area === undefined) { - if (this._main.widgets.length > 0) { + let main = this._main; + + // If main area is a TabPanel, then the widget is added to it. + if (this._mainIsTabPanel) main = main.widgets[0] as TabPanel; + else if (this._main.widgets.length > 0) { // do not add the widget if there is already one return; } - this._main.addWidget(widget); + + main.addWidget(widget); this._main.update(); this._currentChanged.emit(void 0); } @@ -175,7 +198,10 @@ export class NotebookShell extends Widget implements JupyterFrontEnd.IShell { case 'menu': return iter(this._menuHandler.panel.widgets); case 'main': - return iter(this._main.widgets); + // If the main area is a TabPanel returns the list of its Widgets. + if (this._mainIsTabPanel) + return iter((this._main.widgets[0] as TabPanel).widgets); + else return iter(this._main.widgets); default: throw new Error(`Invalid area: ${area}`); } @@ -188,6 +214,7 @@ export class NotebookShell extends Widget implements JupyterFrontEnd.IShell { private _spacer: Widget; private _main: Panel; private _currentChanged = new Signal(this); + private _mainIsTabPanel: Boolean; } /** diff --git a/packages/tree-extension/src/index.ts b/packages/tree-extension/src/index.ts index 5fb709e4fc..38f69f054e 100644 --- a/packages/tree-extension/src/index.ts +++ b/packages/tree-extension/src/index.ts @@ -31,6 +31,7 @@ import { } from '@jupyterlab/ui-components'; import { Menu, MenuBar, TabPanel } from '@lumino/widgets'; +import { NotebookShell } from '@jupyter-notebook/application'; /** * The file browser factory. @@ -116,6 +117,11 @@ const browserWidget: JupyterFrontEndPlugin = { const tabPanel = new TabPanel({ tabPlacement: 'top', tabsMovable: true }); tabPanel.addClass('jp-TreePanel'); + // Add the TabPanel to the main area. + app.shell.add(tabPanel, 'main', { rank: 100 }); + // Set the main area as a TabPanel. + (app.shell as NotebookShell).mainIsTabPanel = true; + const trans = translator.load('notebook'); const { defaultBrowser: browser } = factory; @@ -124,8 +130,7 @@ const browserWidget: JupyterFrontEndPlugin = { browser.node.setAttribute('aria-label', trans.__('File Browser Section')); browser.title.icon = folderIcon; - tabPanel.addWidget(browser); - tabPanel.tabBar.addTab(browser.title); + app.shell.add(browser, 'main'); // Toolbar toolbarRegistry.addFactory( @@ -155,8 +160,7 @@ const browserWidget: JupyterFrontEndPlugin = { running.id = 'jp-running-sessions'; running.title.label = trans.__('Running'); running.title.icon = runningIcon; - tabPanel.addWidget(running); - tabPanel.tabBar.addTab(running.title); + app.shell.add(running, 'main'); } // show checkboxes by default if there is no user setting override @@ -171,8 +175,6 @@ const browserWidget: JupyterFrontEndPlugin = { .catch((reason: Error) => { console.error(reason.message); }); - - app.shell.add(tabPanel, 'main', { rank: 100 }); } };