提交 9b40aa3c 编写于 作者: S Sandeep Somavarapu

#92038 Move tree view away from get*Actions and use menus

上级 14657a93
...@@ -7,12 +7,12 @@ import 'vs/css!./media/views'; ...@@ -7,12 +7,12 @@ import 'vs/css!./media/views';
import { Event, Emitter } from 'vs/base/common/event'; import { Event, Emitter } from 'vs/base/common/event';
import { IDisposable, Disposable, toDisposable } from 'vs/base/common/lifecycle'; import { IDisposable, Disposable, toDisposable } from 'vs/base/common/lifecycle';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IAction, ActionRunner, Action } from 'vs/base/common/actions'; import { IAction, ActionRunner } from 'vs/base/common/actions';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding'; import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView'; import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
import { IMenuService, MenuId, MenuItemAction } from 'vs/platform/actions/common/actions'; import { IMenuService, MenuId, MenuItemAction, registerAction2, Action2 } from 'vs/platform/actions/common/actions';
import { ContextAwareMenuEntryActionViewItem, createAndFillInContextMenuActions } from 'vs/platform/actions/browser/menuEntryActionViewItem'; import { ContextAwareMenuEntryActionViewItem, createAndFillInContextMenuActions } from 'vs/platform/actions/browser/menuEntryActionViewItem';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey'; import { IContextKeyService, ContextKeyExpr, ContextKeyEqualsExpr, RawContextKey, IContextKey } from 'vs/platform/contextkey/common/contextkey';
import { ITreeView, ITreeItem, TreeItemCollapsibleState, ITreeViewDataProvider, TreeViewItemHandleArg, ITreeViewDescriptor, IViewsRegistry, ITreeItemLabel, Extensions, IViewDescriptorService, ViewContainer, ViewContainerLocation } from 'vs/workbench/common/views'; import { ITreeView, ITreeItem, TreeItemCollapsibleState, ITreeViewDataProvider, TreeViewItemHandleArg, ITreeViewDescriptor, IViewsRegistry, ITreeItemLabel, Extensions, IViewDescriptorService, ViewContainer, ViewContainerLocation } from 'vs/workbench/common/views';
import { IViewletViewOptions } from 'vs/workbench/browser/parts/views/viewsViewlet'; import { IViewletViewOptions } from 'vs/workbench/browser/parts/views/viewsViewlet';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
...@@ -92,14 +92,6 @@ export class TreeViewPane extends ViewPane { ...@@ -92,14 +92,6 @@ export class TreeViewPane extends ViewPane {
this.treeView.layout(height, width); this.treeView.layout(height, width);
} }
getActions(): IAction[] {
return [...super.getActions(), ...this.treeView.getPrimaryActions()];
}
getSecondaryActions(): IAction[] {
return [...super.getSecondaryActions(), ...this.treeView.getSecondaryActions()];
}
getOptimalWidth(): number { getOptimalWidth(): number {
return this.treeView.getOptimalWidth(); return this.treeView.getOptimalWidth();
} }
...@@ -126,8 +118,11 @@ export class TreeView extends Disposable implements ITreeView { ...@@ -126,8 +118,11 @@ export class TreeView extends Disposable implements ITreeView {
private isVisible: boolean = false; private isVisible: boolean = false;
private _hasIconForParentNode = false; private _hasIconForParentNode = false;
private _hasIconForLeafNode = false; private _hasIconForLeafNode = false;
private _showCollapseAllAction = false;
private _showRefreshAction = false; private readonly collapseAllContextKey: RawContextKey<boolean>;
private readonly collapseAllContext: IContextKey<boolean>;
private readonly refreshContextKey: RawContextKey<boolean>;
private readonly refreshContext: IContextKey<boolean>;
private focused: boolean = false; private focused: boolean = false;
private domNode!: HTMLElement; private domNode!: HTMLElement;
...@@ -175,10 +170,16 @@ export class TreeView extends Disposable implements ITreeView { ...@@ -175,10 +170,16 @@ export class TreeView extends Disposable implements ITreeView {
@IContextMenuService private readonly contextMenuService: IContextMenuService, @IContextMenuService private readonly contextMenuService: IContextMenuService,
@IKeybindingService private readonly keybindingService: IKeybindingService, @IKeybindingService private readonly keybindingService: IKeybindingService,
@INotificationService private readonly notificationService: INotificationService, @INotificationService private readonly notificationService: INotificationService,
@IViewDescriptorService private readonly viewDescriptorService: IViewDescriptorService @IViewDescriptorService private readonly viewDescriptorService: IViewDescriptorService,
@IContextKeyService contextKeyService: IContextKeyService
) { ) {
super(); super();
this.root = new Root(); this.root = new Root();
this.collapseAllContextKey = new RawContextKey<boolean>(`treeView.${this.id}.enableCollapseAll`, false);
this.collapseAllContext = this.collapseAllContextKey.bindTo(contextKeyService);
this.refreshContextKey = new RawContextKey<boolean>(`treeView.${this.id}.enableRefresh`, false);
this.refreshContext = this.refreshContextKey.bindTo(contextKeyService);
this._register(this.themeService.onDidFileIconThemeChange(() => this.doRefresh([this.root]) /** soft refresh **/)); this._register(this.themeService.onDidFileIconThemeChange(() => this.doRefresh([this.root]) /** soft refresh **/));
this._register(this.themeService.onDidColorThemeChange(() => this.doRefresh([this.root]) /** soft refresh **/)); this._register(this.themeService.onDidColorThemeChange(() => this.doRefresh([this.root]) /** soft refresh **/));
this._register(this.configurationService.onDidChangeConfiguration(e => { this._register(this.configurationService.onDidChangeConfiguration(e => {
...@@ -191,6 +192,7 @@ export class TreeView extends Disposable implements ITreeView { ...@@ -191,6 +192,7 @@ export class TreeView extends Disposable implements ITreeView {
this.tree?.updateOptions({ overrideStyles: { listBackground: this.viewLocation === ViewContainerLocation.Sidebar ? SIDE_BAR_BACKGROUND : PANEL_BACKGROUND } }); this.tree?.updateOptions({ overrideStyles: { listBackground: this.viewLocation === ViewContainerLocation.Sidebar ? SIDE_BAR_BACKGROUND : PANEL_BACKGROUND } });
} }
})); }));
this.registerActions();
this.create(); this.create();
} }
...@@ -275,40 +277,61 @@ export class TreeView extends Disposable implements ITreeView { ...@@ -275,40 +277,61 @@ export class TreeView extends Disposable implements ITreeView {
} }
get showCollapseAllAction(): boolean { get showCollapseAllAction(): boolean {
return this._showCollapseAllAction; return !!this.collapseAllContext.get();
} }
set showCollapseAllAction(showCollapseAllAction: boolean) { set showCollapseAllAction(showCollapseAllAction: boolean) {
if (this._showCollapseAllAction !== !!showCollapseAllAction) { this.collapseAllContext.set(showCollapseAllAction);
this._showCollapseAllAction = !!showCollapseAllAction;
this._onDidChangeActions.fire();
}
} }
get showRefreshAction(): boolean { get showRefreshAction(): boolean {
return this._showRefreshAction; return !!this.refreshContext.get();
} }
set showRefreshAction(showRefreshAction: boolean) { set showRefreshAction(showRefreshAction: boolean) {
if (this._showRefreshAction !== !!showRefreshAction) { this.refreshContext.set(showRefreshAction);
this._showRefreshAction = !!showRefreshAction; }
this._onDidChangeActions.fire();
private registerActions() {
const that = this;
registerAction2(class extends Action2 {
constructor() {
super({
id: `workbench.actions.treeView.${that.id}.refresh`,
title: localize('refresh', "Refresh"),
menu: {
id: MenuId.ViewTitle,
when: ContextKeyExpr.and(ContextKeyEqualsExpr.create('view', that.id), that.refreshContextKey),
group: 'navigation',
order: Number.MAX_SAFE_INTEGER - 1,
},
icon: { id: 'codicon/refresh' }
});
} }
async run(): Promise<void> {
return that.refresh();
} }
});
getPrimaryActions(): IAction[] { registerAction2(class extends Action2 {
const actions: IAction[] = []; constructor() {
if (this.showRefreshAction) { super({
actions.push(new Action('vs.tree.refresh', localize('refresh', "Refresh"), 'monaco-tree-action codicon-refresh', true, () => this.refresh())); id: `workbench.actions.treeView.${that.id}.collapseAll`,
title: localize('collapseAll', "Collapse All"),
menu: {
id: MenuId.ViewTitle,
when: ContextKeyExpr.and(ContextKeyEqualsExpr.create('view', that.id), that.collapseAllContextKey),
group: 'navigation',
order: Number.MAX_SAFE_INTEGER,
},
icon: { id: 'codicon/collapse-all' }
});
} }
if (this.showCollapseAllAction) { async run(): Promise<void> {
actions.push(new Action('vs.tree.collapse', localize('collapseAll', "Collapse All"), 'monaco-tree-action codicon-collapse-all', true, () => this.tree ? new CollapseAllAction<ITreeItem, ITreeItem, FuzzyScore>(this.tree, true).run() : Promise.resolve())); if (that.tree) {
return new CollapseAllAction<ITreeItem, ITreeItem, FuzzyScore>(that.tree, true).run();
} }
return actions;
} }
});
getSecondaryActions(): IAction[] {
return [];
} }
setVisibility(isVisible: boolean): void { setVisibility(isVisible: boolean): void {
...@@ -959,9 +982,10 @@ export class CustomTreeView extends TreeView { ...@@ -959,9 +982,10 @@ export class CustomTreeView extends TreeView {
@IKeybindingService keybindingService: IKeybindingService, @IKeybindingService keybindingService: IKeybindingService,
@INotificationService notificationService: INotificationService, @INotificationService notificationService: INotificationService,
@IViewDescriptorService viewDescriptorService: IViewDescriptorService, @IViewDescriptorService viewDescriptorService: IViewDescriptorService,
@IContextKeyService contextKeyService: IContextKeyService,
@IExtensionService private readonly extensionService: IExtensionService, @IExtensionService private readonly extensionService: IExtensionService,
) { ) {
super(id, title, themeService, instantiationService, commandService, configurationService, progressService, contextMenuService, keybindingService, notificationService, viewDescriptorService); super(id, title, themeService, instantiationService, commandService, configurationService, progressService, contextMenuService, keybindingService, notificationService, viewDescriptorService, contextKeyService);
} }
setVisibility(isVisible: boolean): void { setVisibility(isVisible: boolean): void {
......
...@@ -508,9 +508,6 @@ export interface ITreeView extends IDisposable { ...@@ -508,9 +508,6 @@ export interface ITreeView extends IDisposable {
setFocus(item: ITreeItem): void; setFocus(item: ITreeItem): void;
getPrimaryActions(): IAction[];
getSecondaryActions(): IAction[];
} }
export interface IRevealOptions { export interface IRevealOptions {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册