提交 ed1ecfd5 编写于 作者: R rebornix

kernel picker status bar item.

上级 be44e409
......@@ -4,15 +4,20 @@
*--------------------------------------------------------------------------------------------*/
import * as nls from 'vs/nls';
import { Action2, MenuId, registerAction2 } from 'vs/platform/actions/common/actions';
import { Registry } from 'vs/platform/registry/common/platform';
import { Action2, registerAction2 } from 'vs/platform/actions/common/actions';
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import { IQuickInputService, IQuickPickItem, QuickPickInput } from 'vs/platform/quickinput/common/quickInput';
import { INotebookCellActionContext, NOTEBOOK_ACTIONS_CATEGORY } from 'vs/workbench/contrib/notebook/browser/contrib/coreActions';
import { INotebookEditor, NOTEBOOK_HAS_MULTIPLE_KERNELS, NOTEBOOK_IS_ACTIVE_EDITOR } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { INotebookCellActionContext, NOTEBOOK_ACTIONS_CATEGORY, getActiveNotebookEditor } from 'vs/workbench/contrib/notebook/browser/contrib/coreActions';
import { INotebookEditor, NOTEBOOK_IS_ACTIVE_EDITOR } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { INotebookService } from 'vs/workbench/contrib/notebook/common/notebookService';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { CancellationTokenSource } from 'vs/base/common/cancellation';
import { INotebookKernelInfoDto2, INotebookKernelInfo2 } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { INotebookKernelInfo2, INotebookKernelInfo } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { Extensions as WorkbenchExtensions, IWorkbenchContributionsRegistry, IWorkbenchContribution } from 'vs/workbench/common/contributions';
import { LifecyclePhase } from 'vs/platform/lifecycle/common/lifecycle';
import { Disposable, DisposableStore, MutableDisposable } from 'vs/base/common/lifecycle';
import { IStatusbarEntryAccessor, IStatusbarService, StatusbarAlignment } from 'vs/workbench/services/statusbar/common/statusbar';
registerAction2(class extends Action2 {
......@@ -23,12 +28,6 @@ registerAction2(class extends Action2 {
title: { value: nls.localize('notebookActions.selectKernel', "Select Notebook Kernel"), original: 'Select Notebook Kernel' },
precondition: NOTEBOOK_IS_ACTIVE_EDITOR,
icon: { id: 'codicon/server-environment' },
menu: {
id: MenuId.EditorTitle,
when: NOTEBOOK_HAS_MULTIPLE_KERNELS,
group: 'navigation',
order: -2,
},
f1: true
});
}
......@@ -54,8 +53,8 @@ registerAction2(class extends Action2 {
label: a.label,
picked: a.id === activeKernel?.id,
description:
(a as INotebookKernelInfoDto2).description
? (a as INotebookKernelInfoDto2).description
(a as INotebookKernelInfo2).description
? (a as INotebookKernelInfo2).description
: a.extension.value + (a.id === activeKernel?.id
? nls.localize('currentActiveKernel', " (Currently Active)")
: ''),
......@@ -89,3 +88,53 @@ registerAction2(class extends Action2 {
}
});
export class KernelStatus extends Disposable implements IWorkbenchContribution {
private _editorDisposable = new DisposableStore();
private readonly kernelInfoElement = this._register(new MutableDisposable<IStatusbarEntryAccessor>());
constructor(
@IEditorService private readonly _editorService: IEditorService,
@INotebookService private readonly _notebookService: INotebookService,
@IStatusbarService private readonly _statusbarService: IStatusbarService,
) {
super();
this.registerListeners();
}
registerListeners() {
this._register(this._editorService.onDidActiveEditorChange(() => this.updateStatusbar()));
this._register(this._notebookService.onDidChangeActiveEditor(() => this.updateStatusbar()));
this._register(this._notebookService.onDidChangeKernels(() => this.updateStatusbar()));
}
updateStatusbar() {
this._editorDisposable.clear();
const activeEditor = getActiveNotebookEditor(this._editorService);
if (activeEditor && activeEditor.multipleKernelsAvailable) {
this.showKernelStatus(activeEditor.activeKernel);
this._editorDisposable.add(activeEditor.onDidChangeKernel(() => {
if (activeEditor.multipleKernelsAvailable) {
this.showKernelStatus(activeEditor.activeKernel);
} else {
this.kernelInfoElement.clear();
}
}));
} else {
this.kernelInfoElement.clear();
}
}
showKernelStatus(kernel: INotebookKernelInfo | INotebookKernelInfo2 | undefined) {
this.kernelInfoElement.value = this._statusbarService.addEntry({
text: kernel ? kernel.label : 'Choose Kernel',
ariaLabel: kernel ? kernel.label : 'Choose Kernel',
tooltip: nls.localize('chooseActiveKernel', "Choose kernel for current notebook"),
command: 'notebook.selectKernel',
}, 'notebook.selectKernel', nls.localize('notebook.selectKernel', "Choose kernel for current notebook"), StatusbarAlignment.RIGHT, 100);
}
}
Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench).registerWorkbenchContribution(KernelStatus, LifecyclePhase.Ready);
......@@ -23,7 +23,7 @@ import { OutputRenderer } from 'vs/workbench/contrib/notebook/browser/view/outpu
import { CellLanguageStatusBarItem, TimerRenderer } from 'vs/workbench/contrib/notebook/browser/view/renderers/cellRenderer';
import { CellViewModel, IModelDecorationsChangeAccessor, NotebookViewModel } from 'vs/workbench/contrib/notebook/browser/viewModel/notebookViewModel';
import { NotebookCellTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookCellTextModel';
import { CellKind, IProcessedOutput, IRenderOutput, NotebookCellMetadata, NotebookDocumentMetadata, INotebookKernelInfo, IEditor, INotebookKernelInfoDto2 } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { CellKind, IProcessedOutput, IRenderOutput, NotebookCellMetadata, NotebookDocumentMetadata, INotebookKernelInfo, IEditor, INotebookKernelInfoDto2, INotebookKernelInfo2 } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { Webview } from 'vs/workbench/contrib/webview/browser/webview';
import { NotebookTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookTextModel';
......@@ -171,7 +171,8 @@ export interface INotebookEditor extends IEditor {
readonly onDidChangeModel: Event<NotebookTextModel | undefined>;
readonly onDidFocusEditorWidget: Event<void>;
isNotebookEditor: boolean;
activeKernel: INotebookKernelInfo | INotebookKernelInfoDto2 | undefined;
activeKernel: INotebookKernelInfo | INotebookKernelInfo2 | undefined;
multipleKernelsAvailable: boolean;
readonly onDidChangeKernel: Event<void>;
isDisposed: boolean;
......
......@@ -132,7 +132,7 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor
return this._notebookViewModel?.notebookDocument;
}
private _activeKernel: INotebookKernelInfo | INotebookKernelInfoDto2 | undefined = undefined;
private _activeKernel: INotebookKernelInfo | INotebookKernelInfo2 | undefined = undefined;
private readonly _onDidChangeKernel = this._register(new Emitter<void>());
readonly onDidChangeKernel: Event<void> = this._onDidChangeKernel.event;
......@@ -140,7 +140,7 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor
return this._activeKernel;
}
set activeKernel(kernel: INotebookKernelInfo | INotebookKernelInfoDto2 | undefined) {
set activeKernel(kernel: INotebookKernelInfo | INotebookKernelInfo2 | undefined) {
if (this._isDisposed) {
return;
}
......@@ -149,6 +149,8 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor
this._onDidChangeKernel.fire();
}
multipleKernelsAvailable: boolean = false;
private readonly _onDidChangeActiveEditor = this._register(new Emitter<this>());
readonly onDidChangeActiveEditor: Event<this> = this._onDidChangeActiveEditor.event;
......@@ -560,10 +562,13 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor
if (provider.kernel && (availableKernels.length + availableKernels2.length) > 0) {
this._notebookHasMultipleKernels!.set(true);
this.multipleKernelsAvailable = true;
} else if ((availableKernels.length + availableKernels2.length) > 1) {
this._notebookHasMultipleKernels!.set(true);
this.multipleKernelsAvailable = true;
} else {
this._notebookHasMultipleKernels!.set(false);
this.multipleKernelsAvailable = false;
}
if (provider && provider.kernel) {
......
......@@ -329,7 +329,7 @@ export class NotebookService extends Disposable implements INotebookService, ICu
const tokenSource = new CancellationTokenSource();
return provider.resolveKernel(editorId, uri, dto.id, tokenSource.token);
},
executeNotebook: async (uri: URI, handle: number | undefined, token: CancellationToken) => {
executeNotebookCell: async (uri: URI, handle: number | undefined, token: CancellationToken) => {
return provider.executeNotebook(uri, dto.id, handle, token);
}
};
......
......@@ -62,6 +62,8 @@ export class TestNotebookEditor implements INotebookEditor {
constructor(
) { }
multipleKernelsAvailable: boolean = false;
uri?: URI | undefined;
textModel?: NotebookTextModel | undefined;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册