Skip to content

Commit

Permalink
feat(workbench/perspective): activate first view of each part if not …
Browse files Browse the repository at this point in the history
…specified
  • Loading branch information
Marcarrian committed Jun 12, 2024
1 parent 33b91bc commit 85112d1
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 8 deletions.
9 changes: 2 additions & 7 deletions apps/workbench-testing-app/src/app/workbench.perspectives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,7 @@ function provideDeveloperPerspectiveLayout(factory: WorkbenchLayoutFactory): Wor
.navigateView('search', [], {hint: 'search'})
.navigateView('progress', [], {hint: 'progress'})
.navigateView('outline', [], {hint: 'outline'})
.activateView('package-explorer')
.activateView('git-repositories')
.activateView('console')
.activateView('outline');
.activateView('console');
}

/** @private */
Expand All @@ -144,7 +141,5 @@ function provideDebugPerspectiveLayout(factory: WorkbenchLayoutFactory): Workben
.navigateView('variables', [], {hint: 'variables'})
.navigateView('expressions', [], {hint: 'expressions'})
.navigateView('breakpoints', [], {hint: 'breakpoints'})
.activateView('debug')
.activateView('console')
.activateView('variables');
.activateView('console');
}
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,36 @@ describe('Workbench Perspective', () => {
},
});
});

fit('should activate first view of each part if not specified', async () => {
TestBed.configureTestingModule({
providers: [
provideWorkbenchForTest({
layout: factory => factory
.addPart('left')
.addPart('right', {align: 'right'})
.addView('view.101', {partId: 'left'})
.addView('view.102', {partId: 'left'})
.addView('view.103', {partId: 'left'})
.addView('view.201', {partId: 'right'})
.addView('view.202', {partId: 'right', activateView: true})
.addView('view.203', {partId: 'right'})
}),
],
});

const fixture = styleFixture(TestBed.createComponent(WorkbenchComponent));
await waitForInitialWorkbenchLayout();

expect(fixture.debugElement.query(By.directive(WorkbenchLayoutComponent))).toEqualWorkbenchLayout({
workbenchGrid: {
root: new MTreeNode({
child1: new MPart({id: 'left', views: [{id: 'view.101'},{id: 'view.102'},{id: 'view.103'}], activeViewId: 'view.101'}),
child2: new MPart({id: 'right', views: [{id: 'view.201'},{id: 'view.202'},{id: 'view.203'}], activeViewId: 'view.202'}),
direction: 'row',
ratio: .5,
}),
},
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,24 @@ export class ɵWorkbenchPerspective implements WorkbenchPerspective {
* Creates the initial layout of this perspective as defined in the perspective definition.
*/
private async createInitialPerspectiveLayout(): Promise<ɵWorkbenchLayout> {
return await runInInjectionContext(this._environmentInjector, () => this._initialLayoutFn(this._workbenchLayoutFactory)) as ɵWorkbenchLayout;
let layout = await runInInjectionContext(this._environmentInjector, () => this._initialLayoutFn(this._workbenchLayoutFactory)) as ɵWorkbenchLayout;
layout = this.activateFirstView(layout);
return layout;
}

/**
* Activates the first view of each part if not specified.
*/
private activateFirstView(layout: ɵWorkbenchLayout): ɵWorkbenchLayout {
for (const part of layout.parts()) {
if (!part.views?.length) {
continue;
}
if (!part.activeViewId) {
layout = layout.activateView(part.views[0].id);
}
}
return layout;
}

/**
Expand Down

0 comments on commit 85112d1

Please sign in to comment.