Skip to content

Commit 50bc5d7

Browse files
committed
migrate comment panel to use view container
1 parent 614a837 commit 50bc5d7

3 files changed

Lines changed: 77 additions & 59 deletions

File tree

src/vs/workbench/api/browser/mainThreadComments.ts

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ import * as modes from 'vs/editor/common/modes';
1414
import { ExtensionIdentifier } from 'vs/platform/extensions/common/extensions';
1515
import { Registry } from 'vs/platform/registry/common/platform';
1616
import { extHostNamedCustomer } from 'vs/workbench/api/common/extHostCustomers';
17-
import { Extensions as PanelExtensions, PanelDescriptor, PanelRegistry } from 'vs/workbench/browser/panel';
1817
import { ICommentInfo, ICommentService } from 'vs/workbench/contrib/comments/browser/commentService';
1918
import { CommentsPanel } from 'vs/workbench/contrib/comments/browser/commentsPanel';
20-
import { IPanelService } from 'vs/workbench/services/panel/common/panelService';
2119
import { CommentProviderFeatures, ExtHostCommentsShape, ExtHostContext, IExtHostContext, MainContext, MainThreadCommentsShape, CommentThreadChanges } from '../common/extHost.protocol';
22-
import { COMMENTS_PANEL_ID, COMMENTS_PANEL_TITLE } from 'vs/workbench/contrib/comments/browser/commentsTreeViewer';
20+
import { COMMENTS_VIEW_ID, COMMENTS_VIEW_TITLE } from 'vs/workbench/contrib/comments/browser/commentsTreeViewer';
21+
import { ViewContainer, IViewContainersRegistry, Extensions as ViewExtensions, ViewContainerLocation, IViewsRegistry, IViewsService, IViewDescriptorService } from 'vs/workbench/common/views';
22+
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
23+
import { ViewPaneContainer } from 'vs/workbench/browser/parts/views/viewPaneContainer';
2324

2425

2526
export class MainThreadCommentThread implements modes.CommentThread {
@@ -343,13 +344,14 @@ export class MainThreadComments extends Disposable implements MainThreadComments
343344
private _activeCommentThread?: MainThreadCommentThread;
344345
private readonly _activeCommentThreadDisposables = this._register(new DisposableStore());
345346

346-
private _openPanelListener: IDisposable | null = null;
347+
private _openViewListener: IDisposable | null = null;
347348

348349

349350
constructor(
350351
extHostContext: IExtHostContext,
351352
@ICommentService private readonly _commentService: ICommentService,
352-
@IPanelService private readonly _panelService: IPanelService
353+
@IViewsService private readonly _viewsService: IViewsService,
354+
@IViewDescriptorService private readonly _viewDescriptorService: IViewDescriptorService
353355
) {
354356
super();
355357
this._proxy = extHostContext.getProxy(ExtHostContext.ExtHostComments);
@@ -376,10 +378,10 @@ export class MainThreadComments extends Disposable implements MainThreadComments
376378
this._commentService.registerCommentController(providerId, provider);
377379
this._commentControllers.set(handle, provider);
378380

379-
const commentsPanelAlreadyConstructed = this._panelService.getPanels().some(panel => panel.id === COMMENTS_PANEL_ID);
381+
const commentsPanelAlreadyConstructed = !!this._viewDescriptorService.getViewDescriptor(COMMENTS_VIEW_ID);
380382
if (!commentsPanelAlreadyConstructed) {
381-
this.registerPanel(commentsPanelAlreadyConstructed);
382-
this.registerOpenPanelListener(commentsPanelAlreadyConstructed);
383+
this.registerView(commentsPanelAlreadyConstructed);
384+
this.registerViewOpenedListener(commentsPanelAlreadyConstructed);
383385
}
384386
this._commentService.setWorkspaceComments(String(handle), []);
385387
}
@@ -444,27 +446,36 @@ export class MainThreadComments extends Disposable implements MainThreadComments
444446
return provider.deleteCommentThread(commentThreadHandle);
445447
}
446448

447-
private registerPanel(commentsPanelAlreadyConstructed: boolean) {
448-
if (!commentsPanelAlreadyConstructed) {
449-
Registry.as<PanelRegistry>(PanelExtensions.Panels).registerPanel(PanelDescriptor.create(
450-
CommentsPanel,
451-
COMMENTS_PANEL_ID,
452-
COMMENTS_PANEL_TITLE,
453-
'commentsPanel',
454-
10
455-
));
449+
private registerView(commentsViewAlreadyRegistered: boolean) {
450+
if (!commentsViewAlreadyRegistered) {
451+
const VIEW_CONTAINER: ViewContainer = Registry.as<IViewContainersRegistry>(ViewExtensions.ViewContainersRegistry).registerViewContainer({
452+
id: COMMENTS_VIEW_ID,
453+
name: COMMENTS_VIEW_TITLE,
454+
ctorDescriptor: new SyncDescriptor(ViewPaneContainer, [COMMENTS_VIEW_ID, COMMENTS_VIEW_TITLE, { mergeViewWithContainerWhenSingleView: true, donotShowContainerTitleWhenMergedWithContainer: true }]),
455+
order: 10,
456+
}, ViewContainerLocation.Panel);
457+
458+
Registry.as<IViewsRegistry>(ViewExtensions.ViewsRegistry).registerViews([{
459+
id: COMMENTS_VIEW_ID,
460+
name: COMMENTS_VIEW_TITLE,
461+
canToggleVisibility: false,
462+
ctorDescriptor: new SyncDescriptor(CommentsPanel),
463+
focusCommand: {
464+
id: 'workbench.action.focusCommentsPanel'
465+
}
466+
}], VIEW_CONTAINER);
456467
}
457468
}
458469

459470
/**
460-
* If the comments panel has never been opened, the constructor for it has not yet run so it has
461-
* no listeners for comment threads being set or updated. Listen for the panel opening for the
471+
* If the comments view has never been opened, the constructor for it has not yet run so it has
472+
* no listeners for comment threads being set or updated. Listen for the view opening for the
462473
* first time and send it comments then.
463474
*/
464-
private registerOpenPanelListener(commentsPanelAlreadyConstructed: boolean) {
465-
if (!commentsPanelAlreadyConstructed && !this._openPanelListener) {
466-
this._openPanelListener = this._panelService.onDidPanelOpen(e => {
467-
if (e.panel.getId() === COMMENTS_PANEL_ID) {
475+
private registerViewOpenedListener(commentsPanelAlreadyConstructed: boolean) {
476+
if (!commentsPanelAlreadyConstructed && !this._openViewListener) {
477+
this._openViewListener = this._viewsService.onDidChangeViewVisibility(e => {
478+
if (e.id === COMMENTS_VIEW_ID && e.visible) {
468479
keys(this._commentControllers).forEach(handle => {
469480
let threads = this._commentControllers.get(handle)!.getAllComments();
470481

@@ -474,9 +485,9 @@ export class MainThreadComments extends Disposable implements MainThreadComments
474485
}
475486
});
476487

477-
if (this._openPanelListener) {
478-
this._openPanelListener.dispose();
479-
this._openPanelListener = null;
488+
if (this._openViewListener) {
489+
this._openViewListener.dispose();
490+
this._openViewListener = null;
480491
}
481492
}
482493
});

src/vs/workbench/contrib/comments/browser/commentsPanel.ts

Lines changed: 37 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,25 @@ import { CollapseAllAction } from 'vs/base/browser/ui/tree/treeDefaults';
1111
import { isCodeEditor } from 'vs/editor/browser/editorBrowser';
1212
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
1313
import { TreeResourceNavigator } from 'vs/platform/list/browser/listService';
14-
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
1514
import { IThemeService } from 'vs/platform/theme/common/themeService';
16-
import { Panel } from 'vs/workbench/browser/panel';
1715
import { CommentNode, CommentsModel, ResourceWithCommentThreads, ICommentThreadChangedEvent } from 'vs/workbench/contrib/comments/common/commentModel';
1816
import { CommentController } from 'vs/workbench/contrib/comments/browser/commentsEditorContribution';
19-
import { ICommentService, IWorkspaceCommentThreadsEvent } from 'vs/workbench/contrib/comments/browser/commentService';
17+
import { IWorkspaceCommentThreadsEvent, ICommentService } from 'vs/workbench/contrib/comments/browser/commentService';
2018
import { IEditorService, ACTIVE_GROUP, SIDE_GROUP } from 'vs/workbench/services/editor/common/editorService';
2119
import { CommandsRegistry } from 'vs/platform/commands/common/commands';
2220
import { textLinkForeground, textLinkActiveForeground, focusBorder, textPreformatForeground } from 'vs/platform/theme/common/colorRegistry';
23-
import { IStorageService } from 'vs/platform/storage/common/storage';
2421
import { ResourceLabels } from 'vs/workbench/browser/labels';
25-
import { IPanelService } from 'vs/workbench/services/panel/common/panelService';
26-
import { CommentsList, COMMENTS_PANEL_ID, COMMENTS_PANEL_TITLE } from 'vs/workbench/contrib/comments/browser/commentsTreeViewer';
22+
import { CommentsList, COMMENTS_VIEW_ID, COMMENTS_VIEW_TITLE } from 'vs/workbench/contrib/comments/browser/commentsTreeViewer';
23+
import { ViewPane, IViewPaneOptions } from 'vs/workbench/browser/parts/views/viewPaneContainer';
24+
import { IViewDescriptorService, IViewsService } from 'vs/workbench/common/views';
25+
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
26+
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
27+
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
28+
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
29+
import { IOpenerService } from 'vs/platform/opener/common/opener';
2730

2831

29-
export class CommentsPanel extends Panel {
32+
export class CommentsPanel extends ViewPane {
3033
private treeLabels!: ResourceLabels;
3134
private tree!: CommentsList;
3235
private treeContainer!: HTMLElement;
@@ -35,43 +38,50 @@ export class CommentsPanel extends Panel {
3538
private commentsModel!: CommentsModel;
3639
private collapseAllAction?: IAction;
3740

41+
readonly onDidChangeVisibility = this.onDidChangeBodyVisibility;
42+
3843
constructor(
39-
@IInstantiationService private readonly instantiationService: IInstantiationService,
40-
@ICommentService private readonly commentService: ICommentService,
44+
options: IViewPaneOptions,
45+
@IInstantiationService readonly instantiationService: IInstantiationService,
46+
@IViewDescriptorService viewDescriptorService: IViewDescriptorService,
4147
@IEditorService private readonly editorService: IEditorService,
42-
@ITelemetryService telemetryService: ITelemetryService,
48+
@IConfigurationService configurationService: IConfigurationService,
49+
@IContextKeyService contextKeyService: IContextKeyService,
50+
@IContextMenuService contextMenuService: IContextMenuService,
51+
@IKeybindingService keybindingService: IKeybindingService,
52+
@IOpenerService openerService: IOpenerService,
4353
@IThemeService themeService: IThemeService,
44-
@IStorageService storageService: IStorageService
54+
@ICommentService private readonly commentService: ICommentService
4555
) {
46-
super(COMMENTS_PANEL_ID, telemetryService, themeService, storageService);
56+
super({ ...(options as IViewPaneOptions), id: COMMENTS_VIEW_ID, ariaHeaderLabel: COMMENTS_VIEW_TITLE }, keybindingService, contextMenuService, configurationService, contextKeyService, viewDescriptorService, instantiationService, openerService, themeService);
4757
}
4858

49-
public create(parent: HTMLElement): void {
50-
super.create(parent);
59+
public renderBody(container: HTMLElement): void {
60+
super.renderBody(container);
5161

52-
dom.addClass(parent, 'comments-panel');
62+
dom.addClass(container, 'comments-panel');
5363

54-
let container = dom.append(parent, dom.$('.comments-panel-container'));
55-
this.treeContainer = dom.append(container, dom.$('.tree-container'));
64+
let domContainer = dom.append(container, dom.$('.comments-panel-container'));
65+
this.treeContainer = dom.append(domContainer, dom.$('.tree-container'));
5666
this.commentsModel = new CommentsModel();
5767

5868
this.createTree();
59-
this.createMessageBox(container);
69+
this.createMessageBox(domContainer);
6070

6171
this._register(this.commentService.onDidSetAllCommentThreads(this.onAllCommentsChanged, this));
6272
this._register(this.commentService.onDidUpdateCommentThreads(this.onCommentsUpdated, this));
6373

64-
const styleElement = dom.createStyleSheet(parent);
74+
const styleElement = dom.createStyleSheet(container);
6575
this.applyStyles(styleElement);
6676
this._register(this.themeService.onThemeChange(_ => this.applyStyles(styleElement)));
6777

68-
this._register(this.onDidChangeVisibility(visible => {
78+
this._register(this.onDidChangeBodyVisibility(visible => {
6979
if (visible) {
7080
this.refresh();
7181
}
7282
}));
7383

74-
this.render();
84+
this.renderComments();
7585
}
7686

7787
private applyStyles(styleElement: HTMLStyleElement) {
@@ -101,7 +111,7 @@ export class CommentsPanel extends Panel {
101111
styleElement.innerHTML = content.join('\n');
102112
}
103113

104-
private async render(): Promise<void> {
114+
private async renderComments(): Promise<void> {
105115
dom.toggleClass(this.treeContainer, 'hidden', !this.commentsModel.hasCommentThreads());
106116
await this.tree.setInput(this.commentsModel);
107117
this.renderMessage();
@@ -116,12 +126,12 @@ export class CommentsPanel extends Panel {
116126
return [this.collapseAllAction];
117127
}
118128

119-
public layout(dimensions: dom.Dimension): void {
120-
this.tree.layout(dimensions.height, dimensions.width);
129+
public layoutBody(height: number, width: number): void {
130+
this.tree.layout(height, width);
121131
}
122132

123133
public getTitle(): string {
124-
return COMMENTS_PANEL_TITLE;
134+
return COMMENTS_VIEW_TITLE;
125135
}
126136

127137
private createMessageBox(parent: HTMLElement): void {
@@ -224,10 +234,7 @@ export class CommentsPanel extends Panel {
224234
CommandsRegistry.registerCommand({
225235
id: 'workbench.action.focusCommentsPanel',
226236
handler: async (accessor) => {
227-
const panelService = accessor.get(IPanelService);
228-
const panels = panelService.getPanels();
229-
if (panels.some(panelIdentifier => panelIdentifier.id === COMMENTS_PANEL_ID)) {
230-
await panelService.openPanel(COMMENTS_PANEL_ID, true);
231-
}
237+
const viewsService = accessor.get(IViewsService);
238+
viewsService.openView(COMMENTS_VIEW_ID, true);
232239
}
233240
});

src/vs/workbench/contrib/comments/browser/commentsTreeViewer.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ import { IThemeService } from 'vs/platform/theme/common/themeService';
2222
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
2323
import { PANEL_BACKGROUND } from 'vs/workbench/common/theme';
2424

25-
export const COMMENTS_PANEL_ID = 'workbench.panel.comments';
26-
export const COMMENTS_PANEL_TITLE = 'Comments';
25+
export const COMMENTS_VIEW_ID = 'workbench.panel.comments';
26+
export const COMMENTS_VIEW_TITLE = 'Comments';
2727

2828
export class CommentsAsyncDataSource implements IAsyncDataSource<any, any> {
2929
hasChildren(element: any): boolean {
@@ -176,7 +176,7 @@ export class CommentsList extends WorkbenchAsyncDataTree<any, any> {
176176
renderers,
177177
dataSource,
178178
{
179-
ariaLabel: COMMENTS_PANEL_TITLE,
179+
ariaLabel: COMMENTS_VIEW_TITLE,
180180
keyboardSupport: true,
181181
identityProvider: {
182182
getId: (element: any) => {

0 commit comments

Comments
 (0)