mirror of
https://github.com/Iheuzio/gpt-contextfiles.git
synced 2025-07-18 14:00:48 +00:00
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:
parent
93be5cbce3
commit
fbeb0cc703
73
extension.js
73
extension.js
@ -17,34 +17,32 @@ const selectedFiles = [];
|
|||||||
|
|
||||||
// Tree data provider for the selected files
|
// Tree data provider for the selected files
|
||||||
class FileDataProvider {
|
class FileDataProvider {
|
||||||
constructor() {
|
constructor() {
|
||||||
this._onDidChangeTreeData = new vscode.EventEmitter();
|
this._onDidChangeTreeData = new vscode.EventEmitter();
|
||||||
this.onDidChangeTreeData = this._onDidChangeTreeData.event;
|
this.onDidChangeTreeData = this._onDidChangeTreeData.event;
|
||||||
}
|
}
|
||||||
|
|
||||||
refresh() {
|
refresh() {
|
||||||
this._onDidChangeTreeData.fire();
|
this._onDidChangeTreeData.fire();
|
||||||
}
|
}
|
||||||
|
|
||||||
getTreeItem(element) {
|
getTreeItem(element) {
|
||||||
return {
|
return {
|
||||||
label: element.uri.fsPath,
|
label: element.uri.fsPath,
|
||||||
collapsibleState: vscode.TreeItemCollapsibleState.None
|
collapsibleState: vscode.TreeItemCollapsibleState.None
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
getChildren(element) {
|
getChildren(element) {
|
||||||
if (element) {
|
if (element) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return only the selected files
|
// Return only the selected files
|
||||||
return selectedFiles.filter(file => file.selected);
|
return selectedFiles.filter(file => file.selected);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 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,20 +100,35 @@ 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();
|
||||||
|
});
|
||||||
|
panel.webview.html = getWebviewContent();
|
||||||
|
} else if (message.command === 'refreshFiles') {
|
||||||
fileDataProvider.refresh();
|
fileDataProvider.refresh();
|
||||||
} else if (message.command === 'refreshSelectedFiles') {
|
panel.webview.html = getWebviewContent();
|
||||||
fileDataProvider.refresh();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Command for refreshing the selected files
|
// Command for refreshing the selected files
|
||||||
const refreshSelectedFilesCommand = vscode.commands.registerCommand('extension.refreshSelectedFiles', () => {
|
const refreshSelectedFilesCommand = vscode.commands.registerCommand('extension.refreshSelectedFiles', () => {
|
||||||
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
|
||||||
@ -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(() => {
|
||||||
|
26
package.json
26
package.json
@ -16,15 +16,23 @@
|
|||||||
"main": "./extension.js",
|
"main": "./extension.js",
|
||||||
"contributes": {
|
"contributes": {
|
||||||
"commands": [
|
"commands": [
|
||||||
{
|
{
|
||||||
"command": "extension.addFilesToGPTContext",
|
"command": "extension.addFilesToGPTContext",
|
||||||
"title": "Add Files to GPT Context",
|
"title": "Add Files to GPT Context",
|
||||||
"category": "Explorer"
|
"category": "Explorer"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"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": {
|
||||||
"explorer/context": [
|
"explorer/context": [
|
||||||
|
Loading…
Reference in New Issue
Block a user