Skip to content

Commit 87984c3

Browse files
Fix : Importing .bib file shows correct message and imports groups associated (#12837)
* Fix #11025: Importing .bib file shows correct format message * fix: OpenRewrite test issues * fix: changed method 'determineExtensionFilter' to follow fail-fast principle * Refactor: apply fail-fast principle in determineExtensionFilter and update JavaDoc --------- Co-authored-by: Christoph <[email protected]>
1 parent 1f5d7ab commit 87984c3

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
106106
- We fixed a bug where LaTeX commands were not removed from filenames generated using the `[bibtexkey] - [fulltitle]` pattern. [#12188](https://github.com/JabRef/jabref/issues/12188)
107107
- We fixed an issue where JabRef interface would not properly refresh after a group removal. [#11487](https://github.com/JabRef/jabref/issues/11487)
108108
- We fixed an issue where valid DOI could not be imported if it had special characters like `<` or `>`. [#12434](https://github.com/JabRef/jabref/issues/12434)
109+
- We fixed an issue where JabRef displayed an "unknown format" message when importing a .bib file, preventing the associated groups from being imported as well. [#11025](https://github.com/JabRef/jabref/issues/11025)
109110
- We fixed an issue where the tooltip only displayed the first linked file when hovering. [#12470](https://github.com/JabRef/jabref/issues/12470)
110111
- We fixed an issue where JabRef would crash when trying to display an entry in the Citation Relations tab that had right to left text. [#12410](https://github.com/JabRef/jabref/issues/12410)
111112
- We fixed an issue where some texts in the "Citation Information" tab and the "Preferences" dialog could not be translated. [#12883](https://github.com/JabRef/jabref/pull/12883)

src/main/java/org/jabref/gui/importer/ImportCommand.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ private void importSingleFile(Path file, SortedSet<Importer> importers, FileChoo
102102
return;
103103
}
104104

105+
if (selectedExtensionFilter == FileFilterConverter.ANY_FILE || "Available import formats".equals(selectedExtensionFilter.getDescription())) {
106+
selectedExtensionFilter = FileFilterConverter.determineExtensionFilter(file);
107+
}
108+
105109
Optional<Importer> format = FileFilterConverter.getImporter(selectedExtensionFilter, importers);
106110
BackgroundTask<ParserResult> task = BackgroundTask.wrap(
107111
() -> doImport(Collections.singletonList(file), format.orElse(null)));

src/main/java/org/jabref/gui/util/FileFilterConverter.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.jabref.logic.importer.Importer;
1717
import org.jabref.logic.l10n.Localization;
1818
import org.jabref.logic.util.FileType;
19+
import org.jabref.logic.util.StandardFileType;
1920
import org.jabref.logic.util.io.FileUtil;
2021
import org.jabref.model.strings.StringUtil;
2122

@@ -36,6 +37,21 @@ public static FileChooser.ExtensionFilter toExtensionFilter(String description,
3637
return new FileChooser.ExtensionFilter(description, fileType.getExtensionsWithAsteriskAndDot());
3738
}
3839

40+
/**
41+
* Determines the appropriate file extension filter based on the given file.
42+
* If the file is recognized as a BibTeX file, it returns a BibTeX-specific extension filter.
43+
* Otherwise, it returns a generic filter.
44+
*
45+
* @param file The file to check.
46+
* @return The corresponding Extension Filter for the file type.
47+
*/
48+
public static FileChooser.ExtensionFilter determineExtensionFilter(Path file) {
49+
if (FileUtil.isBibFile(file)) {
50+
return toExtensionFilter("BibTeX", StandardFileType.BIBTEX_DB);
51+
}
52+
return FileFilterConverter.ANY_FILE;
53+
}
54+
3955
public static Optional<Importer> getImporter(FileChooser.ExtensionFilter extensionFilter, Collection<Importer> importers) {
4056
return importers.stream().filter(importer -> importer.getName().equals(extensionFilter.getDescription())).findFirst();
4157
}

0 commit comments

Comments
 (0)