Skip to content

Commit 69f4b0e

Browse files
authored
1 parent 17dd260 commit 69f4b0e

File tree

3 files changed

+85
-42
lines changed

3 files changed

+85
-42
lines changed

src/vs/workbench/browser/parts/activitybar/activitybarPart.ts

Lines changed: 60 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,12 @@ import { ActionsOrientation } from 'vs/base/browser/ui/actionbar/actionbar';
1010
import { Part } from 'vs/workbench/browser/part';
1111
import { ActivityBarPosition, IWorkbenchLayoutService, LayoutSettings, Parts, Position } from 'vs/workbench/services/layout/browser/layoutService';
1212
import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
13-
import { DisposableStore } from 'vs/base/common/lifecycle';
13+
import { DisposableStore, MutableDisposable } from 'vs/base/common/lifecycle';
1414
import { ToggleSidebarPositionAction } from 'vs/workbench/browser/actions/layoutActions';
1515
import { IThemeService, IColorTheme, registerThemingParticipant } from 'vs/platform/theme/common/themeService';
1616
import { ACTIVITY_BAR_BACKGROUND, ACTIVITY_BAR_BORDER, ACTIVITY_BAR_FOREGROUND, ACTIVITY_BAR_ACTIVE_BORDER, ACTIVITY_BAR_BADGE_BACKGROUND, ACTIVITY_BAR_BADGE_FOREGROUND, ACTIVITY_BAR_INACTIVE_FOREGROUND, ACTIVITY_BAR_ACTIVE_BACKGROUND, ACTIVITY_BAR_DRAG_AND_DROP_BORDER, ACTIVITY_BAR_ACTIVE_FOCUS_BORDER } from 'vs/workbench/common/theme';
1717
import { activeContrastBorder, contrastBorder, focusBorder } from 'vs/platform/theme/common/colorRegistry';
18-
import { addDisposableListener, append, EventType, isAncestor, $ } from 'vs/base/browser/dom';
19-
import { ICompositeBarColors, IActivityHoverOptions } from 'vs/workbench/browser/parts/compositeBarActions';
18+
import { addDisposableListener, append, EventType, isAncestor, $, clearNode } from 'vs/base/browser/dom';
2019
import { assertIsDefined } from 'vs/base/common/types';
2120
import { CustomMenubarControl } from 'vs/workbench/browser/parts/titlebar/menubarControl';
2221
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
@@ -57,7 +56,8 @@ export class ActivitybarPart extends Part {
5756

5857
//#endregion
5958

60-
private readonly compositeBar: PaneCompositeBar;
59+
private readonly compositeBar = this._register(new MutableDisposable<PaneCompositeBar>());
60+
private content: HTMLElement | undefined;
6161

6262
constructor(
6363
private readonly paneCompositePart: IPaneCompositePart,
@@ -67,51 +67,59 @@ export class ActivitybarPart extends Part {
6767
@IStorageService storageService: IStorageService,
6868
) {
6969
super(Parts.ACTIVITYBAR_PART, { hasTitle: false }, themeService, storageService, layoutService);
70-
this.compositeBar = this.createCompositeBar();
7170
}
7271

7372
private createCompositeBar(): PaneCompositeBar {
74-
return this._register(this.instantiationService.createInstance(ActivityBarCompositeBar, {
73+
return this.instantiationService.createInstance(ActivityBarCompositeBar, {
7574
partContainerClass: 'activitybar',
7675
pinnedViewContainersKey: ActivitybarPart.pinnedViewContainersKey,
7776
placeholderViewContainersKey: ActivitybarPart.placeholderViewContainersKey,
7877
viewContainersWorkspaceStateKey: ActivitybarPart.viewContainersWorkspaceStateKey,
7978
orientation: ActionsOrientation.VERTICAL,
8079
icon: true,
8180
iconSize: 24,
82-
activityHoverOptions: this.getActivityHoverOptions(),
81+
activityHoverOptions: {
82+
position: () => this.layoutService.getSideBarPosition() === Position.LEFT ? HoverPosition.RIGHT : HoverPosition.LEFT,
83+
},
8384
preventLoopNavigation: true,
8485
recomputeSizes: false,
8586
fillExtraContextMenuActions: (actions, e?: MouseEvent | GestureEvent) => { },
8687
compositeSize: 52,
87-
colors: (theme: IColorTheme) => this.getActivitybarItemColors(theme),
88+
colors: (theme: IColorTheme) => ({
89+
activeForegroundColor: theme.getColor(ACTIVITY_BAR_FOREGROUND),
90+
inactiveForegroundColor: theme.getColor(ACTIVITY_BAR_INACTIVE_FOREGROUND),
91+
activeBorderColor: theme.getColor(ACTIVITY_BAR_ACTIVE_BORDER),
92+
activeBackground: theme.getColor(ACTIVITY_BAR_ACTIVE_BACKGROUND),
93+
badgeBackground: theme.getColor(ACTIVITY_BAR_BADGE_BACKGROUND),
94+
badgeForeground: theme.getColor(ACTIVITY_BAR_BADGE_FOREGROUND),
95+
dragAndDropBorder: theme.getColor(ACTIVITY_BAR_DRAG_AND_DROP_BORDER),
96+
activeBackgroundColor: undefined, inactiveBackgroundColor: undefined, activeBorderBottomColor: undefined,
97+
}),
8898
overflowActionSize: ActivitybarPart.ACTION_HEIGHT,
89-
}, Parts.ACTIVITYBAR_PART, this.paneCompositePart, true));
90-
}
91-
92-
private getActivityHoverOptions(): IActivityHoverOptions {
93-
return {
94-
position: () => this.layoutService.getSideBarPosition() === Position.LEFT ? HoverPosition.RIGHT : HoverPosition.LEFT,
95-
};
99+
}, Parts.ACTIVITYBAR_PART, this.paneCompositePart, true);
96100
}
97101

98102
protected override createContentArea(parent: HTMLElement): HTMLElement {
99103
this.element = parent;
100-
const content = append(this.element, $('.content'));
101-
this.compositeBar.create(content);
102-
return content;
104+
this.content = append(this.element, $('.content'));
105+
106+
if (this.layoutService.isVisible(Parts.ACTIVITYBAR_PART)) {
107+
this.show();
108+
}
109+
110+
return this.content;
103111
}
104112

105113
getPinnedPaneCompositeIds(): string[] {
106-
return this.compositeBar.getPinnedPaneCompositeIds();
114+
return this.compositeBar.value?.getPinnedPaneCompositeIds() ?? [];
107115
}
108116

109117
getVisiblePaneCompositeIds(): string[] {
110-
return this.compositeBar.getVisiblePaneCompositeIds();
118+
return this.compositeBar.value?.getVisiblePaneCompositeIds() ?? [];
111119
}
112120

113121
focus(): void {
114-
this.compositeBar.focus();
122+
this.compositeBar.value?.focus();
115123
}
116124

117125
override updateStyles(): void {
@@ -126,29 +134,47 @@ export class ActivitybarPart extends Part {
126134
container.style.borderColor = borderColor ? borderColor : '';
127135
}
128136

129-
private getActivitybarItemColors(theme: IColorTheme): ICompositeBarColors {
130-
return {
131-
activeForegroundColor: theme.getColor(ACTIVITY_BAR_FOREGROUND),
132-
inactiveForegroundColor: theme.getColor(ACTIVITY_BAR_INACTIVE_FOREGROUND),
133-
activeBorderColor: theme.getColor(ACTIVITY_BAR_ACTIVE_BORDER),
134-
activeBackground: theme.getColor(ACTIVITY_BAR_ACTIVE_BACKGROUND),
135-
badgeBackground: theme.getColor(ACTIVITY_BAR_BADGE_BACKGROUND),
136-
badgeForeground: theme.getColor(ACTIVITY_BAR_BADGE_FOREGROUND),
137-
dragAndDropBorder: theme.getColor(ACTIVITY_BAR_DRAG_AND_DROP_BORDER),
138-
activeBackgroundColor: undefined, inactiveBackgroundColor: undefined, activeBorderBottomColor: undefined,
139-
};
137+
show(): void {
138+
if (!this.content) {
139+
return;
140+
}
141+
142+
if (this.compositeBar.value) {
143+
return;
144+
}
145+
146+
this.compositeBar.value = this.createCompositeBar();
147+
this.compositeBar.value.create(this.content);
148+
149+
if (this.dimension) {
150+
this.layout(this.dimension.width, this.dimension.height);
151+
}
152+
}
153+
154+
hide(): void {
155+
if (!this.compositeBar.value) {
156+
return;
157+
}
158+
159+
this.compositeBar.clear();
160+
161+
if (this.content) {
162+
clearNode(this.content);
163+
}
140164
}
141165

142166
override layout(width: number, height: number): void {
143-
if (!this.layoutService.isVisible(Parts.ACTIVITYBAR_PART)) {
167+
super.layout(width, height, 0, 0);
168+
169+
if (!this.compositeBar.value) {
144170
return;
145171
}
146172

147173
// Layout contents
148174
const contentAreaSize = super.layoutContents(width, height).contentSize;
149175

150176
// Layout composite bar
151-
this.compositeBar.layout(width, contentAreaSize.height);
177+
this.compositeBar.value.layout(width, contentAreaSize.height);
152178
}
153179

154180
toJSON(): object {

src/vs/workbench/browser/parts/paneCompositeBar.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,13 +186,14 @@ export class PaneCompositeBar extends Disposable {
186186
this._register(this.paneCompositePart.onDidPaneCompositeClose(e => this.onDidChangeViewContainerVisibility(e.getId(), false)));
187187

188188
// Extension registration
189-
const disposables = this._register(new DisposableStore());
190-
this._register(this.extensionService.onDidRegisterExtensions(() => {
191-
disposables.clear();
189+
this.extensionService.whenInstalledExtensionsRegistered().then(() => {
190+
if (this._store.isDisposed) {
191+
return;
192+
}
192193
this.onDidRegisterExtensions();
193-
this.compositeBar.onDidChange(() => this.saveCachedViewContainers(), this, disposables);
194-
this.storageService.onDidChangeValue(StorageScope.PROFILE, this.options.pinnedViewContainersKey, disposables)(e => this.onDidPinnedViewContainersStorageValueChange(e), this, disposables);
195-
}));
194+
this._register(this.compositeBar.onDidChange(() => this.saveCachedViewContainers()));
195+
this._register(this.storageService.onDidChangeValue(StorageScope.PROFILE, this.options.pinnedViewContainersKey, this._store)(e => this.onDidPinnedViewContainersStorageValueChange(e)));
196+
});
196197
}
197198

198199
private onDidChangeViewContainers(added: readonly { container: ViewContainer; location: ViewContainerLocation }[], removed: readonly { container: ViewContainer; location: ViewContainerLocation }[]) {

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,13 @@ export class SidebarPart extends AbstractPaneCompositePart {
106106

107107
this.acitivityBarPart = this._register(instantiationService.createInstance(ActivitybarPart, this));
108108
this._register(configurationService.onDidChangeConfiguration(e => {
109-
if (e.affectsConfiguration('workbench.activityBar.location')) {
109+
if (e.affectsConfiguration(LayoutSettings.ACTIVITY_BAR_LOCATION)) {
110110
this.updateTitleArea();
111111
const id = this.getActiveComposite()?.getId();
112112
if (id) {
113113
this.onTitleAreaUpdate(id!);
114114
}
115+
this.updateActivityBarVisiblity();
115116
}
116117
}));
117118

@@ -199,7 +200,22 @@ export class SidebarPart extends AbstractPaneCompositePart {
199200
}
200201

201202
protected shouldShowCompositeBar(): boolean {
202-
return this.layoutService.isVisible(Parts.TITLEBAR_PART) && this.configurationService.getValue('workbench.activityBar.location') === ActivityBarPosition.TOP;
203+
return this.layoutService.isVisible(Parts.TITLEBAR_PART) && this.configurationService.getValue(LayoutSettings.ACTIVITY_BAR_LOCATION) === ActivityBarPosition.TOP;
204+
}
205+
206+
private shouldShowActivityBar(): boolean {
207+
if (this.shouldShowCompositeBar()) {
208+
return false;
209+
}
210+
return this.configurationService.getValue(LayoutSettings.ACTIVITY_BAR_LOCATION) !== ActivityBarPosition.HIDDEN;
211+
}
212+
213+
private updateActivityBarVisiblity(): void {
214+
if (this.shouldShowActivityBar()) {
215+
this.acitivityBarPart.show();
216+
} else {
217+
this.acitivityBarPart.hide();
218+
}
203219
}
204220

205221
override getPinnedPaneCompositeIds(): string[] {

0 commit comments

Comments
 (0)