Skip to content

Commit 97e8957

Browse files
committed
Improved changelists inputs
1 parent 4cfc1c6 commit 97e8957

File tree

3 files changed

+139
-92
lines changed

3 files changed

+139
-92
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,13 +304,13 @@
304304
{
305305
"command": "svn.addChangelist",
306306
"when":
307-
"config.svn.enabled && scmProvider == svn && scmResourceGroup != external",
307+
"config.svn.enabled && scmProvider == svn && scmResourceGroup != unversioned && scmResourceGroup != external",
308308
"group": "inline"
309309
},
310310
{
311311
"command": "svn.addChangelist",
312312
"when":
313-
"config.svn.enabled && scmProvider == svn && scmResourceGroup != external",
313+
"config.svn.enabled && scmProvider == svn && scmResourceGroup != unversioned && scmResourceGroup != external",
314314
"group": "1_modification"
315315
},
316316
{

src/changelistItems.ts

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
import {
2+
QuickPickItem,
3+
SourceControlResourceGroup,
4+
window,
5+
workspace
6+
} from "vscode";
7+
import { Repository } from "./repository";
8+
9+
export class ChangeListItem implements QuickPickItem {
10+
constructor(protected group: SourceControlResourceGroup) {}
11+
12+
get label(): string {
13+
return this.group.label;
14+
}
15+
16+
get description(): string {
17+
return this.group.label;
18+
}
19+
get resourceGroup(): SourceControlResourceGroup {
20+
return this.group;
21+
}
22+
}
23+
24+
export class NewChangeListItem implements QuickPickItem {
25+
constructor() {}
26+
27+
get label(): string {
28+
return "$(plus) New changelist";
29+
}
30+
31+
get description(): string {
32+
return "Create a new change list";
33+
}
34+
}
35+
36+
export function getChangelistPickOptions(
37+
repository: Repository
38+
): QuickPickItem[] {
39+
const picks: QuickPickItem[] = [];
40+
41+
repository.changelists.forEach((group, changelist) => {
42+
if (group.resourceStates.length) {
43+
picks.push(new ChangeListItem(group));
44+
}
45+
});
46+
picks.push(new NewChangeListItem());
47+
48+
return picks;
49+
}
50+
51+
export function getCommitChangelistPickOptions(
52+
repository: Repository
53+
): ChangeListItem[] {
54+
const picks: ChangeListItem[] = [];
55+
56+
if (repository.changes.resourceStates.length) {
57+
picks.push(new ChangeListItem(repository.changes));
58+
}
59+
60+
const svnConfig = workspace.getConfiguration("svn");
61+
const ignoreOnCommitList = svnConfig.get<string[]>(
62+
"sourceControl.ignoreOnCommit",
63+
[]
64+
);
65+
66+
repository.changelists.forEach((group, changelist) => {
67+
if (
68+
group.resourceStates.length &&
69+
!ignoreOnCommitList.includes(changelist)
70+
) {
71+
picks.push(new ChangeListItem(group));
72+
}
73+
});
74+
return picks;
75+
}
76+
77+
export async function inputSwitchChangelist(repository: Repository) {
78+
const picks: QuickPickItem[] = getChangelistPickOptions(repository);
79+
80+
const selectedChoice: any = await window.showQuickPick(picks, {
81+
placeHolder: "Select an existing changelist or create a new"
82+
});
83+
if (!selectedChoice) {
84+
return;
85+
}
86+
87+
let changelistName;
88+
89+
if (selectedChoice instanceof NewChangeListItem) {
90+
const newChangelistName = await window.showInputBox({
91+
placeHolder: "Changelist name",
92+
prompt: "Please enter a changelist name"
93+
});
94+
if (!newChangelistName) {
95+
return;
96+
}
97+
changelistName = newChangelistName;
98+
} else if (selectedChoice instanceof ChangeListItem) {
99+
changelistName = selectedChoice.resourceGroup.id.replace(
100+
/^changelist-/,
101+
""
102+
);
103+
}
104+
105+
return changelistName;
106+
}
107+
108+
export async function inputCommitChangelist(repository: Repository) {
109+
const picks: ChangeListItem[] = getCommitChangelistPickOptions(repository);
110+
111+
if (picks.length === 0) {
112+
window.showInformationMessage("There are no changes to commit.");
113+
return;
114+
}
115+
116+
let choice;
117+
// If has only changes, not prompt to select changelist
118+
if (picks.length === 1 && repository.changes.resourceStates.length) {
119+
choice = picks[0];
120+
} else {
121+
choice = await window.showQuickPick(picks, {
122+
placeHolder: "Select a changelist to commit"
123+
});
124+
}
125+
126+
return choice;
127+
}

src/commands.ts

Lines changed: 10 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ import { start } from "repl";
2929
import { getConflictPickOptions } from "./conflictItems";
3030
import { applyLineChanges } from "./lineChanges";
3131
import { IDisposable } from "./util";
32+
import {
33+
getChangelistPickOptions,
34+
inputSwitchChangelist,
35+
ChangeListItem,
36+
getCommitChangelistPickOptions,
37+
inputCommitChangelist
38+
} from "./changelistItems";
3239

3340
interface CommandOptions {
3441
repository?: boolean;
@@ -111,33 +118,6 @@ class SwitchBranchItem implements QuickPickItem {
111118
}
112119
}
113120

114-
class ChangeListItem implements QuickPickItem {
115-
constructor(protected group: SourceControlResourceGroup) {}
116-
117-
get label(): string {
118-
return this.group.label;
119-
}
120-
121-
get description(): string {
122-
return this.group.label;
123-
}
124-
get resourceGroup(): SourceControlResourceGroup {
125-
return this.group;
126-
}
127-
}
128-
129-
class NewChangeListItem implements QuickPickItem {
130-
constructor() {}
131-
132-
get label(): string {
133-
return "$(plus) New changelist";
134-
}
135-
136-
get description(): string {
137-
return "Create a new change list";
138-
}
139-
}
140-
141121
export class SvnCommands implements IDisposable {
142122
private disposables: Disposable[];
143123

@@ -202,42 +182,7 @@ export class SvnCommands implements IDisposable {
202182
return;
203183
}
204184

205-
const picks: ChangeListItem[] = [];
206-
207-
if (repository.changes.resourceStates.length) {
208-
picks.push(new ChangeListItem(repository.changes));
209-
}
210-
211-
const svnConfig = workspace.getConfiguration("svn");
212-
const ignoreOnCommitList = svnConfig.get<string[]>(
213-
"sourceControl.ignoreOnCommit",
214-
[]
215-
);
216-
217-
repository.changelists.forEach((group, changelist) => {
218-
if (
219-
group.resourceStates.length &&
220-
!ignoreOnCommitList.includes(changelist)
221-
) {
222-
picks.push(new ChangeListItem(group));
223-
}
224-
});
225-
226-
if (picks.length === 0) {
227-
window.showInformationMessage("There are no changes to commit.");
228-
return;
229-
}
230-
231-
let choice;
232-
// If has only changes, not prompt to select changelist
233-
if (picks.length === 1 && repository.changes.resourceStates.length) {
234-
choice = picks[0];
235-
} else {
236-
choice = await window.showQuickPick(picks, {
237-
placeHolder: "Select a changelist to commit"
238-
});
239-
}
240-
185+
const choice = await inputCommitChangelist(repository);
241186
if (!choice) {
242187
return;
243188
}
@@ -310,34 +255,9 @@ export class SvnCommands implements IDisposable {
310255
return;
311256
}
312257

313-
const picks: QuickPickItem[] = [];
258+
const changelistName = await inputSwitchChangelist(repository);
314259

315-
repository.changelists.forEach((group, changelist) => {
316-
if (group.resourceStates.length) {
317-
picks.push(new ChangeListItem(group));
318-
}
319-
});
320-
picks.push(new NewChangeListItem());
321-
322-
const selectedChoice: any = await window.showQuickPick(picks, {});
323-
if (!selectedChoice) {
324-
return;
325-
}
326-
327-
let changelistName = "";
328-
329-
if (selectedChoice instanceof NewChangeListItem) {
330-
const newChangelistName = await window.showInputBox();
331-
if (!newChangelistName) {
332-
return;
333-
}
334-
changelistName = newChangelistName;
335-
} else if (selectedChoice instanceof ChangeListItem) {
336-
changelistName = selectedChoice.resourceGroup.id.replace(
337-
/^changelist-/,
338-
""
339-
);
340-
} else {
260+
if (!changelistName) {
341261
return;
342262
}
343263

0 commit comments

Comments
 (0)