@@ -345,9 +345,26 @@ private void buildFileTree() {
345345 rootNode .setExpanded (true );
346346 rootNode .setChildrenLoaded (true );
347347
348+ // Create a set of all directory paths for quick lookup
349+ Set <String > directoryPaths = new HashSet <>();
350+ for (SelectableFile file : allFiles ) {
351+ String path = file .path ();
352+ String [] parts = path .split ("[/\\ \\ ]" );
353+
354+ // Add all parent directories
355+ StringBuilder currentPath = new StringBuilder ();
356+ for (int i = 0 ; i < parts .length - 1 ; i ++) {
357+ if (currentPath .length () > 0 ) {
358+ currentPath .append ("/" );
359+ }
360+ currentPath .append (parts [i ]);
361+ directoryPaths .add (currentPath .toString ());
362+ }
363+ }
364+
348365 // Build tree from files
349366 for (SelectableFile file : allFiles ) {
350- addFileToTree (file );
367+ addFileToTree (file , directoryPaths );
351368 }
352369
353370 // Render root's children
@@ -358,18 +375,30 @@ private void buildFileTree() {
358375 updateSelectionInfo ();
359376 }
360377
361- private void addFileToTree (SelectableFile file ) {
378+ private void addFileToTree (SelectableFile file , Set < String > directoryPaths ) {
362379 String [] pathParts = file .path ().split ("[/\\ \\ ]" );
363380 FileTreeNode currentNode = rootNode ;
364381
365382 for (int i = 0 ; i < pathParts .length ; i ++) {
366383 String part = pathParts [i ];
367- boolean isLast = (i == pathParts .length - 1 );
384+
385+ // Build the full path up to this point
386+ StringBuilder pathBuilder = new StringBuilder ();
387+ for (int j = 0 ; j <= i ; j ++) {
388+ if (pathBuilder .length () > 0 ) {
389+ pathBuilder .append ("/" );
390+ }
391+ pathBuilder .append (pathParts [j ]);
392+ }
393+ String fullPath = pathBuilder .toString ();
394+
395+ // Determine if this is a directory
396+ boolean isDirectory = directoryPaths .contains (fullPath );
368397
369398 FileTreeNode childNode = findChild (currentNode , part );
370399 if (childNode == null ) {
371400 Path nodePath = currentNode .getPath ().resolve (part );
372- childNode = new FileTreeNode (nodePath , part , ! isLast );
401+ childNode = new FileTreeNode (nodePath , part , isDirectory );
373402 childNode .setChildrenLoaded (true );
374403 currentNode .addChild (childNode );
375404 }
0 commit comments