From fcf4cc85d6a47f382c3f319dddd81f4f254499ff Mon Sep 17 00:00:00 2001 From: Ian Rose Date: Thu, 18 Oct 2018 17:49:04 -0700 Subject: [PATCH] Clean up kernel status item, remove dependency on IFilePath. --- packages/statusbar-extension/package.json | 3 - .../statusbar-extension/src/defaults/index.ts | 1 - .../src/defaults/kernelStatus.tsx | 124 ++++++++---------- packages/statusbar-extension/src/index.ts | 4 +- packages/statusbar-extension/tsconfig.json | 6 - 5 files changed, 60 insertions(+), 78 deletions(-) diff --git a/packages/statusbar-extension/package.json b/packages/statusbar-extension/package.json index 62aa19c117af..5b3ef870b74f 100644 --- a/packages/statusbar-extension/package.json +++ b/packages/statusbar-extension/package.json @@ -37,17 +37,14 @@ "@jupyterlab/apputils": "^0.19.1", "@jupyterlab/cells": "^0.19.1", "@jupyterlab/codeeditor": "^0.19.1", - "@jupyterlab/codemirror": "^0.19.1", "@jupyterlab/console": "^0.19.1", "@jupyterlab/coreutils": "^2.2.1", "@jupyterlab/docmanager": "^0.19.1", "@jupyterlab/docregistry": "^0.19.1", - "@jupyterlab/filebrowser": "^0.19.3", "@jupyterlab/fileeditor": "^0.19.1", "@jupyterlab/notebook": "^0.19.2", "@jupyterlab/services": "^3.2.1", "@jupyterlab/statusbar": "^0.7.1", - "@phosphor/algorithm": "^1.1.2", "@phosphor/commands": "^1.6.1", "@phosphor/coreutils": "^1.3.0", "@phosphor/disposable": "^1.1.2", diff --git a/packages/statusbar-extension/src/defaults/index.ts b/packages/statusbar-extension/src/defaults/index.ts index 6c413bc1bd88..7c6ff590a127 100644 --- a/packages/statusbar-extension/src/defaults/index.ts +++ b/packages/statusbar-extension/src/defaults/index.ts @@ -1,5 +1,4 @@ export * from './lineCol'; -export * from './fileUpload'; export * from './kernelStatus'; export * from './runningSessions'; export * from './filePath'; diff --git a/packages/statusbar-extension/src/defaults/kernelStatus.tsx b/packages/statusbar-extension/src/defaults/kernelStatus.tsx index 35794d2299ec..8d35c8679012 100644 --- a/packages/statusbar-extension/src/defaults/kernelStatus.tsx +++ b/packages/statusbar-extension/src/defaults/kernelStatus.tsx @@ -5,7 +5,6 @@ * Part of Jupyterlab status bar defaults. */ import React from 'react'; -import { IStatusBar, TextItem, TextExt } from '@jupyterlab/statusbar'; import { JupyterLabPlugin, @@ -13,20 +12,32 @@ import { ApplicationShell } from '@jupyterlab/application'; -import { INotebookTracker, NotebookPanel } from '@jupyterlab/notebook'; +import { IClientSession, VDomRenderer, VDomModel } from '@jupyterlab/apputils'; import { IConsoleTracker, ConsolePanel } from '@jupyterlab/console'; -import { IClientSession, VDomRenderer, VDomModel } from '@jupyterlab/apputils'; -import { ISignal } from '@phosphor/signaling'; -import { Token } from '@phosphor/coreutils'; -import { IDisposable } from '@phosphor/disposable'; + +import { INotebookTracker, NotebookPanel } from '@jupyterlab/notebook'; + import { Kernel, Session } from '@jupyterlab/services'; -import { Widget } from '@phosphor/widgets'; -import { IStatusContext } from '../contexts'; + +import { + interactiveItem, + IStatusBar, + TextItem, + TextExt +} from '@jupyterlab/statusbar'; + import { CommandRegistry } from '@phosphor/commands'; -import { interactiveItem } from '@jupyterlab/statusbar'; + +import { IDisposable } from '@phosphor/disposable'; + import { Message } from '@phosphor/messaging'; -import { IFilePath } from './filePath'; + +import { ISignal, Signal } from '@phosphor/signaling'; + +import { Widget } from '@phosphor/widgets'; + +import { IStatusContext } from '../contexts'; // tslint:disable-next-line:variable-name const KernelStatusComponent = ( @@ -59,22 +70,21 @@ class KernelStatus extends VDomRenderer this._consoleTracker = opts.consoleTracker; this._commands = opts.commands; this._shell = opts.shell; - this._filePath = opts.filePath; - this._shell.currentChanged.connect(this._onMainAreaCurrentChange); - this._filePath.model!.stateChanged.connect(this._onFilePathChange); + this._shell.currentChanged.connect( + this._onCurrentChanged, + this + ); this.model = new KernelStatus.Model( this._getFocusedSession(this._shell.currentWidget) ); - if (this.model!.type === 'notebook') { - this.addClass(interactiveItem); - } - - this._onFilePathChange(); + this.addClass(interactiveItem); } + readonly model: KernelStatus.Model; + render() { if (this.model === null) { return null; @@ -91,40 +101,30 @@ class KernelStatus extends VDomRenderer dispose() { super.dispose(); - - this._shell.currentChanged.disconnect(this._onMainAreaCurrentChange); + Signal.disconnectAll(this); + this._shell.currentChanged.disconnect(this._onCurrentChanged); } protected onUpdateRequest(msg: Message) { - this.model!.session = this._getFocusedSession(this._shell.currentWidget); - - if (this.model!.type === 'notebook') { - this.addClass(interactiveItem); - } else { - this.removeClass(interactiveItem); - } - + this.model.session = this._getFocusedSession(this._shell.currentWidget); super.onUpdateRequest(msg); } private _handleClick = () => { - if (this.model!.type === 'notebook') { - this._commands.execute('notebook:change-kernel'); - } + // The kernel menu flavor of change kernel delegates + // based on the active widget, so use that. + this._commands.execute('kernelmenu:change'); }; - private _onFilePathChange = () => { - if (this.model!.type === 'notebook') { - this.node.title = `Change active kernel for ${ - this._filePath.model!.name - }`; - } else { - this.node.title = `Active kernel type for ${this._filePath.model!.name}`; - } + private _onTitleChanged = () => { + const name = this._shell.currentWidget + ? this._shell.currentWidget.title.label + : 'activity'; + this.node.title = `Change active kernel for ${name}`; }; private _getFocusedSession(val: Widget | null): IClientSession | null { - if (val === null) { + if (!val) { return null; } else { if (this._notebookTracker.has(val)) { @@ -137,25 +137,27 @@ class KernelStatus extends VDomRenderer } } - private _onMainAreaCurrentChange = ( + private _onCurrentChanged( shell: ApplicationShell, change: ApplicationShell.IChangedArgs - ) => { - const { newValue } = change; - const editor = this._getFocusedSession(newValue); - this.model!.session = editor; - if (this.model!.type === 'notebook') { - this.addClass(interactiveItem); - } else { - this.removeClass(interactiveItem); + ): void { + if (this._current) { + this._current.title.changed.disconnect(this._onTitleChanged, this); } - }; + this._current = change.newValue; + this._current.title.changed.connect( + this._onTitleChanged, + this + ); + const session = this._getFocusedSession(this._current); + this.model.session = session; + } + private _current: Widget | undefined; private _notebookTracker: INotebookTracker; private _consoleTracker: IConsoleTracker; private _shell: ApplicationShell; private _commands: CommandRegistry; - private _filePath: IFilePath; } namespace KernelStatus { @@ -252,7 +254,6 @@ namespace KernelStatus { consoleTracker: IConsoleTracker; shell: ApplicationShell; commands: CommandRegistry; - filePath: IFilePath; } } @@ -270,28 +271,21 @@ export namespace IKernelStatus { } } -// tslint:disable-next-line:variable-name -export const IKernelStatus = new Token( - '@jupyterlab/statusbar:IKernelStatus' -); - -export const kernelStatusItem: JupyterLabPlugin = { - id: '@jupyterlab/statusbar:kernel-status-item', +export const kernelStatus: JupyterLabPlugin = { + id: '@jupyterlab/statusbar:kernel-status', autoStart: true, - requires: [IStatusBar, INotebookTracker, IConsoleTracker, IFilePath], + requires: [IStatusBar, INotebookTracker, IConsoleTracker], activate: ( app: JupyterLab, statusBar: IStatusBar, notebookTracker: INotebookTracker, - consoleTracker: IConsoleTracker, - filePath: IFilePath + consoleTracker: IConsoleTracker ) => { const item = new KernelStatus({ shell: app.shell, notebookTracker, consoleTracker, - commands: app.commands, - filePath + commands: app.commands }); statusBar.registerStatusItem('kernel-status-item', item, { @@ -302,7 +296,5 @@ export const kernelStatusItem: JupyterLabPlugin = { { tracker: consoleTracker } ]) }); - - return item; } }; diff --git a/packages/statusbar-extension/src/index.ts b/packages/statusbar-extension/src/index.ts index 65daac911480..55c851fe25ff 100644 --- a/packages/statusbar-extension/src/index.ts +++ b/packages/statusbar-extension/src/index.ts @@ -9,7 +9,7 @@ import { IStatusBar, StatusBar } from '@jupyterlab/statusbar'; import { lineColItem, - kernelStatusItem, + kernelStatus, runningSessionsItem, filePathItem, tabSpaceItem, @@ -34,7 +34,7 @@ const statusBar: JupyterLabPlugin = { const plugins: JupyterLabPlugin[] = [ statusBar, lineColItem, - kernelStatusItem, + kernelStatus, runningSessionsItem, filePathItem, tabSpaceItem, diff --git a/packages/statusbar-extension/tsconfig.json b/packages/statusbar-extension/tsconfig.json index 2783fe48cca7..6e056619af2e 100644 --- a/packages/statusbar-extension/tsconfig.json +++ b/packages/statusbar-extension/tsconfig.json @@ -18,9 +18,6 @@ { "path": "../codeeditor" }, - { - "path": "../codemirror" - }, { "path": "../console" }, @@ -33,9 +30,6 @@ { "path": "../docregistry" }, - { - "path": "../filebrowser" - }, { "path": "../fileeditor" },