-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement journal abbreviation storage in separate directory (Closes #10557) #12036
Closed
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3c52c60
Store journal lists in separate directory (#10557)
Daniel-Ruan 3e5b00b
Update CHANGELOG.md: Improve journal abbreviation management (#10557)
Daniel-Ruan 0c623c2
Refactor: Standardize Path creation and improve import order
Daniel-Ruan 977f9a4
Refine JournalAbbreviationPreferences for robustness (#10557)
Daniel-Ruan 302029a
Prevent NullPointerException in JournalAbbreviationPreferences (#10557)
Daniel-Ruan 1ee90d1
Implement centralized journal abbreviation storage (#10557)
Daniel-Ruan 5401d04
Improve null safety in journal abbreviation directory handling (#10557)
Daniel-Ruan 0498c42
Fix NullPointerException in getDefaultAbbreviationDir() method (#10557)
Daniel-Ruan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 55 additions & 1 deletion
56
src/main/java/org/jabref/logic/journals/JournalAbbreviationPreferences.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,75 @@ | ||
package org.jabref.logic.journals; | ||
|
||
import java.nio.file.Path; | ||
import java.util.List; | ||
|
||
import javafx.beans.property.BooleanProperty; | ||
import javafx.beans.property.ObjectProperty; | ||
import javafx.beans.property.SimpleBooleanProperty; | ||
import javafx.beans.property.SimpleObjectProperty; | ||
import javafx.collections.FXCollections; | ||
import javafx.collections.ObservableList; | ||
|
||
public class JournalAbbreviationPreferences { | ||
|
||
private final ObservableList<String> externalJournalLists; | ||
private final BooleanProperty useFJournalField; | ||
private final ObjectProperty<Path> journalAbbreviationDir; | ||
|
||
public JournalAbbreviationPreferences(List<String> externalJournalLists, boolean useFJournalField) { | ||
this(externalJournalLists, useFJournalField, getDefaultAbbreviationDir().toString()); | ||
} | ||
|
||
public JournalAbbreviationPreferences(List<String> externalJournalLists, | ||
boolean useFJournalField) { | ||
boolean useFJournalField, String directory) { | ||
this.externalJournalLists = FXCollections.observableArrayList(externalJournalLists); | ||
this.useFJournalField = new SimpleBooleanProperty(useFJournalField); | ||
this.journalAbbreviationDir = new SimpleObjectProperty<>( | ||
directory != null ? Path.of(directory) : getDefaultAbbreviationDir() | ||
); | ||
|
||
updateCustomCsvFile(this.journalAbbreviationDir.get()); | ||
|
||
this.journalAbbreviationDir.addListener((observable, oldValue, newValue) -> { | ||
updateCustomCsvFile(newValue); | ||
}); | ||
} | ||
|
||
private void updateCustomCsvFile(Path directory) { | ||
if (directory == null) { | ||
return; | ||
} | ||
Path newFilePath = JournalAbbreviationLoader.ensureJournalAbbreviationFileExists(directory); | ||
if (newFilePath != null) { | ||
String newFilePathString = newFilePath.toString(); | ||
// Remove old custom.csv path if it exists | ||
externalJournalLists.removeIf(path -> path.endsWith("custom.csv")); | ||
// Add new custom.csv path | ||
if (!externalJournalLists.contains(newFilePathString)) { | ||
externalJournalLists.add(newFilePathString); | ||
} | ||
} | ||
} | ||
|
||
public Path getJournalAbbreviationDir() { | ||
Path dir = journalAbbreviationDir.get(); | ||
return dir != null ? dir : getDefaultAbbreviationDir(); | ||
} | ||
|
||
public static Path getDefaultAbbreviationDir() { | ||
String appData = System.getenv("APPDATA"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have better methods for getting the AppDAta dir, see Directories class, please use that approach |
||
if (appData == null) { | ||
appData = System.getProperty("user.home"); | ||
} | ||
return Path.of(appData, ".jabref", "journals"); | ||
} | ||
|
||
public void setJournalAbbreviationDir(Path journalAbbreviationDir) { | ||
this.journalAbbreviationDir.set(journalAbbreviationDir); | ||
} | ||
|
||
public ObjectProperty<Path> journalAbbreviationDirProperty() { | ||
return journalAbbreviationDir; | ||
} | ||
|
||
public ObservableList<String> getExternalJournalLists() { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please revert the changes with the spaces here