Skip to content

Commit 7e2e89d

Browse files
authored
allow for multiple files to be discarded (or opened) at once (#104)
1 parent 7c30699 commit 7e2e89d

File tree

2 files changed

+25
-19
lines changed

2 files changed

+25
-19
lines changed

src/extension.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,18 @@ export function activate(context: ExtensionContext) {
3232
});
3333
});
3434

35-
commands.registerCommand(NAMESPACE + '.openFile', node => {
35+
commands.registerCommand(NAMESPACE + '.openFile', (node, nodes) => {
3636
runAfterInit(() => {
37-
provider!.openFile(node);
37+
provider!.openFile(nodes || [node]);
3838
});
3939
});
40-
41-
commands.registerCommand(NAMESPACE + '.discardChanges', node => {
40+
41+
commands.registerCommand(NAMESPACE + '.discardChanges', (node, nodes) => {
4242
runAfterInit(() => {
43-
provider!.discardChanges(node);
43+
provider!.discardChanges(nodes || [node]);
4444
});
4545
});
46-
46+
4747
commands.registerCommand(NAMESPACE + '.discardAllChanges', () => {
4848
runAfterInit(() => {
4949
provider!.discardAllChanges();
@@ -99,7 +99,10 @@ export function activate(context: ExtensionContext) {
9999

100100
const treeView = window.createTreeView(
101101
NAMESPACE,
102-
{treeDataProvider: provider}
102+
{
103+
treeDataProvider: provider,
104+
canSelectMany: true,
105+
}
103106
);
104107

105108
provider.init(treeView);

src/treeProvider.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -829,12 +829,13 @@ export class GitTreeCompareProvider implements TreeDataProvider<Element>, Dispos
829829
}
830830
}
831831

832-
async openFile(fileEntry?: FileElement) {
833-
const diffStatus = this.getDiffStatus(fileEntry);
834-
if (!diffStatus) {
835-
return;
832+
async openFile(fileEntries: FileElement[]) {
833+
for (const fileEntry of fileEntries) {
834+
const diffStatus = this.getDiffStatus(fileEntry);
835+
if (diffStatus) {
836+
await this.doOpenFile(diffStatus.dstAbsPath, diffStatus.status);
837+
}
836838
}
837-
return this.doOpenFile(diffStatus.dstAbsPath, diffStatus.status);
838839
}
839840

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

850-
async discardChanges(entry?: FileElement | FolderElement) {
851+
async discardChanges(entries: (FileElement | FolderElement)[]) {
851852
let statuses: IDiffStatus[] = [];
852-
if (entry instanceof FolderElement) {
853-
statuses = [...this.iterFiles(entry.dstAbsPath)];
854-
} else {
855-
const diffStatus = this.getDiffStatus(entry);
856-
if (diffStatus) {
857-
statuses.push(diffStatus);
853+
for (const entry of entries) {
854+
if (entry instanceof FolderElement) {
855+
statuses = statuses.concat([...this.iterFiles(entry.dstAbsPath)]);
856+
} else {
857+
const diffStatus = this.getDiffStatus(entry);
858+
if (diffStatus) {
859+
statuses.push(diffStatus);
860+
}
858861
}
859862
}
860863
await this.doDiscardChanges(statuses);

0 commit comments

Comments
 (0)