Skip to content

Commit

Permalink
Fix #276 : Sort files by name in attached/popup file list
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanj committed Sep 8, 2024
1 parent 8ff478e commit 41a2434
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/main/java/com/devoxx/genie/service/FileListManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class FileListManager {
Expand Down Expand Up @@ -41,11 +42,12 @@ public void addFiles(@NotNull List<VirtualFile> newFiles) {
}
}
if (!actuallyAddedFiles.isEmpty()) {
actuallyAddedFiles.sort(Comparator.comparing(VirtualFile::getName, String.CASE_INSENSITIVE_ORDER));
notifyObserversOfBatchAdd(actuallyAddedFiles);
}
}

private void notifyObserversOfBatchAdd(List<VirtualFile> addedFiles) {
private void notifyObserversOfBatchAdd(@NotNull List<VirtualFile> addedFiles) {
for (FileListObserver observer : observers) {
observer.filesAdded(addedFiles);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

import static com.devoxx.genie.model.Constant.*;
import static com.devoxx.genie.ui.util.DevoxxGenieIconsUtil.*;
Expand Down Expand Up @@ -157,9 +160,11 @@ private void createSearchButton(@NotNull JPanel panel,
*/
private void selectFilesForPromptContext(ActionEvent e) {
java.util.List<VirtualFile> openFiles = editorFileButtonManager.getOpenFiles();
List<VirtualFile> sortedFiles = new ArrayList<>(openFiles);
sortedFiles.sort(Comparator.comparing(VirtualFile::getName, String.CASE_INSENSITIVE_ORDER));

JBPopup popup = JBPopupFactory.getInstance()
.createComponentPopupBuilder(FileSelectionPanelFactory.createPanel(project, openFiles), null)
.createComponentPopupBuilder(FileSelectionPanelFactory.createPanel(project, sortedFiles), null)
.setTitle("Filter and Double-Click To Add To Prompt Context")
.setRequestFocus(true)
.setResizable(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.awt.*;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;

Expand Down Expand Up @@ -179,6 +180,8 @@ public void run(@NotNull ProgressIndicator indicator) {
}
}
}

foundFiles.sort(Comparator.comparing(VirtualFile::getName, String.CASE_INSENSITIVE_ORDER));
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public class PromptContextFileListPanel extends JPanel
private final JBScrollPane filesScrollPane;
private final JPanel filesPanel; // new panel for files
private final Project project;
private final int MAX_VISIBLE_FILES = 3;

public PromptContextFileListPanel(Project project) {
this.project = project;
Expand Down Expand Up @@ -81,6 +80,7 @@ private void updateFilesPanelVisibility() {
filesScrollPane.setPreferredSize(new Dimension(0, 0));
} else {
filesScrollPane.setVisible(true);
int MAX_VISIBLE_FILES = 3;
int fileCount = Math.min(fileListManager.size(), MAX_VISIBLE_FILES);
int heightPerFile = 30;
int prefHeight = fileCount * heightPerFile;
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<LI>Feat #225 : Support for OpenRouter</LI>
<LI>Fix #220 : Sort conversation history by date</LI>
<LI>Fix #226 : Migrate to Langchain4J 0.34.0 and use new Gemini (with API_KEY) code</LI>
<LI>Fix #276 : Sort the files in the attachment popup</LI>
</UL>
<h2>V0.2.17</h2>
<UL>
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#Sun Sep 08 13:31:24 CEST 2024
#Sun Sep 08 13:44:28 CEST 2024
version=0.2.18

0 comments on commit 41a2434

Please sign in to comment.