changes highlighting

This commit is contained in:
Radek Davidek 2026-01-22 15:31:45 +01:00
parent 42ea4fec7a
commit b7b27d8ced

View File

@ -69,6 +69,8 @@ public class FilePanelTab extends JPanel {
private File currentArchiveSourceFile = null;
private boolean inlineRenameActive = false;
private boolean active = false;
private final Map<String, Long> 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<FileItem> 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<String> changedNames = new ArrayList<>();
Map<String, FileItem> 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);
}
}