Skip to content

Commit

Permalink
Add "Expand All" action to Comments panel
Browse files Browse the repository at this point in the history
Fixes #172539.
  • Loading branch information
hermannloose committed Feb 2, 2023
1 parent cf66f5c commit 947ad09
Showing 1 changed file with 59 additions and 1 deletion.
60 changes: 59 additions & 1 deletion src/vs/workbench/contrib/comments/browser/commentsView.ts
Original file line number Diff line number Diff line change
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();
}
});

0 comments on commit 947ad09

Please sign in to comment.