提交 7e56fc02 编写于 作者: R rebornix

Contributions for notebook cell toolbar

上级 f8083181
......@@ -114,6 +114,7 @@ export class MenuId {
static readonly CommentThreadActions = new MenuId('CommentThreadActions');
static readonly CommentTitle = new MenuId('CommentTitle');
static readonly CommentActions = new MenuId('CommentActions');
static readonly NotebookCellTitle = new MenuId('NotebookCellTitle');
static readonly BulkEditTitle = new MenuId('BulkEditTitle');
static readonly BulkEditContext = new MenuId('BulkEditContext');
static readonly TimelineItemContext = new MenuId('TimelineItemContext');
......
......@@ -131,7 +131,7 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
const extHostWindow = rpcProtocol.set(ExtHostContext.ExtHostWindow, new ExtHostWindow(rpcProtocol));
const extHostProgress = rpcProtocol.set(ExtHostContext.ExtHostProgress, new ExtHostProgress(rpcProtocol.getProxy(MainContext.MainThreadProgress)));
const extHostLabelService = rpcProtocol.set(ExtHostContext.ExtHosLabelService, new ExtHostLabelService(rpcProtocol));
const extHostNotebook = rpcProtocol.set(ExtHostContext.ExtHostNotebook, new ExtHostNotebookController(rpcProtocol, extHostDocumentsAndEditors));
const extHostNotebook = rpcProtocol.set(ExtHostContext.ExtHostNotebook, new ExtHostNotebookController(rpcProtocol, extHostCommands, extHostDocumentsAndEditors));
const extHostTheming = rpcProtocol.set(ExtHostContext.ExtHostTheming, new ExtHostTheming(rpcProtocol));
const extHostAuthentication = rpcProtocol.set(ExtHostContext.ExtHostAuthentication, new ExtHostAuthentication(rpcProtocol));
const extHostTimeline = rpcProtocol.set(ExtHostContext.ExtHostTimeline, new ExtHostTimeline(rpcProtocol, extHostCommands));
......
......@@ -14,6 +14,7 @@ import { Emitter, Event } from 'vs/base/common/event';
import { ExtHostDocumentsAndEditors } from 'vs/workbench/api/common/extHostDocumentsAndEditors';
import { INotebookDisplayOrder, ITransformedDisplayOutputDto, IOrderedMimeType, IStreamOutput, IErrorOutput, mimeTypeSupportedByCore, IOutput, sortMimeTypes, diff, CellUri } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { ISplice } from 'vs/base/common/sequence';
import { ExtHostCommands } from 'vs/workbench/api/common/extHostCommands';
export class ExtHostCell implements vscode.NotebookCell {
......@@ -415,7 +416,7 @@ export class ExtHostNotebookController implements ExtHostNotebookShape, ExtHostN
private static _handlePool: number = 0;
private readonly _proxy: MainThreadNotebookShape;
private readonly _notebookProviders = new Map<string, { readonly provider: vscode.NotebookProvider, readonly extension: IExtensionDescription }>();
private readonly _notebookProviders = new Map<string, { readonly provider: vscode.NotebookProvider, readonly extension: IExtensionDescription; }>();
private readonly _documents = new Map<string, ExtHostNotebookDocument>();
private readonly _editors = new Map<string, ExtHostNotebookEditor>();
private readonly _notebookOutputRenderers = new Map<number, ExtHostNotebookOutputRenderer>();
......@@ -431,8 +432,28 @@ export class ExtHostNotebookController implements ExtHostNotebookShape, ExtHostN
return this._activeNotebookDocument;
}
constructor(mainContext: IMainContext, private _documentsAndEditors: ExtHostDocumentsAndEditors) {
constructor(mainContext: IMainContext, commands: ExtHostCommands, private _documentsAndEditors: ExtHostDocumentsAndEditors) {
this._proxy = mainContext.getProxy(MainContext.MainThreadNotebook);
commands.registerArgumentProcessor({
processArgument: arg => {
if (arg && arg.$mid === 12) {
const documentHandle = arg.notebookEditor?.notebookHandle;
const cellHandle = arg.cell.handle;
for (let value of this._editors) {
if (value[1].document.handle === documentHandle) {
const cell = value[1].document.getCell(cellHandle);
if (cell) {
return cell;
}
}
}
return arg;
}
}
});
}
registerNotebookOutputRenderer(
......
......@@ -51,6 +51,7 @@ namespace schema {
case 'comments/commentThread/context': return MenuId.CommentThreadActions;
case 'comments/comment/title': return MenuId.CommentTitle;
case 'comments/comment/context': return MenuId.CommentActions;
case 'notebook/cell/title': return MenuId.NotebookCellTitle;
case 'extension/context': return MenuId.ExtensionContext;
case 'timeline/title': return MenuId.TimelineTitle;
case 'timeline/item/context': return MenuId.TimelineItemContext;
......@@ -212,6 +213,11 @@ namespace schema {
type: 'array',
items: menuItem
},
'notebook/cell/title': {
description: localize('notebook.cell.title', "The contributed notebook cell title menu"),
type: 'array',
items: menuItem
},
'extension/context': {
description: localize('menus.extensionContext', "The extension context menu"),
type: 'array',
......
......@@ -24,3 +24,6 @@ export const CELL_MARGIN = 32;
export const EDITOR_TOP_PADDING = 8;
export const EDITOR_BOTTOM_PADDING = 8;
export const EDITOR_TOOLBAR_HEIGHT = 22;
// Context Keys
export const NOTEBOOK_CELL_TYPE_CONTEXT_KEY = 'notebookCellType';
......@@ -698,6 +698,12 @@ export class NotebookEditor extends BaseEditor implements INotebookEditor {
}
//#endregion
toJSON(): any {
return {
notebookHandle: this.viewModel?.handle
};
}
}
const embeddedEditorBackground = 'walkThrough.embeddedEditorBackground';
......
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { IDisposable } from 'vs/base/common/lifecycle';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { IMenuService, MenuId, IMenu } from 'vs/platform/actions/common/actions';
import { IAction } from 'vs/base/common/actions';
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
import { createAndFillInContextMenuActions } from 'vs/platform/actions/browser/menuEntryActionViewItem';
export class CellMenus implements IDisposable {
constructor(
@IMenuService private readonly menuService: IMenuService,
@IContextMenuService private readonly contextMenuService: IContextMenuService
) { }
getCellTitleActions(contextKeyService: IContextKeyService): IMenu {
return this.getMenu(MenuId.NotebookCellTitle, contextKeyService);
}
private getMenu(menuId: MenuId, contextKeyService: IContextKeyService): IMenu {
const menu = this.menuService.createMenu(menuId, contextKeyService);
const primary: IAction[] = [];
const secondary: IAction[] = [];
const result = { primary, secondary };
createAndFillInContextMenuActions(menu, { shouldForwardArgs: true }, result, this.contextMenuService, g => /^inline/.test(g));
return menu;
}
dispose(): void {
}
}
......@@ -28,7 +28,9 @@ import { ContextAwareMenuEntryActionViewItem } from 'vs/platform/actions/browser
import { MenuItemAction } from 'vs/platform/actions/common/actions';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { INotificationService } from 'vs/platform/notification/common/notification';
import { EDITOR_TOOLBAR_HEIGHT, EDITOR_TOP_PADDING, EDITOR_BOTTOM_PADDING } from 'vs/workbench/contrib/notebook/browser/constants';
import { EDITOR_TOOLBAR_HEIGHT, EDITOR_TOP_PADDING, EDITOR_BOTTOM_PADDING, NOTEBOOK_CELL_TYPE_CONTEXT_KEY } from 'vs/workbench/contrib/notebook/browser/constants';
import { CellMenus } from 'vs/workbench/contrib/notebook/browser/view/renderers/cellMenus';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
export class NotebookCellListDelegate implements IListVirtualDelegate<ICellViewModel> {
private _lineHeight: number;
......@@ -68,6 +70,7 @@ abstract class AbstractCellRenderer {
private readonly configurationService: IConfigurationService,
private readonly keybindingService: IKeybindingService,
private readonly notificationService: INotificationService,
protected readonly contextKeyService: IContextKeyService,
language: string,
) {
const editorOptions = deepClone(this.configurationService.getValue<IEditorOptions>('editor', { overrideIdentifier: language }));
......@@ -108,6 +111,11 @@ abstract class AbstractCellRenderer {
return toolbar;
}
protected createMenu(): CellMenus {
const menu = this.instantiationService.createInstance(CellMenus);
return menu;
}
showContextMenu(listIndex: number | undefined, element: CellViewModel, x: number, y: number) {
const actions: IAction[] = [
this.instantiationService.createInstance(InsertCodeCellAboveAction),
......@@ -150,8 +158,9 @@ export class MarkdownCellRenderer extends AbstractCellRenderer implements IListR
@IContextMenuService contextMenuService: IContextMenuService,
@IKeybindingService keybindingService: IKeybindingService,
@INotificationService notificationService: INotificationService,
@IContextKeyService contextKeyService: IContextKeyService
) {
super(instantiationService, notehookEditor, contextMenuService, configurationService, keybindingService, notificationService, 'markdown');
super(instantiationService, notehookEditor, contextMenuService, configurationService, keybindingService, notificationService, contextKeyService, 'markdown');
}
get templateId() {
......@@ -165,14 +174,6 @@ export class MarkdownCellRenderer extends AbstractCellRenderer implements IListR
const disposables = new DisposableStore();
const toolbar = this.createToolbar(container);
toolbar.setActions([
this.instantiationService.createInstance(MoveCellUpAction),
this.instantiationService.createInstance(MoveCellDownAction),
this.instantiationService.createInstance(InsertCodeCellBelowAction),
this.instantiationService.createInstance(EditCellAction),
this.instantiationService.createInstance(SaveCellAction),
this.instantiationService.createInstance(DeleteCellAction)
])();
disposables.add(toolbar);
container.appendChild(codeInnerContent);
......@@ -230,11 +231,30 @@ export class MarkdownCellRenderer extends AbstractCellRenderer implements IListR
}));
elementDisposable!.add(new StatefullMarkdownCell(this.notebookEditor, element, templateData, this.editorOptions, this.instantiationService));
const contextKeyService = this.contextKeyService.createScoped(templateData.container);
contextKeyService.createKey(NOTEBOOK_CELL_TYPE_CONTEXT_KEY, 'markdown');
const menu = this.createMenu().getCellTitleActions(this.contextKeyService);
const actions: IAction[] = [];
for (let [, actions] of menu.getActions({ shouldForwardArgs: true })) {
actions.push(...actions);
}
templateData.toolbar!.setActions([
...actions,
this.instantiationService.createInstance(MoveCellUpAction),
this.instantiationService.createInstance(MoveCellDownAction),
this.instantiationService.createInstance(InsertCodeCellBelowAction),
this.instantiationService.createInstance(EditCellAction),
this.instantiationService.createInstance(SaveCellAction),
this.instantiationService.createInstance(DeleteCellAction)
])();
}
templateData.toolbar!.context = <INotebookCellActionContext>{
cell: element,
notebookEditor: this.notebookEditor
notebookEditor: this.notebookEditor,
$mid: 12
};
}
......@@ -269,8 +289,9 @@ export class CodeCellRenderer extends AbstractCellRenderer implements IListRende
@IInstantiationService instantiationService: IInstantiationService,
@IKeybindingService keybindingService: IKeybindingService,
@INotificationService notificationService: INotificationService,
@IContextKeyService contextKeyService: IContextKeyService
) {
super(instantiationService, notebookEditor, contextMenuService, configurationService, keybindingService, notificationService, 'python');
super(instantiationService, notebookEditor, contextMenuService, configurationService, keybindingService, notificationService, contextKeyService, 'python');
}
get templateId() {
......@@ -364,9 +385,26 @@ export class CodeCellRenderer extends AbstractCellRenderer implements IListRende
templateData.focusIndicator!.style.height = `${element.getIndicatorHeight()}px`;
}));
const contextKeyService = this.contextKeyService.createScoped(templateData.container);
contextKeyService.createKey(NOTEBOOK_CELL_TYPE_CONTEXT_KEY, 'code');
const menu = this.createMenu().getCellTitleActions(contextKeyService);
const actions: IAction[] = [];
for (let [, items] of menu.getActions({ shouldForwardArgs: true })) {
actions.push(...items);
}
templateData.toolbar!.setActions([
...actions,
this.instantiationService.createInstance(MoveCellUpAction),
this.instantiationService.createInstance(MoveCellDownAction),
this.instantiationService.createInstance(InsertCodeCellBelowAction),
this.instantiationService.createInstance(DeleteCellAction)
])();
templateData.toolbar!.context = <INotebookCellActionContext>{
cell: element,
notebookEditor: this.notebookEditor
notebookEditor: this.notebookEditor,
$mid: 12
};
}
......
......@@ -519,4 +519,10 @@ export class CellViewModel extends Disposable implements ICellViewModel {
this._outputsTop = new PrefixSumComputer(values);
}
}
toJSON(): any {
return {
handle: this.handle
};
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册