Skip to content
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
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@
"title": "View as Tree",
"icon": "$(list-tree)",
"category": "Git Tree Compare"
},
{
"command": "gitTreeCompare.discardSelectedChanges",
"title": "Discard Selected Changes",
"icon": "$(discard)",
"category": "Git Tree Compare"
}
],
"menus": {
Expand Down
17 changes: 10 additions & 7 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,18 @@ export function activate(context: ExtensionContext) {
});
});

commands.registerCommand(NAMESPACE + '.openFile', node => {
commands.registerCommand(NAMESPACE + '.openFile', (_, nodes) => {
runAfterInit(() => {
provider!.openFile(node);
provider!.openFile(nodes);
});
});
commands.registerCommand(NAMESPACE + '.discardChanges', node => {

commands.registerCommand(NAMESPACE + '.discardChanges', (_, nodes) => {
runAfterInit(() => {
provider!.discardChanges(node);
provider!.discardChanges(nodes);
});
});

commands.registerCommand(NAMESPACE + '.discardAllChanges', () => {
runAfterInit(() => {
provider!.discardAllChanges();
Expand Down Expand Up @@ -99,7 +99,10 @@ export function activate(context: ExtensionContext) {

const treeView = window.createTreeView(
NAMESPACE,
{treeDataProvider: provider}
{
treeDataProvider: provider,
canSelectMany: true,
}
);

provider.init(treeView);
Expand Down
27 changes: 15 additions & 12 deletions src/treeProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -829,12 +829,13 @@ export class GitTreeCompareProvider implements TreeDataProvider<Element>, Dispos
}
}

async openFile(fileEntry?: FileElement) {
const diffStatus = this.getDiffStatus(fileEntry);
if (!diffStatus) {
return;
async openFile(fileEntries: FileElement[]) {
for (const fileEntry of fileEntries) {
const diffStatus = this.getDiffStatus(fileEntry);
if (diffStatus) {
await this.doOpenFile(diffStatus.dstAbsPath, diffStatus.status);
}
}
return this.doOpenFile(diffStatus.dstAbsPath, diffStatus.status);
}

async doOpenFile(dstAbsPath: string, status: StatusCode, preview=false) {
Expand All @@ -847,14 +848,16 @@ export class GitTreeCompareProvider implements TreeDataProvider<Element>, Dispos
return commands.executeCommand('vscode.open', uri, options);
}

async discardChanges(entry?: FileElement | FolderElement) {
async discardChanges(entries: (FileElement | FolderElement)[]) {
let statuses: IDiffStatus[] = [];
if (entry instanceof FolderElement) {
statuses = [...this.iterFiles(entry.dstAbsPath)];
} else {
const diffStatus = this.getDiffStatus(entry);
if (diffStatus) {
statuses.push(diffStatus);
for (const entry of entries) {
if (entry instanceof FolderElement) {
statuses = statuses.concat([...this.iterFiles(entry.dstAbsPath)]);
} else {
const diffStatus = this.getDiffStatus(entry);
if (diffStatus) {
statuses.push(diffStatus);
}
}
}
await this.doDiscardChanges(statuses);
Expand Down