-
-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added Branches tree view (#729)
- Loading branch information
1 parent
4824881
commit cecd185
Showing
10 changed files
with
352 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { ISvnPath } from "./common/types"; | ||
import * as xml2js from "xml2js"; | ||
import { camelcase } from "./util"; | ||
|
||
export async function parseDiffXml(content: string): Promise<ISvnPath[]> { | ||
return new Promise<ISvnPath[]>((resolve, reject) => { | ||
xml2js.parseString( | ||
content, | ||
{ | ||
mergeAttrs: true, | ||
explicitRoot: false, | ||
explicitArray: false, | ||
attrNameProcessors: [camelcase], | ||
tagNameProcessors: [camelcase] | ||
}, | ||
(err, result) => { | ||
if ( | ||
err || | ||
!result.paths || | ||
!result.paths.path | ||
) { | ||
reject(); | ||
} | ||
|
||
if (!Array.isArray(result.paths.path)) { | ||
result.paths.path = [result.paths.path]; | ||
} | ||
|
||
resolve(result.paths.path); | ||
} | ||
); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import { | ||
TreeDataProvider, | ||
Disposable, | ||
TreeItem, | ||
commands, | ||
EventEmitter | ||
} from "vscode"; | ||
import { Model } from "../model"; | ||
import { ISvnPathChange, Status } from "../common/types"; | ||
import { openDiff, getIconObject, openFileRemote } from "./common"; | ||
import { dispose } from "../util"; | ||
|
||
export class BranchChangesProvider | ||
implements TreeDataProvider<ISvnPathChange>, Disposable { | ||
private _dispose: Disposable[] = []; | ||
private _onDidChangeTreeData = new EventEmitter<ISvnPathChange | undefined>(); | ||
public readonly onDidChangeTreeData = this._onDidChangeTreeData.event; | ||
|
||
constructor(private model: Model) { | ||
this._dispose.push( | ||
commands.registerCommand( | ||
"svn.branchchanges.openDiff", | ||
this.openDiffCmd, | ||
this | ||
) | ||
); | ||
|
||
this._dispose.push( | ||
commands.registerCommand( | ||
"svn.branchchanges.refresh", | ||
() => this._onDidChangeTreeData.fire(), | ||
this | ||
) | ||
); | ||
|
||
this.model.onDidChangeRepository(() => this._onDidChangeTreeData.fire()); | ||
} | ||
|
||
dispose() { | ||
dispose(this._dispose); | ||
} | ||
|
||
getTreeItem(element: ISvnPathChange): TreeItem | Thenable<TreeItem> { | ||
let iconName: string = ""; | ||
if (element.item === Status.ADDED) { | ||
iconName = "status-added"; | ||
} else if (element.item === Status.DELETED) { | ||
iconName = "status-deleted"; | ||
} else if (element.item === Status.MODIFIED) { | ||
iconName = "status-modified"; | ||
} | ||
|
||
const iconPath = getIconObject(iconName); | ||
|
||
return { | ||
label: element.newPath.toString(), | ||
command: { | ||
command: "svn.branchchanges.openDiff", | ||
title: "Open diff", | ||
arguments: [element] | ||
}, | ||
iconPath, | ||
tooltip: `${element.oldPath}@r${element.oldRevision} → ${element.newPath}@r${element.newRevision}` | ||
}; | ||
} | ||
|
||
getChildren(element?: ISvnPathChange): Promise<ISvnPathChange[]> { | ||
if (element !== undefined) { | ||
return Promise.resolve([]); | ||
} | ||
|
||
const changes: Promise<ISvnPathChange[]>[] = []; | ||
|
||
for (const repo of this.model.repositories) { | ||
changes.push(repo.getChanges()); | ||
} | ||
|
||
return Promise.all(changes).then(value => | ||
value.reduce((prev, curr) => prev.concat(curr), []) | ||
); | ||
} | ||
|
||
public async openDiffCmd(element: ISvnPathChange) { | ||
const repo = await this.model.getRemoteRepository(element.repo); | ||
|
||
if (element.item === Status.MODIFIED) { | ||
return openDiff( | ||
repo, | ||
element.oldPath, | ||
element.oldRevision, | ||
element.newRevision, | ||
element.newPath | ||
); | ||
} | ||
if (element.item === Status.ADDED) { | ||
return openFileRemote(repo, element.newPath, element.newRevision); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.