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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
|
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import 'vs/css!./media/activityaction';
import { localize } from 'vs/nls';
import { EventType, addDisposableListener, EventHelper } from 'vs/base/browser/dom';
import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent';
import { EventType as TouchEventType, GestureEvent } from 'vs/base/browser/touch';
import { Action, IAction, Separator, SubmenuAction, toAction } from 'vs/base/common/actions';
import { KeyCode } from 'vs/base/common/keyCodes';
import { DisposableStore } from 'vs/base/common/lifecycle';
import { IMenuService, MenuId, IMenu, registerAction2, Action2, IAction2Options } from 'vs/platform/actions/common/actions';
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { activeContrastBorder, focusBorder } from 'vs/platform/theme/common/colorRegistry';
import { IColorTheme, IThemeService, registerThemingParticipant } from 'vs/platform/theme/common/themeService';
import { ActivityAction, ActivityActionViewItem, IActivityHoverOptions, ICompositeBar, ICompositeBarColors, ToggleCompositePinnedAction } from 'vs/workbench/browser/parts/compositeBarActions';
import { CATEGORIES } from 'vs/workbench/common/actions';
import { IActivity } from 'vs/workbench/common/activity';
import { ACTIVITY_BAR_FOREGROUND, ACTIVITY_BAR_ACTIVE_BORDER, ACTIVITY_BAR_ACTIVE_FOCUS_BORDER, ACTIVITY_BAR_ACTIVE_BACKGROUND } from 'vs/workbench/common/theme';
import { IWorkbenchLayoutService, Parts } from 'vs/workbench/services/layout/browser/layoutService';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { createAndFillInActionBarActions } from 'vs/platform/actions/browser/menuEntryActionViewItem';
import { isMacintosh, isWeb } from 'vs/base/common/platform';
import { getCurrentAuthenticationSessionInfo } from 'vs/workbench/services/authentication/browser/authenticationService';
import { AuthenticationSession, IAuthenticationService } from 'vs/workbench/services/authentication/common/authentication';
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IProductService } from 'vs/platform/product/common/productService';
import { AnchorAlignment, AnchorAxisAlignment } from 'vs/base/browser/ui/contextview/contextview';
import { getTitleBarStyle } from 'vs/platform/window/common/window';
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import { IStorageService, StorageScope, StorageTarget } from 'vs/platform/storage/common/storage';
import { IHoverService } from 'vs/workbench/services/hover/browser/hover';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { IPaneCompositePartService } from 'vs/workbench/services/panecomposite/browser/panecomposite';
import { ViewContainerLocation } from 'vs/workbench/common/views';
import { IPaneCompositePart } from 'vs/workbench/browser/parts/paneCompositePart';
import { ICredentialsService } from 'vs/platform/credentials/common/credentials';
export class ViewContainerActivityAction extends ActivityAction {
private static readonly preventDoubleClickDelay = 300;
private lastRun = 0;
constructor(
activity: IActivity,
private readonly paneCompositePart: IPaneCompositePart,
@IWorkbenchLayoutService private readonly layoutService: IWorkbenchLayoutService,
@ITelemetryService private readonly telemetryService: ITelemetryService,
@IConfigurationService private readonly configurationService: IConfigurationService
) {
super(activity);
}
updateActivity(activity: IActivity): void {
this.activity = activity;
}
override async run(event: { preserveFocus: boolean }): Promise<void> {
if (event instanceof MouseEvent && event.button === 2) {
return; // do not run on right click
}
// prevent accident trigger on a doubleclick (to help nervous people)
const now = Date.now();
if (now > this.lastRun /* https://github.com/microsoft/vscode/issues/25830 */ && now - this.lastRun < ViewContainerActivityAction.preventDoubleClickDelay) {
return;
}
this.lastRun = now;
const sideBarVisible = this.layoutService.isVisible(Parts.SIDEBAR_PART);
const activeViewlet = this.paneCompositePart.getActivePaneComposite();
const focusBehavior = this.configurationService.getValue<string>('workbench.activityBar.iconClickBehavior');
const focus = (event && 'preserveFocus' in event) ? !event.preserveFocus : true;
if (sideBarVisible && activeViewlet?.getId() === this.activity.id) {
switch (focusBehavior) {
case 'focus':
this.logAction('refocus');
this.paneCompositePart.openPaneComposite(this.activity.id, focus);
break;
case 'toggle':
default:
// Hide sidebar if selected viewlet already visible
this.logAction('hide');
this.layoutService.setPartHidden(true, Parts.SIDEBAR_PART);
break;
}
return;
}
this.logAction('show');
await this.paneCompositePart.openPaneComposite(this.activity.id, focus);
return this.activate();
}
private logAction(action: string) {
type ActivityBarActionClassification = {
owner: 'sbatten';
viewletId: { classification: 'SystemMetaData'; purpose: 'FeatureInsight' };
action: { classification: 'SystemMetaData'; purpose: 'FeatureInsight' };
};
this.telemetryService.publicLog2<{ viewletId: String; action: String }, ActivityBarActionClassification>('activityBarAction', { viewletId: this.activity.id, action });
}
}
class MenuActivityActionViewItem extends ActivityActionViewItem {
constructor(
private readonly menuId: MenuId,
action: ActivityAction,
private contextMenuActionsProvider: () => IAction[],
colors: (theme: IColorTheme) => ICompositeBarColors,
hoverOptions: IActivityHoverOptions,
@IThemeService themeService: IThemeService,
@IHoverService hoverService: IHoverService,
@IMenuService protected readonly menuService: IMenuService,
@IContextMenuService protected readonly contextMenuService: IContextMenuService,
@IContextKeyService protected readonly contextKeyService: IContextKeyService,
@IConfigurationService configurationService: IConfigurationService,
@IWorkbenchEnvironmentService protected readonly environmentService: IWorkbenchEnvironmentService,
@IKeybindingService keybindingService: IKeybindingService,
) {
super(action, { draggable: false, colors, icon: true, hasPopup: true, hoverOptions }, themeService, hoverService, configurationService, keybindingService);
}
override render(container: HTMLElement): void {
super.render(container);
// Context menus are triggered on mouse down so that an item can be picked
// and executed with releasing the mouse over it
this._register(addDisposableListener(this.container, EventType.MOUSE_DOWN, (e: MouseEvent) => {
EventHelper.stop(e, true);
this.showContextMenu(e);
}));
this._register(addDisposableListener(this.container, EventType.KEY_UP, (e: KeyboardEvent) => {
const event = new StandardKeyboardEvent(e);
if (event.equals(KeyCode.Enter) || event.equals(KeyCode.Space)) {
EventHelper.stop(e, true);
this.showContextMenu();
}
}));
this._register(addDisposableListener(this.container, TouchEventType.Tap, (e: GestureEvent) => {
EventHelper.stop(e, true);
this.showContextMenu();
}));
}
private async showContextMenu(e?: MouseEvent): Promise<void> {
const disposables = new DisposableStore();
let actions: IAction[];
if (e?.button !== 2) {
const menu = disposables.add(this.menuService.createMenu(this.menuId, this.contextKeyService));
actions = await this.resolveMainMenuActions(menu, disposables);
} else {
actions = await this.resolveContextMenuActions(disposables);
}
const isUsingCustomMenu = isWeb || (getTitleBarStyle(this.configurationService) !== 'native' && !isMacintosh); // see #40262
const position = this.configurationService.getValue('workbench.sideBar.location');
this.contextMenuService.showContextMenu({
getAnchor: () => isUsingCustomMenu ? this.container : e || this.container,
anchorAlignment: isUsingCustomMenu ? (position === 'left' ? AnchorAlignment.RIGHT : AnchorAlignment.LEFT) : undefined,
anchorAxisAlignment: isUsingCustomMenu ? AnchorAxisAlignment.HORIZONTAL : AnchorAxisAlignment.VERTICAL,
getActions: () => actions,
onHide: () => disposables.dispose()
});
}
protected async resolveMainMenuActions(menu: IMenu, disposables: DisposableStore): Promise<IAction[]> {
const actions: IAction[] = [];
disposables.add(createAndFillInActionBarActions(menu, undefined, { primary: [], secondary: actions }));
return actions;
}
protected async resolveContextMenuActions(disposables: DisposableStore): Promise<IAction[]> {
return this.contextMenuActionsProvider();
}
}
export class AccountsActivityActionViewItem extends MenuActivityActionViewItem {
static readonly ACCOUNTS_VISIBILITY_PREFERENCE_KEY = 'workbench.activity.showAccounts';
constructor(
action: ActivityAction,
contextMenuActionsProvider: () => IAction[],
colors: (theme: IColorTheme) => ICompositeBarColors,
activityHoverOptions: IActivityHoverOptions,
@IThemeService themeService: IThemeService,
@IHoverService hoverService: IHoverService,
@IContextMenuService contextMenuService: IContextMenuService,
@IMenuService menuService: IMenuService,
@IContextKeyService contextKeyService: IContextKeyService,
@IAuthenticationService private readonly authenticationService: IAuthenticationService,
@IWorkbenchEnvironmentService environmentService: IWorkbenchEnvironmentService,
@IProductService private readonly productService: IProductService,
@IConfigurationService configurationService: IConfigurationService,
@IStorageService private readonly storageService: IStorageService,
@IKeybindingService keybindingService: IKeybindingService,
@ICredentialsService private readonly credentialsService: ICredentialsService,
) {
super(MenuId.AccountsContext, action, contextMenuActionsProvider, colors, activityHoverOptions, themeService, hoverService, menuService, contextMenuService, contextKeyService, configurationService, environmentService, keybindingService);
}
protected override async resolveMainMenuActions(accountsMenu: IMenu, disposables: DisposableStore): Promise<IAction[]> {
await super.resolveMainMenuActions(accountsMenu, disposables);
const otherCommands = accountsMenu.getActions();
const providers = this.authenticationService.getProviderIds();
const allSessions = providers.map(async providerId => {
try {
const sessions = await this.authenticationService.getSessions(providerId);
const groupedSessions: { [label: string]: AuthenticationSession[] } = {};
sessions.forEach(session => {
if (groupedSessions[session.account.label]) {
groupedSessions[session.account.label].push(session);
} else {
groupedSessions[session.account.label] = [session];
}
});
return { providerId, sessions: groupedSessions };
} catch {
return { providerId };
}
});
const result = await Promise.all(allSessions);
let menus: IAction[] = [];
const authenticationSession = await getCurrentAuthenticationSessionInfo(this.credentialsService, this.productService);
result.forEach(sessionInfo => {
const providerDisplayName = this.authenticationService.getLabel(sessionInfo.providerId);
if (sessionInfo.sessions) {
Object.keys(sessionInfo.sessions).forEach(accountName => {
const manageExtensionsAction = disposables.add(new Action(`configureSessions${accountName}`, localize('manageTrustedExtensions', "Manage Trusted Extensions"), '', true, () => {
return this.authenticationService.manageTrustedExtensionsForAccount(sessionInfo.providerId, accountName);
}));
const signOutAction = disposables.add(new Action('signOut', localize('signOut', "Sign Out"), '', true, () => {
return this.authenticationService.removeAccountSessions(sessionInfo.providerId, accountName, sessionInfo.sessions[accountName]);
}));
const providerSubMenuActions = [manageExtensionsAction];
const hasEmbedderAccountSession = sessionInfo.sessions[accountName].some(session => session.id === (authenticationSession?.id));
if (!hasEmbedderAccountSession || authenticationSession?.canSignOut) {
providerSubMenuActions.push(signOutAction);
}
const providerSubMenu = disposables.add(new SubmenuAction('activitybar.submenu', `${accountName} (${providerDisplayName})`, providerSubMenuActions));
menus.push(providerSubMenu);
});
} else {
const providerUnavailableAction = disposables.add(new Action('providerUnavailable', localize('authProviderUnavailable', '{0} is currently unavailable', providerDisplayName)));
menus.push(providerUnavailableAction);
}
});
if (providers.length && !menus.length) {
const noAccountsAvailableAction = disposables.add(new Action('noAccountsAvailable', localize('noAccounts', "You are not signed in to any accounts"), undefined, false));
menus.push(noAccountsAvailableAction);
}
if (menus.length && otherCommands.length) {
menus.push(disposables.add(new Separator()));
}
otherCommands.forEach((group, i) => {
const actions = group[1];
menus = menus.concat(actions);
if (i !== otherCommands.length - 1) {
menus.push(disposables.add(new Separator()));
}
});
return menus;
}
protected override async resolveContextMenuActions(disposables: DisposableStore): Promise<IAction[]> {
const actions = await super.resolveContextMenuActions(disposables);
actions.unshift(...[
toAction({ id: 'hideAccounts', label: localize('hideAccounts', "Hide Accounts"), run: () => this.storageService.store(AccountsActivityActionViewItem.ACCOUNTS_VISIBILITY_PREFERENCE_KEY, false, StorageScope.PROFILE, StorageTarget.USER) }),
new Separator()
]);
return actions;
}
}
export class GlobalActivityActionViewItem extends MenuActivityActionViewItem {
constructor(
action: ActivityAction,
contextMenuActionsProvider: () => IAction[],
colors: (theme: IColorTheme) => ICompositeBarColors,
activityHoverOptions: IActivityHoverOptions,
@IThemeService themeService: IThemeService,
@IHoverService hoverService: IHoverService,
@IMenuService menuService: IMenuService,
@IContextMenuService contextMenuService: IContextMenuService,
@IContextKeyService contextKeyService: IContextKeyService,
@IConfigurationService configurationService: IConfigurationService,
@IWorkbenchEnvironmentService environmentService: IWorkbenchEnvironmentService,
@IKeybindingService keybindingService: IKeybindingService,
) {
super(MenuId.GlobalActivity, action, contextMenuActionsProvider, colors, activityHoverOptions, themeService, hoverService, menuService, contextMenuService, contextKeyService, configurationService, environmentService, keybindingService);
}
}
export class PlaceHolderViewContainerActivityAction extends ViewContainerActivityAction { }
export class PlaceHolderToggleCompositePinnedAction extends ToggleCompositePinnedAction {
constructor(id: string, compositeBar: ICompositeBar) {
super({ id, name: id, cssClass: undefined }, compositeBar);
}
setActivity(activity: IActivity): void {
this.label = activity.name;
}
}
class SwitchSideBarViewAction extends Action2 {
constructor(
desc: Readonly<IAction2Options>,
private readonly offset: number
) {
super(desc);
}
async run(accessor: ServicesAccessor): Promise<void> {
const paneCompositeService = accessor.get(IPaneCompositePartService);
const visibleViewletIds = paneCompositeService.getVisiblePaneCompositeIds(ViewContainerLocation.Sidebar);
const activeViewlet = paneCompositeService.getActivePaneComposite(ViewContainerLocation.Sidebar);
if (!activeViewlet) {
return;
}
let targetViewletId: string | undefined;
for (let i = 0; i < visibleViewletIds.length; i++) {
if (visibleViewletIds[i] === activeViewlet.getId()) {
targetViewletId = visibleViewletIds[(i + visibleViewletIds.length + this.offset) % visibleViewletIds.length];
break;
}
}
await paneCompositeService.openPaneComposite(targetViewletId, ViewContainerLocation.Sidebar, true);
}
}
registerAction2(
class PreviousSideBarViewAction extends SwitchSideBarViewAction {
constructor() {
super({
id: 'workbench.action.previousSideBarView',
title: { value: localize('previousSideBarView', "Previous Primary Side Bar View"), original: 'Previous Primary Side Bar View' },
category: CATEGORIES.View,
f1: true
}, -1);
}
}
);
registerAction2(
class NextSideBarViewAction extends SwitchSideBarViewAction {
constructor() {
super({
id: 'workbench.action.nextSideBarView',
title: { value: localize('nextSideBarView', "Next Primary Side Bar View"), original: 'Next Primary Side Bar View' },
category: CATEGORIES.View,
f1: true
}, 1);
}
}
);
registerAction2(
class FocusActivityBarAction extends Action2 {
constructor() {
super({
id: 'workbench.action.focusActivityBar',
title: { value: localize('focusActivityBar', "Focus Activity Bar"), original: 'Focus Activity Bar' },
category: CATEGORIES.View,
f1: true
});
}
async run(accessor: ServicesAccessor): Promise<void> {
const layoutService = accessor.get(IWorkbenchLayoutService);
layoutService.setPartHidden(false, Parts.ACTIVITYBAR_PART);
layoutService.focusPart(Parts.ACTIVITYBAR_PART);
}
});
registerThemingParticipant((theme, collector) => {
const activityBarForegroundColor = theme.getColor(ACTIVITY_BAR_FOREGROUND);
if (activityBarForegroundColor) {
collector.addRule(`
.monaco-workbench .activitybar > .content :not(.monaco-menu) > .monaco-action-bar .action-item.active .action-label:not(.codicon),
.monaco-workbench .activitybar > .content :not(.monaco-menu) > .monaco-action-bar .action-item:focus .action-label:not(.codicon),
.monaco-workbench .activitybar > .content :not(.monaco-menu) > .monaco-action-bar .action-item:hover .action-label:not(.codicon) {
background-color: ${activityBarForegroundColor} !important;
}
.monaco-workbench .activitybar > .content :not(.monaco-menu) > .monaco-action-bar .action-item.active .action-label.codicon,
.monaco-workbench .activitybar > .content :not(.monaco-menu) > .monaco-action-bar .action-item:focus .action-label.codicon,
.monaco-workbench .activitybar > .content :not(.monaco-menu) > .monaco-action-bar .action-item:hover .action-label.codicon {
color: ${activityBarForegroundColor} !important;
}
`);
}
const activityBarActiveBorderColor = theme.getColor(ACTIVITY_BAR_ACTIVE_BORDER);
if (activityBarActiveBorderColor) {
collector.addRule(`
.monaco-workbench .activitybar > .content :not(.monaco-menu) > .monaco-action-bar .action-item.checked .active-item-indicator:before {
border-left-color: ${activityBarActiveBorderColor};
}
`);
}
const activityBarActiveFocusBorderColor = theme.getColor(ACTIVITY_BAR_ACTIVE_FOCUS_BORDER);
if (activityBarActiveFocusBorderColor) {
collector.addRule(`
.monaco-workbench .activitybar > .content :not(.monaco-menu) > .monaco-action-bar .action-item.checked:focus::before {
visibility: hidden;
}
.monaco-workbench .activitybar > .content :not(.monaco-menu) > .monaco-action-bar .action-item.checked:focus .active-item-indicator:before {
visibility: visible;
border-left-color: ${activityBarActiveFocusBorderColor};
}
`);
}
const activityBarActiveBackgroundColor = theme.getColor(ACTIVITY_BAR_ACTIVE_BACKGROUND);
if (activityBarActiveBackgroundColor) {
collector.addRule(`
.monaco-workbench .activitybar > .content :not(.monaco-menu) > .monaco-action-bar .action-item.checked .active-item-indicator {
z-index: 0;
background-color: ${activityBarActiveBackgroundColor};
}
`);
}
// Styling with Outline color (e.g. high contrast theme)
const outline = theme.getColor(activeContrastBorder);
if (outline) {
collector.addRule(`
.monaco-workbench .activitybar > .content :not(.monaco-menu) > .monaco-action-bar .action-item:before {
content: "";
position: absolute;
top: 8px;
left: 8px;
height: 32px;
width: 32px;
z-index: 1;
}
.monaco-workbench .activitybar > .content :not(.monaco-menu) > .monaco-action-bar .action-item.active:before,
.monaco-workbench .activitybar > .content :not(.monaco-menu) > .monaco-action-bar .action-item.active:hover:before,
.monaco-workbench .activitybar > .content :not(.monaco-menu) > .monaco-action-bar .action-item.checked:before,
.monaco-workbench .activitybar > .content :not(.monaco-menu) > .monaco-action-bar .action-item.checked:hover:before {
outline: 1px solid;
}
.monaco-workbench .activitybar > .content :not(.monaco-menu) > .monaco-action-bar .action-item:hover:before {
outline: 1px dashed;
}
.monaco-workbench .activitybar > .content :not(.monaco-menu) > .monaco-action-bar .action-item:focus .active-item-indicator:before {
border-left-color: ${outline};
}
.monaco-workbench .activitybar > .content :not(.monaco-menu) > .monaco-action-bar .action-item.active:before,
.monaco-workbench .activitybar > .content :not(.monaco-menu) > .monaco-action-bar .action-item.active:hover:before,
.monaco-workbench .activitybar > .content :not(.monaco-menu) > .monaco-action-bar .action-item.checked:before,
.monaco-workbench .activitybar > .content :not(.monaco-menu) > .monaco-action-bar .action-item.checked:hover:before,
.monaco-workbench .activitybar > .content :not(.monaco-menu) > .monaco-action-bar .action-item:hover:before {
outline-color: ${outline};
}
`);
}
// Styling without outline color
else {
const focusBorderColor = theme.getColor(focusBorder);
if (focusBorderColor) {
collector.addRule(`
.monaco-workbench .activitybar > .content :not(.monaco-menu) > .monaco-action-bar .action-item:focus .active-item-indicator:before {
border-left-color: ${focusBorderColor};
}
`);
}
}
});
|