From c5e16a6ae941d006e88103ac29c4a09de9d8825d Mon Sep 17 00:00:00 2001 From: abhishekbhakat Date: Tue, 11 Mar 2025 17:53:37 +0000 Subject: [PATCH] fix file selection --- src/extension.ts | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 9c503f5..7319afe 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -74,15 +74,30 @@ class PrompterTreeProvider implements vscode.TreeDataProvider { toggleSelection(item: FileTreeItem): void { const filePath = item.resourceUri.fsPath; + console.log('Toggle selection called for:', filePath); if (this.selectedFiles.has(filePath)) { - this.selectedFiles.delete(filePath); + this.removeFromSelection(item); } else { - this.selectedFiles.add(filePath); + this.addToSelection(item); } + } + + addToSelection(item: FileTreeItem): void { + const filePath = item.resourceUri.fsPath; + this.selectedFiles.add(filePath); + console.log('Added file to selection, count:', this.selectedFiles.size); + this._onDidChangeTreeData.fire(); + } + + removeFromSelection(item: FileTreeItem): void { + const filePath = item.resourceUri.fsPath; + this.selectedFiles.delete(filePath); + console.log('Removed file from selection, count:', this.selectedFiles.size); this._onDidChangeTreeData.fire(); } getSelectedFiles(): Set { + console.log('getSelectedFiles called, count:', this.selectedFiles.size); return this.selectedFiles; } @@ -151,10 +166,25 @@ export function activate(context: vscode.ExtensionContext) { const workspaceRoot = vscode.workspace.workspaceFolders?.[0]?.uri?.fsPath; const prompterTreeProvider = new PrompterTreeProvider(workspaceRoot); - // Register the TreeView + // Register the TreeView with checkbox support const treeView = vscode.window.createTreeView('prompterView', { treeDataProvider: prompterTreeProvider, - showCollapseAll: true + showCollapseAll: true, + canSelectMany: true + }); + + // Handle checkbox changes + treeView.onDidChangeCheckboxState(e => { + console.log('Checkbox state changed'); + for (const [item, state] of e.items) { + const fileItem = item as FileTreeItem; + console.log(`Checkbox changed for ${fileItem.resourceUri.fsPath} to ${state}`); + if (state === vscode.TreeItemCheckboxState.Checked) { + prompterTreeProvider.addToSelection(fileItem); + } else { + prompterTreeProvider.removeFromSelection(fileItem); + } + } }); // Create XML edits toggle button @@ -173,6 +203,7 @@ export function activate(context: vscode.ExtensionContext) { // Register command to toggle file selection let toggleSelectionCommand = vscode.commands.registerCommand('prompter.toggleSelection', (item: FileTreeItem) => { + console.log('Toggle selection command triggered for:', item.resourceUri.fsPath); prompterTreeProvider.toggleSelection(item); }); @@ -186,6 +217,7 @@ export function activate(context: vscode.ExtensionContext) { // Register command to generate prompt from selected files let generatePromptCommand = vscode.commands.registerCommand('prompter.generatePrompt', async () => { const selectedFiles = prompterTreeProvider.getSelectedFiles(); + console.log('Generate prompt command triggered, selected files:', [...selectedFiles]); if (selectedFiles.size === 0) { vscode.window.showInformationMessage('Please select files first'); return;