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 "Expand All" action to Comments panel #173132

Merged
merged 1 commit into from Feb 2, 2023
Merged
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
60 changes: 59 additions & 1 deletion src/vs/workbench/contrib/comments/browser/commentsView.ts
Expand Up @@ -43,6 +43,7 @@ import { ITreeElement } from 'vs/base/browser/ui/tree/tree';
import { Iterable } from 'vs/base/common/iterator';

const CONTEXT_KEY_HAS_COMMENTS = new RawContextKey<boolean>('commentsView.hasComments', false);
const CONTEXT_KEY_SOME_COMMENTS_EXPANDED = new RawContextKey<boolean>('commentsView.someCommentsExpanded', false);
const VIEW_STORAGE_ID = 'commentsViewState';

function createResourceCommentsIterator(model: CommentsModel): Iterable<ITreeElement<ResourceWithCommentThreads | CommentNode>> {
Expand All @@ -63,6 +64,7 @@ export class CommentsPanel extends FilterViewPane implements ICommentsView {
private totalComments: number = 0;
private totalUnresolved = 0;
private readonly hasCommentsContextKey: IContextKey<boolean>;
private readonly someCommentsExpandedContextKey: IContextKey<boolean>;
private readonly filter: Filter;
readonly filters: CommentsFilters;
private readonly activity = this._register(new MutableDisposable<IDisposable>());
Expand Down Expand Up @@ -105,6 +107,7 @@ export class CommentsPanel extends FilterViewPane implements ICommentsView {
}
}, keybindingService, contextMenuService, configurationService, contextKeyService, viewDescriptorService, instantiationService, openerService, themeService, telemetryService);
this.hasCommentsContextKey = CONTEXT_KEY_HAS_COMMENTS.bindTo(contextKeyService);
this.someCommentsExpandedContextKey = CONTEXT_KEY_SOME_COMMENTS_EXPANDED.bindTo(contextKeyService);
this.stateMemento = stateMemento;
this.viewState = viewState;

Expand Down Expand Up @@ -256,6 +259,16 @@ export class CommentsPanel extends FilterViewPane implements ICommentsView {
}
}

public expandAll() {
if (this.tree) {
this.tree.expandAll();
this.tree.setSelection([]);
this.tree.setFocus([]);
this.tree.domFocus();
this.tree.focusFirst();
}
}

public get hasRendered(): boolean {
return !!this.tree;
}
Expand Down Expand Up @@ -319,6 +332,14 @@ export class CommentsPanel extends FilterViewPane implements ICommentsView {
this._register(this.tree.onDidOpen(e => {
this.openFile(e.element, e.editorOptions.pinned, e.editorOptions.preserveFocus, e.sideBySide);
}));


this._register(this.tree.onDidChangeModel(() => {
this.updateSomeCommentsExpanded();
}));
this._register(this.tree.onDidChangeCollapseState(() => {
this.updateSomeCommentsExpanded();
}));
}

private openFile(element: any, pinned?: boolean, preserveFocus?: boolean, sideBySide?: boolean): boolean {
Expand Down Expand Up @@ -439,6 +460,22 @@ export class CommentsPanel extends FilterViewPane implements ICommentsView {
}
}

private updateSomeCommentsExpanded() {
this.someCommentsExpandedContextKey.set(this.isSomeCommentsExpanded());
}

private isSomeCommentsExpanded(): boolean {
if (!this.tree) {
return false;
}
const navigator = this.tree.navigate();
while (navigator.next()) {
if (!this.tree.isCollapsed(navigator.current())) {
return true;
}
}
return false;
}
}

CommandsRegistry.registerCommand({
Expand All @@ -460,7 +497,7 @@ registerAction2(class Collapse extends ViewAction<CommentsPanel> {
menu: {
id: MenuId.ViewTitle,
group: 'navigation',
when: ContextKeyExpr.and(ContextKeyExpr.equals('view', COMMENTS_VIEW_ID), CONTEXT_KEY_HAS_COMMENTS),
when: ContextKeyExpr.and(ContextKeyExpr.and(ContextKeyExpr.equals('view', COMMENTS_VIEW_ID), CONTEXT_KEY_HAS_COMMENTS), CONTEXT_KEY_SOME_COMMENTS_EXPANDED),
order: 100
}
});
Expand All @@ -469,3 +506,24 @@ registerAction2(class Collapse extends ViewAction<CommentsPanel> {
view.collapseAll();
}
});

registerAction2(class Expand extends ViewAction<CommentsPanel> {
constructor() {
super({
viewId: COMMENTS_VIEW_ID,
id: 'comments.expand',
title: nls.localize('expandAll', "Expand All"),
f1: false,
icon: Codicon.expandAll,
menu: {
id: MenuId.ViewTitle,
group: 'navigation',
when: ContextKeyExpr.and(ContextKeyExpr.and(ContextKeyExpr.equals('view', COMMENTS_VIEW_ID), CONTEXT_KEY_HAS_COMMENTS), ContextKeyExpr.not(CONTEXT_KEY_SOME_COMMENTS_EXPANDED.key)),
order: 100
}
});
}
runInView(_accessor: ServicesAccessor, view: CommentsPanel) {
view.expandAll();
}
});