From 1796919b1d259002f56f0f1852046434e9053ad1 Mon Sep 17 00:00:00 2001 From: Deepti Date: Sat, 29 Nov 2025 22:05:35 +0530 Subject: [PATCH 1/5] Convert absolute paths to relative paths in Recent Files --- .../LastFilesOpenedPreferences.java | 42 ++++++++++++++++--- .../org/jabref/logic/util/io/FileHistory.java | 23 +++++++++- 2 files changed, 57 insertions(+), 8 deletions(-) diff --git a/jablib/src/main/java/org/jabref/logic/preferences/LastFilesOpenedPreferences.java b/jablib/src/main/java/org/jabref/logic/preferences/LastFilesOpenedPreferences.java index f136c0aa64a..dbc5ff1ce1e 100644 --- a/jablib/src/main/java/org/jabref/logic/preferences/LastFilesOpenedPreferences.java +++ b/jablib/src/main/java/org/jabref/logic/preferences/LastFilesOpenedPreferences.java @@ -14,20 +14,23 @@ public class LastFilesOpenedPreferences { // the last libraries that were open when jabref closes and should be reopened on startup private final ObservableList lastFilesOpened; - private final ObjectProperty lastFocusedFile; // observable list last files opened in the file menu private final FileHistory fileHistory; public LastFilesOpenedPreferences(List lastFilesOpened, Path lastFocusedFile, FileHistory fileHistory) { - this.lastFilesOpened = FXCollections.observableArrayList(lastFilesOpened); - this.lastFocusedFile = new SimpleObjectProperty<>(lastFocusedFile); + this.lastFilesOpened = FXCollections.observableArrayList( + lastFilesOpened.stream().map(this::toRelative).toList() + ); + this.lastFocusedFile = new SimpleObjectProperty<>(toRelative(lastFocusedFile)); this.fileHistory = fileHistory; } public ObservableList getLastFilesOpened() { - return lastFilesOpened; + return FXCollections.observableArrayList( + lastFilesOpened.stream().map(this::toAbsolute).toList() + ); } public void setLastFilesOpened(List files) { @@ -35,7 +38,7 @@ public void setLastFilesOpened(List files) { } public Path getLastFocusedFile() { - return lastFocusedFile.get(); + return toAbsolute(lastFocusedFile.get()); } public ObjectProperty lastFocusedFileProperty() { @@ -43,10 +46,37 @@ public ObjectProperty lastFocusedFileProperty() { } public void setLastFocusedFile(Path lastFocusedFile) { - this.lastFocusedFile.set(lastFocusedFile); + this.lastFocusedFile.set(toRelative(lastFocusedFile)); } public FileHistory getFileHistory() { return fileHistory; } + + // ------------------------- + // Relative / Absolute helpers + // ------------------------- + + private Path toRelative(Path absolutePath) { + if (absolutePath == null) { + return null; + } + Path workingDir = Path.of("").toAbsolutePath(); + try { + return workingDir.relativize(absolutePath); + } catch (Exception e) { + return absolutePath; // fallback + } + } + + private Path toAbsolute(Path storedPath) { + if (storedPath == null) { + return null; + } + Path workingDir = Path.of("").toAbsolutePath(); + if (!storedPath.isAbsolute()) { + return workingDir.resolve(storedPath).normalize(); + } + return storedPath; + } } diff --git a/jablib/src/main/java/org/jabref/logic/util/io/FileHistory.java b/jablib/src/main/java/org/jabref/logic/util/io/FileHistory.java index 7ccbcadc88d..77a4c3cc1d2 100644 --- a/jablib/src/main/java/org/jabref/logic/util/io/FileHistory.java +++ b/jablib/src/main/java/org/jabref/logic/util/io/FileHistory.java @@ -27,7 +27,8 @@ public int size() { @Override protected void doAdd(int index, Path element) { - history.add(index, element); + history.add(index, toRelative(element.toAbsolutePath())); + } @Override @@ -45,7 +46,8 @@ protected Path doRemove(int index) { */ public void newFile(Path file) { removeItem(file); - this.addFirst(file); + this.addFirst(toRelative(file.toAbsolutePath())); + while (size() > HISTORY_SIZE) { history.remove(HISTORY_SIZE); } @@ -58,4 +60,21 @@ public void removeItem(Path file) { public static FileHistory of(List list) { return new FileHistory(new ArrayList<>(list)); } + + private Path toRelative(Path absolutePath) { + Path workingDir = Path.of("").toAbsolutePath(); + try { + return workingDir.relativize(absolutePath); + } catch (Exception e) { + return absolutePath; // fallback + } +} + +private Path toAbsolute(Path storedPath) { + Path workingDir = Path.of("").toAbsolutePath(); + if (!storedPath.isAbsolute()) { + return workingDir.resolve(storedPath).normalize(); + } + return storedPath; } +} \ No newline at end of file From 6d767edf4aa2bc943a177548b59fbebdc43295ee Mon Sep 17 00:00:00 2001 From: Carl Christian Snethlage <50491877+calixtus@users.noreply.github.com> Date: Sun, 30 Nov 2025 19:17:40 +0100 Subject: [PATCH 2/5] Indentation --- .../org/jabref/logic/util/io/FileHistory.java | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/jablib/src/main/java/org/jabref/logic/util/io/FileHistory.java b/jablib/src/main/java/org/jabref/logic/util/io/FileHistory.java index 77a4c3cc1d2..c83cf593716 100644 --- a/jablib/src/main/java/org/jabref/logic/util/io/FileHistory.java +++ b/jablib/src/main/java/org/jabref/logic/util/io/FileHistory.java @@ -62,19 +62,19 @@ public static FileHistory of(List list) { } private Path toRelative(Path absolutePath) { - Path workingDir = Path.of("").toAbsolutePath(); - try { - return workingDir.relativize(absolutePath); - } catch (Exception e) { - return absolutePath; // fallback + Path workingDir = Path.of("").toAbsolutePath(); + try { + return workingDir.relativize(absolutePath); + } catch (Exception e) { + return absolutePath; // fallback + } } -} -private Path toAbsolute(Path storedPath) { - Path workingDir = Path.of("").toAbsolutePath(); - if (!storedPath.isAbsolute()) { - return workingDir.resolve(storedPath).normalize(); + private Path toAbsolute(Path storedPath) { + Path workingDir = Path.of("").toAbsolutePath(); + if (!storedPath.isAbsolute()) { + return workingDir.resolve(storedPath).normalize(); + } + return storedPath; } - return storedPath; } -} \ No newline at end of file From c358a9ae745d85dc91ed476623730819a16e9a33 Mon Sep 17 00:00:00 2001 From: Carl Christian Snethlage <50491877+calixtus@users.noreply.github.com> Date: Sun, 30 Nov 2025 19:18:23 +0100 Subject: [PATCH 3/5] Clean up LastFilesOpenedPreferences.java Removed commented-out section for relative/absolute helpers. --- .../jabref/logic/preferences/LastFilesOpenedPreferences.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/jablib/src/main/java/org/jabref/logic/preferences/LastFilesOpenedPreferences.java b/jablib/src/main/java/org/jabref/logic/preferences/LastFilesOpenedPreferences.java index dbc5ff1ce1e..36b0136a151 100644 --- a/jablib/src/main/java/org/jabref/logic/preferences/LastFilesOpenedPreferences.java +++ b/jablib/src/main/java/org/jabref/logic/preferences/LastFilesOpenedPreferences.java @@ -53,10 +53,6 @@ public FileHistory getFileHistory() { return fileHistory; } - // ------------------------- - // Relative / Absolute helpers - // ------------------------- - private Path toRelative(Path absolutePath) { if (absolutePath == null) { return null; From 1dc798612dfcbaaf5f045c8c9c93cd250b382cf8 Mon Sep 17 00:00:00 2001 From: Carl Christian Snethlage <50491877+calixtus@users.noreply.github.com> Date: Sun, 30 Nov 2025 19:19:11 +0100 Subject: [PATCH 4/5] Restore newline --- .../org/jabref/logic/preferences/LastFilesOpenedPreferences.java | 1 + 1 file changed, 1 insertion(+) diff --git a/jablib/src/main/java/org/jabref/logic/preferences/LastFilesOpenedPreferences.java b/jablib/src/main/java/org/jabref/logic/preferences/LastFilesOpenedPreferences.java index 36b0136a151..b5e69988ba3 100644 --- a/jablib/src/main/java/org/jabref/logic/preferences/LastFilesOpenedPreferences.java +++ b/jablib/src/main/java/org/jabref/logic/preferences/LastFilesOpenedPreferences.java @@ -14,6 +14,7 @@ public class LastFilesOpenedPreferences { // the last libraries that were open when jabref closes and should be reopened on startup private final ObservableList lastFilesOpened; + private final ObjectProperty lastFocusedFile; // observable list last files opened in the file menu From 3d4e7b35a2361ef9c47a8f2a5aeefe5f81d1e1be Mon Sep 17 00:00:00 2001 From: Deepti Date: Tue, 2 Dec 2025 19:40:48 +0530 Subject: [PATCH 5/5] Fix indentation and formatting in FileHistory.java --- .../src/main/java/org/jabref/logic/util/io/FileHistory.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jablib/src/main/java/org/jabref/logic/util/io/FileHistory.java b/jablib/src/main/java/org/jabref/logic/util/io/FileHistory.java index c83cf593716..d80e13e1701 100644 --- a/jablib/src/main/java/org/jabref/logic/util/io/FileHistory.java +++ b/jablib/src/main/java/org/jabref/logic/util/io/FileHistory.java @@ -28,7 +28,6 @@ public int size() { @Override protected void doAdd(int index, Path element) { history.add(index, toRelative(element.toAbsolutePath())); - } @Override @@ -42,7 +41,8 @@ protected Path doRemove(int index) { } /** - * Adds the file to the top of the list. If it already is in the list, it is merely moved to the top. + * Adds the file to the top of the list. If it already is in the list, it is + * merely moved to the top. */ public void newFile(Path file) { removeItem(file);