提交 7285f791 编写于 作者: S Sandeep Somavarapu

Use menu

上级 9bfa4c1d
......@@ -7,10 +7,9 @@ import 'vs/css!./media/panel';
import * as nls from 'vs/nls';
import * as dom from 'vs/base/browser/dom';
import { basename } from 'vs/base/common/resources';
import { IAction, Action } from 'vs/base/common/actions';
import { CollapseAllAction } from 'vs/base/browser/ui/tree/treeDefaults';
import { isCodeEditor } from 'vs/editor/browser/editorBrowser';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { CommentNode, CommentsModel, ResourceWithCommentThreads, ICommentThreadChangedEvent } from 'vs/workbench/contrib/comments/common/commentModel';
import { CommentController } from 'vs/workbench/contrib/comments/browser/commentsEditorContribution';
......@@ -20,15 +19,19 @@ import { CommandsRegistry } from 'vs/platform/commands/common/commands';
import { textLinkForeground, textLinkActiveForeground, focusBorder, textPreformatForeground } from 'vs/platform/theme/common/colorRegistry';
import { ResourceLabels } from 'vs/workbench/browser/labels';
import { CommentsList, COMMENTS_VIEW_ID, COMMENTS_VIEW_TITLE } from 'vs/workbench/contrib/comments/browser/commentsTreeViewer';
import { ViewPane, IViewPaneOptions } from 'vs/workbench/browser/parts/views/viewPane';
import { ViewPane, IViewPaneOptions, ViewAction } from 'vs/workbench/browser/parts/views/viewPane';
import { IViewDescriptorService, IViewsService } from 'vs/workbench/common/views';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { ContextKeyAndExpr, ContextKeyEqualsExpr, IContextKey, IContextKeyService, RawContextKey } from 'vs/platform/contextkey/common/contextkey';
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { IOpenerService } from 'vs/platform/opener/common/opener';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { IUriIdentityService } from 'vs/workbench/services/uriIdentity/common/uriIdentity';
import { MenuId, registerAction2 } from 'vs/platform/actions/common/actions';
import { Codicon } from 'vs/base/common/codicons';
const CONTEXT_KEY_HAS_COMMENTS = new RawContextKey<boolean>('commentsView.hasComments', false);
export class CommentsPanel extends ViewPane {
private treeLabels!: ResourceLabels;
......@@ -36,7 +39,7 @@ export class CommentsPanel extends ViewPane {
private treeContainer!: HTMLElement;
private messageBoxContainer!: HTMLElement;
private commentsModel!: CommentsModel;
private collapseAllAction?: IAction;
private readonly hasCommentsContextKey: IContextKey<boolean>;
readonly onDidChangeVisibility = this.onDidChangeBodyVisibility;
......@@ -56,6 +59,7 @@ export class CommentsPanel extends ViewPane {
@IUriIdentityService private readonly uriIdentityService: IUriIdentityService
) {
super(options, keybindingService, contextMenuService, configurationService, contextKeyService, viewDescriptorService, instantiationService, openerService, themeService, telemetryService);
this.hasCommentsContextKey = CONTEXT_KEY_HAS_COMMENTS.bindTo(contextKeyService);
}
public renderBody(container: HTMLElement): void {
......@@ -131,13 +135,10 @@ export class CommentsPanel extends ViewPane {
await this.tree.setInput(this.commentsModel);
}
public getActions(): IAction[] {
if (!this.collapseAllAction) {
this.collapseAllAction = new Action('vs.tree.collapse', nls.localize('collapseAll', "Collapse All"), 'collapse-all', true, () => this.tree ? new CollapseAllAction<any, any>(this.tree, true).run() : Promise.resolve());
this._register(this.collapseAllAction);
public collapseAll() {
if (this.tree) {
new CollapseAllAction<any, any>(this.tree, true).run();
}
return [this.collapseAllAction];
}
public layoutBody(height: number, width: number): void {
......@@ -245,9 +246,7 @@ export class CommentsPanel extends ViewPane {
private async refresh(): Promise<void> {
if (this.isVisible()) {
if (this.collapseAllAction) {
this.collapseAllAction.enabled = this.commentsModel.hasCommentThreads();
}
this.hasCommentsContextKey.set(this.commentsModel.hasCommentThreads());
this.treeContainer.classList.toggle('hidden', !this.commentsModel.hasCommentThreads());
this.renderMessage();
......@@ -283,3 +282,23 @@ CommandsRegistry.registerCommand({
viewsService.openView(COMMENTS_VIEW_ID, true);
}
});
registerAction2(class Collapse extends ViewAction<CommentsPanel> {
constructor() {
super({
viewId: COMMENTS_VIEW_ID,
id: 'comments.collapse',
title: nls.localize('collapseAll', "Collapse All"),
f1: false,
icon: Codicon.collapseAll,
menu: {
id: MenuId.ViewTitle,
group: 'navigation',
when: ContextKeyAndExpr.create([ContextKeyEqualsExpr.create('view', COMMENTS_VIEW_ID), CONTEXT_KEY_HAS_COMMENTS])
}
});
}
runInView(_accessor: ServicesAccessor, view: CommentsPanel) {
view.collapseAll();
}
});
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册