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 File currentArchiveSourceFile = null;
private boolean inlineRenameActive = false; private boolean inlineRenameActive = false;
private boolean active = 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) { public FilePanelTab(String initialPath) {
this(initialPath, true); this(initialPath, true);
@ -1011,24 +1013,28 @@ public class FilePanelTab extends JPanel {
*/ */
public void refresh(boolean requestFocus) { public void refresh(boolean requestFocus) {
List<FileItem> newItems = createFileItemList(currentDirectory); 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)) { if (isSameContent(newItems, tableModel.items)) {
// Nothing changed since last refresh. If there were any "recently changed" // Nothing changed on disk since last refresh.
// highlights, clear them now as the files have stabilized. // Check if we need to clear highlight for items whose duration expired.
boolean found = false; boolean repainNeeded = false;
for (FileItem item : tableModel.items) { for (FileItem item : tableModel.items) {
if (item.isRecentlyChanged()) { if (item.isRecentlyChanged() && !changeTimestamps.containsKey(item.getName())) {
item.setRecentlyChanged(false); item.setRecentlyChanged(false);
found = true; repainNeeded = true;
} }
} }
if (found) { if (repainNeeded) {
fileTable.repaint(); fileTable.repaint();
} }
return; return;
} }
// Identify which items are new or have changed metadata (size/date) // Identify which items are new or have changed metadata (size/date)
final List<String> changedNames = new ArrayList<>();
Map<String, FileItem> oldItemsMap = new HashMap<>(); Map<String, FileItem> oldItemsMap = new HashMap<>();
for (FileItem item : tableModel.items) { for (FileItem item : tableModel.items) {
oldItemsMap.put(item.getName(), item); oldItemsMap.put(item.getName(), item);
@ -1037,7 +1043,8 @@ public class FilePanelTab extends JPanel {
for (FileItem newItem : newItems) { for (FileItem newItem : newItems) {
FileItem oldItem = oldItemsMap.get(newItem.getName()); FileItem oldItem = oldItemsMap.get(newItem.getName());
if (oldItem == null || !newItem.isSameAs(oldItem)) { 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, () -> { 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) { for (FileItem item : tableModel.items) {
if (markedNames.contains(item.getName())) { if (markedNames.contains(item.getName())) {
item.setMarked(true); item.setMarked(true);
} }
if (changedNames.contains(item.getName())) { if (changeTimestamps.containsKey(item.getName())) {
item.setRecentlyChanged(true); item.setRecentlyChanged(true);
} }
} }