Skip to content

Commit a147afb

Browse files
author
Benjamin Pasero
committed
debt - declarative viewlet service
1 parent 667868b commit a147afb

4 files changed

Lines changed: 34 additions & 22 deletions

File tree

src/vs/workbench/browser/parts/sidebar/sidebarPart.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import { IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/c
3131
import { AnchorAlignment } from 'vs/base/browser/ui/contextview/contextview';
3232
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
3333
import { LayoutPriority } from 'vs/base/browser/ui/grid/gridview';
34+
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
3435

3536
export class SidebarPart extends CompositePart<Viewlet> implements IViewletService {
3637

@@ -296,3 +297,5 @@ const registry = Registry.as<IWorkbenchActionRegistry>(ActionExtensions.Workbenc
296297
registry.registerWorkbenchAction(new SyncActionDescriptor(FocusSideBarAction, FocusSideBarAction.ID, FocusSideBarAction.LABEL, {
297298
primary: KeyMod.CtrlCmd | KeyCode.KEY_0
298299
}), 'View: Focus into Side Bar', nls.localize('viewCategory', "View"));
300+
301+
registerSingleton(IViewletService, SidebarPart);

src/vs/workbench/electron-browser/workbench.ts

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@ export class Workbench extends Disposable implements IWorkbenchLayoutService {
170170

171171
private parts: Map<string, Part> = new Map<string, Part>();
172172

173-
private sidebarPart: SidebarPart;
174173
private statusbarPart: StatusbarPart;
175174

176175
constructor(
@@ -434,10 +433,6 @@ export class Workbench extends Disposable implements IWorkbenchLayoutService {
434433
serviceCollection.set(IContextMenuService, new SyncDescriptor(NativeContextMenuService));
435434
}
436435

437-
// Viewlet service (sidebar part)
438-
this.sidebarPart = this.instantiationService.createInstance(SidebarPart);
439-
serviceCollection.set(IViewletService, this.sidebarPart); // TODO@Ben use SyncDescriptor
440-
441436
// Contributed services
442437
const contributedServices = getServices();
443438
for (let contributedService of contributedServices) {
@@ -578,7 +573,7 @@ export class Workbench extends Disposable implements IWorkbenchLayoutService {
578573
private createSidebarPart(): void {
579574
const sidebarPartContainer = this.createPart(Parts.SIDEBAR_PART, 'complementary', 'sidebar', this.state.sideBar.position === Position.LEFT ? 'left' : 'right');
580575

581-
this.sidebarPart.create(sidebarPartContainer);
576+
this.parts.get(Parts.SIDEBAR_PART).create(sidebarPartContainer);
582577
}
583578

584579
private createPanelPart(): void {
@@ -774,6 +769,7 @@ export class Workbench extends Disposable implements IWorkbenchLayoutService {
774769
private editorService: IEditorService;
775770
private editorGroupService: IEditorGroupsService;
776771
private panelService: IPanelService;
772+
private viewletService: IViewletService;
777773

778774
private readonly state = {
779775
fullscreen: false,
@@ -928,6 +924,7 @@ export class Workbench extends Disposable implements IWorkbenchLayoutService {
928924

929925
private setSideBarPosition(position: Position): void {
930926
const activityBar = this.parts.get(Parts.ACTIVITYBAR_PART);
927+
const sideBar = this.parts.get(Parts.SIDEBAR_PART);
931928
const wasHidden = this.state.sideBar.hidden;
932929

933930
if (this.state.sideBar.hidden) {
@@ -940,13 +937,13 @@ export class Workbench extends Disposable implements IWorkbenchLayoutService {
940937

941938
// Adjust CSS
942939
removeClass(activityBar.getContainer(), oldPositionValue);
943-
removeClass(this.sidebarPart.getContainer(), oldPositionValue);
940+
removeClass(sideBar.getContainer(), oldPositionValue);
944941
addClass(activityBar.getContainer(), newPositionValue);
945-
addClass(this.sidebarPart.getContainer(), newPositionValue);
942+
addClass(sideBar.getContainer(), newPositionValue);
946943

947944
// Update Styles
948945
activityBar.updateStyles();
949-
this.sidebarPart.updateStyles();
946+
sideBar.updateStyles();
950947

951948
// Layout
952949
if (this.workbenchGrid instanceof Grid) {
@@ -1149,7 +1146,7 @@ export class Workbench extends Disposable implements IWorkbenchLayoutService {
11491146
case Parts.ACTIVITYBAR_PART:
11501147
return this.parts.get(Parts.ACTIVITYBAR_PART).getContainer();
11511148
case Parts.SIDEBAR_PART:
1152-
return this.sidebarPart.getContainer();
1149+
return this.parts.get(Parts.SIDEBAR_PART).getContainer();
11531150
case Parts.PANEL_PART:
11541151
return this.parts.get(Parts.PANEL_PART).getContainer();
11551152
case Parts.EDITOR_PART:
@@ -1323,16 +1320,17 @@ export class Workbench extends Disposable implements IWorkbenchLayoutService {
13231320
}
13241321

13251322
private createWorkbenchLayout(): void {
1326-
const titlePart = this.parts.get(Parts.TITLEBAR_PART);
1323+
const titleBar = this.parts.get(Parts.TITLEBAR_PART);
13271324
const editorPart = this.parts.get(Parts.EDITOR_PART);
13281325
const activityBar = this.parts.get(Parts.ACTIVITYBAR_PART);
13291326
const panelPart = this.parts.get(Parts.PANEL_PART);
1327+
const sideBar = this.parts.get(Parts.SIDEBAR_PART);
13301328

13311329
if (this.configurationService.getValue('workbench.useExperimentalGridLayout')) {
13321330

13331331
// Create view wrappers for all parts
1334-
this.titleBarPartView = new View(titlePart);
1335-
this.sideBarPartView = new View(this.sidebarPart);
1332+
this.titleBarPartView = new View(titleBar);
1333+
this.sideBarPartView = new View(sideBar);
13361334
this.activityBarPartView = new View(activityBar);
13371335
this.editorPartView = new View(editorPart);
13381336
this.panelPartView = new View(panelPart);
@@ -1347,10 +1345,10 @@ export class Workbench extends Disposable implements IWorkbenchLayoutService {
13471345
this.container,
13481346
this.workbench,
13491347
{
1350-
titlebar: titlePart,
1348+
titlebar: titleBar,
13511349
activitybar: activityBar,
13521350
editor: editorPart,
1353-
sidebar: this.sidebarPart,
1351+
sidebar: sideBar,
13541352
panel: panelPart,
13551353
statusbar: this.statusbarPart,
13561354
}
@@ -1557,8 +1555,8 @@ export class Workbench extends Disposable implements IWorkbenchLayoutService {
15571555
}
15581556

15591557
// If sidebar becomes hidden, also hide the current active Viewlet if any
1560-
if (hidden && this.sidebarPart.getActiveViewlet()) {
1561-
this.sidebarPart.hideActiveViewlet();
1558+
if (hidden && this.viewletService.getActiveViewlet()) {
1559+
this.viewletService.hideActiveViewlet();
15621560

15631561
// Pass Focus to Editor or Panel if Sidebar is now hidden
15641562
const activePanel = this.panelService.getActivePanel();
@@ -1570,12 +1568,12 @@ export class Workbench extends Disposable implements IWorkbenchLayoutService {
15701568
}
15711569

15721570
// If sidebar becomes visible, show last active Viewlet or default viewlet
1573-
else if (!hidden && !this.sidebarPart.getActiveViewlet()) {
1574-
const viewletToOpen = this.sidebarPart.getLastActiveViewletId();
1571+
else if (!hidden && !this.viewletService.getActiveViewlet()) {
1572+
const viewletToOpen = this.viewletService.getLastActiveViewletId();
15751573
if (viewletToOpen) {
1576-
const viewlet = this.sidebarPart.openViewlet(viewletToOpen, true);
1574+
const viewlet = this.viewletService.openViewlet(viewletToOpen, true);
15771575
if (!viewlet) {
1578-
this.sidebarPart.openViewlet(this.sidebarPart.getDefaultViewletId(), true);
1576+
this.viewletService.openViewlet(this.viewletService.getDefaultViewletId(), true);
15791577
}
15801578
}
15811579
}

src/vs/workbench/services/viewlet/browser/viewlet.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,17 @@ export interface IViewletService {
4545
getViewlets(): ViewletDescriptor[];
4646

4747
/**
48-
*
48+
* Returns the progress indicator for the side bar.
4949
*/
5050
getProgressIndicator(id: string): IProgressService | null;
51+
52+
/**
53+
* Hide the active viewlet.
54+
*/
55+
hideActiveViewlet(): void;
56+
57+
/**
58+
* Return the last active viewlet id.
59+
*/
60+
getLastActiveViewletId(): string;
5161
}

src/vs/workbench/workbench.main.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ import 'vs/workbench/browser/parts/titlebar/titlebarPart';
8787
import 'vs/workbench/browser/parts/editor/editorPart';
8888
import 'vs/workbench/browser/parts/activitybar/activitybarPart';
8989
import 'vs/workbench/browser/parts/panel/panelPart';
90+
import 'vs/workbench/browser/parts/sidebar/sidebarPart';
9091

9192
registerSingleton(IMenuService, MenuService, true);
9293
registerSingleton(IListService, ListService, true);

0 commit comments

Comments
 (0)