Skip to content

Commit

Permalink
activity bar - change visibility of entries to checkboxes (#113757)
Browse files Browse the repository at this point in the history
  • Loading branch information
bpasero committed Jan 12, 2021
1 parent 6dc7795 commit d61eb64
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 58 deletions.
23 changes: 3 additions & 20 deletions src/vs/workbench/browser/actions/layoutActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { IConfigurationService } from 'vs/platform/configuration/common/configur
import { IWorkbenchLayoutService, Parts, Position } from 'vs/workbench/services/layout/browser/layoutService';
import { ServicesAccessor, IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { KeyMod, KeyCode, KeyChord } from 'vs/base/common/keyCodes';
import { getMenuBarVisibility } from 'vs/platform/windows/common/windows';
import { isWindows, isLinux, isWeb } from 'vs/base/common/platform';
import { IsMacNativeContext } from 'vs/platform/contextkey/common/contextkeys';
import { KeybindingsRegistry, KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
Expand Down Expand Up @@ -441,32 +440,16 @@ export class ToggleMenuBarAction extends Action {
static readonly ID = 'workbench.action.toggleMenuBar';
static readonly LABEL = nls.localize('toggleMenuBar', "Toggle Menu Bar");

private static readonly menuBarVisibilityKey = 'window.menuBarVisibility';

constructor(
id: string,
label: string,
@IConfigurationService private readonly configurationService: IConfigurationService
@IWorkbenchLayoutService private readonly layoutService: IWorkbenchLayoutService
) {
super(id, label);
}

run(): Promise<void> {
let currentVisibilityValue = getMenuBarVisibility(this.configurationService);
if (typeof currentVisibilityValue !== 'string') {
currentVisibilityValue = 'default';
}

let newVisibilityValue: string;
if (currentVisibilityValue === 'visible' || currentVisibilityValue === 'default') {
newVisibilityValue = 'toggle';
} else if (currentVisibilityValue === 'compact') {
newVisibilityValue = 'hidden';
} else {
newVisibilityValue = (isWeb && currentVisibilityValue === 'hidden') ? 'compact' : 'default';
}

return this.configurationService.updateValue(ToggleMenuBarAction.menuBarVisibilityKey, newVisibilityValue);
async run(): Promise<void> {
this.layoutService.toggleMenuBar();
}
}

Expand Down
30 changes: 25 additions & 5 deletions src/vs/workbench/browser/layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ enum Storage {

GRID_LAYOUT = 'workbench.grid.layout',
GRID_WIDTH = 'workbench.grid.width',
GRID_HEIGHT = 'workbench.grid.height'
GRID_HEIGHT = 'workbench.grid.height',

MENU_VISIBILITY = 'window.menuBarVisibility'
}

enum Classes {
Expand Down Expand Up @@ -622,7 +624,7 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
return this._openedDefaultEditors;
}

private getInitialFilesToOpen(): { filesToOpenOrCreate?: IPath[], filesToDiff?: IPath[] } | undefined {
private getInitialFilesToOpen(): { filesToOpenOrCreate?: IPath[], filesToDiff?: IPath[]; } | undefined {
const defaultLayout = this.environmentService.options?.defaultLayout;
if (defaultLayout?.editors?.length && this.storageService.isNew(StorageScope.WORKSPACE)) {
this._openedDefaultEditors = true;
Expand Down Expand Up @@ -677,9 +679,9 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
if (this.state.views.defaults?.length) {
mark('code/willOpenDefaultViews');

let locationsRestored: { id: string; order: number }[] = [];
let locationsRestored: { id: string; order: number; }[] = [];

const tryOpenView = (view: { id: string; order: number }): boolean => {
const tryOpenView = (view: { id: string; order: number; }): boolean => {
const location = this.viewDescriptorService.getViewLocationById(view.id);
if (location !== null) {
const container = this.viewDescriptorService.getViewContainerByViewId(view.id);
Expand Down Expand Up @@ -1128,7 +1130,7 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
[Parts.STATUSBAR_PART]: this.statusBarPartView
};

const fromJSON = ({ type }: { type: Parts }) => viewMap[type];
const fromJSON = ({ type }: { type: Parts; }) => viewMap[type];
const workbenchGrid = SerializableGrid.deserialize(
this.createGridDescriptor(),
{ fromJSON },
Expand Down Expand Up @@ -1551,6 +1553,24 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
return this.state.menuBar.visibility;
}

toggleMenuBar(): void {
let currentVisibilityValue = getMenuBarVisibility(this.configurationService);
if (typeof currentVisibilityValue !== 'string') {
currentVisibilityValue = 'default';
}

let newVisibilityValue: string;
if (currentVisibilityValue === 'visible' || currentVisibilityValue === 'default') {
newVisibilityValue = 'toggle';
} else if (currentVisibilityValue === 'compact') {
newVisibilityValue = 'hidden';
} else {
newVisibilityValue = (isWeb && currentVisibilityValue === 'hidden') ? 'compact' : 'default';
}

this.configurationService.updateValue(Storage.MENU_VISIBILITY, newVisibilityValue);
}

getPanelPosition(): Position {
return this.state.panel.position;
}
Expand Down
51 changes: 29 additions & 22 deletions src/vs/workbench/browser/parts/activitybar/activitybarPart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { IBadge, NumberBadge } from 'vs/workbench/services/activity/common/activ
import { IWorkbenchLayoutService, Parts } from 'vs/workbench/services/layout/browser/layoutService';
import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import { IDisposable, toDisposable, DisposableStore, Disposable } from 'vs/base/common/lifecycle';
import { ToggleActivityBarVisibilityAction, ToggleMenuBarAction, ToggleSidebarPositionAction } from 'vs/workbench/browser/actions/layoutActions';
import { ToggleActivityBarVisibilityAction, ToggleSidebarPositionAction } from 'vs/workbench/browser/actions/layoutActions';
import { IThemeService, IColorTheme, ThemeIcon } from 'vs/platform/theme/common/themeService';
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 } from 'vs/workbench/common/theme';
import { contrastBorder } from 'vs/platform/theme/common/colorRegistry';
Expand Down Expand Up @@ -49,7 +49,7 @@ interface IPlaceholderViewContainer {
readonly name?: string;
readonly iconUrl?: UriComponents;
readonly themeIcon?: ThemeIcon;
readonly views?: { when?: string }[];
readonly views?: { when?: string; }[];
}

interface IPinnedViewContainer {
Expand All @@ -66,7 +66,7 @@ interface ICachedViewContainer {
readonly pinned: boolean;
readonly order?: number;
visible: boolean;
views?: { when?: string }[];
views?: { when?: string; }[];
}

const settingsViewBarIcon = registerIcon('settings-view-bar-icon', Codicon.settingsGear, nls.localize('settingsViewBarIcon', 'Settings icon in the view bar.'));
Expand Down Expand Up @@ -110,7 +110,7 @@ export class ActivitybarPart extends Part implements IActivityBarService {

private readonly accountsActivity: ICompositeActivity[] = [];

private readonly compositeActions = new Map<string, { activityAction: ViewContainerActivityAction, pinnedAction: ToggleCompositePinnedAction }>();
private readonly compositeActions = new Map<string, { activityAction: ViewContainerActivityAction, pinnedAction: ToggleCompositePinnedAction; }>();
private readonly viewContainerDisposables = new Map<string, IDisposable>();

private readonly keyboardNavigationDisposables = this._register(new DisposableStore());
Expand Down Expand Up @@ -170,29 +170,36 @@ export class ActivitybarPart extends Part implements IActivityBarService {

// Home
if (this.homeBarContainer) {
actions.push(new Action(
'toggleHomeBarAction',
this.homeBarVisibilityPreference ? nls.localize('hideHomeBar', "Hide Home Button") : nls.localize('showHomeBar', "Show Home Button"),
undefined,
true,
async () => { this.homeBarVisibilityPreference = !this.homeBarVisibilityPreference; }
));
actions.push({
id: 'toggleHomeBarAction',
label: nls.localize('homeButton', "Home Button"),
checked: this.homeBarVisibilityPreference,
enabled: true,
run: () => this.homeBarVisibilityPreference = !this.homeBarVisibilityPreference
});
}

// Menu
const menuBarVisibility = getMenuBarVisibility(this.configurationService);
if (menuBarVisibility === 'compact' || (menuBarVisibility === 'hidden' && isWeb)) {
actions.push(this.instantiationService.createInstance(ToggleMenuBarAction, ToggleMenuBarAction.ID, menuBarVisibility === 'compact' ? nls.localize('hideMenu', "Hide Menu") : nls.localize('showMenu', "Show Menu")));
actions.push({
id: 'toggleMenuVisibility',
label: nls.localize('menu', "Menu"),
checked: menuBarVisibility === 'compact',
enabled: true,
run: () => this.layoutService.toggleMenuBar()
});
}

// Accounts
actions.push(new Action(
'toggleAccountsVisibility',
this.accountsVisibilityPreference ? nls.localize('hideAccounts', "Hide Accounts") : nls.localize('showAccounts', "Show Accounts"),
undefined,
true,
async () => { this.accountsVisibilityPreference = !this.accountsVisibilityPreference; }
));
actions.push({
id: 'toggleAccountsVisibility',
label: nls.localize('accounts', "Accounts"),
checked: this.accountsVisibilityPreference,
enabled: true,
run: () => this.accountsVisibilityPreference = !this.accountsVisibilityPreference
});

actions.push(new Separator());

// Toggle Sidebar
Expand Down Expand Up @@ -278,7 +285,7 @@ export class ActivitybarPart extends Part implements IActivityBarService {
}));
}

private onDidChangeViewContainers(added: ReadonlyArray<{ container: ViewContainer, location: ViewContainerLocation }>, removed: ReadonlyArray<{ container: ViewContainer, location: ViewContainerLocation }>) {
private onDidChangeViewContainers(added: ReadonlyArray<{ container: ViewContainer, location: ViewContainerLocation; }>, removed: ReadonlyArray<{ container: ViewContainer, location: ViewContainerLocation; }>) {
removed.filter(({ location }) => location === ViewContainerLocation.Sidebar).forEach(({ container }) => this.onDidDeregisterViewContainer(container));
this.onDidRegisterViewContainers(added.filter(({ location }) => location === ViewContainerLocation.Sidebar).map(({ container }) => container));
}
Expand Down Expand Up @@ -640,7 +647,7 @@ export class ActivitybarPart extends Part implements IActivityBarService {
this.updateGlobalActivity(ACCOUNTS_ACTIVITY_ID);
}

private getCompositeActions(compositeId: string): { activityAction: ViewContainerActivityAction, pinnedAction: ToggleCompositePinnedAction } {
private getCompositeActions(compositeId: string): { activityAction: ViewContainerActivityAction, pinnedAction: ToggleCompositePinnedAction; } {
let compositeActions = this.compositeActions.get(compositeId);
if (!compositeActions) {
const viewContainer = this.getViewContainer(compositeId);
Expand Down Expand Up @@ -921,7 +928,7 @@ export class ActivitybarPart extends Part implements IActivityBarService {
const viewContainer = this.getViewContainer(compositeItem.id);
if (viewContainer) {
const viewContainerModel = this.viewDescriptorService.getViewContainerModel(viewContainer);
const views: { when: string | undefined }[] = [];
const views: { when: string | undefined; }[] = [];
for (const { when } of viewContainerModel.allViewDescriptors) {
views.push({ when: when ? when.serialize() : undefined });
}
Expand Down
9 changes: 7 additions & 2 deletions src/vs/workbench/services/layout/browser/layoutService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function positionToString(position: Position): string {
}
}

const positionsByString: { [key: string]: Position } = {
const positionsByString: { [key: string]: Position; } = {
[positionToString(Position.LEFT)]: Position.LEFT,
[positionToString(Position.RIGHT)]: Position.RIGHT,
[positionToString(Position.BOTTOM)]: Position.BOTTOM
Expand All @@ -62,7 +62,7 @@ export function panelOpensMaximizedSettingToString(setting: PanelOpensMaximizedO
}
}

const panelOpensMaximizedByString: { [key: string]: PanelOpensMaximizedOptions } = {
const panelOpensMaximizedByString: { [key: string]: PanelOpensMaximizedOptions; } = {
[panelOpensMaximizedSettingToString(PanelOpensMaximizedOptions.ALWAYS)]: PanelOpensMaximizedOptions.ALWAYS,
[panelOpensMaximizedSettingToString(PanelOpensMaximizedOptions.NEVER)]: PanelOpensMaximizedOptions.NEVER,
[panelOpensMaximizedSettingToString(PanelOpensMaximizedOptions.REMEMBER_LAST)]: PanelOpensMaximizedOptions.REMEMBER_LAST
Expand Down Expand Up @@ -194,6 +194,11 @@ export interface IWorkbenchLayoutService extends ILayoutService {
*/
getMenubarVisibility(): MenuBarVisibility;

/**
* Toggles the menu bar visibility.
*/
toggleMenuBar(): void;

/**
* Gets the current panel position. Note that the panel can be hidden too.
*/
Expand Down
19 changes: 10 additions & 9 deletions src/vs/workbench/test/browser/workbenchTestServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export interface ITestInstantiationService extends IInstantiationService {

export function workbenchInstantiationService(
overrides?: {
textFileService?: (instantiationService: IInstantiationService) => ITextFileService
textFileService?: (instantiationService: IInstantiationService) => ITextFileService;
pathService?: (instantiationService: IInstantiationService) => IPathService,
editorService?: (instantiationService: IInstantiationService) => IEditorService,
contextKeyService?: (instantiationService: IInstantiationService) => IContextKeyService,
Expand Down Expand Up @@ -456,6 +456,7 @@ export class TestLayoutService implements IWorkbenchLayoutService {
toggleMaximizedPanel(): void { }
isPanelMaximized(): boolean { return false; }
getMenubarVisibility(): MenuBarVisibility { throw new Error('not implemented'); }
toggleMenuBar(): void { }
getSideBarPosition() { return 0; }
getPanelPosition() { return 0; }
async setPanelPosition(_position: PartPosition): Promise<void> { }
Expand Down Expand Up @@ -504,7 +505,7 @@ export class TestViewletService implements IViewletService {
export class TestPanelService implements IPanelService {
declare readonly _serviceBrand: undefined;

onDidPanelOpen = new Emitter<{ panel: IPanel, focus: boolean }>().event;
onDidPanelOpen = new Emitter<{ panel: IPanel, focus: boolean; }>().event;
onDidPanelClose = new Emitter<IPanel>().event;

async openPanel(id?: string, focus?: boolean): Promise<undefined> { return undefined; }
Expand All @@ -524,7 +525,7 @@ export class TestViewsService implements IViewsService {
declare readonly _serviceBrand: undefined;


onDidChangeViewContainerVisibility = new Emitter<{ id: string; visible: boolean; location: ViewContainerLocation }>().event;
onDidChangeViewContainerVisibility = new Emitter<{ id: string; visible: boolean; location: ViewContainerLocation; }>().event;
isViewContainerVisible(id: string): boolean { return true; }
getVisibleViewContainer(): ViewContainer | null { return null; }
openViewContainer(id: string, focus?: boolean): Promise<IPaneComposite | null> { return Promise.resolve(null); }
Expand Down Expand Up @@ -570,8 +571,8 @@ export class TestEditorGroupsService implements IEditorGroupsService {
findGroup(_scope: IFindGroupScope, _source?: number | IEditorGroup, _wrap?: boolean): IEditorGroup { throw new Error('not implemented'); }
activateGroup(_group: number | IEditorGroup): IEditorGroup { throw new Error('not implemented'); }
restoreGroup(_group: number | IEditorGroup): IEditorGroup { throw new Error('not implemented'); }
getSize(_group: number | IEditorGroup): { width: number, height: number } { return { width: 100, height: 100 }; }
setSize(_group: number | IEditorGroup, _size: { width: number, height: number }): void { }
getSize(_group: number | IEditorGroup): { width: number, height: number; } { return { width: 100, height: 100 }; }
setSize(_group: number | IEditorGroup, _size: { width: number, height: number; }): void { }
arrangeGroups(_arrangement: GroupsArrangement): void { }
applyLayout(_layout: EditorGroupLayout): void { }
setGroupOrientation(_orientation: GroupOrientation): void { }
Expand Down Expand Up @@ -729,7 +730,7 @@ export class TestEditorService implements EditorServiceImpl {
saveAll(options?: ISaveEditorsOptions): Promise<boolean> { throw new Error('Method not implemented.'); }
revert(editors: IEditorIdentifier[], options?: IRevertOptions): Promise<boolean> { throw new Error('Method not implemented.'); }
revertAll(options?: IRevertAllEditorsOptions): Promise<boolean> { throw new Error('Method not implemented.'); }
whenClosed(editors: IResourceEditorInput[], options?: { waitForSaved: boolean }): Promise<void> { throw new Error('Method not implemented.'); }
whenClosed(editors: IResourceEditorInput[], options?: { waitForSaved: boolean; }): Promise<void> { throw new Error('Method not implemented.'); }
}

export class TestFileService implements IFileService {
Expand Down Expand Up @@ -769,7 +770,7 @@ export class TestFileService implements IFileService {
});
}

async resolveAll(toResolve: { resource: URI, options?: IResolveFileOptions }[]): Promise<IResolveFileResult[]> {
async resolveAll(toResolve: { resource: URI, options?: IResolveFileOptions; }[]): Promise<IResolveFileResult[]> {
const stats = await Promise.all(toResolve.map(resourceAndOption => this.resolve(resourceAndOption.resource, resourceAndOption.options)));

return stats.map(stat => ({ stat, success: true }));
Expand Down Expand Up @@ -873,7 +874,7 @@ export class TestFileService implements IFileService {
return false;
}

async del(_resource: URI, _options?: { useTrash?: boolean, recursive?: boolean }): Promise<void> { }
async del(_resource: URI, _options?: { useTrash?: boolean, recursive?: boolean; }): Promise<void> { }

readonly watches: URI[] = [];
watch(_resource: URI): IDisposable {
Expand Down Expand Up @@ -1056,7 +1057,7 @@ export class TestHostService implements IHostService {
async reload(): Promise<void> { }
async close(): Promise<void> { }

async focus(options?: { force: boolean }): Promise<void> { }
async focus(options?: { force: boolean; }): Promise<void> { }

async openWindow(arg1?: IOpenEmptyWindowOptions | IWindowOpenable[], arg2?: IOpenWindowOptions): Promise<void> { }

Expand Down

0 comments on commit d61eb64

Please sign in to comment.