From 9d84ec94058abc13821a98fcbaec653eca88d979 Mon Sep 17 00:00:00 2001 From: Thomas Willheim Date: Thu, 14 Nov 2024 14:37:09 -0800 Subject: [PATCH 1/2] allow for multiple files to be discarded (or opened) at once --- package.json | 6 ++++++ src/extension.ts | 17 ++++++++++------- src/treeProvider.ts | 27 +++++++++++++++------------ 3 files changed, 31 insertions(+), 19 deletions(-) diff --git a/package.json b/package.json index dd190c0..2c2b70b 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/extension.ts b/src/extension.ts index 526494c..386bb17 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -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(); @@ -99,7 +99,10 @@ export function activate(context: ExtensionContext) { const treeView = window.createTreeView( NAMESPACE, - {treeDataProvider: provider} + { + treeDataProvider: provider, + canSelectMany: true, + } ); provider.init(treeView); diff --git a/src/treeProvider.ts b/src/treeProvider.ts index e46855e..0c38188 100644 --- a/src/treeProvider.ts +++ b/src/treeProvider.ts @@ -829,12 +829,13 @@ export class GitTreeCompareProvider implements TreeDataProvider, 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) { @@ -847,14 +848,16 @@ export class GitTreeCompareProvider implements TreeDataProvider, 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); From ddb15c1271b1dbf665db9c8396b650271d50621a Mon Sep 17 00:00:00 2001 From: Thomas Willheim Date: Fri, 15 Nov 2024 11:14:20 -0800 Subject: [PATCH 2/2] fix open/discard single, remove unused code --- package.json | 6 ------ src/extension.ts | 8 ++++---- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index 2c2b70b..dd190c0 100644 --- a/package.json +++ b/package.json @@ -147,12 +147,6 @@ "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": { diff --git a/src/extension.ts b/src/extension.ts index 386bb17..a2408b8 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -32,15 +32,15 @@ export function activate(context: ExtensionContext) { }); }); - commands.registerCommand(NAMESPACE + '.openFile', (_, nodes) => { + commands.registerCommand(NAMESPACE + '.openFile', (node, nodes) => { runAfterInit(() => { - provider!.openFile(nodes); + provider!.openFile(nodes || [node]); }); }); - commands.registerCommand(NAMESPACE + '.discardChanges', (_, nodes) => { + commands.registerCommand(NAMESPACE + '.discardChanges', (node, nodes) => { runAfterInit(() => { - provider!.discardChanges(nodes); + provider!.discardChanges(nodes || [node]); }); });