disk selection fix
This commit is contained in:
parent
a3f97f9369
commit
7cbff72d38
@ -19,6 +19,7 @@ public class FilePanel extends JPanel {
|
|||||||
private JLabel driveInfoLabel;
|
private JLabel driveInfoLabel;
|
||||||
private cz.kamma.kfmanager.config.AppConfig appConfig;
|
private cz.kamma.kfmanager.config.AppConfig appConfig;
|
||||||
private Runnable onDirectoryChangedAll;
|
private Runnable onDirectoryChangedAll;
|
||||||
|
private boolean ignoreComboActions = false;
|
||||||
|
|
||||||
public FilePanel(String initialPath) {
|
public FilePanel(String initialPath) {
|
||||||
initComponents();
|
initComponents();
|
||||||
@ -112,12 +113,22 @@ public class FilePanel extends JPanel {
|
|||||||
driveInfoLabel.setFont(new Font("SansSerif", Font.PLAIN, 12));
|
driveInfoLabel.setFont(new Font("SansSerif", Font.PLAIN, 12));
|
||||||
driveInfoLabel.setBorder(BorderFactory.createEmptyBorder(0,6,0,6));
|
driveInfoLabel.setBorder(BorderFactory.createEmptyBorder(0,6,0,6));
|
||||||
|
|
||||||
// Require explicit confirmation (Enter) to load selected drive.
|
// Interaction behavior:
|
||||||
// Selection changes (mouse/typing) only update the selected item; loading occurs on Enter.
|
// - Mouse click in dropdown: Refresh immediately.
|
||||||
driveCombo.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_ENTER, 0), "confirmDrive");
|
// - Keyboard navigation (arrows): Update info label only, refresh only on Enter.
|
||||||
driveCombo.getActionMap().put("confirmDrive", new AbstractAction() {
|
driveCombo.addActionListener(e -> {
|
||||||
@Override
|
if (ignoreComboActions) return;
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
|
// Determine if we should trigger directory load.
|
||||||
|
// We want to skip arrow keys and only react to Mouse or Enter.
|
||||||
|
java.awt.AWTEvent currentEvent = java.awt.EventQueue.getCurrentEvent();
|
||||||
|
if (currentEvent instanceof java.awt.event.KeyEvent) {
|
||||||
|
java.awt.event.KeyEvent ke = (java.awt.event.KeyEvent) currentEvent;
|
||||||
|
if (ke.getKeyCode() != java.awt.event.KeyEvent.VK_ENTER) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Object selObj = driveCombo.getSelectedItem();
|
Object selObj = driveCombo.getSelectedItem();
|
||||||
if (selObj instanceof File) {
|
if (selObj instanceof File) {
|
||||||
File sel = (File) selObj;
|
File sel = (File) selObj;
|
||||||
@ -129,7 +140,6 @@ public class FilePanel extends JPanel {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
// Compose a small left panel with the combo and info label
|
// Compose a small left panel with the combo and info label
|
||||||
JPanel leftPanel = new JPanel();
|
JPanel leftPanel = new JPanel();
|
||||||
@ -413,6 +423,8 @@ public class FilePanel extends JPanel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void populateDrives() {
|
private void populateDrives() {
|
||||||
|
ignoreComboActions = true;
|
||||||
|
try {
|
||||||
driveCombo.removeAllItems();
|
driveCombo.removeAllItems();
|
||||||
java.util.Set<File> driveSet = new java.util.LinkedHashSet<>();
|
java.util.Set<File> driveSet = new java.util.LinkedHashSet<>();
|
||||||
|
|
||||||
@ -472,6 +484,9 @@ public class FilePanel extends JPanel {
|
|||||||
|
|
||||||
// Update info for currently selected drive
|
// Update info for currently selected drive
|
||||||
updateDriveInfoFromSelection();
|
updateDriveInfoFromSelection();
|
||||||
|
} finally {
|
||||||
|
ignoreComboActions = false;
|
||||||
|
}
|
||||||
|
|
||||||
// Update info label on selection changes (visual selection only)
|
// Update info label on selection changes (visual selection only)
|
||||||
driveCombo.addItemListener(ev -> {
|
driveCombo.addItemListener(ev -> {
|
||||||
@ -577,6 +592,7 @@ public class FilePanel extends JPanel {
|
|||||||
FilePanelTab currentTab = getCurrentTab();
|
FilePanelTab currentTab = getCurrentTab();
|
||||||
if (currentTab != null) {
|
if (currentTab != null) {
|
||||||
// Update drive combo selection to match current directory
|
// Update drive combo selection to match current directory
|
||||||
|
ignoreComboActions = true;
|
||||||
try {
|
try {
|
||||||
File cur = currentTab.getCurrentDirectory();
|
File cur = currentTab.getCurrentDirectory();
|
||||||
if (cur != null) {
|
if (cur != null) {
|
||||||
@ -585,7 +601,10 @@ public class FilePanel extends JPanel {
|
|||||||
// also update info label to reflect current tab's root
|
// also update info label to reflect current tab's root
|
||||||
updateDriveInfo(root);
|
updateDriveInfo(root);
|
||||||
}
|
}
|
||||||
} catch (Exception ignore) {}
|
} catch (Exception ignore) {
|
||||||
|
} finally {
|
||||||
|
ignoreComboActions = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user