Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added revert and revert all command icons to SCM view #549

Merged
merged 2 commits into from
Apr 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,20 @@
{
"command": "svn.revert",
"title": "Revert Selected File",
"category": "SVN"
"category": "SVN",
"icon": {
"light": "icons/light/clean.svg",
"dark": "icons/dark/clean.svg"
}
},
{
"command": "svn.revertAll",
"title": "Revert All Changes",
"category": "SVN",
"icon": {
"light": "icons/light/clean.svg",
"dark": "icons/dark/clean.svg"
}
},
{
"command": "svn.update",
Expand Down Expand Up @@ -481,6 +494,10 @@
"command": "svn.revertChange",
"when": "false"
},
{
"command": "svn.revertAll",
"when": "false"
},
{
"command": "svn.revertSelectedRanges",
"when": "config.svn.enabled && svnOpenRepositoryCount != 0 && svnHasSupportToRegisterDiffCommand == 1"
Expand Down Expand Up @@ -693,6 +710,16 @@
"command": "svn.refreshRemoteChanges",
"when": "config.svn.enabled && scmProvider == svn && scmResourceGroup == remotechanges",
"group": "navigation"
},
{
"command": "svn.revertAll",
"when": "config.svn.enabled && scmProvider == svn && scmResourceGroup == changes",
"group": "navigation"
},
{
"command": "svn.revertAll",
"when": "config.svn.enabled && scmProvider == svn && scmResourceGroup == changes",
"group": "inline"
}
],
"scm/resourceState/context": [
Expand Down Expand Up @@ -761,6 +788,11 @@
"when": "config.svn.enabled && scmProvider == svn && scmResourceGroup != unversioned && scmResourceGroup != external && scmResourceGroup != conflicts && scmResourceGroup != remotechanged",
"group": "2_modification"
},
{
"command": "svn.revert",
"when": "config.svn.enabled && scmProvider == svn && scmResourceGroup != unversioned && scmResourceGroup != external && scmResourceGroup != conflicts && scmResourceGroup != remotechanged",
"group": "inline"
},
{
"command": "svn.remove",
"when": "config.svn.enabled && scmProvider == svn && scmResourceGroup != unversioned && scmResourceGroup != external && scmResourceGroup != conflicts && scmResourceGroup != remotechanged",
Expand Down
2 changes: 2 additions & 0 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { Resolve } from "./commands/resolve";
import { ResolveAll } from "./commands/resolveAll";
import { Resolved } from "./commands/resolved";
import { Revert } from "./commands/revert";
import { RevertAll } from "./commands/revertAll";
import { RevertChange } from "./commands/revertChange";
import { RevertSelectedRanges } from "./commands/revertSelectedRanges";
import { SwitchBranch } from "./commands/switchBranch";
Expand Down Expand Up @@ -82,4 +83,5 @@ export function registerCommands(model: Model, disposables: Disposable[]) {
disposables.push(new DeleteUnversioned());
disposables.push(new OpenChangeHead());
disposables.push(new OpenHeadFile());
disposables.push(new RevertAll());
}
44 changes: 44 additions & 0 deletions src/commands/revertAll.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { SourceControlResourceGroup, window } from "vscode";
import { Command } from "./command";

export class RevertAll extends Command {
constructor() {
super("svn.revertAll");
}

public async execute(resourceGroup: SourceControlResourceGroup) {
const resourceStates = resourceGroup.resourceStates;

if (resourceStates.length === 0) {
return;
}

const yes = "Yes I'm sure";
const answer = await window.showWarningMessage(
"Are you sure? This will wipe all local changes.",
{ modal: true },
yes
);

if (answer !== yes) {
return;
}

const uris = resourceStates.map(resource => resource.resourceUri);

await this.runByRepository(uris, async (repository, resources) => {
if (!repository) {
return;
}

const paths = resources.map(resource => resource.fsPath);

try {
await repository.revert(paths);
} catch (error) {
console.log(error);
window.showErrorMessage("Unable to revert");
}
});
}
}