From b7b27d8ced0498e3cfa8f498027a7ede7d3bd9bb Mon Sep 17 00:00:00 2001 From: Radek Davidek Date: Thu, 22 Jan 2026 15:31:45 +0100 Subject: [PATCH] changes highlighting --- .../cz/kamma/kfmanager/ui/FilePanelTab.java | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/main/java/cz/kamma/kfmanager/ui/FilePanelTab.java b/src/main/java/cz/kamma/kfmanager/ui/FilePanelTab.java index b7fd5e4..dc74cc1 100644 --- a/src/main/java/cz/kamma/kfmanager/ui/FilePanelTab.java +++ b/src/main/java/cz/kamma/kfmanager/ui/FilePanelTab.java @@ -69,6 +69,8 @@ public class FilePanelTab extends JPanel { private File currentArchiveSourceFile = null; private boolean inlineRenameActive = false; private boolean active = false; + private final Map changeTimestamps = new HashMap<>(); + private static final long CHANGE_HIGHLIGHT_DURATION = 500; // 0.5 seconds per item public FilePanelTab(String initialPath) { this(initialPath, true); @@ -1011,24 +1013,28 @@ public class FilePanelTab extends JPanel { */ public void refresh(boolean requestFocus) { List newItems = createFileItemList(currentDirectory); + long now = System.currentTimeMillis(); + + // Clean up expired timestamps + changeTimestamps.entrySet().removeIf(entry -> now - entry.getValue() > CHANGE_HIGHLIGHT_DURATION); + if (isSameContent(newItems, tableModel.items)) { - // Nothing changed since last refresh. If there were any "recently changed" - // highlights, clear them now as the files have stabilized. - boolean found = false; + // Nothing changed on disk since last refresh. + // Check if we need to clear highlight for items whose duration expired. + boolean repainNeeded = false; for (FileItem item : tableModel.items) { - if (item.isRecentlyChanged()) { + if (item.isRecentlyChanged() && !changeTimestamps.containsKey(item.getName())) { item.setRecentlyChanged(false); - found = true; + repainNeeded = true; } } - if (found) { + if (repainNeeded) { fileTable.repaint(); } return; } // Identify which items are new or have changed metadata (size/date) - final List changedNames = new ArrayList<>(); Map oldItemsMap = new HashMap<>(); for (FileItem item : tableModel.items) { oldItemsMap.put(item.getName(), item); @@ -1037,7 +1043,8 @@ public class FilePanelTab extends JPanel { for (FileItem newItem : newItems) { FileItem oldItem = oldItemsMap.get(newItem.getName()); if (oldItem == null || !newItem.isSameAs(oldItem)) { - changedNames.add(newItem.getName()); + // This is a new or modified item + changeTimestamps.put(newItem.getName(), now); } } @@ -1052,12 +1059,12 @@ public class FilePanelTab extends JPanel { } loadDirectory(currentDirectory, false, requestFocus, () -> { - // Restore marks and set recentlyChanged flag + // Restore marks and set recentlyChanged flag based on active timestamps for (FileItem item : tableModel.items) { if (markedNames.contains(item.getName())) { item.setMarked(true); } - if (changedNames.contains(item.getName())) { + if (changeTimestamps.containsKey(item.getName())) { item.setRecentlyChanged(true); } }