Skip to content

Commit

Permalink
Do not show the accounts icon without registered authentication provi…
Browse files Browse the repository at this point in the history
…ders
  • Loading branch information
vinokurig committed Sep 4, 2020
1 parent d5ab07b commit 61a76ca
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
14 changes: 13 additions & 1 deletion packages/core/src/browser/common-frontend-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import { ClipboardService } from './clipboard-service';
import { EncodingRegistry } from './encoding-registry';
import { UTF8 } from '../common/encodings';
import { EnvVariablesServer } from '../common/env-variables';
import { AuthenticationService } from './authentication-service';

export namespace CommonMenus {

Expand Down Expand Up @@ -327,6 +328,9 @@ export class CommonFrontendContribution implements FrontendApplicationContributi
@inject(EnvVariablesServer)
protected readonly environments: EnvVariablesServer;

@inject(AuthenticationService)
protected readonly authenticationService: AuthenticationService;

async configure(app: FrontendApplication): Promise<void> {
const configDirUri = await this.environments.getConfigDirUri();
// Global settings
Expand Down Expand Up @@ -362,12 +366,20 @@ export class CommonFrontendContribution implements FrontendApplicationContributi
menuPath: SETTINGS_MENU,
order: 0,
});
app.shell.leftPanelHandler.addMenu({
const accountsMenu = {
id: 'accounts-menu',
iconClass: 'codicon codicon-person',
title: 'Accounts',
menuPath: ACCOUNTS_MENU,
order: 1,
};
this.authenticationService.onDidRegisterAuthenticationProvider(() => {
app.shell.leftPanelHandler.addMenu(accountsMenu);
});
this.authenticationService.onDidUnregisterAuthenticationProvider(() => {
if (this.authenticationService.getProviderIds().length === 0) {
app.shell.leftPanelHandler.removeMenu(accountsMenu.id);
}
});
}

Expand Down
9 changes: 9 additions & 0 deletions packages/core/src/browser/shell/side-panel-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,15 @@ export class SidePanelHandler {
this.bottomMenu.addMenu(menu);
}

/**
* Remove a menu from the sidebar bottom.
*
* @param menuId id of the menu to remove
*/
removeMenu(menuId: string): void {
this.bottomMenu.removeMenu(menuId);
}

// should be a property to preserve fn identity
protected updateToolbarTitle = (): void => {
const currentTitle = this.tabBar && this.tabBar.currentTitle;
Expand Down
11 changes: 11 additions & 0 deletions packages/core/src/browser/shell/sidebar-bottom-menu-widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,17 @@ export class SidebarBottomMenuWidget extends ReactWidget {
this.update();
}

removeMenu(menuId: string): void {
const menu = this.menus.find(m => m.id === menuId);
if (menu) {
const index = this.menus.indexOf(menu);
if (index !== -1) {
this.menus.splice(index, 1);
}
this.update();
}
}

protected onClick(e: React.MouseEvent<HTMLElement, MouseEvent>, menuPath: MenuPath): void {
this.contextMenuRenderer.render({
menuPath,
Expand Down

0 comments on commit 61a76ca

Please sign in to comment.