fix(context-window): FIxed the clear and refresh and updated the commands. Now the buttons will clear the items and refresh correctly.

This commit is contained in:
Christopher 2023-06-18 16:57:05 -04:00
parent 93be5cbce3
commit fbeb0cc703
2 changed files with 61 additions and 38 deletions

View File

@ -43,8 +43,6 @@ class FileDataProvider {
} }
} }
// Command for adding files to gpt-contextfiles // Command for adding files to gpt-contextfiles
const addFilesCommand = vscode.commands.registerCommand('extension.addFilesToGPTContext', () => { const addFilesCommand = vscode.commands.registerCommand('extension.addFilesToGPTContext', () => {
const editor = vscode.window.activeTextEditor; const editor = vscode.window.activeTextEditor;
@ -102,13 +100,15 @@ const openGPTContextPanelCommand = vscode.commands.registerCommand('extension.op
fileDataProvider.refresh(); fileDataProvider.refresh();
} }
} else if (message.command === 'clearSelectedFiles') { } else if (message.command === 'clearSelectedFiles') {
selectedFiles.forEach(file => { const clearedFiles = selectedFiles.filter(file => file.selected === false);
file.selected = false;
});
selectedFiles.length = 0; // Clear the array selectedFiles.length = 0; // Clear the array
clearedFiles.forEach(file => {
fileDataProvider.refresh(); fileDataProvider.refresh();
} else if (message.command === 'refreshSelectedFiles') { });
panel.webview.html = getWebviewContent();
} else if (message.command === 'refreshFiles') {
fileDataProvider.refresh(); fileDataProvider.refresh();
panel.webview.html = getWebviewContent();
} }
}); });
}); });
@ -118,6 +118,19 @@ const refreshSelectedFilesCommand = vscode.commands.registerCommand('extension.r
fileDataProvider.refresh(); fileDataProvider.refresh();
}); });
// Command for clearing the selected files
const clearSelectedFilesCommand = vscode.commands.registerCommand('extension.clearSelectedFiles', () => {
selectedFiles.forEach(file => {
file.selected = false;
});
fileDataProvider.refresh();
});
// Command for refreshing all files
const refreshFilesCommand = vscode.commands.registerCommand('extension.refreshFiles', () => {
fileDataProvider.refresh();
});
// Helper function to generate the HTML content for the webview panel // Helper function to generate the HTML content for the webview panel
function getWebviewContent(fileContents, question) { function getWebviewContent(fileContents, question) {
const fileList = selectedFiles const fileList = selectedFiles
@ -166,7 +179,7 @@ function getWebviewContent(fileContents, question) {
function refreshSelectedFiles() { function refreshSelectedFiles() {
vscode.postMessage({ vscode.postMessage({
command: 'refreshSelectedFiles' command: 'refreshFiles'
}); });
} }
@ -194,6 +207,8 @@ function activate(context) {
context.subscriptions.push(addFilesCommand); context.subscriptions.push(addFilesCommand);
context.subscriptions.push(openGPTContextPanelCommand); context.subscriptions.push(openGPTContextPanelCommand);
context.subscriptions.push(refreshSelectedFilesCommand); context.subscriptions.push(refreshSelectedFilesCommand);
context.subscriptions.push(clearSelectedFilesCommand);
context.subscriptions.push(refreshFilesCommand);
// Refresh the file data provider when a file is added or removed from the workspace // Refresh the file data provider when a file is added or removed from the workspace
vscode.workspace.onDidChangeWorkspaceFolders(() => { vscode.workspace.onDidChangeWorkspaceFolders(() => {

View File

@ -24,6 +24,14 @@
{ {
"command": "extension.openGPTContextPanel", "command": "extension.openGPTContextPanel",
"title": "Open GPT Context Panel" "title": "Open GPT Context Panel"
},
{
"command": "extension.refreshSelectedFiles",
"title": "Refresh Selected Files"
},
{
"command": "extension.clearSelectedFiles",
"title": "Clear Selected Files"
} }
], ],
"menus": { "menus": {