From 9c2ac5c84683344911b6d79f757a33276c8ca264 Mon Sep 17 00:00:00 2001 From: Radek Davidek Date: Tue, 3 Feb 2026 17:00:53 +0100 Subject: [PATCH] selecting files with ctrl and shift --- .../cz/kamma/kfmanager/ui/FilePanelTab.java | 63 ++++++++++++++++++- 1 file changed, 60 insertions(+), 3 deletions(-) diff --git a/src/main/java/cz/kamma/kfmanager/ui/FilePanelTab.java b/src/main/java/cz/kamma/kfmanager/ui/FilePanelTab.java index f8fa9a7..4231ba6 100644 --- a/src/main/java/cz/kamma/kfmanager/ui/FilePanelTab.java +++ b/src/main/java/cz/kamma/kfmanager/ui/FilePanelTab.java @@ -361,9 +361,9 @@ public class FilePanelTab extends JPanel { // Request focus on table even if clicking on empty area fileTable.requestFocusInWindow(); - // Single left-click should focus/select the item under cursor but - // should NOT toggle its marked state. This preserves keyboard - // marking (Insert) while making mouse clicks act as simple focus. + // Single left-click should focus/select the item under cursor and + // toggle its marked state if CTRL is held. + // Note: Marking toggle is handled in MOUSE_PRESSED for better responsiveness. if (e.getClickCount() % 2 == 1 && javax.swing.SwingUtilities.isLeftMouseButton(e)) { boolean selected = false; if (row >= 0) { @@ -420,6 +420,36 @@ public class FilePanelTab extends JPanel { FileItem item = tableModel.getItemFromBriefLayout(row, col); if (item != null) { int index = tableModel.items.indexOf(item); + + // Handle SHIFT+click selection range + if (e.isShiftDown()) { + int anchorRow = fileTable.getSelectionModel().getAnchorSelectionIndex(); + int anchorCol = briefCurrentColumn; + int anchorIndex = anchorCol * tableModel.briefRowsPerColumn + anchorRow; + + if (anchorIndex >= 0 && anchorIndex < tableModel.items.size()) { + int start = Math.min(anchorIndex, index); + int end = Math.max(anchorIndex, index); + for (int i = start; i <= end; i++) { + FileItem rangeItem = tableModel.items.get(i); + if (rangeItem != null && !rangeItem.getName().equals("..")) { + rangeItem.setMarked(true); + } + } + updateStatus(); + } + } + + // If CTRL is NOT pressed and SHIFT is NOT pressed, unselect all other items before selecting this one + if (!e.isControlDown() && !e.isShiftDown()) { + unselectAll(); + } + // Toggle marked state if CTRL is pressed + if (e.isControlDown() && !item.getName().equals("..")) { + item.setMarked(!item.isMarked()); + updateStatus(); + } + if (index >= 0) { int selRow = index % tableModel.briefRowsPerColumn; fileTable.setRowSelectionInterval(selRow, selRow); @@ -428,6 +458,33 @@ public class FilePanelTab extends JPanel { } } } else { + FileItem item = tableModel.getItem(row); + if (item != null) { + // Handle SHIFT+click selection range + if (e.isShiftDown()) { + int anchorIndex = fileTable.getSelectionModel().getAnchorSelectionIndex(); + if (anchorIndex >= 0 && anchorIndex < tableModel.items.size()) { + int start = Math.min(anchorIndex, row); + int end = Math.max(anchorIndex, row); + for (int i = start; i <= end; i++) { + FileItem rangeItem = tableModel.items.get(i); + if (rangeItem != null && !rangeItem.getName().equals("..")) { + rangeItem.setMarked(true); + } + } + updateStatus(); + } + } + + // If CTRL is NOT pressed and SHIFT is NOT pressed, unselect all other items before selecting this one + if (!e.isControlDown() && !e.isShiftDown()) { + unselectAll(); + } + if (e.isControlDown() && !item.getName().equals("..")) { + item.setMarked(!item.isMarked()); + updateStatus(); + } + } fileTable.setRowSelectionInterval(row, row); selected = true; }