forked from gitkraken/vscode-gitlens
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetViewsLayout.ts
87 lines (77 loc) · 2.33 KB
/
setViewsLayout.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
import { window } from 'vscode';
import { viewsConfigKeys } from '../config';
import { Commands, CoreCommands } from '../constants';
import type { Container } from '../container';
import { command, executeCommand, executeCoreCommand } from '../system/command';
import { Command } from './base';
export enum ViewsLayout {
GitLens = 'gitlens',
SourceControl = 'scm',
}
export interface SetViewsLayoutCommandArgs {
layout: ViewsLayout;
}
@command()
export class SetViewsLayoutCommand extends Command {
constructor(private readonly container: Container) {
super(Commands.SetViewsLayout);
}
async execute(args?: SetViewsLayoutCommandArgs) {
let layout = args?.layout;
if (layout == null) {
const pick = await window.showQuickPick(
[
{
label: 'Source Control Layout',
description: '(default)',
detail: 'Shows all the views together on the Source Control side bar',
layout: ViewsLayout.SourceControl,
},
{
label: 'GitLens Layout',
description: '',
detail: 'Shows all the views together on the GitLens side bar',
layout: ViewsLayout.GitLens,
},
],
{
placeHolder: 'Choose a GitLens views layout',
},
);
if (pick == null) return;
layout = pick.layout;
}
void this.container.storage.store('views:layout', layout);
const views = viewsConfigKeys.filter(v => v !== 'contributors');
switch (layout) {
case ViewsLayout.GitLens:
try {
// Because of https://github.com/microsoft/vscode/issues/105774, run the command twice which seems to fix things
let count = 0;
while (count++ < 2) {
void (await executeCoreCommand(CoreCommands.MoveViews, {
viewIds: views.map(v => `gitlens.views.${v}`),
destinationId: 'workbench.view.extension.gitlens',
}));
}
} catch {}
break;
case ViewsLayout.SourceControl:
try {
// Because of https://github.com/microsoft/vscode/issues/105774, run the command twice which seems to fix things
let count = 0;
while (count++ < 2) {
void (await executeCoreCommand(CoreCommands.MoveViews, {
viewIds: views.map(v => `gitlens.views.${v}`),
destinationId: 'workbench.view.scm',
}));
}
} catch {
for (const view of views) {
void (await executeCommand(`gitlens.views.${view}.resetViewLocation`));
}
}
break;
}
}
}