disk change opens oposite panel location
This commit is contained in:
parent
561beb1e3e
commit
d7bcc04893
@ -23,6 +23,7 @@ public class FilePanel extends JPanel {
|
|||||||
private cz.kamma.kfmanager.config.AppConfig appConfig;
|
private cz.kamma.kfmanager.config.AppConfig appConfig;
|
||||||
private Runnable onDirectoryChangedAll;
|
private Runnable onDirectoryChangedAll;
|
||||||
private java.util.function.Consumer<JTable> onTableCreated;
|
private java.util.function.Consumer<JTable> onTableCreated;
|
||||||
|
private java.util.function.Function<File, File> driveSelectionTargetResolver;
|
||||||
private boolean ignoreComboActions = false;
|
private boolean ignoreComboActions = false;
|
||||||
private boolean active = false;
|
private boolean active = false;
|
||||||
|
|
||||||
@ -39,6 +40,10 @@ public class FilePanel extends JPanel {
|
|||||||
this.onTableCreated = callback;
|
this.onTableCreated = callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setDriveSelectionTargetResolver(java.util.function.Function<File, File> resolver) {
|
||||||
|
this.driveSelectionTargetResolver = resolver;
|
||||||
|
}
|
||||||
|
|
||||||
/** Start inline rename on the currently selected tab/table. */
|
/** Start inline rename on the currently selected tab/table. */
|
||||||
public void startInlineRename() {
|
public void startInlineRename() {
|
||||||
FilePanelTab tab = getCurrentTab();
|
FilePanelTab tab = getCurrentTab();
|
||||||
@ -117,7 +122,19 @@ public class FilePanel extends JPanel {
|
|||||||
if (selObj instanceof File sel) {
|
if (selObj instanceof File sel) {
|
||||||
FilePanelTab currentTab = getCurrentTab();
|
FilePanelTab currentTab = getCurrentTab();
|
||||||
if (currentTab != null) {
|
if (currentTab != null) {
|
||||||
currentTab.loadDirectory(sel);
|
File targetDirectory = sel;
|
||||||
|
if (driveSelectionTargetResolver != null) {
|
||||||
|
try {
|
||||||
|
File resolved = driveSelectionTargetResolver.apply(sel);
|
||||||
|
if (resolved != null && resolved.exists() && resolved.isDirectory() && isWithinSelectedDrive(resolved, sel)) {
|
||||||
|
targetDirectory = resolved;
|
||||||
|
}
|
||||||
|
} catch (Exception ignore) {
|
||||||
|
// fall back to selected drive root
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
currentTab.loadDirectory(targetDirectory);
|
||||||
SwingUtilities.invokeLater(() -> {
|
SwingUtilities.invokeLater(() -> {
|
||||||
try { currentTab.getFileTable().requestFocusInWindow(); } catch (Exception ignore) {}
|
try { currentTab.getFileTable().requestFocusInWindow(); } catch (Exception ignore) {}
|
||||||
});
|
});
|
||||||
@ -238,6 +255,25 @@ public class FilePanel extends JPanel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isWithinSelectedDrive(File directory, File selectedDrive) {
|
||||||
|
try {
|
||||||
|
java.nio.file.Path dirPath = directory.toPath().toAbsolutePath().normalize();
|
||||||
|
java.nio.file.Path selectedPath = selectedDrive.toPath().toAbsolutePath().normalize();
|
||||||
|
if (dirPath.startsWith(selectedPath)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
java.nio.file.Path dirRoot = dirPath.getRoot();
|
||||||
|
java.nio.file.Path selectedRoot = selectedPath.getRoot();
|
||||||
|
return dirRoot != null
|
||||||
|
&& selectedRoot != null
|
||||||
|
&& dirRoot.equals(selectedRoot)
|
||||||
|
&& selectedPath.equals(selectedRoot);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show the drive dropdown popup and focus it.
|
* Show the drive dropdown popup and focus it.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -144,11 +144,14 @@ public class MainWindow extends JFrame {
|
|||||||
// Provide a callback so tabs inside the panel can request switching panels with TAB
|
// Provide a callback so tabs inside the panel can request switching panels with TAB
|
||||||
rightPanel.setSwitchPanelCallback(() -> switchPanelsFromChild());
|
rightPanel.setSwitchPanelCallback(() -> switchPanelsFromChild());
|
||||||
rightPanel.setOnDirectoryChangedAll(() -> updateCommandLinePrompt());
|
rightPanel.setOnDirectoryChangedAll(() -> updateCommandLinePrompt());
|
||||||
rightPanel.setOnTableCreated(table -> {
|
rightPanel.setOnTableCreated(table -> {
|
||||||
setupFileTable(table, rightPanel);
|
setupFileTable(table, rightPanel);
|
||||||
});
|
});
|
||||||
setupFileTable(rightPanel.getFileTable(), rightPanel);
|
setupFileTable(rightPanel.getFileTable(), rightPanel);
|
||||||
|
|
||||||
|
leftPanel.setDriveSelectionTargetResolver(selectedDrive -> getPreferredDirectoryFromOppositePanel(selectedDrive, rightPanel));
|
||||||
|
rightPanel.setDriveSelectionTargetResolver(selectedDrive -> getPreferredDirectoryFromOppositePanel(selectedDrive, leftPanel));
|
||||||
|
|
||||||
// Load and set ViewMode for right panel
|
// Load and set ViewMode for right panel
|
||||||
try {
|
try {
|
||||||
ViewMode rightViewMode = ViewMode.valueOf(config.getRightPanelViewMode());
|
ViewMode rightViewMode = ViewMode.valueOf(config.getRightPanelViewMode());
|
||||||
@ -2312,6 +2315,33 @@ public class MainWindow extends JFrame {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private File getPreferredDirectoryFromOppositePanel(File selectedDrive, FilePanel oppositePanel) {
|
||||||
|
if (selectedDrive == null || oppositePanel == null) return selectedDrive;
|
||||||
|
File oppositeDirectory = oppositePanel.getCurrentDirectory();
|
||||||
|
if (oppositeDirectory == null || !oppositeDirectory.exists() || !oppositeDirectory.isDirectory()) {
|
||||||
|
return selectedDrive;
|
||||||
|
}
|
||||||
|
return isWithinSelectedDrive(oppositeDirectory, selectedDrive) ? oppositeDirectory : selectedDrive;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isWithinSelectedDrive(File directory, File selectedDrive) {
|
||||||
|
try {
|
||||||
|
java.nio.file.Path dirPath = directory.toPath().toAbsolutePath().normalize();
|
||||||
|
java.nio.file.Path selectedPath = selectedDrive.toPath().toAbsolutePath().normalize();
|
||||||
|
if (dirPath.startsWith(selectedPath)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
java.nio.file.Path dirRoot = dirPath.getRoot();
|
||||||
|
java.nio.file.Path selectedRoot = selectedPath.getRoot();
|
||||||
|
return dirRoot != null
|
||||||
|
&& selectedRoot != null
|
||||||
|
&& dirRoot.equals(selectedRoot)
|
||||||
|
&& selectedPath.equals(selectedRoot);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the view mode for the active panel
|
* Set the view mode for the active panel
|
||||||
*/
|
*/
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user