-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Fix for issue 10042 #12854
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
Fix for issue 10042 #12854
Conversation
* Localize string, add preview header Signed-off-by: subhramit <[email protected]> * Add changelog entry Signed-off-by: subhramit <[email protected]> --------- Signed-off-by: subhramit <[email protected]>
Did you search for "default" in JabRef's code? Hint: org.jabref.gui.preferences.JabRefGuiPreferences#JabRefGuiPreferences I replied here, because the question belongs more to the code than to the issue itself. |
Hi, yes, I looked into the JabRefGuiPreferences file. However, there is no gui/linkedfiles/LinkedFilesPreferences similar to say gui/groups/GroupsPreferences or gui/entryeditors/EntryEditorPreferences, and was wondering how the linked files preferences, such as autolinking files with names starting with the citation key or moving deleted files to trash are set. (I could not find where any of the linked file preferences are set either together or separately) I may be overlooking something simple, but in this case, would it require me to create the gui/linkedfile/LinkedFilesPreferences and refactor? |
AUTOLINK_EXACT_KEY_ONLY is in CliPreferences, use double shift in Intellij so search for stuff |
storagepath += preferences.getFilePreferences().getLinkedFileDirectory(); | ||
} | ||
|
||
Pattern pattern = Pattern.compile("/"); |
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.
The pattern is compiled inside the method and used multiple times. It should be a static final field to avoid recompilation and improve performance.
if (generalFileDirectory.isPresent()) { | ||
storagepath += generalFileDirectory.get(); | ||
} else { | ||
storagepath += preferences.getFilePreferences().getLinkedFileDirectory(); | ||
} |
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.
The code should follow the fail-fast principle by handling invalid states early and avoiding else branches. This can be refactored for better readability.
Thank you! |
b702a3d
to
411c380
Compare
public BooleanProperty copyLinkedFilesProperty() { | ||
return this.copyLinkedFilesProperty; | ||
} |
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.
The method 'copyLinkedFilesProperty' should return an Optional instead of potentially returning null, adhering to modern Java practices.
public StringProperty linkedFileDirectoryProperty() { | ||
return linkedFileDirectoryProperty; | ||
} |
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.
The method 'linkedFileDirectoryProperty' should return an Optional instead of potentially returning null, following modern Java practices.
Do not force-push! Force pushing is a very bad practice when working together on a project (mainly because it is not supported well by GitHub itself). Commits are lost and comments on commits lose their context, thus making it harder to review changes. At the end, all commits will be squashed anyway before being merged into the |
public String getLinkedFileDirectory() { | ||
return linkedFileDirectory.get(); | ||
} |
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.
The method 'getLinkedFileDirectory' should return an Optional to avoid returning null and handle absent values safely.
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.
JabRef works with ...Property; not with the data directly.
Please refer to other methods and class variables in that class.
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.
This is correct. See other Preferences e.g.
public boolean shouldKeepDownloadUrl() {
return shouldKeepDownloadUrl.get();
}
importHandler.importEntriesWithDuplicateCheck(bibDatabaseContext, entriesToAdd); | ||
boolean checkCopyPreferences = preferences.getFilePreferences().copyLinkedFiles(); | ||
|
||
if (checkCopyPreferences && (bibDatabaseContext.getLocation() == DatabaseLocation.SHARED)) { |
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.
The condition should follow the fail-fast principle by handling invalid states early and returning, instead of nesting logic inside else branches.
@FXML private CheckBox confirmLinkedFileDelete; | ||
@FXML private CheckBox moveToTrash; | ||
|
||
@FXML private CheckBox copyLinkedFiles; |
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.
The addition of the 'copyLinkedFiles' checkbox should be accompanied by a preference migration to handle any changes in default settings.
Please give a title to the PR that summarizes your changes/what issue it fixes. |
Closing this PR due to inactivity 💤 Please reopen the PR when you continue working on this |
Closes #10042
Description
This pull request addresses the issue where, when an entry is copied from one library to another, the linked files are not copied over. The linked files need to be stored according to the destination library directory settings + file path, as opposed to source library directory settings + file path. The latter is the current implementation, which results in losing the file(s) or making them inaccessible.
Our change adds the default behaviour of copying over linked files to a different library when copying over an entry. This setting can later be disabled depending on the user's preference, through the Linked Files tab in Preferences.
Additionally, we have introduced a preference for setting a default file path if the database file path is inaccessible. This helps prevent issues when database-specific paths are unavailable or incorrectly stored.
Change Locations
Next Steps
While working on adding a default file path if the database file path is inaccessible, we faced an issue where database.getMetaData().getLibrarySpecificFileDirectory(); currently returns Optional.empty every time. Due to time constraints, we were unable to look more into this, and an investigation as to what might be the issue may be required.
Tests
We used manual testing to determine if the file path name was being changed when adding entries to the shared library
Screenshots
Mandatory checks
CHANGELOG.md
described in a way that is understandable for the average user (if change is visible to the user)