Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Support undo from viewlet (inline) #99

Merged
merged 2 commits into from
Feb 10, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
39 changes: 33 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,35 @@
}
],
"scm/resource/context": [
{
"command": "tfvc.Include",
"when": "scmProvider == tfvc && scmResourceGroup == excluded",
"group": "navigation"
},
{
"command": "tfvc.Include",
"when": "scmProvider == tfvc && scmResourceGroup == included",
"group": "navigation"
},
{
"command": "tfvc.Exclude",
"when": "scmProvider == tfvc && scmResourceGroup == included",
"group": "1_sync"
},
{
"command": "tfvc.Undo",
"when": "scmProvider == tfvc",
"group": "inline@1"
},
{
"command": "tfvc.Include",
"when": "scmProvider == tfvc && scmResourceGroup == excluded",
"group": "navigation"
"group": "inline@2"
},
{
"command": "tfvc.Include",
"command": "tfvc.Exclude",
"when": "scmProvider == tfvc && scmResourceGroup == included",
"group": "navigation"
"group": "inline@2"
}
]
},
Expand Down Expand Up @@ -233,7 +248,11 @@
{
"command": "tfvc.Exclude",
"title": "Exclude",
"category": "TFVC"
"category": "TFVC",
"icon": {
"light": "resources/icons/light/unstage.svg",
"dark": "resources/icons/dark/unstage.svg"
}
},
{
"command": "tfvc.IncludeAll",
Expand All @@ -243,7 +262,11 @@
{
"command": "tfvc.Include",
"title": "Include",
"category": "TFVC"
"category": "TFVC",
"icon": {
"light": "resources/icons/light/stage.svg",
"dark": "resources/icons/dark/stage.svg"
}
},
{
"command": "tfvc.ShowOutput",
Expand All @@ -262,7 +285,11 @@
{
"command": "tfvc.Undo",
"title": "Undo",
"category": "TFVC"
"category": "TFVC",
"icon": {
"light": "resources/icons/light/clean.svg",
"dark": "resources/icons/dark/clean.svg"
}
}
]
},
Expand Down
1 change: 1 addition & 0 deletions resources/icons/dark/clean.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions resources/icons/dark/stage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions resources/icons/dark/unstage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions resources/icons/light/clean.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions resources/icons/light/stage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions resources/icons/light/unstage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 9 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,15 @@ export async function activate(context: ExtensionContext) {

// TFVC Commands
context.subscriptions.push(commands.registerCommand(TfvcCommandNames.Status, () => _extensionManager.Tfvc.TfvcStatus()));
context.subscriptions.push(commands.registerCommand(TfvcCommandNames.Undo, () => _extensionManager.Tfvc.TfvcUndo()));
context.subscriptions.push(commands.registerCommand(TfvcCommandNames.Undo, (...args) => {
if (args) {
//TODO: Multi-select?
_extensionManager.Tfvc.TfvcUndo(args[0]);
} else {
_extensionManager.Tfvc.TfvcUndo();
}
}
));
context.subscriptions.push(commands.registerCommand(TfvcCommandNames.Exclude, () => _extensionManager.Tfvc.TfvcExclude()));
context.subscriptions.push(commands.registerCommand(TfvcCommandNames.ExcludeAll, () => _extensionManager.Tfvc.TfvcExcludeAll()));
context.subscriptions.push(commands.registerCommand(TfvcCommandNames.Include, () => _extensionManager.Tfvc.TfvcInclude()));
Expand Down
1 change: 1 addition & 0 deletions src/helpers/strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export class Strings {
static TfExecFailedError: string = "Execution of the TFVC command line failed unexpectedly.";
static TfVersionWarning: string = "The installed version of the TF command line does not meet the minimum suggested version. You may run into errors or limitations with certain commands until you upgrade. Minimum suggested version: ";
static TfNoPendingChanges: string = "There are no matching pending changes.";
static UndoChanges: string = "Undo Changes";

// TFVC viewlet Strings
static ExcludedGroupName: string = "Excluded changes";
Expand Down
31 changes: 24 additions & 7 deletions src/tfvc/tfvc-extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@
*--------------------------------------------------------------------------------------------*/
"use strict";

import * as path from "path";
import url = require("url");
import { TextEditor, window, workspace } from "vscode";
import { Uri, window, workspace } from "vscode";
import { RepositoryType } from "../contexts/repositorycontext";
import { TfvcContext } from "../contexts/tfvccontext";
import { ExtensionManager } from "../extensionmanager";
import { TfvcTelemetryEvents } from "../helpers/constants";
import { Strings } from "../helpers/strings";
import { Utils } from "../helpers/utils";
import { Tfvc } from "./tfvc";
import { TfvcSCMProvider } from "./tfvcscmprovider";
import { TfvcErrorCodes } from "./tfvcerror";
import { Repository } from "./repository";
import { UIHelper } from "./uihelper";
Expand Down Expand Up @@ -78,18 +81,32 @@ export class TfvcExtension {
* editor. If the undo command applies to the file, the pending changes will be undone. The
* file system watcher will update the UI soon thereafter. No results are displayed to the user.
*/
public async TfvcUndo(): Promise<void> {
public async TfvcUndo(uri?: Uri): Promise<void> {
if (!this._manager.EnsureInitialized(RepositoryType.TFVC)) {
this._manager.DisplayErrorMessage();
return;
}

try {
this._manager.Telemetry.SendEvent(TfvcTelemetryEvents.Undo);
//TODO: When calling from UI, UI will need to call repository.Undo([filePath]);
let editor: TextEditor = window.activeTextEditor;
if (editor) {
await this._repo.Undo([editor.document.fileName]);
//When calling from UI, we have the uri of the resource from which the command was invoked
let pathToUndo: string = TfvcSCMProvider.GetPathFromUri(uri);
if (!pathToUndo) {
//This is called from the command palette, so check for an open file in the editor
if (window.activeTextEditor) {
pathToUndo = window.activeTextEditor.document.fileName;
}
}
if (pathToUndo) {
const basename: string = path.basename(pathToUndo);
const message: string = `Are you sure you want to undo changes in ${basename}?`;
//TODO: use Modal api once vscode.d.ts exposes it (currently proposed)
const pick: string = await window.showWarningMessage(message, /*{ modal: true },*/ Strings.UndoChanges);
if (pick !== Strings.UndoChanges) {
return;
}

this._manager.Telemetry.SendEvent(TfvcTelemetryEvents.Undo);
await this._repo.Undo([pathToUndo]);
}
} catch (err) {
this._manager.DisplayErrorMessage(err.message);
Expand Down
31 changes: 30 additions & 1 deletion src/tfvc/tfvcscmprovider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
"use strict";

import { commands, scm, Uri, Disposable, SCMProvider, SCMResourceGroup, Event, ProviderResult, workspace } from "vscode";
import { commands, scm, Uri, Disposable, SCMProvider, SCMResource, SCMResourceGroup, Event, ProviderResult, workspace } from "vscode";
import { Model } from "./scm/model";
import { Status } from "./scm/status";
import { Resource } from "./scm/resource";
Expand Down Expand Up @@ -173,4 +173,33 @@ export class TfvcSCMProvider implements SCMProvider {

return "";
}

private static ResolveTfvcURI(uri: Uri): SCMResource | SCMResourceGroup | undefined {
if (uri.authority !== TfvcSCMProvider.scmScheme) {
return;
}

return scm.getResourceFromURI(uri);
}

private static ResolveTfvcResource(uri: Uri): Resource | undefined {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

personally, I don't think we should include the "| undefined". It seems unnecessary.

const resource = TfvcSCMProvider.ResolveTfvcURI(uri);

if (!(resource instanceof Resource)) {
return;
}

return resource;
}

public static GetPathFromUri(uri: Uri): string | undefined {
if (uri) {
const resource = TfvcSCMProvider.ResolveTfvcResource(uri);
if (resource) {
return resource.uri.fsPath;
}
}
return undefined;
}

}