Skip to content

Commit 79a7756

Browse files
Siedlerchrkoppor
andauthored
Fix duplicate check/merge entries dialog not triggered on import from… (#10914)
* Fix duplicate check/merge entries dialog not triggered on import from browser Refs #5858 * changelog * remove double duplicate check * remove l10n * add icon, downloading is also handled in import entries * changelog * fix l10n * Update JabRef_en.properties * Update ImportEntriesDialog.java --------- Co-authored-by: Oliver Kopp <[email protected]>
1 parent b4c4272 commit 79a7756

File tree

4 files changed

+11
-112
lines changed

4 files changed

+11
-112
lines changed

Diff for: CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
3333
- We changed the arrangement of the lists in the "Citation relations" tab. `Cites` are now on the left and `Cited by` on the right [#10572](https://github.com/JabRef/jabref/pull/10752)
3434
- Sub libraries based on `aux` file can now also be generated if some citations are not found library. [#10775](https://github.com/JabRef/jabref/pull/10775)
3535
- We rearranged the tab order in the entry editor and renamed the "Scite Tab" to "Citation information". [#10821](https://github.com/JabRef/jabref/issues/10821)
36+
- We changed the duplicate handling in the Import entries dialog. Potential duplicate entries are marked with an icon and importing will now trigger the merge dialog [#10914](https://github.com/JabRef/jabref/pull/10914)
3637
- We made the command "Push to TexShop" more robust to allow cite commands with a character before the first slash. [forum#2699](https://discourse.jabref.org/t/push-to-texshop-mac/2699/17?u=siedlerchr)
3738
- We only show the notification "Saving library..." if the library contains more than 2000 entries. [#9803](https://github.com/JabRef/jabref/issues/9803)
3839
- We enhanced the dialog for adding new fields in the content selector with a selection box containing a list of standard fields. [#10912](https://github.com/JabRef/jabref/pull/10912)

Diff for: src/main/java/org/jabref/gui/importer/ImportEntriesDialog.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,10 @@ private void initialize() {
158158

159159
BackgroundTask.wrap(() -> viewModel.hasDuplicate(entry)).onSuccess(duplicateFound -> {
160160
if (duplicateFound) {
161-
Button duplicateButton = IconTheme.JabRefIcons.DUPLICATE.asButton();
162-
duplicateButton.setTooltip(new Tooltip(Localization.lang("Possible duplicate of existing entry. Click to resolve.")));
163-
duplicateButton.setOnAction(event -> viewModel.resolveDuplicate(entry));
164-
container.getChildren().add(1, duplicateButton);
161+
Node icon = IconTheme.JabRefIcons.ERROR.getGraphicNode();
162+
Tooltip tooltip = new Tooltip(Localization.lang("Possible duplicate of existing entry. Will be resolved on import."));
163+
Tooltip.install(icon, tooltip);
164+
container.getChildren().add(icon);
165165
}
166166
}).executeWith(taskExecutor);
167167

Diff for: src/main/java/org/jabref/gui/importer/ImportEntriesViewModel.java

+2-102
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@
1717
import org.jabref.gui.AbstractViewModel;
1818
import org.jabref.gui.DialogService;
1919
import org.jabref.gui.StateManager;
20-
import org.jabref.gui.duplicationFinder.DuplicateResolverDialog;
2120
import org.jabref.gui.externalfiles.ImportHandler;
22-
import org.jabref.gui.fieldeditors.LinkedFileViewModel;
2321
import org.jabref.gui.util.BackgroundTask;
2422
import org.jabref.gui.util.TaskExecutor;
2523
import org.jabref.logic.bibtex.BibEntryWriter;
@@ -33,7 +31,6 @@
3331
import org.jabref.model.database.BibDatabaseContext;
3432
import org.jabref.model.entry.BibEntry;
3533
import org.jabref.model.entry.BibEntryTypesManager;
36-
import org.jabref.model.entry.LinkedFile;
3734
import org.jabref.model.util.FileUpdateMonitor;
3835
import org.jabref.preferences.PreferencesService;
3936

@@ -142,48 +139,9 @@ public String getSourceString(BibEntry entry) {
142139
* @param entriesToImport subset of the entries contained in parserResult
143140
*/
144141
public void importEntries(List<BibEntry> entriesToImport, boolean shouldDownloadFiles) {
145-
// Check if we are supposed to warn about duplicates.
146-
// If so, then see if there are duplicates, and warn if yes.
147-
if (preferences.getImporterPreferences().shouldWarnAboutDuplicatesOnImport()) {
148-
BackgroundTask.wrap(() -> entriesToImport.stream()
149-
.anyMatch(this::hasDuplicate)).onSuccess(duplicateFound -> {
150-
if (duplicateFound) {
151-
boolean continueImport = dialogService.showConfirmationDialogWithOptOutAndWait(Localization.lang("Duplicates found"),
152-
Localization.lang("There are possible duplicates that haven't been resolved. Continue?"),
153-
Localization.lang("Continue with import"),
154-
Localization.lang("Cancel import"),
155-
Localization.lang("Do not ask again"),
156-
optOut -> preferences.getImporterPreferences().setWarnAboutDuplicatesOnImport(!optOut));
157-
158-
if (!continueImport) {
159-
dialogService.notify(Localization.lang("Import canceled"));
160-
} else {
161-
buildImportHandlerThenImportEntries(entriesToImport);
162-
}
163-
} else {
164-
buildImportHandlerThenImportEntries(entriesToImport);
165-
}
166-
}).executeWith(taskExecutor);
167-
} else {
168-
buildImportHandlerThenImportEntries(entriesToImport);
169-
}
170-
171142
// Remember the selection in the dialog
172143
preferences.getFilePreferences().setDownloadLinkedFiles(shouldDownloadFiles);
173144

174-
if (shouldDownloadFiles) {
175-
for (BibEntry bibEntry : entriesToImport) {
176-
bibEntry.getFiles().stream().filter(LinkedFile::isOnlineLink).forEach(linkedFile ->
177-
new LinkedFileViewModel(
178-
linkedFile,
179-
bibEntry,
180-
databaseContext,
181-
taskExecutor,
182-
dialogService,
183-
preferences).download());
184-
}
185-
}
186-
187145
new DatabaseMerger(preferences.getBibEntryPreferences().getKeywordSeparator()).mergeStrings(
188146
databaseContext.getDatabase(),
189147
parserResult.getDatabase());
@@ -193,7 +151,7 @@ public void importEntries(List<BibEntry> entriesToImport, boolean shouldDownload
193151
parserResult.getPath().map(path -> path.getFileName().toString()).orElse("unknown"),
194152
parserResult.getDatabase().getEntries());
195153

196-
// JabRefGUI.getMainFrame().getCurrentLibraryTab().markBaseChanged();
154+
buildImportHandlerThenImportEntries(entriesToImport);
197155
}
198156

199157
private void buildImportHandlerThenImportEntries(List<BibEntry> entriesToImport) {
@@ -205,8 +163,7 @@ private void buildImportHandlerThenImportEntries(List<BibEntry> entriesToImport)
205163
stateManager,
206164
dialogService,
207165
taskExecutor);
208-
importHandler.importEntries(entriesToImport);
209-
dialogService.notify(Localization.lang("Number of entries successfully imported") + ": " + entriesToImport.size());
166+
importHandler.importEntriesWithDuplicateCheck(selectedDb.getValue(), entriesToImport);
210167
}
211168

212169
/**
@@ -226,61 +183,4 @@ private Optional<BibEntry> findInternalDuplicate(BibEntry entry) {
226183
}
227184
return Optional.empty();
228185
}
229-
230-
public void resolveDuplicate(BibEntry entry) {
231-
// First, try to find duplicate in the existing library
232-
Optional<BibEntry> other = new DuplicateCheck(entryTypesManager).containsDuplicate(databaseContext.getDatabase(), entry, databaseContext.getMode());
233-
if (other.isPresent()) {
234-
DuplicateResolverDialog dialog = new DuplicateResolverDialog(other.get(),
235-
entry, DuplicateResolverDialog.DuplicateResolverType.IMPORT_CHECK, databaseContext, stateManager, dialogService, preferences);
236-
237-
DuplicateResolverDialog.DuplicateResolverResult result = dialogService.showCustomDialogAndWait(dialog)
238-
.orElse(DuplicateResolverDialog.DuplicateResolverResult.BREAK);
239-
240-
if (result == DuplicateResolverDialog.DuplicateResolverResult.KEEP_LEFT) {
241-
// TODO: Remove old entry. Or... add it to a list of entries
242-
// to be deleted. We only delete
243-
// it after Ok is clicked.
244-
// entriesToDelete.add(other.get());
245-
} else if (result == DuplicateResolverDialog.DuplicateResolverResult.KEEP_RIGHT) {
246-
// Remove the entry from the import inspection dialog.
247-
entries.remove(entry);
248-
} else if (result == DuplicateResolverDialog.DuplicateResolverResult.KEEP_BOTH) {
249-
// Do nothing.
250-
} else if (result == DuplicateResolverDialog.DuplicateResolverResult.KEEP_MERGE) {
251-
// TODO: Remove old entry. Or... add it to a list of entries
252-
// to be deleted. We only delete
253-
// it after Ok is clicked.
254-
// entriesToDelete.add(other.get());
255-
256-
// Replace entry by merged entry
257-
entries.add(dialog.getMergedEntry());
258-
entries.remove(entry);
259-
}
260-
return;
261-
}
262-
// Second, check if the duplicate is of another entry in the import:
263-
other = findInternalDuplicate(entry);
264-
if (other.isPresent()) {
265-
DuplicateResolverDialog diag = new DuplicateResolverDialog(entry,
266-
other.get(), DuplicateResolverDialog.DuplicateResolverType.DUPLICATE_SEARCH, databaseContext, stateManager, dialogService, preferences);
267-
268-
DuplicateResolverDialog.DuplicateResolverResult answer = dialogService.showCustomDialogAndWait(diag)
269-
.orElse(DuplicateResolverDialog.DuplicateResolverResult.BREAK);
270-
if (answer == DuplicateResolverDialog.DuplicateResolverResult.KEEP_LEFT) {
271-
// Remove other entry
272-
entries.remove(other.get());
273-
} else if (answer == DuplicateResolverDialog.DuplicateResolverResult.KEEP_RIGHT) {
274-
// Remove entry
275-
entries.remove(entry);
276-
} else if (answer == DuplicateResolverDialog.DuplicateResolverResult.KEEP_BOTH) {
277-
// Do nothing
278-
} else if (answer == DuplicateResolverDialog.DuplicateResolverResult.KEEP_MERGE) {
279-
// Replace both entries by merged entry
280-
entries.add(diag.getMergedEntry());
281-
entries.remove(entry);
282-
entries.remove(other.get());
283-
}
284-
}
285-
}
286186
}

Diff for: src/main/resources/l10n/JabRef_en.properties

+4-6
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,10 @@ Please\ restart\ JabRef\ for\ preferences\ to\ take\ effect.=Please restart JabR
633633

634634
Possible\ duplicate\ entries=Possible duplicate entries
635635

636-
Possible\ duplicate\ of\ existing\ entry.\ Click\ to\ resolve.=Possible duplicate of existing entry. Click to resolve.
636+
Possible\ duplicate\ of\ existing\ entry.\ Will\ be\ resolved\ on\ import.=Possible duplicate of existing entry. Will be resolved on import.
637+
638+
Import\ canceled=Import canceled
639+
637640

638641
Preferences=Preferences
639642

@@ -894,8 +897,6 @@ The\ label\ of\ the\ string\ cannot\ contain\ the\ '\#'\ character.=The label of
894897

895898
The\ output\ option\ depends\ on\ a\ valid\ import\ option.=The output option depends on a valid import option.
896899

897-
There\ are\ possible\ duplicates\ that\ haven't\ been\ resolved.\ Continue?=There are possible duplicates that haven't been resolved. Continue?
898-
899900
This\ operation\ requires\ all\ selected\ entries\ to\ have\ citation\ keys\ defined.=This operation requires all selected entries to have citation keys defined.
900901

901902
This\ operation\ requires\ one\ or\ more\ entries\ to\ be\ selected.=This operation requires one or more entries to be selected.
@@ -1968,9 +1969,6 @@ Export\ format\ name\:=Export format name\:
19681969
Cleared\ connection\ settings=Cleared connection settings
19691970
Error\ adding\ discovered\ CitationStyles=Error adding discovered CitationStyles
19701971
(more)=(more)
1971-
Cancel\ import=Cancel import
1972-
Continue\ with\ import=Continue with import
1973-
Import\ canceled=Import canceled
19741972
Select\ all\ new\ entries=Select all new entries
19751973
Select\ all\ entries=Select all entries
19761974
Total\ items\ found\:=Total items found:

0 commit comments

Comments
 (0)