-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add multiple selected files using right-click #221
Comments
According to Claude this is what needs happening: To add the feature of selecting multiple files for the "Add file to window context" menu, we need to modify a few components of the plugin. Let's go through the changes step by step:
public class AddFileAction extends DumbAwareAction {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
Project project = e.getProject();
if (project == null) {
return;
}
ensureToolWindowVisible(project);
FileListManager fileListManager = FileListManager.getInstance();
VirtualFile[] selectedFiles = e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY);
if (selectedFiles != null && selectedFiles.length > 0) {
List<VirtualFile> filesToAdd = new ArrayList<>();
for (VirtualFile file : selectedFiles) {
if (!file.isDirectory() && !fileListManager.contains(file)) {
filesToAdd.add(file);
}
}
if (!filesToAdd.isEmpty()) {
fileListManager.addFiles(filesToAdd);
NotificationUtil.sendNotification(project, "Added " + filesToAdd.size() + " file(s) to prompt context");
} else {
NotificationUtil.sendNotification(project, "No new files to add or only directories selected");
}
} else {
NotificationUtil.sendNotification(project, "No files selected");
}
}
@Override
public void update(@NotNull AnActionEvent e) {
VirtualFile[] files = e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY);
e.getPresentation().setEnabledAndVisible(files != null && files.length > 0);
}
}
public class FileListManager {
// ... existing code ...
public void addFiles(@NotNull List<VirtualFile> newFiles) {
List<VirtualFile> actuallyAddedFiles = new ArrayList<>();
for (VirtualFile file : newFiles) {
if (!files.contains(file)) {
files.add(file);
actuallyAddedFiles.add(file);
}
}
if (!actuallyAddedFiles.isEmpty()) {
notifyObserversOfBatchAdd(actuallyAddedFiles);
}
}
private void notifyObserversOfBatchAdd(List<VirtualFile> addedFiles) {
for (FileListObserver observer : observers) {
observer.filesAdded(addedFiles);
}
}
// ... existing code ...
}
public interface FileListObserver {
void fileAdded(VirtualFile file);
void filesAdded(List<VirtualFile> files);
void allFilesRemoved();
}
public class PromptContextFileListPanel extends JPanel implements FileListObserver {
// ... existing code ...
@Override
public void filesAdded(List<VirtualFile> files) {
for (VirtualFile file : files) {
FileEntryComponent fileLabel = new FileEntryComponent(project, file, this);
filesPanel.add(fileLabel);
}
updateFilesPanelVisibility();
updateUIState();
}
// ... existing code ...
}
<action id="AddFileToContextWindow"
class="com.devoxx.genie.action.AddFileAction"
text="Add File(s) to Window Context"
description="Add selected file(s) to the prompt context">
<add-to-group group-id="ProjectViewPopupMenu" anchor="after" relative-to-action="AddToFavorites"/>
</action> These changes will allow users to select multiple files and add them all to the window context at once. The action will be enabled as long as at least one file is selected, and it will handle both single and multiple file selections appropriately. Remember to update any relevant tests to cover the new functionality, especially for the This implementation maintains the existing functionality while extending it to handle multiple files. It also provides feedback to the user about how many files were added or if no new files could be added (e.g., if all selected files were already in the context or if only directories were selected). |
When more than one file is selected and user opens the popup menu, the "Add file to window context" should add all selected files not just one.
It should also say : "Add File(s) to Context Window"
The text was updated successfully, but these errors were encountered: