forked from JohnstonCode/svn-scm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchangelistItems.ts
171 lines (141 loc) · 4.35 KB
/
changelistItems.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
import { QuickPickItem, window } from "vscode";
import { configuration } from "./helpers/configuration";
import ChangeListItem from "./quickPickItems/changeListItem";
import IgnoredChangeListItem from "./quickPickItems/ignoredChangeListItem";
import NewChangeListItem from "./quickPickItems/newChangeListItem";
import RemoveChangeListItem from "./quickPickItems/removeChangeListItem";
import { Repository } from "./repository";
import { FileItem } from "./quickPickItems/fileItem";
export function getChangelistPickOptions(
repository: Repository,
canRemove = false
): QuickPickItem[] {
const picks: QuickPickItem[] = [];
picks.push(new NewChangeListItem());
repository.changelists.forEach((group, _changelist) => {
if (group.resourceStates.length) {
picks.push(new ChangeListItem(group));
}
});
const ignoreOnCommitList = configuration.get<string[]>(
"sourceControl.ignoreOnCommit"
);
for (const ignoreOnCommit of ignoreOnCommitList) {
if (!picks.some(p => p.label === ignoreOnCommit)) {
picks.push(new IgnoredChangeListItem(ignoreOnCommit));
}
}
if (canRemove) {
picks.push(new RemoveChangeListItem());
}
return picks;
}
export function getCommitChangelistPickOptions(
repository: Repository
): ChangeListItem[] {
const picks: ChangeListItem[] = [];
if (repository.changes.resourceStates.length) {
picks.push(new ChangeListItem(repository.changes));
}
const ignoreOnCommitList = configuration.get<string[]>(
"sourceControl.ignoreOnCommit"
);
repository.changelists.forEach((group, changelist) => {
if (
group.resourceStates.length &&
!ignoreOnCommitList.includes(changelist)
) {
picks.push(new ChangeListItem(group));
}
});
return picks;
}
export async function inputSwitchChangelist(
repository: Repository,
canRemove = false
) {
const picks: QuickPickItem[] = getChangelistPickOptions(
repository,
canRemove
);
const selectedChoice: any = await window.showQuickPick(picks, {
placeHolder: "Select an existing changelist or create a new"
});
if (!selectedChoice) {
return;
}
let changelistName;
if (selectedChoice instanceof RemoveChangeListItem) {
return false;
} else if (selectedChoice instanceof NewChangeListItem) {
const newChangelistName = await window.showInputBox({
placeHolder: "Changelist name",
prompt: "Please enter a changelist name"
});
if (!newChangelistName) {
return;
}
changelistName = newChangelistName;
} else {
changelistName = selectedChoice.label;
}
return changelistName;
}
export async function inputCommitChangelist(repository: Repository) {
const picks: ChangeListItem[] = getCommitChangelistPickOptions(repository);
if (picks.length === 0) {
window.showInformationMessage("There are no changes to commit.");
return;
}
let choice;
// If has only changes, not prompt to select changelist
if (picks.length === 1 && repository.changes.resourceStates.length) {
choice = picks[0];
} else {
choice = await window.showQuickPick(picks, {
placeHolder: "Select a changelist to commit"
});
}
return choice;
}
export async function inputCommitFiles(repository: Repository) {
const choice = await inputCommitChangelist(repository);
if (!choice) {
return;
}
if (choice.id === "changes") {
const picks = choice.resourceGroup.resourceStates.map(r => new FileItem(repository, r));
const selected = await window.showQuickPick(picks, {
placeHolder: "Select files to commit",
canPickMany: true
});
if (selected) {
return selected.map(s => s.state);
}
return;
}
return choice.resourceGroup.resourceStates;
}
export function patchChangelistOptions(repository: Repository) {
const picks: QuickPickItem[] = [];
repository.changelists.forEach((group, _changelist) => {
if (group.resourceStates.length) {
picks.push(new ChangeListItem(group));
}
});
return picks;
}
export async function getPatchChangelist(repository: Repository) {
const picks: QuickPickItem[] = patchChangelistOptions(repository);
if (!picks.length) {
window.showErrorMessage("No changelists to pick from");
return;
}
const selectedChoice: any = await window.showQuickPick(picks, {
placeHolder: "Select a changelist"
});
if (!selectedChoice) {
return;
}
return selectedChoice.label;
}