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

TreeViewPane command context selected TreeItem #157803

Merged
merged 2 commits into from
Aug 11, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions src/vs/workbench/api/common/extHostTreeViews.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { URI } from 'vs/base/common/uri';
import { Emitter, Event } from 'vs/base/common/event';
import { Disposable, DisposableStore, IDisposable } from 'vs/base/common/lifecycle';
import { DataTransferDTO, ExtHostTreeViewsShape, MainThreadTreeViewsShape } from './extHost.protocol';
import { ITreeItem, TreeViewItemHandleArg, ITreeItemLabel, IRevealOptions, TreeCommand } from 'vs/workbench/common/views';
import { ITreeItem, TreeViewItemHandleArg, ITreeItemLabel, IRevealOptions, TreeCommand, TreeViewPaneHandleArg } from 'vs/workbench/common/views';
import { ExtHostCommands, CommandsConverter } from 'vs/workbench/api/common/extHostCommands';
import { asPromise } from 'vs/base/common/async';
import { TreeItemCollapsibleState, ThemeIcon, MarkdownString as MarkdownStringType, TreeItem } from 'vs/workbench/api/common/extHostTypes';
Expand Down Expand Up @@ -58,16 +58,16 @@ export class ExtHostTreeViews implements ExtHostTreeViewsShape {
private logService: ILogService
) {

function isTreeViewItemHandleArg(arg: any): boolean {
return arg && arg.$treeViewId && arg.$treeItemHandle;
function isTreeViewConvertableItem(arg: any): boolean {
return arg && arg.$treeViewId && (arg.$treeItemHandle || arg.$selectedTreeItems);
}
commands.registerArgumentProcessor({
processArgument: arg => {
if (isTreeViewItemHandleArg(arg)) {
if (isTreeViewConvertableItem(arg)) {
return this.convertArgument(arg);
} else if (Array.isArray(arg) && (arg.length > 0)) {
return arg.map(item => {
if (isTreeViewItemHandleArg(item)) {
if (isTreeViewConvertableItem(item)) {
return this.convertArgument(item);
}
return item;
Expand Down Expand Up @@ -235,9 +235,15 @@ export class ExtHostTreeViews implements ExtHostTreeViewsShape {
return treeView;
}

private convertArgument(arg: TreeViewItemHandleArg): any {
private convertArgument(arg: TreeViewItemHandleArg | TreeViewPaneHandleArg): any {
const treeView = this.treeViews.get(arg.$treeViewId);
return treeView ? treeView.getExtensionElement(arg.$treeItemHandle) : null;
if (treeView && '$treeItemHandle' in arg) {
return treeView.getExtensionElement(arg.$treeItemHandle);
}
if (treeView && '$selectedTreeItems' in arg && arg.$selectedTreeItems) {
return { selectedTreeItems: treeView.selectedElements };
benibenj marked this conversation as resolved.
Show resolved Hide resolved
}
return null;
}
}

Expand Down
12 changes: 10 additions & 2 deletions src/vs/workbench/browser/parts/views/treeView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ import { API_OPEN_DIFF_EDITOR_COMMAND_ID, API_OPEN_EDITOR_COMMAND_ID } from 'vs/
import { IViewPaneOptions, ViewPane } from 'vs/workbench/browser/parts/views/viewPane';
import { IViewletViewOptions } from 'vs/workbench/browser/parts/views/viewsViewlet';
import { PANEL_BACKGROUND, SIDE_BAR_BACKGROUND } from 'vs/workbench/common/theme';
import { Extensions, ITreeItem, ITreeItemLabel, ITreeView, ITreeViewDataProvider, ITreeViewDescriptor, ITreeViewDragAndDropController, IViewBadge, IViewDescriptorService, IViewsRegistry, ResolvableTreeItem, TreeCommand, TreeItemCollapsibleState, TreeViewItemHandleArg, ViewContainer, ViewContainerLocation } from 'vs/workbench/common/views';
import { Extensions, ITreeItem, ITreeItemLabel, ITreeView, ITreeViewDataProvider, ITreeViewDescriptor, ITreeViewDragAndDropController, IViewBadge, IViewDescriptorService, IViewsRegistry, ResolvableTreeItem, TreeCommand, TreeItemCollapsibleState, TreeViewItemHandleArg, TreeViewPaneHandleArg, ViewContainer, ViewContainerLocation } from 'vs/workbench/common/views';
import { IActivityService, NumberBadge } from 'vs/workbench/services/activity/common/activity';
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
import { IHoverService } from 'vs/workbench/services/hover/browser/hover';
Expand All @@ -84,7 +84,7 @@ export class TreeViewPane extends ViewPane {
@IThemeService themeService: IThemeService,
@ITelemetryService telemetryService: ITelemetryService,
) {
super({ ...(options as IViewPaneOptions), titleMenuId: MenuId.ViewTitle, donotForwardArgs: true }, keybindingService, contextMenuService, configurationService, contextKeyService, viewDescriptorService, instantiationService, openerService, themeService, telemetryService);
super({ ...(options as IViewPaneOptions), titleMenuId: MenuId.ViewTitle, donotForwardArgs: false }, keybindingService, contextMenuService, configurationService, contextKeyService, viewDescriptorService, instantiationService, openerService, themeService, telemetryService);
const { treeView } = (<ITreeViewDescriptor>Registry.as<IViewsRegistry>(Extensions.ViewsRegistry).getView(options.id));
this.treeView = treeView;
this._register(this.treeView.onDidChangeActions(() => this.updateActions(), this));
Expand Down Expand Up @@ -142,6 +142,14 @@ export class TreeViewPane extends ViewPane {
private updateTreeVisibility(): void {
this.treeView.setVisibility(this.isBodyVisible());
}

override getActionsContext(): TreeViewPaneHandleArg {
return {
$selectedTreeItems: true,
$treeViewId: this.id
};
}

}

class Root implements ITreeItem {
Expand Down
5 changes: 5 additions & 0 deletions src/vs/workbench/common/views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,11 @@ export interface ITreeViewDescriptor extends IViewDescriptor {
treeView: ITreeView;
}

export type TreeViewPaneHandleArg = {
$treeViewId: string;
$selectedTreeItems: boolean;
};

export type TreeViewItemHandleArg = {
$treeViewId: string;
$treeItemHandle: string;
Expand Down