Add support for remembering last-used directory in file attachment dialog#12797
Conversation
Previously, the file chooser always opened in the default working directory, even if the user had just selected a different folder. This change stores the last-used folder in preferences and reuses it the next time a file is attached to a BibEntry. Fixes: JabRef#12554
|
Maybe this should be configurable. If i look at other office applications, like word, it opens the folder always on documents folder or for the working directory. A simple pref option "remember last folder a file was opened" or sthg. |
|
@calixtus Thanks for the feedback! That sounds like a really good idea, as I'm sure some users prefer always starting in the same directory, while others would benefit from remembering the last one. Do you think it might also make sense to add an additional setting to remember the last-used directory per library? For example, when I'm working on two different projects (or using two different .bib libraries simultaneously), it could be more helpful if each library remembered its own last-used folder. Meanwhile, for users who always attach files from the same place (e.g., Downloads), the default behavior would still be sufficient. Curious what you (and others) think! |
|
i think, the setting should go into "Linked files". I think, two preferencesd are enough
Default should be the first one as indicated For the concrete wording, please check the other strings in JabRef JabRef_en.properties |
| getBoolean(TRASH_INSTEAD_OF_DELETE, moveToTrashSupported()), | ||
| getBoolean(KEEP_DOWNLOAD_URL)); | ||
| getBoolean(KEEP_DOWNLOAD_URL), | ||
| getPath(LAST_USED_DIRECTORY, getDefaultPath())); |
There was a problem hiding this comment.
Default values are handled in a different way in JabRef.
There is a default mapping somewhere in JabRefCliPreferences.java
There was a problem hiding this comment.
Or you have to specify default there because of some AWT initialization (as described in comment above)?
There was a problem hiding this comment.
Yes. We do defaults.put(preference, defaultValue) in the constructor for most preferences.
Some of these are using impromptu fallbacks - and their design (for the matter of style/neatness or maybe simply as a result of non-uniformity) is such that we do getProperty(PREFERENCE, defaultFunction()) instead of defaults.put and getProperty(PREFERENCE).
Example - getPath expects a second parameter (default) of type Path (not String), whereas getBoolean has an implementation which does not.
There was a problem hiding this comment.
Delayed notice: I implemented the requested changes described here ~3 days ago leveraging defaults.put() as suggested.
|
|
||
| Path workingDirectory = databaseContext.getFirstExistingFileDir(filePreferences) | ||
| .orElse(filePreferences.getWorkingDirectory()); | ||
| Path workingDirectory = Optional.ofNullable(filePreferences.getLastUsedDirectory()) |
There was a problem hiding this comment.
Why ofNullable is used here?
If last user directory can be empty, then it should be Optional. (BTW, there is a special property class for this, something like OptionalObjectProperty)
There was a problem hiding this comment.
Here, the preference mentioned in #12797 (comment) comes into play. Thus, the highlighted code should be adapted accordingly.
There was a problem hiding this comment.
The lastUsedDirectory can fall back to
databaseContext.getFirstExistingFileDir(filePreferences)
.orElse(filePreferences.getWorkingDirectory());
There was a problem hiding this comment.
Note: This comment is a delayed response from me (because I implemented the requested changes described here ~3 days ago)
I tackled the issues suggested here. Since a preference determined by user was suggested, I added conditionals. ofNullable initially solved a bug, so I had added it. Should have only been a provisional solution but I changed that now.
- Added preference options to choose between opening file explorer in: * Files directory (default) * Last opened directory - Updated AttachFileAction to use the selected preference - Added localization strings for the new UI options - Added necessary view model bindings This enhancement gives users control over where the file dialog opens when attaching files, making the workflow more customizable. See: [#XXXX](https://github.com/JabRef/jabref/issues/XXXX)
subhramit
left a comment
There was a problem hiding this comment.
Please address the redundancy in defaults.
| getBoolean(OPEN_FILE_EXPLORER_IN_FILE_DIRECTORY, Boolean.TRUE), | ||
| getBoolean(OPEN_FILE_EXPLORER_IN_LAST_USED_DIRECTORY, Boolean.FALSE)); |
There was a problem hiding this comment.
You have already put defaults for these two, so no utility of passing them here.
There was a problem hiding this comment.
Thanks for the notice! I deleted them. (as part of a commit from around 3 days ago so this is a delayed comment response by me)
| private final BooleanProperty openFileExplorerInFileDirectory = new SimpleBooleanProperty(true); | ||
| private final BooleanProperty openFileExplorerInLastUsedDirectory = new SimpleBooleanProperty(false); |
There was a problem hiding this comment.
Again, no need of passing defaults in the constructor here, you have already handled them in JabRefCliPreferences.
See how the other properties are handled ^
There was a problem hiding this comment.
Thanks, I got rid of the parameters!
|
GitHub keeps messing up the order of review comments somehow these days. Fixed them via edits. |
| public Path getLastUsedDirectory() { | ||
| return lastUsedDirectory.get(); | ||
| } |
There was a problem hiding this comment.
New public methods should not return null. Consider using Optional to avoid returning null and improve null safety.
|
Please fix the submodules, then it's fine https://devdocs.jabref.org/code-howtos/faq.html#submodules |
| getInternalPreferences().getUserAndHost(), | ||
| getInternalPreferences().getUserAndHost(), |
There was a problem hiding this comment.
Ah, this indent is off - I will fix it.
|
@trag-bot didn't find any issues in the code! ✅✨ |
…alog (JabRef#12797) * Add support for remembering last-used directory for file attachments Previously, the file chooser always opened in the default working directory, even if the user had just selected a different folder. This change stores the last-used folder in preferences and reuses it the next time a file is attached to a BibEntry. Fixes: JabRef#12554 * Add option to configure file explorer directory in preferences - Added preference options to choose between opening file explorer in: * Files directory (default) * Last opened directory - Updated AttachFileAction to use the selected preference - Added localization strings for the new UI options - Added necessary view model bindings This enhancement gives users control over where the file dialog opens when attaching files, making the workflow more customizable. See: [#XXXX](https://github.com/JabRef/jabref/issues/XXXX) * Remove redundant default values after merging with main * Fix submodules * Fix csl-styles * Fix indent --------- Co-authored-by: Oliver Kopp <kopp.dev@gmail.com>
…alog (JabRef#12797) * Add support for remembering last-used directory for file attachments Previously, the file chooser always opened in the default working directory, even if the user had just selected a different folder. This change stores the last-used folder in preferences and reuses it the next time a file is attached to a BibEntry. Fixes: JabRef#12554 * Add option to configure file explorer directory in preferences - Added preference options to choose between opening file explorer in: * Files directory (default) * Last opened directory - Updated AttachFileAction to use the selected preference - Added localization strings for the new UI options - Added necessary view model bindings This enhancement gives users control over where the file dialog opens when attaching files, making the workflow more customizable. See: [#XXXX](https://github.com/JabRef/jabref/issues/XXXX) * Remove redundant default values after merging with main * Fix submodules * Fix csl-styles * Fix indent --------- Co-authored-by: Oliver Kopp <kopp.dev@gmail.com>

Previously, the file chooser always opened in the default working directory, even if the user had just selected a different folder. This change stores the last-used folder in preferences and reuses it the next time a file is attached to a BibEntry.
Closes #12554
This change:
lastUsedDirectoryfield toFilePreferencesAttachFileActionto store and retrieve the last-used directoryManual Testing
This feature was manually tested:
No test case added because this is a UI feature, and the file dialog is not easily mockable.
Screenshot
Mandatory checks
CHANGELOG.mddescribed in a way that is understandable for the average user (if change is visible to the user)