Skip to content

Commit 56a66d0

Browse files
authored
feat: Added revert and revert all command icons to SCM view (#549)
1 parent 2cd2b2e commit 56a66d0

File tree

3 files changed

+79
-1
lines changed

3 files changed

+79
-1
lines changed

package.json

+33-1
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,20 @@
295295
{
296296
"command": "svn.revert",
297297
"title": "Revert Selected File",
298-
"category": "SVN"
298+
"category": "SVN",
299+
"icon": {
300+
"light": "icons/light/clean.svg",
301+
"dark": "icons/dark/clean.svg"
302+
}
303+
},
304+
{
305+
"command": "svn.revertAll",
306+
"title": "Revert All Changes",
307+
"category": "SVN",
308+
"icon": {
309+
"light": "icons/light/clean.svg",
310+
"dark": "icons/dark/clean.svg"
311+
}
299312
},
300313
{
301314
"command": "svn.update",
@@ -481,6 +494,10 @@
481494
"command": "svn.revertChange",
482495
"when": "false"
483496
},
497+
{
498+
"command": "svn.revertAll",
499+
"when": "false"
500+
},
484501
{
485502
"command": "svn.revertSelectedRanges",
486503
"when": "config.svn.enabled && svnOpenRepositoryCount != 0 && svnHasSupportToRegisterDiffCommand == 1"
@@ -693,6 +710,16 @@
693710
"command": "svn.refreshRemoteChanges",
694711
"when": "config.svn.enabled && scmProvider == svn && scmResourceGroup == remotechanges",
695712
"group": "navigation"
713+
},
714+
{
715+
"command": "svn.revertAll",
716+
"when": "config.svn.enabled && scmProvider == svn && scmResourceGroup == changes",
717+
"group": "navigation"
718+
},
719+
{
720+
"command": "svn.revertAll",
721+
"when": "config.svn.enabled && scmProvider == svn && scmResourceGroup == changes",
722+
"group": "inline"
696723
}
697724
],
698725
"scm/resourceState/context": [
@@ -761,6 +788,11 @@
761788
"when": "config.svn.enabled && scmProvider == svn && scmResourceGroup != unversioned && scmResourceGroup != external && scmResourceGroup != conflicts && scmResourceGroup != remotechanged",
762789
"group": "2_modification"
763790
},
791+
{
792+
"command": "svn.revert",
793+
"when": "config.svn.enabled && scmProvider == svn && scmResourceGroup != unversioned && scmResourceGroup != external && scmResourceGroup != conflicts && scmResourceGroup != remotechanged",
794+
"group": "inline"
795+
},
764796
{
765797
"command": "svn.remove",
766798
"when": "config.svn.enabled && scmProvider == svn && scmResourceGroup != unversioned && scmResourceGroup != external && scmResourceGroup != conflicts && scmResourceGroup != remotechanged",

src/commands.ts

+2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import { Resolve } from "./commands/resolve";
3434
import { ResolveAll } from "./commands/resolveAll";
3535
import { Resolved } from "./commands/resolved";
3636
import { Revert } from "./commands/revert";
37+
import { RevertAll } from "./commands/revertAll";
3738
import { RevertChange } from "./commands/revertChange";
3839
import { RevertSelectedRanges } from "./commands/revertSelectedRanges";
3940
import { SwitchBranch } from "./commands/switchBranch";
@@ -82,4 +83,5 @@ export function registerCommands(model: Model, disposables: Disposable[]) {
8283
disposables.push(new DeleteUnversioned());
8384
disposables.push(new OpenChangeHead());
8485
disposables.push(new OpenHeadFile());
86+
disposables.push(new RevertAll());
8587
}

src/commands/revertAll.ts

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { SourceControlResourceGroup, window } from "vscode";
2+
import { Command } from "./command";
3+
4+
export class RevertAll extends Command {
5+
constructor() {
6+
super("svn.revertAll");
7+
}
8+
9+
public async execute(resourceGroup: SourceControlResourceGroup) {
10+
const resourceStates = resourceGroup.resourceStates;
11+
12+
if (resourceStates.length === 0) {
13+
return;
14+
}
15+
16+
const yes = "Yes I'm sure";
17+
const answer = await window.showWarningMessage(
18+
"Are you sure? This will wipe all local changes.",
19+
{ modal: true },
20+
yes
21+
);
22+
23+
if (answer !== yes) {
24+
return;
25+
}
26+
27+
const uris = resourceStates.map(resource => resource.resourceUri);
28+
29+
await this.runByRepository(uris, async (repository, resources) => {
30+
if (!repository) {
31+
return;
32+
}
33+
34+
const paths = resources.map(resource => resource.fsPath);
35+
36+
try {
37+
await repository.revert(paths);
38+
} catch (error) {
39+
console.log(error);
40+
window.showErrorMessage("Unable to revert");
41+
}
42+
});
43+
}
44+
}

0 commit comments

Comments
 (0)