Skip to content

Commit

Permalink
Clean up kernel status item, remove dependency on IFilePath.
Browse files Browse the repository at this point in the history
  • Loading branch information
ian-r-rose committed Oct 19, 2018
1 parent e012000 commit fcf4cc8
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 78 deletions.
3 changes: 0 additions & 3 deletions packages/statusbar-extension/package.json
Expand Up @@ -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",
Expand Down
1 change: 0 additions & 1 deletion 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';
Expand Down
124 changes: 58 additions & 66 deletions packages/statusbar-extension/src/defaults/kernelStatus.tsx
Expand Up @@ -5,28 +5,39 @@
* Part of Jupyterlab status bar defaults.
*/
import React from 'react';
import { IStatusBar, TextItem, TextExt } from '@jupyterlab/statusbar';

import {
JupyterLabPlugin,
JupyterLab,
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 = (
Expand Down Expand Up @@ -59,22 +70,21 @@ class KernelStatus extends VDomRenderer<KernelStatus.Model>
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;
Expand All @@ -91,40 +101,30 @@ class KernelStatus extends VDomRenderer<KernelStatus.Model>

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)) {
Expand All @@ -137,25 +137,27 @@ class KernelStatus extends VDomRenderer<KernelStatus.Model>
}
}

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 {
Expand Down Expand Up @@ -252,7 +254,6 @@ namespace KernelStatus {
consoleTracker: IConsoleTracker;
shell: ApplicationShell;
commands: CommandRegistry;
filePath: IFilePath;
}
}

Expand All @@ -270,28 +271,21 @@ export namespace IKernelStatus {
}
}

// tslint:disable-next-line:variable-name
export const IKernelStatus = new Token<IKernelStatus>(
'@jupyterlab/statusbar:IKernelStatus'
);

export const kernelStatusItem: JupyterLabPlugin<IKernelStatus> = {
id: '@jupyterlab/statusbar:kernel-status-item',
export const kernelStatus: JupyterLabPlugin<void> = {
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, {
Expand All @@ -302,7 +296,5 @@ export const kernelStatusItem: JupyterLabPlugin<IKernelStatus> = {
{ tracker: consoleTracker }
])
});

return item;
}
};
4 changes: 2 additions & 2 deletions packages/statusbar-extension/src/index.ts
Expand Up @@ -9,7 +9,7 @@ import { IStatusBar, StatusBar } from '@jupyterlab/statusbar';

import {
lineColItem,
kernelStatusItem,
kernelStatus,
runningSessionsItem,
filePathItem,
tabSpaceItem,
Expand All @@ -34,7 +34,7 @@ const statusBar: JupyterLabPlugin<IStatusBar> = {
const plugins: JupyterLabPlugin<any>[] = [
statusBar,
lineColItem,
kernelStatusItem,
kernelStatus,
runningSessionsItem,
filePathItem,
tabSpaceItem,
Expand Down
6 changes: 0 additions & 6 deletions packages/statusbar-extension/tsconfig.json
Expand Up @@ -18,9 +18,6 @@
{
"path": "../codeeditor"
},
{
"path": "../codemirror"
},
{
"path": "../console"
},
Expand All @@ -33,9 +30,6 @@
{
"path": "../docregistry"
},
{
"path": "../filebrowser"
},
{
"path": "../fileeditor"
},
Expand Down

0 comments on commit fcf4cc8

Please sign in to comment.