-
Notifications
You must be signed in to change notification settings - Fork 29.8k
/
panelActions.ts
475 lines (416 loc) · 17.3 KB
/
panelActions.ts
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
/*---------------------------------------------------------------------------------------------
* 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/panelpart';
import { localize, localize2 } from 'vs/nls';
import { KeyMod, KeyCode } from 'vs/base/common/keyCodes';
import { MenuId, MenuRegistry, registerAction2, Action2, IAction2Options } from 'vs/platform/actions/common/actions';
import { Categories } from 'vs/platform/action/common/actionCommonCategories';
import { ActivityBarPosition, isHorizontal, IWorkbenchLayoutService, LayoutSettings, PanelAlignment, Parts, Position, positionToString } from 'vs/workbench/services/layout/browser/layoutService';
import { AuxiliaryBarVisibleContext, PanelAlignmentContext, PanelMaximizedContext, PanelPositionContext, PanelVisibleContext } from 'vs/workbench/common/contextkeys';
import { ContextKeyExpr, ContextKeyExpression } from 'vs/platform/contextkey/common/contextkey';
import { Codicon } from 'vs/base/common/codicons';
import { registerIcon } from 'vs/platform/theme/common/iconRegistry';
import { ServicesAccessor } from 'vs/editor/browser/editorExtensions';
import { ViewContainerLocationToString, ViewContainerLocation, IViewDescriptorService } from 'vs/workbench/common/views';
import { IViewsService } from 'vs/workbench/services/views/common/viewsService';
import { IPaneCompositePartService } from 'vs/workbench/services/panecomposite/browser/panecomposite';
import { INotificationService } from 'vs/platform/notification/common/notification';
import { ICommandActionTitle } from 'vs/platform/action/common/action';
import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
const maximizeIcon = registerIcon('panel-maximize', Codicon.chevronUp, localize('maximizeIcon', 'Icon to maximize a panel.'));
const restoreIcon = registerIcon('panel-restore', Codicon.chevronDown, localize('restoreIcon', 'Icon to restore a panel.'));
const closeIcon = registerIcon('panel-close', Codicon.close, localize('closeIcon', 'Icon to close a panel.'));
const panelIcon = registerIcon('panel-layout-icon', Codicon.layoutPanel, localize('togglePanelOffIcon', 'Icon to toggle the panel off when it is on.'));
const panelOffIcon = registerIcon('panel-layout-icon-off', Codicon.layoutPanelOff, localize('togglePanelOnIcon', 'Icon to toggle the panel on when it is off.'));
export class TogglePanelAction extends Action2 {
static readonly ID = 'workbench.action.togglePanel';
static readonly LABEL = localize2('togglePanelVisibility', "Toggle Panel Visibility");
constructor() {
super({
id: TogglePanelAction.ID,
title: TogglePanelAction.LABEL,
toggled: {
condition: PanelVisibleContext,
title: localize('toggle panel', "Panel"),
mnemonicTitle: localize({ key: 'toggle panel mnemonic', comment: ['&& denotes a mnemonic'] }, "&&Panel"),
},
f1: true,
category: Categories.View,
keybinding: { primary: KeyMod.CtrlCmd | KeyCode.KeyJ, weight: KeybindingWeight.WorkbenchContrib },
menu: [
{
id: MenuId.MenubarAppearanceMenu,
group: '2_workbench_layout',
order: 5
}, {
id: MenuId.LayoutControlMenuSubmenu,
group: '0_workbench_layout',
order: 4
},
]
});
}
override async run(accessor: ServicesAccessor): Promise<void> {
const layoutService = accessor.get(IWorkbenchLayoutService);
layoutService.setPartHidden(layoutService.isVisible(Parts.PANEL_PART), Parts.PANEL_PART);
}
}
registerAction2(TogglePanelAction);
registerAction2(class extends Action2 {
static readonly ID = 'workbench.action.focusPanel';
static readonly LABEL = localize('focusPanel', "Focus into Panel");
constructor() {
super({
id: 'workbench.action.focusPanel',
title: localize2('focusPanel', "Focus into Panel"),
category: Categories.View,
f1: true,
});
}
override async run(accessor: ServicesAccessor): Promise<void> {
const layoutService = accessor.get(IWorkbenchLayoutService);
const paneCompositeService = accessor.get(IPaneCompositePartService);
// Show panel
if (!layoutService.isVisible(Parts.PANEL_PART)) {
layoutService.setPartHidden(false, Parts.PANEL_PART);
}
// Focus into active panel
const panel = paneCompositeService.getActivePaneComposite(ViewContainerLocation.Panel);
panel?.focus();
}
});
const PositionPanelActionId = {
LEFT: 'workbench.action.positionPanelLeft',
RIGHT: 'workbench.action.positionPanelRight',
BOTTOM: 'workbench.action.positionPanelBottom',
TOP: 'workbench.action.positionPanelTop'
};
const AlignPanelActionId = {
LEFT: 'workbench.action.alignPanelLeft',
RIGHT: 'workbench.action.alignPanelRight',
CENTER: 'workbench.action.alignPanelCenter',
JUSTIFY: 'workbench.action.alignPanelJustify',
};
interface PanelActionConfig<T> {
id: string;
when: ContextKeyExpression;
title: ICommandActionTitle;
shortLabel: string;
value: T;
}
function createPanelActionConfig<T>(id: string, title: ICommandActionTitle, shortLabel: string, value: T, when: ContextKeyExpression): PanelActionConfig<T> {
return {
id,
title,
shortLabel,
value,
when,
};
}
function createPositionPanelActionConfig(id: string, title: ICommandActionTitle, shortLabel: string, position: Position): PanelActionConfig<Position> {
return createPanelActionConfig<Position>(id, title, shortLabel, position, PanelPositionContext.notEqualsTo(positionToString(position)));
}
function createAlignmentPanelActionConfig(id: string, title: ICommandActionTitle, shortLabel: string, alignment: PanelAlignment): PanelActionConfig<PanelAlignment> {
return createPanelActionConfig<PanelAlignment>(id, title, shortLabel, alignment, PanelAlignmentContext.notEqualsTo(alignment));
}
const PositionPanelActionConfigs: PanelActionConfig<Position>[] = [
createPositionPanelActionConfig(PositionPanelActionId.TOP, localize2('positionPanelTop', "Move Panel To Top"), localize('positionPanelTopShort', "Top"), Position.TOP),
createPositionPanelActionConfig(PositionPanelActionId.LEFT, localize2('positionPanelLeft', "Move Panel Left"), localize('positionPanelLeftShort', "Left"), Position.LEFT),
createPositionPanelActionConfig(PositionPanelActionId.RIGHT, localize2('positionPanelRight', "Move Panel Right"), localize('positionPanelRightShort', "Right"), Position.RIGHT),
createPositionPanelActionConfig(PositionPanelActionId.BOTTOM, localize2('positionPanelBottom', "Move Panel To Bottom"), localize('positionPanelBottomShort', "Bottom"), Position.BOTTOM),
];
const AlignPanelActionConfigs: PanelActionConfig<PanelAlignment>[] = [
createAlignmentPanelActionConfig(AlignPanelActionId.LEFT, localize2('alignPanelLeft', "Set Panel Alignment to Left"), localize('alignPanelLeftShort', "Left"), 'left'),
createAlignmentPanelActionConfig(AlignPanelActionId.RIGHT, localize2('alignPanelRight', "Set Panel Alignment to Right"), localize('alignPanelRightShort', "Right"), 'right'),
createAlignmentPanelActionConfig(AlignPanelActionId.CENTER, localize2('alignPanelCenter', "Set Panel Alignment to Center"), localize('alignPanelCenterShort', "Center"), 'center'),
createAlignmentPanelActionConfig(AlignPanelActionId.JUSTIFY, localize2('alignPanelJustify', "Set Panel Alignment to Justify"), localize('alignPanelJustifyShort', "Justify"), 'justify'),
];
MenuRegistry.appendMenuItem(MenuId.MenubarAppearanceMenu, {
submenu: MenuId.PanelPositionMenu,
title: localize('positionPanel', "Panel Position"),
group: '3_workbench_layout_move',
order: 4
});
PositionPanelActionConfigs.forEach((positionPanelAction, index) => {
const { id, title, shortLabel, value, when } = positionPanelAction;
registerAction2(class extends Action2 {
constructor() {
super({
id,
title,
category: Categories.View,
f1: true
});
}
run(accessor: ServicesAccessor): void {
const layoutService = accessor.get(IWorkbenchLayoutService);
layoutService.setPanelPosition(value === undefined ? Position.BOTTOM : value);
}
});
MenuRegistry.appendMenuItem(MenuId.PanelPositionMenu, {
command: {
id,
title: shortLabel,
toggled: when.negate()
},
order: 5 + index
});
});
MenuRegistry.appendMenuItem(MenuId.MenubarAppearanceMenu, {
submenu: MenuId.PanelAlignmentMenu,
title: localize('alignPanel', "Align Panel"),
group: '3_workbench_layout_move',
order: 5
});
AlignPanelActionConfigs.forEach(alignPanelAction => {
const { id, title, shortLabel, value, when } = alignPanelAction;
registerAction2(class extends Action2 {
constructor() {
super({
id,
title,
category: Categories.View,
toggled: when.negate(),
f1: true
});
}
run(accessor: ServicesAccessor): void {
const layoutService = accessor.get(IWorkbenchLayoutService);
layoutService.setPanelAlignment(value === undefined ? 'center' : value);
}
});
MenuRegistry.appendMenuItem(MenuId.PanelAlignmentMenu, {
command: {
id,
title: shortLabel,
toggled: when.negate()
},
order: 5
});
});
class SwitchPanelViewAction extends Action2 {
constructor(id: string, title: ICommandActionTitle) {
super({
id,
title,
category: Categories.View,
f1: true,
});
}
override async run(accessor: ServicesAccessor, offset: number): Promise<void> {
const paneCompositeService = accessor.get(IPaneCompositePartService);
const pinnedPanels = paneCompositeService.getVisiblePaneCompositeIds(ViewContainerLocation.Panel);
const activePanel = paneCompositeService.getActivePaneComposite(ViewContainerLocation.Panel);
if (!activePanel) {
return;
}
let targetPanelId: string | undefined;
for (let i = 0; i < pinnedPanels.length; i++) {
if (pinnedPanels[i] === activePanel.getId()) {
targetPanelId = pinnedPanels[(i + pinnedPanels.length + offset) % pinnedPanels.length];
break;
}
}
if (typeof targetPanelId === 'string') {
await paneCompositeService.openPaneComposite(targetPanelId, ViewContainerLocation.Panel, true);
}
}
}
registerAction2(class extends SwitchPanelViewAction {
constructor() {
super('workbench.action.previousPanelView', localize2('previousPanelView', "Previous Panel View"));
}
override run(accessor: ServicesAccessor): Promise<void> {
return super.run(accessor, -1);
}
});
registerAction2(class extends SwitchPanelViewAction {
constructor() {
super('workbench.action.nextPanelView', localize2('nextPanelView', "Next Panel View"));
}
override run(accessor: ServicesAccessor): Promise<void> {
return super.run(accessor, 1);
}
});
registerAction2(class extends Action2 {
constructor() {
super({
id: 'workbench.action.toggleMaximizedPanel',
title: localize2('toggleMaximizedPanel', 'Toggle Maximized Panel'),
tooltip: localize('maximizePanel', "Maximize Panel Size"),
category: Categories.View,
f1: true,
icon: maximizeIcon, // This is being rotated in CSS depending on the panel position
// the workbench grid currently prevents us from supporting panel maximization with non-center panel alignment
precondition: ContextKeyExpr.or(PanelAlignmentContext.isEqualTo('center'), ContextKeyExpr.and(PanelPositionContext.notEqualsTo('bottom'), PanelPositionContext.notEqualsTo('top'))),
toggled: { condition: PanelMaximizedContext, icon: restoreIcon, tooltip: localize('minimizePanel', "Restore Panel Size") },
menu: [{
id: MenuId.PanelTitle,
group: 'navigation',
order: 1,
// the workbench grid currently prevents us from supporting panel maximization with non-center panel alignment
when: ContextKeyExpr.or(PanelAlignmentContext.isEqualTo('center'), ContextKeyExpr.and(PanelPositionContext.notEqualsTo('bottom'), PanelPositionContext.notEqualsTo('top')))
}]
});
}
run(accessor: ServicesAccessor) {
const layoutService = accessor.get(IWorkbenchLayoutService);
const notificationService = accessor.get(INotificationService);
if (layoutService.getPanelAlignment() !== 'center' && isHorizontal(layoutService.getPanelPosition())) {
notificationService.warn(localize('panelMaxNotSupported', "Maximizing the panel is only supported when it is center aligned."));
return;
}
if (!layoutService.isVisible(Parts.PANEL_PART)) {
layoutService.setPartHidden(false, Parts.PANEL_PART);
// If the panel is not already maximized, maximize it
if (!layoutService.isPanelMaximized()) {
layoutService.toggleMaximizedPanel();
}
}
else {
layoutService.toggleMaximizedPanel();
}
}
});
registerAction2(class extends Action2 {
constructor() {
super({
id: 'workbench.action.closePanel',
title: localize2('closePanel', 'Hide Panel'),
category: Categories.View,
icon: closeIcon,
menu: [{
id: MenuId.CommandPalette,
when: PanelVisibleContext,
}, {
id: MenuId.PanelTitle,
group: 'navigation',
order: 2
}]
});
}
run(accessor: ServicesAccessor) {
accessor.get(IWorkbenchLayoutService).setPartHidden(true, Parts.PANEL_PART);
}
});
registerAction2(class extends Action2 {
constructor() {
super({
id: 'workbench.action.closeAuxiliaryBar',
title: localize2('closeSecondarySideBar', 'Hide Secondary Side Bar'),
category: Categories.View,
icon: closeIcon,
menu: [{
id: MenuId.CommandPalette,
when: AuxiliaryBarVisibleContext,
}, {
id: MenuId.AuxiliaryBarTitle,
group: 'navigation',
order: 2,
when: ContextKeyExpr.notEquals(`config.${LayoutSettings.ACTIVITY_BAR_LOCATION}`, ActivityBarPosition.TOP)
}]
});
}
run(accessor: ServicesAccessor) {
accessor.get(IWorkbenchLayoutService).setPartHidden(true, Parts.AUXILIARYBAR_PART);
}
});
MenuRegistry.appendMenuItems([
{
id: MenuId.LayoutControlMenu,
item: {
group: '0_workbench_toggles',
command: {
id: TogglePanelAction.ID,
title: localize('togglePanel', "Toggle Panel"),
icon: panelOffIcon,
toggled: { condition: PanelVisibleContext, icon: panelIcon }
},
when: ContextKeyExpr.or(ContextKeyExpr.equals('config.workbench.layoutControl.type', 'toggles'), ContextKeyExpr.equals('config.workbench.layoutControl.type', 'both')),
order: 1
}
}, {
id: MenuId.ViewTitleContext,
item: {
group: '3_workbench_layout_move',
command: {
id: TogglePanelAction.ID,
title: localize2('hidePanel', 'Hide Panel'),
},
when: ContextKeyExpr.and(PanelVisibleContext, ContextKeyExpr.equals('viewLocation', ViewContainerLocationToString(ViewContainerLocation.Panel))),
order: 2
}
}
]);
class MoveViewsBetweenPanelsAction extends Action2 {
constructor(private readonly source: ViewContainerLocation, private readonly destination: ViewContainerLocation, desc: Readonly<IAction2Options>) {
super(desc);
}
run(accessor: ServicesAccessor, ...args: any[]): void {
const viewDescriptorService = accessor.get(IViewDescriptorService);
const layoutService = accessor.get(IWorkbenchLayoutService);
const viewsService = accessor.get(IViewsService);
const srcContainers = viewDescriptorService.getViewContainersByLocation(this.source);
const destContainers = viewDescriptorService.getViewContainersByLocation(this.destination);
if (srcContainers.length) {
const activeViewContainer = viewsService.getVisibleViewContainer(this.source);
srcContainers.forEach(viewContainer => viewDescriptorService.moveViewContainerToLocation(viewContainer, this.destination, undefined, this.desc.id));
layoutService.setPartHidden(false, this.destination === ViewContainerLocation.Panel ? Parts.PANEL_PART : Parts.AUXILIARYBAR_PART);
if (activeViewContainer && destContainers.length === 0) {
viewsService.openViewContainer(activeViewContainer.id, true);
}
}
}
}
// --- Move Panel Views To Secondary Side Bar
class MovePanelToSidePanelAction extends MoveViewsBetweenPanelsAction {
static readonly ID = 'workbench.action.movePanelToSidePanel';
constructor() {
super(ViewContainerLocation.Panel, ViewContainerLocation.AuxiliaryBar, {
id: MovePanelToSidePanelAction.ID,
title: localize2('movePanelToSecondarySideBar', "Move Panel Views To Secondary Side Bar"),
category: Categories.View,
f1: false
});
}
}
export class MovePanelToSecondarySideBarAction extends MoveViewsBetweenPanelsAction {
static readonly ID = 'workbench.action.movePanelToSecondarySideBar';
constructor() {
super(ViewContainerLocation.Panel, ViewContainerLocation.AuxiliaryBar, {
id: MovePanelToSecondarySideBarAction.ID,
title: localize2('movePanelToSecondarySideBar', "Move Panel Views To Secondary Side Bar"),
category: Categories.View,
f1: true
});
}
}
registerAction2(MovePanelToSidePanelAction);
registerAction2(MovePanelToSecondarySideBarAction);
// --- Move Secondary Side Bar Views To Panel
class MoveSidePanelToPanelAction extends MoveViewsBetweenPanelsAction {
static readonly ID = 'workbench.action.moveSidePanelToPanel';
constructor() {
super(ViewContainerLocation.AuxiliaryBar, ViewContainerLocation.Panel, {
id: MoveSidePanelToPanelAction.ID,
title: localize2('moveSidePanelToPanel', "Move Secondary Side Bar Views To Panel"),
category: Categories.View,
f1: false
});
}
}
export class MoveSecondarySideBarToPanelAction extends MoveViewsBetweenPanelsAction {
static readonly ID = 'workbench.action.moveSecondarySideBarToPanel';
constructor() {
super(ViewContainerLocation.AuxiliaryBar, ViewContainerLocation.Panel, {
id: MoveSecondarySideBarToPanelAction.ID,
title: localize2('moveSidePanelToPanel', "Move Secondary Side Bar Views To Panel"),
category: Categories.View,
f1: true
});
}
}
registerAction2(MoveSidePanelToPanelAction);
registerAction2(MoveSecondarySideBarToPanelAction);