Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make path relative after BibTeX-from-PDF import #11576

Merged
merged 16 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,15 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv

- We fixed an issue where the "Check for updates" preference was not saved. [#11485](https://github.com/JabRef/jabref/pull/11485)
- We fixed an issue where an exception was thrown after changing "show preview as a tab" in the preferences. [#11515](https://github.com/JabRef/jabref/pull/11515)
- We fixed an issue where JabRef put file paths as absolute path when an entry was created using drag and drop of a PDF file. [#11173](https://github.com/JabRef/jabref/issues/11173)
- We fixed an issue that online and offline mode for new library creation were handled incorrectly. [#11565](https://github.com/JabRef/jabref/pull/11565)
- We fixed an issue with colors in the search bar when dark theme is enabled. [#11569](https://github.com/JabRef/jabref/issues/11569)
- We fixed an issue where a new unsaved library was not marked with an asterisk. [#11519](https://github.com/JabRef/jabref/pull/11519)
- We fixed an issue where JabRef starts without window decorations. [#11440](https://github.com/JabRef/jabref/pull/11440)

### Removed


- We removed support for importing using the SilverPlatterImporter (`Record INSPEC`). [#11576](https://github.com/JabRef/jabref/pull/11576)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did not want the translators to translate something 🤣🤣

Historical note: Tests were added at #510 - and




Expand Down
9 changes: 5 additions & 4 deletions src/main/java/org/jabref/gui/externalfiles/ImportHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import org.jabref.model.groups.GroupTreeNode;
import org.jabref.model.util.FileUpdateMonitor;
import org.jabref.model.util.OptionalUtil;
import org.jabref.preferences.FilePreferences;
import org.jabref.preferences.PreferencesService;

import com.airhacks.afterburner.injection.Injector;
Expand Down Expand Up @@ -99,7 +100,7 @@ public ExternalFilesEntryLinker getLinker() {
return linker;
}

public BackgroundTask<List<ImportFilesResultItemViewModel>> importFilesInBackground(final List<Path> files) {
public BackgroundTask<List<ImportFilesResultItemViewModel>> importFilesInBackground(final List<Path> files, final BibDatabaseContext bibDatabaseContext, final FilePreferences filePreferences) {
return new BackgroundTask<>() {
private int counter;
private final List<ImportFilesResultItemViewModel> results = new ArrayList<>();
Expand Down Expand Up @@ -130,11 +131,11 @@ protected List<ImportFilesResultItemViewModel> call() {
}

if (!pdfEntriesInFile.isEmpty()) {
entriesToAdd.addAll(pdfEntriesInFile);
entriesToAdd.addAll(FileUtil.relativize(pdfEntriesInFile, bibDatabaseContext, filePreferences));
addResultToList(file, true, Localization.lang("File was successfully imported as a new entry"));
} else {
entriesToAdd.add(createEmptyEntryWithLink(file));
addResultToList(file, false, Localization.lang("No metadata was found. An empty entry was created with file link"));
addResultToList(file, false, Localization.lang("No BibTeX was found. An empty entry was created with file link."));
}
} else if (FileUtil.isBibFile(file)) {
var bibtexParserResult = contentImporter.importFromBibFile(file, fileUpdateMonitor);
Expand All @@ -146,7 +147,7 @@ protected List<ImportFilesResultItemViewModel> call() {
addResultToList(file, true, Localization.lang("Bib entry was successfully imported"));
} else {
entriesToAdd.add(createEmptyEntryWithLink(file));
addResultToList(file, false, Localization.lang("No BibTeX data was found. An empty entry was created with file link"));
addResultToList(file, false, Localization.lang("No BibTeX data was found. An empty entry was created with file link."));
}
} catch (IOException ex) {
LOGGER.error("Error importing", ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public void startImport() {
}
resultList.clear();

importFilesBackgroundTask = importHandler.importFilesInBackground(fileList)
importFilesBackgroundTask = importHandler.importFilesInBackground(fileList, bibDatabase, preferences.getFilePreferences())
.onRunning(() -> {
progressValueProperty.bind(importFilesBackgroundTask.workDonePercentageProperty());
progressTextProperty.bind(importFilesBackgroundTask.messageProperty());
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/org/jabref/gui/maintable/MainTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import org.jabref.model.entry.BibEntryTypesManager;
import org.jabref.model.entry.BibtexString;
import org.jabref.model.util.FileUpdateMonitor;
import org.jabref.preferences.FilePreferences;
import org.jabref.preferences.PreferencesService;

import com.airhacks.afterburner.injection.Injector;
Expand Down Expand Up @@ -84,6 +85,7 @@ public class MainTable extends TableView<BibEntryTableViewModel> {
private final BibEntryTypesManager entryTypesManager;
private final TaskExecutor taskExecutor;
private final UndoManager undoManager;
private final FilePreferences filePreferences;
private long lastKeyPressTime;
private String columnSearchTerm;

Expand All @@ -110,6 +112,8 @@ public MainTable(MainTableDataModel model,
this.entryTypesManager = entryTypesManager;
this.taskExecutor = taskExecutor;
this.undoManager = libraryTab.getUndoManager();
this.filePreferences = preferencesService.getFilePreferences();

MainTablePreferences mainTablePreferences = preferencesService.getMainTablePreferences();

importHandler = new ImportHandler(
Expand Down Expand Up @@ -492,8 +496,7 @@ private void handleOnDragDropped(TableRow<BibEntryTableViewModel> row, BibEntryT
// Center -> link files to entry
// Depending on the pressed modifier, move/copy/link files to drop target
switch (ControlHelper.getDroppingMouseLocation(row, event)) {
case TOP, BOTTOM ->
importHandler.importFilesInBackground(files).executeWith(taskExecutor);
case TOP, BOTTOM -> importHandler.importFilesInBackground(files, database, filePreferences).executeWith(taskExecutor);
case CENTER -> {
BibEntry entry = target.getEntry();
switch (event.getTransferMode()) {
Expand Down Expand Up @@ -524,9 +527,8 @@ private void handleOnDragDroppedTableView(DragEvent event) {
boolean success = false;

if (event.getDragboard().hasFiles()) {
List<Path> files = event.getDragboard().getFiles().stream().map(File::toPath).collect(Collectors.toList());
importHandler.importFilesInBackground(files).executeWith(taskExecutor);

List<Path> files = event.getDragboard().getFiles().stream().map(File::toPath).toList();
importHandler.importFilesInBackground(files, this.database, filePreferences).executeWith(taskExecutor);
success = true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
*/
public class FetchAndMergeEntry {

// A list of all field which are supported
public static List<Field> SUPPORTED_FIELDS = Arrays.asList(StandardField.DOI, StandardField.EPRINT, StandardField.ISBN);

private static final Logger LOGGER = LoggerFactory.getLogger(FetchAndMergeEntry.class);
private final DialogService dialogService;
private final UndoManager undoManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import org.jabref.logic.importer.fileformat.PdfXmpImporter;
import org.jabref.logic.importer.fileformat.RepecNepImporter;
import org.jabref.logic.importer.fileformat.RisImporter;
import org.jabref.logic.importer.fileformat.SilverPlatterImporter;
import org.jabref.logic.l10n.Localization;
import org.jabref.model.database.BibDatabases;
import org.jabref.model.entry.BibEntry;
Expand All @@ -55,7 +54,8 @@ public class ImportFormatReader {

public ImportFormatReader(ImporterPreferences importerPreferences,
ImportFormatPreferences importFormatPreferences,
CitationKeyPatternPreferences citationKeyPatternPreferences, FileUpdateMonitor fileUpdateMonitor) {
CitationKeyPatternPreferences citationKeyPatternPreferences,
FileUpdateMonitor fileUpdateMonitor) {
this.importerPreferences = importerPreferences;
this.importFormatPreferences = importFormatPreferences;
this.fileUpdateMonitor = fileUpdateMonitor;
Expand Down Expand Up @@ -84,7 +84,6 @@ public void reset() {
formats.add(new PdfXmpImporter(importFormatPreferences.xmpPreferences()));
formats.add(new RepecNepImporter(importFormatPreferences));
formats.add(new RisImporter());
formats.add(new SilverPlatterImporter());
formats.add(new CffImporter(citationKeyPatternPreferences));
formats.add(new BiblioscapeImporter());
formats.add(new BibtexImporter(importFormatPreferences, fileUpdateMonitor));
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/org/jabref/logic/importer/WebFetchers.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,6 @@ public static SortedSet<IdBasedFetcher> getIdBasedFetchers(ImportFormatPreferenc
return set;
}

/**
* @return sorted set containing entry based fetchers
*/
public static SortedSet<EntryBasedFetcher> getEntryBasedFetchers(ImporterPreferences importerPreferences,
ImportFormatPreferences importFormatPreferences,
FilePreferences filePreferences,
Expand All @@ -178,9 +175,13 @@ public static SortedSet<EntryBasedFetcher> getEntryBasedFetchers(ImporterPrefere
set.add(new MathSciNet(importFormatPreferences));
set.add(new CrossRef());
set.add(new ZbMATH(importFormatPreferences));
set.add(new PdfMergeMetadataImporter.EntryBasedFetcherWrapper(importFormatPreferences, filePreferences, databaseContext));
set.add(new SemanticScholar(importerPreferences));
set.add(new ResearchGate(importFormatPreferences));

// Uses the PDFs - and then uses the parsed DOI. Makes it 10% a web fetcher.
// We list it here, because otherwise, it would be much more effort (other UI button, ...)
set.add(new PdfMergeMetadataImporter.EntryBasedFetcherWrapper(importFormatPreferences, filePreferences, databaseContext));

return set;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public String getName() {

@Override
public String getDescription() {
return "Reads the references from the 'References' section of a PDF file.";
return Localization.lang("Reads the references from the 'References' section of a PDF file.");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import org.jabref.logic.importer.Importer;
import org.jabref.logic.importer.ParserResult;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.util.StandardFileType;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.field.Field;
Expand Down Expand Up @@ -38,8 +39,7 @@ public StandardFileType getFileType() {

@Override
public String getDescription() {
return "Imports a Biblioscape Tag File.\n" +
"Several Biblioscape field types are ignored. Others are only included in the BibTeX field \"comment\".";
return Localization.lang("Imports a Biblioscape Tag File.\nSeveral Biblioscape field types are ignored. Others are only included in the BibTeX field \"comment\".");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.jabref.logic.importer.ImportFormatPreferences;
import org.jabref.logic.importer.Importer;
import org.jabref.logic.importer.ParserResult;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.util.StandardFileType;
import org.jabref.model.database.BibDatabaseModeDetection;
import org.jabref.model.util.FileUpdateMonitor;
Expand Down Expand Up @@ -139,7 +140,7 @@ public StandardFileType getFileType() {

@Override
public String getDescription() {
return "This importer enables `--importToOpen someEntry.bib`";
return Localization.lang("This importer enables \"--importToOpen someEntry.bib\"");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.jabref.logic.exporter.CffExporter;
import org.jabref.logic.importer.Importer;
import org.jabref.logic.importer.ParserResult;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.util.StandardFileType;
import org.jabref.model.entry.Author;
import org.jabref.model.entry.AuthorList;
Expand Down Expand Up @@ -57,7 +58,7 @@ public String getId() {

@Override
public String getDescription() {
return "Importer for the CFF format, which is intended to make software and datasets citable.";
return Localization.lang("Importer for the CFF format, which is intended to make software and datasets citable.");
}

// POJO classes for yaml data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.jabref.logic.importer.fileformat.citavi.CitaviExchangeData.KnowledgeItems;
import org.jabref.logic.importer.fileformat.citavi.CitaviExchangeData.KnowledgeItems.KnowledgeItem;
import org.jabref.logic.importer.fileformat.citavi.CitaviExchangeData.Persons.Person;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.util.StandardFileType;
import org.jabref.model.entry.Author;
import org.jabref.model.entry.AuthorList;
Expand Down Expand Up @@ -108,7 +109,7 @@ public String getId() {

@Override
public String getDescription() {
return "Importer for the Citavi XML format.";
return Localization.lang("Importer for the Citavi XML format.");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import org.jabref.logic.importer.Importer;
import org.jabref.logic.importer.ParserResult;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.util.StandardFileType;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.field.Field;
Expand Down Expand Up @@ -43,7 +44,7 @@ public String getId() {

@Override
public String getDescription() {
return "Importer for COPAC format.";
return Localization.lang("Importer for COPAC format.");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.jabref.logic.citationkeypattern.CitationKeyGenerator;
import org.jabref.logic.importer.Importer;
import org.jabref.logic.importer.ParserResult;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.util.StandardFileType;
import org.jabref.model.entry.AuthorList;
import org.jabref.model.entry.BibEntry;
Expand Down Expand Up @@ -52,7 +53,7 @@ public String getId() {

@Override
public String getDescription() {
return "Importer for the Refer/Endnote format. Modified to use article number for pages if pages are missing.";
return Localization.lang("Importer for the Refer/Endnote format. Modified to use article number for pages if pages are missing.");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.jabref.logic.importer.ParseException;
import org.jabref.logic.importer.Parser;
import org.jabref.logic.importer.ParserResult;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.util.StandardFileType;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.KeywordList;
Expand Down Expand Up @@ -121,7 +122,7 @@ public String getId() {

@Override
public String getDescription() {
return "Importer for the EndNote XML format.";
return Localization.lang("Importer for the EndNote XML format.");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import org.jabref.logic.importer.Importer;
import org.jabref.logic.importer.ParserResult;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.util.StandardFileType;
import org.jabref.model.entry.AuthorList;
import org.jabref.model.entry.BibEntry;
Expand Down Expand Up @@ -38,7 +39,7 @@ public StandardFileType getFileType() {

@Override
public String getDescription() {
return "INSPEC format importer.";
return Localization.lang("Importer for the INSPEC format.");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.jabref.logic.formatter.casechanger.TitleCaseFormatter;
import org.jabref.logic.importer.Importer;
import org.jabref.logic.importer.ParserResult;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.util.StandardFileType;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.Month;
Expand Down Expand Up @@ -72,7 +73,7 @@ public String getId() {

@Override
public String getDescription() {
return "Importer for the ISI Web of Science, INSPEC and Medline format.";
return Localization.lang("Importer for the ISI Web of Science, INSPEC and Medline format.");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.jabref.logic.importer.fileformat.medline.OtherId;
import org.jabref.logic.importer.fileformat.medline.PersonalNameSubject;
import org.jabref.logic.importer.util.MathMLParser;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.util.StandardFileType;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.Date;
Expand Down Expand Up @@ -85,7 +86,7 @@ public String getId() {

@Override
public String getDescription() {
return "Importer for the Medline format.";
return Localization.lang("Importer for the Medline format.");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.jabref.logic.importer.ImportFormatPreferences;
import org.jabref.logic.importer.Importer;
import org.jabref.logic.importer.ParserResult;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.util.StandardFileType;
import org.jabref.model.entry.AuthorList;
import org.jabref.model.entry.BibEntry;
Expand Down Expand Up @@ -51,7 +52,7 @@ public StandardFileType getFileType() {

@Override
public String getDescription() {
return "Importer for the MedlinePlain format.";
return Localization.lang("Importer for the MedlinePlain format.");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.jabref.logic.importer.fileformat.mods.Identifier;
import org.jabref.logic.importer.fileformat.mods.Name;
import org.jabref.logic.importer.fileformat.mods.RecordInfo;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.util.StandardFileType;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.Date;
Expand Down Expand Up @@ -624,7 +625,7 @@ public StandardFileType getFileType() {

@Override
public String getDescription() {
return "Importer for the MODS format";
return Localization.lang("Importer for the MODS format.");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public StandardFileType getFileType() {

@Override
public String getDescription() {
return "Takes valid JSON documents from the Mr. DLib API and parses them into a BibEntry";
return "Takes valid JSON documents from the Mr. DLib API and parses them into a BibEntry.";
}

/**
Expand Down
Loading
Loading