Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add first item to context menu for notebook variables #204549

Merged
merged 3 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/vs/platform/actions/common/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export class MenuId {
static readonly DebugCallStackContext = new MenuId('DebugCallStackContext');
static readonly DebugConsoleContext = new MenuId('DebugConsoleContext');
static readonly DebugVariablesContext = new MenuId('DebugVariablesContext');
static readonly NotebookVariablesContext = new MenuId('NotebookVariablesContext');
static readonly DebugHoverContext = new MenuId('DebugHoverContext');
static readonly DebugWatchContext = new MenuId('DebugWatchContext');
static readonly DebugToolBar = new MenuId('DebugToolBar');
Expand Down
3 changes: 3 additions & 0 deletions src/vs/workbench/contrib/debug/browser/debug.contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import { DebugContentProvider } from 'vs/workbench/contrib/debug/common/debugCon
import { DebugLifecycle } from 'vs/workbench/contrib/debug/common/debugLifecycle';
import { DebugVisualizerService, IDebugVisualizerService } from 'vs/workbench/contrib/debug/common/debugVisualizers';
import { DisassemblyViewInput } from 'vs/workbench/contrib/debug/common/disassemblyViewInput';
import { COPY_NOTEBOOK_VARIABLE_VALUE_ID, COPY_NOTEBOOK_VARIABLE_VALUE_LABEL } from 'vs/workbench/contrib/notebook/browser/contrib/notebookVariables/notebookVariableCommands';
import { launchSchemaId } from 'vs/workbench/services/configuration/common/configuration';
import { LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle';

Expand Down Expand Up @@ -196,6 +197,8 @@ registerDebugViewMenuItem(MenuId.DebugWatchContext, VIEW_MEMORY_ID, nls.localize
registerDebugViewMenuItem(MenuId.DebugWatchContext, REMOVE_EXPRESSION_COMMAND_ID, nls.localize('removeWatchExpression', "Remove Expression"), 20, CONTEXT_WATCH_ITEM_TYPE.isEqualTo('expression'), undefined, 'inline', icons.watchExpressionRemove);
registerDebugViewMenuItem(MenuId.DebugWatchContext, REMOVE_WATCH_EXPRESSIONS_COMMAND_ID, REMOVE_WATCH_EXPRESSIONS_LABEL, 20, undefined, undefined, 'z_commands');

registerDebugViewMenuItem(MenuId.NotebookVariablesContext, COPY_NOTEBOOK_VARIABLE_VALUE_ID, COPY_NOTEBOOK_VARIABLE_VALUE_LABEL, 20);

// Touch Bar
if (isMacintosh) {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { localize } from 'vs/nls';
import { Action2, registerAction2 } from 'vs/platform/actions/common/actions';
import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService';
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import { contextMenuArg } from 'vs/workbench/contrib/notebook/browser/contrib/notebookVariables/notebookVariablesView';

export const COPY_NOTEBOOK_VARIABLE_VALUE_ID = 'workbench.debug.viewlet.action.copyWorkspaceVariableValue';
export const COPY_NOTEBOOK_VARIABLE_VALUE_LABEL = localize('copyWorkspaceVariableValue', "Copy Value");
registerAction2(class extends Action2 {
constructor() {
super({
id: COPY_NOTEBOOK_VARIABLE_VALUE_ID,
title: COPY_NOTEBOOK_VARIABLE_VALUE_LABEL,
f1: false,
precondition: ContextKeyExpr.has('value')
});
}

run(accessor: ServicesAccessor, context: contextMenuArg): void {
const clipboardService = accessor.get(IClipboardService);

if (context.value) {
clipboardService.writeText(context.value);
}
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { ITreeContextMenuEvent } from 'vs/base/browser/ui/tree/tree';
import { IAction } from 'vs/base/common/actions';
import { RunOnceScheduler } from 'vs/base/common/async';
import { URI } from 'vs/base/common/uri';
import * as nls from 'vs/nls';
import { ILocalizedString } from 'vs/platform/action/common/action';
import { createAndFillInContextMenuActions } from 'vs/platform/actions/browser/menuEntryActionViewItem';
import { IMenu, IMenuService, MenuId } from 'vs/platform/actions/common/actions';
import { ICommandService } from 'vs/platform/commands/common/commands';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';

import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { WorkbenchAsyncDataTree } from 'vs/platform/list/browser/listService';
Expand All @@ -28,13 +33,16 @@ import { ICellExecutionStateChangedEvent, IExecutionStateChangedEvent, INotebook
import { INotebookKernelService } from 'vs/workbench/contrib/notebook/common/notebookKernelService';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';

export type contextMenuArg = { source?: string; type?: string; value?: string };

export class NotebookVariablesView extends ViewPane {

static readonly ID = 'notebookVariablesView';
static readonly TITLE: ILocalizedString = nls.localize2('notebook.notebookVariables', "Notebook Variables");

private tree: WorkbenchAsyncDataTree<INotebookScope, INotebookVariableElement> | undefined;
private activeNotebook: NotebookTextModel | undefined;
private readonly menu: IMenu;
private readonly dataSource: NotebookVariableDataSource;

private updateScheduler: RunOnceScheduler;
Expand All @@ -55,6 +63,7 @@ export class NotebookVariablesView extends ViewPane {
@ICommandService protected commandService: ICommandService,
@IThemeService themeService: IThemeService,
@ITelemetryService telemetryService: ITelemetryService,
@IMenuService menuService: IMenuService
) {
super(options, keybindingService, contextMenuService, configurationService, contextKeyService, viewDescriptorService, instantiationService, openerService, themeService, telemetryService);

Expand All @@ -64,6 +73,7 @@ export class NotebookVariablesView extends ViewPane {

this.setActiveNotebook();

this.menu = menuService.createMenu(MenuId.NotebookVariablesContext, contextKeyService);
this.dataSource = new NotebookVariableDataSource(this.notebookKernelService);
this.updateScheduler = new RunOnceScheduler(() => this.tree?.updateChildren(), 100);
}
Expand All @@ -87,6 +97,28 @@ export class NotebookVariablesView extends ViewPane {
if (this.activeNotebook) {
this.tree.setInput({ kind: 'root', notebook: this.activeNotebook });
}

this._register(this.tree.onContextMenu(e => this.onContextMenu(e)));
}

private onContextMenu(e: ITreeContextMenuEvent<INotebookVariableElement>): any {
const element = e.element;

const context = {
type: element?.type
};
const arg: contextMenuArg = {
source: element?.notebook.uri.toString(),
value: element?.value,
...context
};
const actions: IAction[] = [];
createAndFillInContextMenuActions(this.menu, { arg, shouldForwardArgs: true }, actions);
this.contextMenuService.showContextMenu({
getAnchor: () => e.anchor,
getActions: () => actions,
getActionsContext: () => context,
});
}

protected override layoutBody(height: number, width: number): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ const apiMenus: IAPIMenu[] = [
id: MenuId.DebugToolBar,
description: localize('menus.debugToolBar', "The debug toolbar menu")
},
{
key: 'notebook/variables/context',
id: MenuId.NotebookVariablesContext,
description: localize('menus.notebookVariablesContext', "The notebook variables view context menu")
},
{
key: 'menuBar/home',
id: MenuId.MenubarHomeMenu,
Expand Down