-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Duplicate check on import should be run in background Task #4963 #4981
Changes from 7 commits
f86ce7c
ebefc85
6ec9ee8
c27f6e6
bb5b2a9
f7c0551
300eae7
006a443
a6fc6f3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
import javafx.collections.FXCollections; | ||
import javafx.collections.ObservableList; | ||
|
||
import org.jabref.Globals; | ||
import org.jabref.gui.AbstractViewModel; | ||
import org.jabref.gui.DialogService; | ||
import org.jabref.gui.StateManager; | ||
|
@@ -50,7 +51,7 @@ public ImportEntriesViewModel(BackgroundTask<List<BibEntry>> task, TaskExecutor | |
this.message.bind(task.messageProperty()); | ||
|
||
task.onSuccess(entriesToImport -> entries.addAll(entriesToImport)) | ||
.executeWith(taskExecutor); | ||
.executeWith(taskExecutor); | ||
} | ||
|
||
public String getMessage() { | ||
|
@@ -75,24 +76,33 @@ public void importEntries(List<BibEntry> entriesToImport) { | |
// Check if we are supposed to warn about duplicates. | ||
// If so, then see if there are duplicates, and warn if yes. | ||
if (preferences.shouldWarnAboutDuplicatesForImport()) { | ||
boolean containsDuplicate = entriesToImport.stream() | ||
.anyMatch(this::hasDuplicate); | ||
|
||
if (containsDuplicate) { | ||
boolean continueImport = dialogService.showConfirmationDialogWithOptOutAndWait(Localization.lang("Duplicates found"), | ||
Localization.lang("There are possible duplicates (marked with an icon) that haven't been resolved. Continue?"), | ||
Localization.lang("Continue with import"), | ||
Localization.lang("Cancel import"), | ||
Localization.lang("Disable this confirmation dialog"), | ||
optOut -> preferences.setShouldWarnAboutDuplicatesForImport(!optOut)); | ||
|
||
if (!continueImport) { | ||
dialogService.notify(Localization.lang("Import canceled")); | ||
return; | ||
BackgroundTask.wrap(() -> entriesToImport.stream() | ||
.anyMatch(this::hasDuplicate)).onSuccess(duplicateFound -> { | ||
if (duplicateFound) { | ||
boolean continueImport = dialogService.showConfirmationDialogWithOptOutAndWait(Localization.lang("Duplicates found"), | ||
Localization.lang("There are possible duplicates (marked with an icon) that haven't been resolved. Continue?"), | ||
Localization.lang("Continue with import"), | ||
Localization.lang("Cancel import"), | ||
Localization.lang("Disable this confirmation dialog"), | ||
optOut -> preferences.setShouldWarnAboutDuplicatesForImport(!optOut)); | ||
|
||
if (!continueImport) { | ||
dialogService.notify(Localization.lang("Import canceled")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a small problem with the current solution: because the background task is called asynchronously, the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The importEntries function depends on duplicateCheck from the beginning it seems. Does it mean the importEntries requires some refactoring so that duplicate check will not be called inside that method, or I took it wrong? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it should be enough to move the rest of the method up here:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the update. It looks almost good now: the import should also be performed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks, sure There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as abvoe, please no abbreviations like "e" for variables (except for exceptions maybe) |
||
} else { | ||
buildImportHandlerThenImportEntries(entriesToImport); | ||
dialogService.notify(Localization.lang("Number of entries successfully imported") + ": " + entriesToImport.size()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please move the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure, should be done |
||
} | ||
} else { | ||
buildImportHandlerThenImportEntries(entriesToImport); | ||
} | ||
} | ||
}).executeWith(Globals.TASK_EXECUTOR); | ||
} else { | ||
buildImportHandlerThenImportEntries(entriesToImport); | ||
} | ||
|
||
} | ||
|
||
private void buildImportHandlerThenImportEntries(List<BibEntry> entriesToImport) { | ||
ImportHandler importHandler = new ImportHandler( | ||
dialogService, | ||
database, | ||
|
@@ -104,8 +114,6 @@ public void importEntries(List<BibEntry> entriesToImport) { | |
undoManager, | ||
stateManager); | ||
importHandler.importEntries(entriesToImport); | ||
|
||
dialogService.notify(Localization.lang("Number of entries successfully imported") + ": " + entriesToImport.size()); | ||
} | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please no single abbrevations, try to specify the result in the variable name, e.g. duplicateFound
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You apparently overlooked this one here