Skip to content

Commit

Permalink
allow for multiple files to be discarded (or opened) at once (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
tnrich authored Nov 15, 2024
1 parent 7c30699 commit 7e2e89d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 19 deletions.
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', (node, nodes) => {
runAfterInit(() => {
provider!.openFile(node);
provider!.openFile(nodes || [node]);
});
});
commands.registerCommand(NAMESPACE + '.discardChanges', node => {

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

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

0 comments on commit 7e2e89d

Please sign in to comment.