blob: 469e7cbef3d95ba6109ac8d45714fa07b3a4b6be (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as DOM from 'vs/base/browser/dom';
import { DisposableStore } from 'vs/base/common/lifecycle';
import { ICellViewModel, INotebookEditorDelegate } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { CellViewModelStateChangeEvent } from 'vs/workbench/contrib/notebook/browser/notebookViewEvents';
import { CellPart } from 'vs/workbench/contrib/notebook/browser/view/cellPart';
import { NotebookCellInternalMetadata } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { NotebookKernelType } from 'vs/workbench/contrib/notebook/common/notebookKernelService';
export class CellExecutionPart extends CellPart {
private kernelDisposables = this._register(new DisposableStore());
constructor(
private readonly _notebookEditor: INotebookEditorDelegate,
private readonly _executionOrderLabel: HTMLElement
) {
super();
this._register(this._notebookEditor.onDidChangeActiveKernel(() => {
if (this.currentCell) {
this.kernelDisposables.clear();
if (this._notebookEditor.activeKernel) {
this.kernelDisposables.add(this._notebookEditor.activeKernel.onDidChange(() => {
if (this.currentCell) {
this.updateExecutionOrder(this.currentCell.internalMetadata);
}
}));
}
this.updateExecutionOrder(this.currentCell.internalMetadata);
}
}));
}
protected override didRenderCell(element: ICellViewModel): void {
this.updateExecutionOrder(element.internalMetadata);
}
private updateExecutionOrder(internalMetadata: NotebookCellInternalMetadata): void {
if (this._notebookEditor.activeKernel?.type === NotebookKernelType.Resolved && this._notebookEditor.activeKernel?.implementsExecutionOrder) {
const executionOrderLabel = typeof internalMetadata.executionOrder === 'number' ?
`[${internalMetadata.executionOrder}]` :
'[ ]';
this._executionOrderLabel.innerText = executionOrderLabel;
} else {
this._executionOrderLabel.innerText = '';
}
}
override updateState(element: ICellViewModel, e: CellViewModelStateChangeEvent): void {
if (e.internalMetadataChanged) {
this.updateExecutionOrder(element.internalMetadata);
}
}
override updateInternalLayoutNow(element: ICellViewModel): void {
if (element.isInputCollapsed) {
DOM.hide(this._executionOrderLabel);
} else {
DOM.show(this._executionOrderLabel);
const top = element.layoutInfo.editorHeight - 22 + element.layoutInfo.statusBarHeight;
this._executionOrderLabel.style.top = `${top}px`;
}
}
}
|