Skip to content

Commit 0f8795b

Browse files
davidemdotSiedlerchr
authored andcommitted
Fix the 'Attach file' dialog for starting on the user's main directory (#4996)
1 parent 8e43be3 commit 0f8795b

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
118118
- We fixed an issue where a database exception related to a missing timezone was too big. [#4827](https://github.com/JabRef/jabref/issues/4827)
119119
- We fixed an issue where the command line help text had several errors, and arguments and descriptions have been rewritten to simplify and detail them better. [#4932](https://github.com/JabRef/jabref/issues/2016)
120120
- We fixed an issue where the same menu for changing entry type had two different sizes and weights. [#4977](https://github.com/JabRef/jabref/issues/4977)
121+
- We fixed an issue where the "Attach file" dialog, in the right-click menu for an entry, started on the working directory instead of the user's main directory. [#4995](https://github.com/JabRef/jabref/issues/4995)
121122

122123

123124
### Removed

src/main/java/org/jabref/gui/filelist/AttachFileAction.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.jabref.gui.filelist;
22

3+
import java.nio.file.Path;
4+
import java.nio.file.Paths;
35
import java.util.Optional;
46

57
import org.jabref.Globals;
@@ -32,14 +34,21 @@ public void execute() {
3234
dialogService.notify(Localization.lang("This operation requires exactly one item to be selected."));
3335
return;
3436
}
37+
3538
BibEntry entry = panel.getSelectedEntries().get(0);
39+
40+
Path workingDirectory = panel.getBibDatabaseContext()
41+
.getFirstExistingFileDir(Globals.prefs.getFilePreferences())
42+
.orElse(Paths.get(Globals.prefs.get(JabRefPreferences.WORKING_DIRECTORY)));
43+
3644
FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder()
37-
.withInitialDirectory(Globals.prefs.get(JabRefPreferences.WORKING_DIRECTORY))
38-
.build();
45+
.withInitialDirectory(workingDirectory)
46+
.build();
3947

4048
dialogService.showFileOpenDialog(fileDialogConfiguration).ifPresent(newFile -> {
41-
42-
LinkedFile linkedFile = LinkedFilesEditorViewModel.fromFile(newFile, panel.getBibDatabaseContext().getFileDirectoriesAsPaths(Globals.prefs.getFilePreferences()), ExternalFileTypes.getInstance());
49+
LinkedFile linkedFile = LinkedFilesEditorViewModel.fromFile(newFile,
50+
panel.getBibDatabaseContext().getFileDirectoriesAsPaths(Globals.prefs.getFilePreferences()),
51+
ExternalFileTypes.getInstance());
4352

4453
LinkedFileEditDialogView dialog = new LinkedFileEditDialogView(linkedFile);
4554

0 commit comments

Comments
 (0)