diff --git a/src/main/java/cz/kamma/kfmanager/ui/FilePanel.java b/src/main/java/cz/kamma/kfmanager/ui/FilePanel.java index 5e259ad..d67ae85 100644 --- a/src/main/java/cz/kamma/kfmanager/ui/FilePanel.java +++ b/src/main/java/cz/kamma/kfmanager/ui/FilePanel.java @@ -189,8 +189,7 @@ public class FilePanel extends JPanel { rootButton.setToolTipText("Computer / Root"); rootButton.addActionListener(e -> { if (MainApp.CURRENT_OS == MainApp.OS.WINDOWS) { - // On Windows, the "root" is typically C:\ - loadDirectory(new File("C:\\")); + loadDirectory(resolveWindowsCurrentDriveRoot()); } else { loadDirectory(new File("/")); } @@ -766,6 +765,34 @@ public class FilePanel extends JPanel { double gb = bytes / 1024.0 / 1024.0 / 1024.0; return "%.1f".formatted(gb); } + + private File resolveWindowsCurrentDriveRoot() { + // Prefer root of the active tab's current directory, e.g. D:\\ when browsing D:. + File currentDir = getCurrentDirectory(); + if (currentDir != null) { + try { + java.nio.file.Path rootPath = currentDir.toPath().toAbsolutePath().normalize().getRoot(); + if (rootPath != null) { + return rootPath.toFile(); + } + } catch (Exception ignore) { + } + } + + // Fallback to selected drive in dropdown. + Object selected = driveCombo != null ? driveCombo.getSelectedItem() : null; + if (selected instanceof File drive) { + return drive; + } + + // Final fallback: first available filesystem root. + File[] roots = File.listRoots(); + if (roots != null && roots.length > 0) { + return roots[0]; + } + + return new File("C:\\"); + } /** * Request focus on the table in the current tab