Skip to content

Commit 7435ec7

Browse files
committed
Merge remote-tracking branch 'upstream/main' into addNoopReader
* upstream/main: Added static (stream & preferences) constructors to BibDatabaseContext (#13694) New Crowdin updates (#13698) fix git modules requires and uses (#13696) Focus "Specify Bib(La)TeX" when Bib(La)TeX is in clipboard (#13633)
2 parents 3694fe1 + bbb88cc commit 7435ec7

File tree

11 files changed

+247
-287
lines changed

11 files changed

+247
-287
lines changed

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,11 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
7373
- We introduced walkthrough functionality [#12664](https://github.com/JabRef/jabref/issues/12664)
7474

7575
### Fixed
76-
76+
77+
- We fixed an issue where "Specify Bib(La)TeX" tab was not focused when Bib(La)TeX was in the clipboard [#13597](https://github.com/JabRef/jabref/issues/13597)
7778
- We fixed an issue whereby the 'About' dialog was not honouring the user's configured font preferences. [#13558](https://github.com/JabRef/jabref/issues/13558)
7879
- We fixed an issue where the Pagetotal column was sorting the values alphabetically instead of numerically. [#12533](https://github.com/JabRef/jabref/issues/12533)
79-
- We fixed dark mode of BibTeX Source dialog in Citation Relations tab. [#13599](https://github.com/JabRef/jabref/issues/13599)
80+
- We fixed the dark mode of the BibTeX Source dialog in the Citation Relations tab. [#13599](https://github.com/JabRef/jabref/issues/13599)
8081
- We fixed an issue where the LibreOffice integration did not support citation keys containing Unicode characters. [#13301](https://github.com/JabRef/jabref/issues/13301)
8182
- We fixed an issue where the "Search ShortScience" action did not convert LaTeX-formatted titles to Unicode. [#13418](https://github.com/JabRef/jabref/issues/13418)
8283
- We fixed an issue where LaTeX file directories were not properly shared between different users on the same host. [#9990](https://github.com/JabRef/jabref/issues/9990)

jabgui/src/main/java/org/jabref/gui/newentry/NewEntryView.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@
7474
import jakarta.inject.Inject;
7575

7676
public class NewEntryView extends BaseDialog<BibEntry> {
77+
private static final String BIBTEX_REGEX = "^@([A-Za-z]+)\\{,";
78+
private static final String LINE_BREAK = "\n";
79+
7780
private NewEntryViewModel viewModel;
7881

7982
private final NewEntryDialogTab initialApproach;
@@ -164,6 +167,8 @@ private void finalizeTabs() {
164167
approach = NewEntryDialogTab.ENTER_IDENTIFIER;
165168
interpretText.setText(clipboardText);
166169
interpretText.selectAll();
170+
} else if (clipboardText.split(LINE_BREAK)[0].matches(BIBTEX_REGEX)) {
171+
approach = NewEntryDialogTab.SPECIFY_BIBTEX;
167172
} else {
168173
approach = preferences.getLatestApproach();
169174
}
@@ -288,7 +293,7 @@ private void initializeLookupIdentifier() {
288293
Tooltip.uninstall(idText, idTextTooltip);
289294
}
290295
});
291-
296+
292297
idText.setText(ClipBoardManager.getContents().trim());
293298
idText.selectAll();
294299

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

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package org.jabref.model.database;
22

3+
import java.io.BufferedReader;
34
import java.io.IOException;
5+
import java.io.InputStream;
6+
import java.io.InputStreamReader;
47
import java.io.Reader;
58
import java.nio.file.Files;
69
import java.nio.file.Path;
@@ -282,14 +285,25 @@ public Path getFulltextIndexPath() {
282285
return indexPath;
283286
}
284287

285-
public static BibDatabaseContext of(String bibContent, ImportFormatPreferences importFormatPreferences) throws JabRefException {
288+
public static BibDatabaseContext of(Reader bibContentReader, ImportFormatPreferences importFormatPreferences) throws JabRefException {
286289
BibtexParser parser = new BibtexParser(importFormatPreferences);
287290
try {
288-
Reader reader = Reader.of(bibContent);
289-
ParserResult result = parser.parse(reader);
291+
ParserResult result = parser.parse(bibContentReader);
290292
return result.getDatabaseContext();
291293
} catch (IOException e) {
292-
throw new JabRefException("Failed to parse BibTeX content", e);
294+
throw new JabRefException("Failed to parse BibTeX", e);
295+
}
296+
}
297+
298+
public static BibDatabaseContext of(String bibContent, ImportFormatPreferences importFormatPreferences) throws JabRefException {
299+
return of(Reader.of(bibContent), importFormatPreferences);
300+
}
301+
302+
public static BibDatabaseContext of(InputStream bibContentStream, ImportFormatPreferences importFormatPreferences) throws JabRefException {
303+
try (Reader reader = new BufferedReader(new InputStreamReader(bibContentStream))) {
304+
return of(reader, importFormatPreferences);
305+
} catch (IOException e) {
306+
throw new JabRefException("Failed to close stream", e);
293307
}
294308
}
295309

jablib/src/main/resources/l10n/JabRef_fr.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,8 +1086,11 @@ Waiting\ for\ background\ tasks\ to\ finish.\ Quit\ anyway?=En attente de la fin
10861086
Find\ and\ remove\ duplicate\ citation\ keys=Rechercher et supprimer les clefs de citation dupliquées
10871087

10881088
Library-specific\ file\ directory=Répertoire spécifique au fichier
1089+
Library-specific\ file\ directory\:\ %0=Répertoire spécifique aux fichiers bibliographiques \: %0
10891090
LaTeX\ file\ directory=Répertoire de fichiers LaTeX
1091+
LaTeX\ file\ directory\:\ %0=Répertoire de fichiers LaTeX \: %0
10901092
User-specific\ file\ directory=Répertoire de fichiers spécifique à l'utilisateur
1093+
User-specific\ file\ directory\:\ %0=Répertoire spécifique des fichiers de l'utilisateur \: %0
10911094

10921095
Path\ %0\ could\ not\ be\ resolved.\ Using\ working\ directory.=Le chemin %0 n'a pas pu être trouvé. Utilisation du répertoire de travail.
10931096
Switch\ to\ absolute\ path\:\ converts\ the\ path\ to\ an\ absolute\ path.=Basculer vers un chemin absolu \: convertit le chemin vers un chemin absolu.

jablib/src/main/resources/l10n/JabRef_pt_BR.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,8 +1086,11 @@ Waiting\ for\ background\ tasks\ to\ finish.\ Quit\ anyway?=Aguardando a finaliz
10861086
Find\ and\ remove\ duplicate\ citation\ keys=Localizar e remover chaves de citação duplicadas
10871087
10881088
Library-specific\ file\ directory=Diretório de arquivos específicos da biblioteca
1089+
Library-specific\ file\ directory\:\ %0=Diretório de arquivo específico de biblioteca\: %0
10891090
LaTeX\ file\ directory=Diretório de arquivos LaTeX
1091+
LaTeX\ file\ directory\:\ %0=Diretório de arquivos LaTeX\: %0
10901092
User-specific\ file\ directory=Diretório de arquivo específico do usuário
1093+
User-specific\ file\ directory\:\ %0=Diretório do arquivo específico do usuário\: %0
10911094
10921095
Path\ %0\ could\ not\ be\ resolved.\ Using\ working\ directory.=Caminho %0 não pode ser resolvido. Usando o diretório de trabalho.
10931096
Switch\ to\ absolute\ path\:\ converts\ the\ path\ to\ an\ absolute\ path.=Alternar para caminho absoluto\: converte o caminho para um caminho absoluto.

jablib/src/test/java/org/jabref/logic/auxparser/AuxParserTest.java

Lines changed: 32 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,15 @@
22

33
import java.io.IOException;
44
import java.io.InputStream;
5-
import java.io.InputStreamReader;
65
import java.net.URISyntaxException;
7-
import java.nio.charset.StandardCharsets;
86
import java.nio.file.Path;
97
import java.util.List;
108
import java.util.Optional;
119

10+
import org.jabref.logic.JabRefException;
1211
import org.jabref.logic.importer.ImportFormatPreferences;
13-
import org.jabref.logic.importer.ParserResult;
14-
import org.jabref.logic.importer.fileformat.BibtexParser;
1512
import org.jabref.model.database.BibDatabase;
13+
import org.jabref.model.database.BibDatabaseContext;
1614
import org.jabref.model.entry.BibEntry;
1715

1816
import org.junit.jupiter.api.AfterEach;
@@ -39,13 +37,11 @@ void tearDown() {
3937
}
4038

4139
@Test
42-
void normal() throws URISyntaxException, IOException {
43-
InputStream originalStream = AuxParserTest.class.getResourceAsStream("origin.bib");
44-
Path auxFile = Path.of(AuxParserTest.class.getResource("paper.aux").toURI());
45-
try (InputStreamReader originalReader = new InputStreamReader(originalStream, StandardCharsets.UTF_8)) {
46-
ParserResult result = new BibtexParser(importFormatPreferences).parse(originalReader);
47-
48-
AuxParser auxParser = new DefaultAuxParser(result.getDatabase());
40+
void normal() throws URISyntaxException, IOException, JabRefException {
41+
try (InputStream originalStream = AuxParserTest.class.getResourceAsStream("origin.bib")) {
42+
Path auxFile = Path.of(AuxParserTest.class.getResource("paper.aux").toURI());
43+
final BibDatabaseContext bibDatabaseContext = BibDatabaseContext.of(originalStream, importFormatPreferences);
44+
AuxParser auxParser = new DefaultAuxParser(bibDatabaseContext.getDatabase());
4945
AuxParserResult auxResult = auxParser.parse(auxFile);
5046

5147
assertTrue(auxResult.getGeneratedBibDatabase().hasEntries());
@@ -64,15 +60,12 @@ void normal() throws URISyntaxException, IOException {
6460
}
6561

6662
@Test
67-
void twoArgMacro() throws URISyntaxException, IOException {
63+
void twoArgMacro() throws URISyntaxException, IOException, JabRefException {
6864
// Result should be identical to that of testNormal
69-
70-
InputStream originalStream = AuxParserTest.class.getResourceAsStream("origin.bib");
71-
Path auxFile = Path.of(AuxParserTest.class.getResource("papertwoargmacro.aux").toURI());
72-
try (InputStreamReader originalReader = new InputStreamReader(originalStream, StandardCharsets.UTF_8)) {
73-
ParserResult result = new BibtexParser(importFormatPreferences).parse(originalReader);
74-
75-
AuxParser auxParser = new DefaultAuxParser(result.getDatabase());
65+
try (InputStream originalStream = AuxParserTest.class.getResourceAsStream("origin.bib")) {
66+
Path auxFile = Path.of(AuxParserTest.class.getResource("papertwoargmacro.aux").toURI());
67+
final BibDatabaseContext bibDatabaseContext = BibDatabaseContext.of(originalStream, importFormatPreferences);
68+
AuxParser auxParser = new DefaultAuxParser(bibDatabaseContext.getDatabase());
7669
AuxParserResult auxResult = auxParser.parse(auxFile);
7770

7871
assertTrue(auxResult.getGeneratedBibDatabase().hasEntries());
@@ -91,13 +84,11 @@ void twoArgMacro() throws URISyntaxException, IOException {
9184
}
9285

9386
@Test
94-
void notAllFound() throws URISyntaxException, IOException {
95-
InputStream originalStream = AuxParserTest.class.getResourceAsStream("origin.bib");
96-
Path auxFile = Path.of(AuxParserTest.class.getResource("badpaper.aux").toURI());
97-
try (InputStreamReader originalReader = new InputStreamReader(originalStream, StandardCharsets.UTF_8)) {
98-
ParserResult result = new BibtexParser(importFormatPreferences).parse(originalReader);
99-
100-
AuxParser auxParser = new DefaultAuxParser(result.getDatabase());
87+
void notAllFound() throws URISyntaxException, IOException, JabRefException {
88+
try (InputStream originalStream = AuxParserTest.class.getResourceAsStream("origin.bib")) {
89+
Path auxFile = Path.of(AuxParserTest.class.getResource("badpaper.aux").toURI());
90+
final BibDatabaseContext bibDatabaseContext = BibDatabaseContext.of(originalStream, importFormatPreferences);
91+
AuxParser auxParser = new DefaultAuxParser(bibDatabaseContext.getDatabase());
10192
AuxParserResult auxResult = auxParser.parse(auxFile);
10293

10394
assertTrue(auxResult.getGeneratedBibDatabase().hasEntries());
@@ -113,13 +104,11 @@ void notAllFound() throws URISyntaxException, IOException {
113104
}
114105

115106
@Test
116-
void duplicateBibDatabaseConfiguration() throws URISyntaxException, IOException {
117-
InputStream originalStream = AuxParserTest.class.getResourceAsStream("config.bib");
118-
Path auxFile = Path.of(AuxParserTest.class.getResource("paper.aux").toURI());
119-
try (InputStreamReader originalReader = new InputStreamReader(originalStream, StandardCharsets.UTF_8)) {
120-
ParserResult result = new BibtexParser(importFormatPreferences).parse(originalReader);
121-
122-
AuxParser auxParser = new DefaultAuxParser(result.getDatabase());
107+
void duplicateBibDatabaseConfiguration() throws URISyntaxException, IOException, JabRefException {
108+
try (InputStream originalStream = AuxParserTest.class.getResourceAsStream("config.bib")) {
109+
Path auxFile = Path.of(AuxParserTest.class.getResource("paper.aux").toURI());
110+
final BibDatabaseContext bibDatabaseContext = BibDatabaseContext.of(originalStream, importFormatPreferences);
111+
AuxParser auxParser = new DefaultAuxParser(bibDatabaseContext.getDatabase());
123112
AuxParserResult auxResult = auxParser.parse(auxFile);
124113
BibDatabase db = auxResult.getGeneratedBibDatabase();
125114

@@ -129,13 +118,11 @@ void duplicateBibDatabaseConfiguration() throws URISyntaxException, IOException
129118
}
130119

131120
@Test
132-
void nestedAux() throws URISyntaxException, IOException {
133-
InputStream originalStream = AuxParserTest.class.getResourceAsStream("origin.bib");
134-
Path auxFile = Path.of(AuxParserTest.class.getResource("nested.aux").toURI());
135-
try (InputStreamReader originalReader = new InputStreamReader(originalStream, StandardCharsets.UTF_8)) {
136-
ParserResult result = new BibtexParser(importFormatPreferences).parse(originalReader);
137-
138-
AuxParser auxParser = new DefaultAuxParser(result.getDatabase());
121+
void nestedAux() throws URISyntaxException, IOException, JabRefException {
122+
try (InputStream originalStream = AuxParserTest.class.getResourceAsStream("origin.bib")) {
123+
Path auxFile = Path.of(AuxParserTest.class.getResource("nested.aux").toURI());
124+
final BibDatabaseContext bibDatabaseContext = BibDatabaseContext.of(originalStream, importFormatPreferences);
125+
AuxParser auxParser = new DefaultAuxParser(bibDatabaseContext.getDatabase());
139126
AuxParserResult auxResult = auxParser.parse(auxFile);
140127

141128
assertTrue(auxResult.getGeneratedBibDatabase().hasEntries());
@@ -151,13 +138,11 @@ void nestedAux() throws URISyntaxException, IOException {
151138
}
152139

153140
@Test
154-
void crossRef() throws URISyntaxException, IOException {
155-
InputStream originalStream = AuxParserTest.class.getResourceAsStream("origin.bib");
156-
Path auxFile = Path.of(AuxParserTest.class.getResource("crossref.aux").toURI());
157-
try (InputStreamReader originalReader = new InputStreamReader(originalStream, StandardCharsets.UTF_8)) {
158-
ParserResult result = new BibtexParser(importFormatPreferences).parse(originalReader);
159-
160-
AuxParser auxParser = new DefaultAuxParser(result.getDatabase());
141+
void crossRef() throws URISyntaxException, IOException, JabRefException {
142+
try (InputStream originalStream = AuxParserTest.class.getResourceAsStream("origin.bib")) {
143+
Path auxFile = Path.of(AuxParserTest.class.getResource("crossref.aux").toURI());
144+
final BibDatabaseContext bibDatabaseContext = BibDatabaseContext.of(originalStream, importFormatPreferences);
145+
AuxParser auxParser = new DefaultAuxParser(bibDatabaseContext.getDatabase());
161146
AuxParserResult auxResult = auxParser.parse(auxFile);
162147

163148
assertTrue(auxResult.getGeneratedBibDatabase().hasEntries());

0 commit comments

Comments
 (0)