Skip to content

Commit 523e90e

Browse files
raquelgraosSiedlerchrkoppor
authoredMar 19, 2025··
Fix option to "Search for unlinked local files" for new library (#12738)
Disables the option to "Search for unlinked local files" in the Lookup menu before the newly created library is saved as the action shold only be available when the .bib file path is known Fixes #12558 Co-authored-by: Christoph <siedlerkiller@gmail.com> Co-authored-by: Oliver Kopp <kopp.dev@gmail.com>
1 parent 3611d6f commit 523e90e

File tree

3 files changed

+70
-2
lines changed

3 files changed

+70
-2
lines changed
 

‎CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
7777
- We fixed an issue where month values 21–24 (ISO 8601-2019 season codes) in Biblatex date fields were not recognized as seasons during parsing. [#12437](https://github.com/JabRef/jabref/issues/12437)
7878
- We fixed an issue where migration of "Search groups" would fail with an exception when the search query is invalid. [#12555](https://github.com/JabRef/jabref/issues/12555)
7979
- We fixed an issue where not all linked files from BibDesk in the field `bdsk-file-...` were parsed. [#12555](https://github.com/JabRef/jabref/issues/12555)
80+
- We fixed an issue where it was possible to select "Search for unlinked local files" for a new (unsaved) library. [#12558](https://github.com/JabRef/jabref/issues/12558)
8081
- We fixed an issue where user-defined keyword separator does not apply to Merge Groups. [#12535](https://github.com/JabRef/jabref/issues/12535)
8182
- We fixed an issue where duplicate items cannot be removed correctly when merging groups or keywords. [#12585](https://github.com/JabRef/jabref/issues/12585)
8283
- We fixed an issue where JabRef displayed an incorrect deletion notification when canceling entry deletion [#12645](https://github.com/JabRef/jabref/issues/12645)

‎src/main/java/org/jabref/gui/externalfiles/FindUnlinkedFilesAction.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import org.jabref.gui.StateManager;
55
import org.jabref.gui.actions.SimpleCommand;
66

7-
import static org.jabref.gui.actions.ActionHelper.needsDatabase;
7+
import static org.jabref.gui.actions.ActionHelper.needsSavedLocalDatabase;
88

99
public class FindUnlinkedFilesAction extends SimpleCommand {
1010

@@ -15,7 +15,7 @@ public FindUnlinkedFilesAction(DialogService dialogService, StateManager stateMa
1515
this.dialogService = dialogService;
1616
this.stateManager = stateManager;
1717

18-
this.executable.bind(needsDatabase(this.stateManager));
18+
this.executable.bind(needsSavedLocalDatabase(this.stateManager));
1919
}
2020

2121
@Override
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package org.jabref.gui.externalfiles;
2+
3+
import java.nio.file.Path;
4+
import java.util.Optional;
5+
6+
import org.jabref.gui.DialogService;
7+
import org.jabref.gui.StateManager;
8+
import org.jabref.logic.shared.DatabaseLocation;
9+
import org.jabref.model.database.BibDatabaseContext;
10+
11+
import org.junit.jupiter.api.BeforeEach;
12+
import org.junit.jupiter.api.Test;
13+
import org.mockito.Mock;
14+
import org.mockito.MockitoAnnotations;
15+
16+
import static org.junit.jupiter.api.Assertions.assertFalse;
17+
import static org.junit.jupiter.api.Assertions.assertTrue;
18+
import static org.mockito.Mockito.when;
19+
20+
class FindUnlinkedFilesActionTest {
21+
22+
@Mock
23+
private DialogService dialogService;
24+
25+
@Mock
26+
private BibDatabaseContext databaseContext;
27+
28+
private StateManager stateManager;
29+
private FindUnlinkedFilesAction action;
30+
31+
@BeforeEach
32+
void setUp() {
33+
MockitoAnnotations.openMocks(this);
34+
stateManager = new StateManager();
35+
action = new FindUnlinkedFilesAction(dialogService, stateManager);
36+
}
37+
38+
@Test
39+
void isEnabledWhenNewDatabaseIsSavedTest() {
40+
when(databaseContext.getDatabasePath()).thenReturn(Optional.of(Path.of("test.bib")));
41+
when(databaseContext.getLocation()).thenReturn(DatabaseLocation.LOCAL);
42+
43+
stateManager.activeDatabaseProperty().setValue(Optional.of(databaseContext));
44+
45+
assertTrue(action.executableProperty().get());
46+
}
47+
48+
@Test
49+
void isDisabledWhenNewDatabasePathIsEmptyTest() {
50+
when(databaseContext.getDatabasePath()).thenReturn(Optional.empty());
51+
when(databaseContext.getLocation()).thenReturn(DatabaseLocation.LOCAL);
52+
53+
stateManager.activeDatabaseProperty().setValue(Optional.of(databaseContext));
54+
55+
assertFalse(action.executableProperty().get());
56+
}
57+
58+
@Test
59+
void isDisabledWhenNewDatabaseIsNotLocalTest() {
60+
when(databaseContext.getDatabasePath()).thenReturn(Optional.of(Path.of("test.bib")));
61+
when(databaseContext.getLocation()).thenReturn(DatabaseLocation.SHARED);
62+
63+
stateManager.activeDatabaseProperty().setValue(Optional.of(databaseContext));
64+
65+
assertFalse(action.executableProperty().get());
66+
}
67+
}

0 commit comments

Comments
 (0)
Please sign in to comment.