Skip to content

Commit e7a78e0

Browse files
authored
Show source action in select more picker. (microsoft#166734)
1 parent 79c26b4 commit e7a78e0

File tree

1 file changed

+36
-6
lines changed

1 file changed

+36
-6
lines changed

src/vs/workbench/contrib/notebook/browser/viewParts/notebookKernelQuickPickStrategy.ts

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import { MarshalledId } from 'vs/base/common/marshallingIds';
3434
import { IAction } from 'vs/base/common/actions';
3535
import { ThemeIcon } from 'vs/platform/theme/common/themeService';
3636
import { executingStateIcon, selectKernelIcon } from 'vs/workbench/contrib/notebook/browser/notebookIcons';
37+
import { MenuItemAction } from 'vs/platform/actions/common/actions';
3738

3839
type KernelPick = IQuickPickItem & { kernel: INotebookKernel };
3940
function isKernelPick(item: QuickPickInput<IQuickPickItem>): item is KernelPick {
@@ -238,7 +239,7 @@ abstract class KernelPickerStrategyBase implements IKernelPickerStrategy {
238239
});
239240

240241
if (pick) {
241-
return await this._handleQuickPick(notebook, pick, context);
242+
return await this._handleQuickPick(notebook, pick, context, editor.scopedContextKeyService);
242243
}
243244

244245
return false;
@@ -255,7 +256,7 @@ abstract class KernelPickerStrategyBase implements IKernelPickerStrategy {
255256
scopedContextKeyService: IContextKeyService
256257
): QuickPickInput<KernelQuickPickItem>[];
257258

258-
protected async _handleQuickPick(notebook: NotebookTextModel, pick: KernelQuickPickItem, context?: KernelQuickPickContext) {
259+
protected async _handleQuickPick(notebook: NotebookTextModel, pick: KernelQuickPickItem, context?: KernelQuickPickContext, contextKeyService?: IContextKeyService) {
259260
if (isKernelPick(pick)) {
260261
const newKernel = pick.kernel;
261262
this._selecteKernel(notebook, newKernel);
@@ -658,15 +659,15 @@ export class KernelPickerMRUStrategy extends KernelPickerStrategyBase {
658659
};
659660
}
660661

661-
protected override async _handleQuickPick(notebook: NotebookTextModel, pick: KernelQuickPickItem, context?: KernelQuickPickContext): Promise<boolean> {
662+
protected override async _handleQuickPick(notebook: NotebookTextModel, pick: KernelQuickPickItem, context?: KernelQuickPickContext, contextKeyService?: IContextKeyService): Promise<boolean> {
662663
if (pick.id === 'selectAnother') {
663664
return this.displaySelectAnotherQuickPick(notebook, context);
664665
}
665666

666667
return super._handleQuickPick(notebook, pick, context);
667668
}
668669

669-
private async displaySelectAnotherQuickPick(notebook: NotebookTextModel, context?: KernelQuickPickContext) {
670+
private async displaySelectAnotherQuickPick(notebook: NotebookTextModel, context?: KernelQuickPickContext, contextKeyService?: IContextKeyService) {
670671
const disposables = new DisposableStore();
671672
return new Promise<boolean>(resolve => {
672673
// select from kernel sources
@@ -698,11 +699,15 @@ export class KernelPickerMRUStrategy extends KernelPickerStrategyBase {
698699
}
699700
resolve(true);
700701
} else {
701-
return resolve(this.displaySelectAnotherQuickPick(notebook));
702+
return resolve(this.displaySelectAnotherQuickPick(notebook, context, contextKeyService));
702703
}
703-
} else if ('kernel' in quickPick.selectedItems[0]) {
704+
} else if (isKernelPick(quickPick.selectedItems[0])) {
704705
await this._selecteKernel(notebook, quickPick.selectedItems[0].kernel);
705706
resolve(true);
707+
} else if (isSourcePick(quickPick.selectedItems[0])) {
708+
// selected explicilty, it should trigger the execution?
709+
quickPick.selectedItems[0].action.runAction();
710+
resolve(true);
706711
}
707712
}
708713
}));
@@ -727,6 +732,18 @@ export class KernelPickerMRUStrategy extends KernelPickerStrategyBase {
727732
};
728733
}));
729734

735+
const sourceActionCommands = this._notebookKernelService.getSourceActions(notebook, contextKeyService);
736+
sourceActionCommands.forEach(sourceAction => {
737+
const res = <SourcePick>{
738+
action: sourceAction,
739+
picked: false,
740+
label: sourceAction.action.label,
741+
detail: (sourceAction.action as MenuItemAction)?.item?.source
742+
};
743+
744+
quickPickItems.push(res);
745+
});
746+
730747
quickPick.items = quickPickItems;
731748
});
732749
}).finally(() => {
@@ -761,6 +778,19 @@ export class KernelPickerMRUStrategy extends KernelPickerStrategyBase {
761778
return;
762779
}
763780

781+
const runningActions = notebookKernelService.getRunningSourceActions(notebook);
782+
783+
const updateActionFromSourceAction = (sourceAction: ISourceAction, running: boolean) => {
784+
const sAction = sourceAction.action;
785+
action.class = running ? ThemeIcon.asClassName(ThemeIcon.modify(executingStateIcon, 'spin')) : ThemeIcon.asClassName(selectKernelIcon);
786+
action.label = sAction.label;
787+
action.enabled = true;
788+
};
789+
790+
if (runningActions.length) {
791+
return updateActionFromSourceAction(runningActions[0] /** TODO handle multiple actions state */, true);
792+
}
793+
764794
const info = notebookKernelService.getMatchingKernel(notebook);
765795
const suggested = (info.suggestions.length === 1 ? info.suggestions[0] : undefined)
766796
?? (info.all.length === 1) ? info.all[0] : undefined;

0 commit comments

Comments
 (0)