Skip to content

Commit ffa07cd

Browse files
authored
Merge pull request #6451 from silverhorse/fix-for-issue-5891
Removed BIB file directory from search when preferences has option unchecked
2 parents 526ba89 + 6a1940f commit ffa07cd

File tree

8 files changed

+33
-12
lines changed

8 files changed

+33
-12
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
4343

4444
### Fixed
4545

46+
- We fixed to only search file links in the BIB file location directory when preferences has corresponding checkbox checked. [#5891](https://github.com/JabRef/jabref/issues/5891)
4647
- We fixed wrong button order (Apply and Cancel) in ManageProtectedTermsDialog.
4748
- We fixed an issue with incompatible characters at BibTeX key [#6257](https://github.com/JabRef/jabref/issues/6257)
4849
- We fixed an issue where dash (`-`) was reported as illegal BibTeX key [#6295](https://github.com/JabRef/jabref/issues/6295)

src/main/java/org/jabref/gui/preferences/FileTab.fxml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
<TextField fx:id="mainFileDir" HBox.hgrow="ALWAYS"/>
4444
<Button onAction="#mainFileDirBrowse" text="%Browse"/>
4545
</HBox>
46-
<CheckBox fx:id="useBibLocationAsPrimary" text="%Use the BIB file location as primary file directory">
46+
<CheckBox fx:id="useBibLocationAsPrimary" text="%Search and store files relative to library file location">
4747
<tooltip>
4848
<Tooltip
4949
text="%When downloading files, or moving linked files to the file directory, prefer the BIB file location rather than the file directory set above"/>

src/main/java/org/jabref/model/database/BibDatabaseContext.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,6 @@ public List<Path> getFileDirectoriesAsPaths(FilePreferences preferences) {
144144
// Check if we should add it as primary file dir (first in the list) or not:
145145
if (preferences.isBibLocationAsPrimary()) {
146146
fileDirs.add(0, parentPath);
147-
} else {
148-
fileDirs.add(parentPath);
149147
}
150148
});
151149

src/main/resources/l10n/JabRef_en.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1096,7 +1096,7 @@ Web\ search=Web search
10961096
Style\ selection=Style selection
10971097
No\ valid\ style\ file\ defined=No valid style file defined
10981098
Choose\ pattern=Choose pattern
1099-
Use\ the\ BIB\ file\ location\ as\ primary\ file\ directory=Use the BIB file location as primary file directory
1099+
Search\ and\ store\ files\ relative\ to\ library\ file\ location=Search and store files relative to library file location
11001100
Could\ not\ run\ the\ gnuclient/emacsclient\ program.\ Make\ sure\ you\ have\ the\ emacsclient/gnuclient\ program\ installed\ and\ available\ in\ the\ PATH.=Could not run the gnuclient/emacsclient program. Make sure you have the emacsclient/gnuclient program installed and available in the PATH.
11011101
You\ must\ select\ either\ a\ valid\ style\ file,\ or\ use\ one\ of\ the\ default\ styles.=You must select either a valid style file, or use one of the default styles.
11021102

src/main/resources/l10n/JabRef_ru.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2168,7 +2168,7 @@ This\ entry\ type\ is\ intended\ for\ sources\ such\ as\ web\ sites\ which\ are\
21682168
A\ single-volume\ work\ of\ reference\ such\ as\ an\ encyclopedia\ or\ a\ dictionary.=Неделимая работа или ссылка, как энциклопедия или словарь.
21692169
A\ technical\ report,\ research\ report,\ or\ white\ paper\ published\ by\ a\ university\ or\ some\ other\ institution.=Технический отчет, исследовательский отчет, или белая книга, выпущенная институтом или другим учреждением.
21702170
An\ entry\ set\ is\ a\ group\ of\ entries\ which\ are\ cited\ as\ a\ single\ reference\ and\ listed\ as\ a\ single\ item\ in\ the\ bibliography.=Набор записей представляет собой группу записей, которые приводятся в виде единой ссылки и перечислены в виде одного элемента в библиографии.
2171-
Supplemental\ material\ in\ a\ "Book".\ This\ type\ is\ provided\ for\ elements\ such\ as\ prefaces,\ introductions,\ forewords,\ afterwords,\ etc.\ which\ often\ have\ a\ generic\ title\ only.=Дополнительный материал в "Книге" предназначен для таких элементов, как предисловия, введения, послесловия и т.д.
2171+
Supplemental\ material\ in\ a\ "Book".\ This\ type\ is\ provided\ for\ elements\ such\ as\ prefaces,\ introductions,\ forewords,\ afterwords,\ etc.\ which\ often\ have\ a\ generic\ title\ only.=Дополнительный материал в "Книге" предназначен для таких элементов, как предисловия, введения, послесловия и т.д.
21722172
Supplemental\ material\ in\ a\ "Collection".=Дополнительные материалы в "Коллекции".
21732173
Supplemental\ material\ in\ a\ "Periodical".\ This\ type\ may\ be\ useful\ when\ referring\ to\ items\ such\ as\ regular\ columns,\ obituaries,\ letters\ to\ the\ editor,\ etc.\ which\ only\ have\ a\ generic\ title.=Дополнительные материалы в "Периодическом издании". Этот тип может быть полезен при обращении к таким элементам, как обычные колонки, некрологи, письма к редактору и т.д., которые имеют только общее название.
21742174
A\ thesis\ written\ for\ an\ educational\ institution\ to\ satisfy\ the\ requirements\ for\ a\ degree.=Тезис, написанный для учебного заведения с целью удовлетворения требований к степени.

src/test/java/org/jabref/gui/externalfiles/AutoSetFileLinksUtilTest.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,31 @@ public class AutoSetFileLinksUtilTest {
3030
private final BibDatabaseContext databaseContext = mock(BibDatabaseContext.class);
3131
private final ExternalFileTypes externalFileTypes = mock(ExternalFileTypes.class);
3232
private final BibEntry entry = new BibEntry(StandardEntryType.Article);
33+
private Path path = null;
3334

3435
@BeforeEach
3536
public void setUp(@TempDir Path folder) throws Exception {
36-
Path path = folder.resolve("CiteKey.pdf");
37+
path = folder.resolve("CiteKey.pdf");
3738
Files.createFile(path);
3839
entry.setCiteKey("CiteKey");
39-
when(databaseContext.getFileDirectoriesAsPaths(any())).thenReturn(Collections.singletonList(path.getParent()));
4040
when(externalFileTypes.getExternalFileTypeSelection()).thenReturn(new TreeSet<>(ExternalFileTypes.getDefaultExternalFileTypes()));
4141
}
4242

4343
@Test
44-
public void test() throws Exception {
44+
public void testFindAssociatedNotLinkedFilesSuccess() throws Exception {
4545
// Due to mocking the externalFileType class, the file extension will not be found
46-
46+
when(databaseContext.getFileDirectoriesAsPaths(any())).thenReturn(Collections.singletonList(path.getParent()));
4747
List<LinkedFile> expected = Collections.singletonList(new LinkedFile("", "CiteKey.pdf", ""));
48-
4948
AutoSetFileLinksUtil util = new AutoSetFileLinksUtil(databaseContext, fileDirPrefs, autoLinkPrefs, externalFileTypes);
5049
List<LinkedFile> actual = util.findAssociatedNotLinkedFiles(entry);
5150
assertEquals(expected, actual);
5251
}
52+
53+
@Test
54+
public void testFindAssociatedNotLinkedFilesForEmptySearchDir() throws Exception {
55+
when(fileDirPrefs.isBibLocationAsPrimary()).thenReturn(false);
56+
AutoSetFileLinksUtil util = new AutoSetFileLinksUtil(databaseContext, fileDirPrefs, autoLinkPrefs, externalFileTypes);
57+
List<LinkedFile> actual = util.findAssociatedNotLinkedFiles(entry);
58+
assertEquals(Collections.emptyList(), actual);
59+
}
5360
}

src/test/java/org/jabref/logic/cleanup/MoveFilesCleanupTest.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@
44
import java.nio.file.Files;
55
import java.nio.file.Path;
66
import java.util.Arrays;
7+
import java.util.Collections;
8+
import java.util.List;
79
import java.util.Optional;
810

11+
import org.jabref.model.FieldChange;
912
import org.jabref.model.database.BibDatabase;
1013
import org.jabref.model.database.BibDatabaseContext;
1114
import org.jabref.model.entry.BibEntry;
@@ -32,6 +35,7 @@ class MoveFilesCleanupTest {
3235
private MoveFilesCleanup cleanup;
3336
private BibEntry entry;
3437
private FilePreferences filePreferences;
38+
private BibDatabaseContext databaseContext;
3539

3640
@BeforeEach
3741
void setUp(@TempDir Path bibFolder) throws IOException {
@@ -47,7 +51,7 @@ void setUp(@TempDir Path bibFolder) throws IOException {
4751

4852
MetaData metaData = new MetaData();
4953
metaData.setDefaultFileDirectory(defaultFileFolder.toAbsolutePath().toString());
50-
BibDatabaseContext databaseContext = new BibDatabaseContext(new BibDatabase(), metaData);
54+
databaseContext = new BibDatabaseContext(new BibDatabase(), metaData);
5155
Files.createFile(bibFolder.resolve("test.bib"));
5256
databaseContext.setDatabasePath(bibFolder.resolve("test.bib"));
5357

@@ -119,4 +123,12 @@ void movesFileWithSubdirectoryPattern() throws Exception {
119123
assertFalse(Files.exists(fileBefore));
120124
assertTrue(Files.exists(fileAfter));
121125
}
126+
127+
@Test
128+
void movesFileWithNoDirectory() throws Exception {
129+
databaseContext.setMetaData(new MetaData());
130+
when(filePreferences.getFileDirPattern()).thenReturn("");
131+
List<FieldChange> changes = cleanup.cleanup(entry);
132+
assertEquals(Collections.emptyList(), changes);
133+
}
122134
}

src/test/java/org/jabref/logic/integrity/IntegrityCheckTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import static org.junit.jupiter.api.Assertions.assertNotEquals;
3737
import static org.mockito.ArgumentMatchers.any;
3838
import static org.mockito.Mockito.mock;
39+
import static org.mockito.Mockito.when;
3940

4041
/**
4142
* This class tests the Integrity Checker as a whole.
@@ -177,8 +178,10 @@ private void assertWrong(BibDatabaseContext context) {
177178
}
178179

179180
private void assertCorrect(BibDatabaseContext context) {
181+
FilePreferences filePreferencesMock = mock(FilePreferences.class);
182+
when(filePreferencesMock.isBibLocationAsPrimary()).thenReturn(true);
180183
List<IntegrityMessage> messages = new IntegrityCheck(context,
181-
mock(FilePreferences.class),
184+
filePreferencesMock,
182185
createBibtexKeyPatternPreferences(),
183186
JournalAbbreviationLoader.loadBuiltInRepository(), false
184187
).check();

0 commit comments

Comments
 (0)