-
-
Notifications
You must be signed in to change notification settings - Fork 438
/
Copy pathsidebar-bottom-menu-widget.tsx
91 lines (86 loc) · 2.86 KB
/
sidebar-bottom-menu-widget.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import { SidebarBottomMenuWidget as TheiaSidebarBottomMenuWidget } from '@theia/core/lib/browser/shell/sidebar-bottom-menu-widget';
import type { SidebarMenu } from '@theia/core/lib/browser/shell/sidebar-menu-widget';
import type { MenuPath } from '@theia/core/lib/common/menu';
import { nls } from '@theia/core/lib/common/nls';
import {
inject,
injectable,
postConstruct,
} from '@theia/core/shared/inversify';
import React from '@theia/core/shared/react';
import { accountMenu } from '../../contributions/account';
import { CreateFeatures } from '../../create/create-features';
import { ApplicationConnectionStatusContribution } from './connection-status-service';
@injectable()
export class SidebarBottomMenuWidget extends TheiaSidebarBottomMenuWidget {
@inject(CreateFeatures)
private readonly createFeatures: CreateFeatures;
@inject(ApplicationConnectionStatusContribution)
private readonly connectionStatue: ApplicationConnectionStatusContribution;
@postConstruct()
protected init(): void {
this.toDispose.pushAll([
this.createFeatures.onDidChangeSession(() => this.update()),
this.connectionStatue.onOfflineStatusDidChange(() => this.update()),
]);
}
protected override onClick(
e: React.MouseEvent<HTMLElement, MouseEvent>,
menuPath: MenuPath
): void {
const button = e.currentTarget.getBoundingClientRect();
const options = {
menuPath,
includeAnchorArg: false,
anchor: {
x: button.left + button.width,
// Bogus y coordinate?
// https://github.com/eclipse-theia/theia/discussions/12170
y: button.top,
},
showDisabled: true,
};
this.contextMenuRenderer.render(options);
}
protected override render(): React.ReactNode {
return (
<React.Fragment>
{this.menus.map((menu) => this.renderMenu(menu))}
</React.Fragment>
);
}
private renderMenu(menu: SidebarMenu): React.ReactNode {
// Removes the _Settings_ (cog) icon from the left sidebar
if (menu.id === 'settings-menu') {
return undefined;
}
const arduinoAccount = menu.id === accountMenu.id;
const picture =
arduinoAccount &&
this.connectionStatue.offlineStatus !== 'internet' &&
this.createFeatures.session?.account.picture;
const className = typeof picture === 'string' ? undefined : menu.iconClass;
return (
<i
key={menu.id}
className={className}
title={menu.title}
onClick={(e) => this.onClick(e, menu.menuPath)}
onMouseDown={this.onMouseDown}
onMouseOut={this.onMouseOut}
>
{picture && (
<div className="account-icon">
<img
src={picture}
alt={nls.localize(
'arduino/cloud/profilePicture',
'Profile picture'
)}
/>
</div>
)}
</i>
);
}
}