Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into dependabot/gradle/c…
Browse files Browse the repository at this point in the history
…om.github.tomtung-latex2unicode_2.12-0.3.0

* upstream/main:
  Remove obsolete comments
  Improve key generation (#8641)
  Refine search code (#8636)
  Fix import entry by id does not generate citation key (#8361)
  Update Gradle Wrapper from 7.4.1 to 7.4.2. (#8637)
  Bump hmarr/auto-approve-action from 2.1.0 to 2.2.0 (#8638)
  • Loading branch information
Siedlerchr committed Apr 5, 2022
2 parents d7fbd59 + dbf921e commit cce5a92
Show file tree
Hide file tree
Showing 27 changed files with 314 additions and 325 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/automerge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
- name: Auto approve
uses: hmarr/auto-approve-action@v2.1.0
uses: hmarr/auto-approve-action@v2.2.0
if: steps.waitforstatuschecks.outputs.status == 'success'
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- We fixed an issue where opening the changelog from withing JabRef led to a 404 error [#8563](https://github.com/JabRef/jabref/issues/8563)
- We fixed an issue where not all found unlinked local files were imported correctly due to some race condition. [#8444](https://github.com/JabRef/jabref/issues/8444)
- We fixed an issue where Merge entries dialog exceeds screen boundaries.
- We fixed an issue where no citationkey was generated on import, pasting a doi or an entry on the main table [8406](https://github.com/JabRef/jabref/issues/8406), [koppor#553](https://github.com/koppor/jabref/issues/553)

### Removed

Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionSha256Sum=e5444a57cda4a95f90b0c9446a9e1b47d3d7f69057765bfb54bd4f482542d548
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.1-bin.zip
distributionSha256Sum=29e49b10984e585d8118b7d0bc452f944e386458df27371b49b4ac1dec4b7fda
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
32 changes: 6 additions & 26 deletions src/main/java/org/jabref/gui/EntryTypeViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@
import javafx.concurrent.Task;
import javafx.concurrent.Worker;

import org.jabref.gui.duplicationFinder.DuplicateResolverDialog;
import org.jabref.gui.externalfiles.ImportHandler;
import org.jabref.gui.externalfiletype.ExternalFileTypes;
import org.jabref.gui.importer.NewEntryAction;
import org.jabref.logic.citationkeypattern.CitationKeyGenerator;
import org.jabref.logic.database.DuplicateCheck;
import org.jabref.logic.importer.FetcherException;
import org.jabref.logic.importer.IdBasedFetcher;
import org.jabref.logic.importer.ImportCleanup;
import org.jabref.logic.importer.WebFetchers;
import org.jabref.logic.importer.fetcher.DoiFetcher;
import org.jabref.logic.l10n.Localization;
Expand Down Expand Up @@ -153,28 +151,10 @@ public void runFetcherWorker() {
Optional<BibEntry> result = fetcherWorker.getValue();
if (result.isPresent()) {
final BibEntry entry = result.get();
ImportCleanup cleanup = new ImportCleanup(libraryTab.getBibDatabaseContext().getMode());
cleanup.doPostCleanup(entry);
Optional<BibEntry> duplicate = new DuplicateCheck(Globals.entryTypesManager).containsDuplicate(libraryTab.getDatabase(), entry, libraryTab.getBibDatabaseContext().getMode());
if (duplicate.isPresent()) {
DuplicateResolverDialog dialog = new DuplicateResolverDialog(entry, duplicate.get(), DuplicateResolverDialog.DuplicateResolverType.IMPORT_CHECK, libraryTab.getBibDatabaseContext(), stateManager);
switch (dialogService.showCustomDialogAndWait(dialog)
.orElse(DuplicateResolverDialog.DuplicateResolverResult.BREAK)) {
case KEEP_LEFT -> {
libraryTab.getDatabase().removeEntry(duplicate.get());
libraryTab.getDatabase().insertEntry(entry);
}
case KEEP_BOTH -> libraryTab.getDatabase().insertEntry(entry);
case KEEP_MERGE -> {
libraryTab.getDatabase().removeEntry(duplicate.get());
libraryTab.getDatabase().insertEntry(dialog.getMergedEntry());
}
}
} else {
// Regenerate CiteKey of imported BibEntry
new CitationKeyGenerator(libraryTab.getBibDatabaseContext(), preferencesService.getCitationKeyPatternPreferences()).generateAndSetKey(entry);
libraryTab.insertEntry(entry);
}

ImportHandler handler = new ImportHandler(libraryTab.getBibDatabaseContext(), ExternalFileTypes.getInstance(), preferencesService, Globals.getFileUpdateMonitor(), libraryTab.getUndoManager(), stateManager, dialogService);
handler.importEntryWithDuplicateCheck(libraryTab.getBibDatabaseContext(), entry);

searchSuccesfulProperty.set(true);
} else if (StringUtil.isBlank(idText.getValue())) {
dialogService.showWarningDialogAndWait(Localization.lang("Empty search ID"), Localization.lang("The given search ID was empty."));
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/LibraryTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ public void copy() {
}

public void paste() {
mainTable.paste(this.bibDatabaseContext.getMode());
mainTable.paste();
}

public void cut() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public BibtexExtractorViewModel(BibDatabaseContext bibdatabaseContext,
preferencesService,
fileUpdateMonitor,
undoManager,
stateManager);
stateManager,
dialogService);
}

public StringProperty inputTextProperty() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void setAccepted(boolean accepted) {
public void makeChange(BibDatabaseContext database, NamedCompound undoEdit) {
this.description(); // Init dialog to prevent NPE
database.getDatabase().removeEntry(oldEntry);
BibEntry mergedEntry = mergePanel.getMergeEntry();
BibEntry mergedEntry = mergePanel.getMergedEntry();
mergedEntry.setId(oldEntry.getId()); // Keep ID
database.getDatabase().insertEntry(mergedEntry);
undoEdit.addEdit(new UndoableInsertEntries(database.getDatabase(), oldEntry));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public enum DuplicateResolverResult {
BREAK
}

private MergeEntries me;
private MergeEntries mergeEntries;

public DuplicateResolverDialog(BibEntry one, BibEntry two, DuplicateResolverType type, BibDatabaseContext database, StateManager stateManager) {
this.setTitle(Localization.lang("Possible duplicate entries"));
Expand All @@ -48,7 +48,6 @@ public DuplicateResolverDialog(BibEntry one, BibEntry two, DuplicateResolverType
}

private void init(BibEntry one, BibEntry two, DuplicateResolverType type) {

HelpAction helpCommand = new HelpAction(HelpFile.FIND_DUPLICATES);
ButtonType help = new ButtonType(Localization.lang("Help"), ButtonData.HELP);

Expand All @@ -67,13 +66,13 @@ private void init(BibEntry one, BibEntry two, DuplicateResolverType type) {
first = new ButtonType(Localization.lang("Keep left"), ButtonData.APPLY);
second = new ButtonType(Localization.lang("Keep right"), ButtonData.APPLY);
both = new ButtonType(Localization.lang("Keep both"), ButtonData.APPLY);
me = new MergeEntries(one, two);
mergeEntries = new MergeEntries(one, two);
break;
case INSPECTION:
first = new ButtonType(Localization.lang("Remove old entry"), ButtonData.APPLY);
second = new ButtonType(Localization.lang("Remove entry from import"), ButtonData.APPLY);
both = new ButtonType(Localization.lang("Keep both"), ButtonData.APPLY);
me = new MergeEntries(one, two, Localization.lang("Old entry"),
mergeEntries = new MergeEntries(one, two, Localization.lang("Old entry"),
Localization.lang("From import"));
break;
case DUPLICATE_SEARCH_WITH_EXACT:
Expand All @@ -83,13 +82,13 @@ private void init(BibEntry one, BibEntry two, DuplicateResolverType type) {

removeExactVisible = true;

me = new MergeEntries(one, two);
mergeEntries = new MergeEntries(one, two);
break;
default:
first = new ButtonType(Localization.lang("Import and remove old entry"), ButtonData.APPLY);
second = new ButtonType(Localization.lang("Do not import entry"), ButtonData.APPLY);
both = new ButtonType(Localization.lang("Import and keep old entry"), ButtonData.APPLY);
me = new MergeEntries(one, two, Localization.lang("Old entry"),
mergeEntries = new MergeEntries(one, two, Localization.lang("Old entry"),
Localization.lang("From import"));
break;
}
Expand All @@ -107,7 +106,7 @@ private void init(BibEntry one, BibEntry two, DuplicateResolverType type) {
this.setY(state.getY());
}

BorderPane borderPane = new BorderPane(me);
BorderPane borderPane = new BorderPane(mergeEntries);
borderPane.setBottom(options);

this.setResultConverter(button -> {
Expand All @@ -134,6 +133,6 @@ private void init(BibEntry one, BibEntry two, DuplicateResolverType type) {
}

public BibEntry getMergedEntry() {
return me.getMergeEntry();
return mergeEntries.getMergedEntry();
}
}
67 changes: 57 additions & 10 deletions src/main/java/org/jabref/gui/externalfiles/ImportHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,21 @@
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Optional;

import javax.swing.undo.CompoundEdit;
import javax.swing.undo.UndoManager;

import org.jabref.gui.DialogService;
import org.jabref.gui.Globals;
import org.jabref.gui.StateManager;
import org.jabref.gui.duplicationFinder.DuplicateResolverDialog;
import org.jabref.gui.externalfiletype.ExternalFileTypes;
import org.jabref.gui.undo.UndoableInsertEntries;
import org.jabref.gui.util.BackgroundTask;
import org.jabref.gui.util.DefaultTaskExecutor;
import org.jabref.logic.citationkeypattern.CitationKeyGenerator;
import org.jabref.logic.database.DuplicateCheck;
import org.jabref.logic.externalfiles.ExternalFilesContentImporter;
import org.jabref.logic.importer.ImportCleanup;
import org.jabref.logic.l10n.Localization;
Expand All @@ -36,25 +41,28 @@
public class ImportHandler {

private static final Logger LOGGER = LoggerFactory.getLogger(ImportHandler.class);
private final BibDatabaseContext bibdatabase;
private final BibDatabaseContext bibDatabaseContext;
private final PreferencesService preferencesService;
private final FileUpdateMonitor fileUpdateMonitor;
private final ExternalFilesEntryLinker linker;
private final ExternalFilesContentImporter contentImporter;
private final UndoManager undoManager;
private final StateManager stateManager;
private final DialogService dialogService;

public ImportHandler(BibDatabaseContext database,
ExternalFileTypes externalFileTypes,
PreferencesService preferencesService,
FileUpdateMonitor fileupdateMonitor,
UndoManager undoManager,
StateManager stateManager) {
StateManager stateManager,
DialogService dialogService) {

this.bibdatabase = database;
this.bibDatabaseContext = database;
this.preferencesService = preferencesService;
this.fileUpdateMonitor = fileupdateMonitor;
this.stateManager = stateManager;
this.dialogService = dialogService;

this.linker = new ExternalFilesEntryLinker(externalFileTypes, preferencesService.getFilePreferences(), database);
this.contentImporter = new ExternalFilesContentImporter(
Expand Down Expand Up @@ -127,7 +135,7 @@ protected List<ImportFilesResultItemViewModel> call() {
// We need to run the actual import on the FX Thread, otherwise we will get some deadlocks with the UIThreadList
DefaultTaskExecutor.runInJavaFXThread(() -> importEntries(entriesToAdd));

ce.addEdit(new UndoableInsertEntries(bibdatabase.getDatabase(), entriesToAdd));
ce.addEdit(new UndoableInsertEntries(bibDatabaseContext.getDatabase(), entriesToAdd));
ce.end();
undoManager.addEdit(ce);

Expand All @@ -151,9 +159,9 @@ private BibEntry createEmptyEntryWithLink(Path file) {
}

public void importEntries(List<BibEntry> entries) {
ImportCleanup cleanup = new ImportCleanup(bibdatabase.getMode());
ImportCleanup cleanup = new ImportCleanup(bibDatabaseContext.getMode());
cleanup.doPostCleanup(entries);
bibdatabase.getDatabase().insertEntries(entries);
bibDatabaseContext.getDatabase().insertEntries(entries);

// Set owner/timestamp
UpdateField.setAutomaticFields(entries,
Expand All @@ -166,7 +174,46 @@ public void importEntries(List<BibEntry> entries) {
}

// Add to group
addToGroups(entries, stateManager.getSelectedGroup(bibdatabase));
addToGroups(entries, stateManager.getSelectedGroup(bibDatabaseContext));
}

public void importEntryWithDuplicateCheck(BibDatabaseContext bibDatabaseContext, BibEntry entry) {
ImportCleanup cleanup = new ImportCleanup(bibDatabaseContext.getMode());
BibEntry cleanedEntry = cleanup.doPostCleanup(entry);
BibEntry entryToInsert = cleanedEntry;

Optional<BibEntry> existingDuplicateInLibrary = new DuplicateCheck(Globals.entryTypesManager).containsDuplicate(bibDatabaseContext.getDatabase(), entryToInsert, bibDatabaseContext.getMode());
if (existingDuplicateInLibrary.isPresent()) {
DuplicateResolverDialog dialog = new DuplicateResolverDialog(existingDuplicateInLibrary.get(), entryToInsert, DuplicateResolverDialog.DuplicateResolverType.IMPORT_CHECK, bibDatabaseContext, stateManager);
switch (dialogService.showCustomDialogAndWait(dialog).orElse(DuplicateResolverDialog.DuplicateResolverResult.BREAK)) {
case KEEP_LEFT:
bibDatabaseContext.getDatabase().removeEntry(existingDuplicateInLibrary.get());
break;
case KEEP_BOTH:
break;
case KEEP_MERGE:
bibDatabaseContext.getDatabase().removeEntry(existingDuplicateInLibrary.get());
entryToInsert = dialog.getMergedEntry();
break;
case KEEP_RIGHT:
case AUTOREMOVE_EXACT:
case BREAK:
default:
return;
}
}
// Regenerate CiteKey of imported BibEntry
if (preferencesService.getImporterPreferences().isGenerateNewKeyOnImport()) {
generateKeys(List.of(entryToInsert));
}
bibDatabaseContext.getDatabase().insertEntry(entryToInsert);

// Set owner/timestamp
UpdateField.setAutomaticFields(List.of(entryToInsert),
preferencesService.getOwnerPreferences(),
preferencesService.getTimestampPreferences());

addToGroups(List.of(entry), stateManager.getSelectedGroup(this.bibDatabaseContext));
}

private void addToGroups(List<BibEntry> entries, Collection<GroupTreeNode> groups) {
Expand All @@ -189,9 +236,9 @@ private void addToGroups(List<BibEntry> entries, Collection<GroupTreeNode> group
*/
private void generateKeys(List<BibEntry> entries) {
CitationKeyGenerator keyGenerator = new CitationKeyGenerator(
bibdatabase.getMetaData().getCiteKeyPattern(preferencesService.getCitationKeyPatternPreferences()
.getKeyPattern()),
bibdatabase.getDatabase(),
bibDatabaseContext.getMetaData().getCiteKeyPattern(preferencesService.getCitationKeyPatternPreferences()
.getKeyPattern()),
bibDatabaseContext.getDatabase(),
preferencesService.getCitationKeyPatternPreferences());

for (BibEntry entry : entries) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ public UnlinkedFilesDialogViewModel(DialogService dialogService,
preferences,
fileUpdateMonitor,
undoManager,
stateManager);
stateManager,
dialogService);

this.fileFilterList = FXCollections.observableArrayList(
new FileExtensionViewModel(StandardFileType.ANY_FILE, externalFileTypes),
Expand Down
Loading

0 comments on commit cce5a92

Please sign in to comment.