From 144a37d10e955d8a27ba8e04ef000d86947cd5f0 Mon Sep 17 00:00:00 2001 From: Benedikt Tutzer Date: Fri, 17 Dec 2021 20:40:22 +0100 Subject: [PATCH] Don't register any database changes to the indexer while dropping a file (#8334) * Don't register any database changes to the indexer while dropping a file * Changelog * Use try-with-resources construct * Moved blocking to ExternalFilesEntryLinker --- CHANGELOG.md | 1 + .../gui/entryeditor/DeprecatedFieldsTab.java | 4 +- .../jabref/gui/entryeditor/EntryEditor.java | 18 ++++---- .../gui/entryeditor/FieldsEditorTab.java | 7 ++- .../gui/entryeditor/OptionalFields2Tab.java | 3 ++ .../gui/entryeditor/OptionalFieldsTab.java | 3 ++ .../entryeditor/OptionalFieldsTabBase.java | 4 +- .../gui/entryeditor/OtherFieldsTab.java | 4 +- .../jabref/gui/entryeditor/PreviewTab.java | 7 ++- .../gui/entryeditor/RequiredFieldsTab.java | 4 +- .../gui/entryeditor/UserDefinedFieldsTab.java | 4 +- .../ExternalFilesEntryLinker.java | 46 +++++++++++++++---- .../org/jabref/gui/maintable/MainTable.java | 9 +++- .../org/jabref/gui/preview/PreviewPanel.java | 9 ++-- .../search/indexing/IndexingTaskManager.java | 28 ++++++++--- 15 files changed, 112 insertions(+), 39 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3cf29517dd8..d5615127b62 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -79,6 +79,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve - We fixed an issue where an exception would occur when clicking on a DOI link in the preview pane [#7706](https://github.com/JabRef/jabref/issues/7706) - We fixed an issue where XMP and embedded BibTeX export would not work [#8278](https://github.com/JabRef/jabref/issues/8278) - We fixed an issue where the XMP and embedded BibTeX import of a file containing multiple schemas failed [#8278](https://github.com/JabRef/jabref/issues/8278) +- We fixed an issue where pdf-paths and the pdf-indexer could get out of sync [#8182](https://github.com/JabRef/jabref/issues/8182) ### Removed diff --git a/src/main/java/org/jabref/gui/entryeditor/DeprecatedFieldsTab.java b/src/main/java/org/jabref/gui/entryeditor/DeprecatedFieldsTab.java index 0c52de20ef8..72a9de903ed 100644 --- a/src/main/java/org/jabref/gui/entryeditor/DeprecatedFieldsTab.java +++ b/src/main/java/org/jabref/gui/entryeditor/DeprecatedFieldsTab.java @@ -16,6 +16,7 @@ import org.jabref.gui.util.TaskExecutor; import org.jabref.logic.journals.JournalAbbreviationRepository; import org.jabref.logic.l10n.Localization; +import org.jabref.logic.pdf.search.indexing.IndexingTaskManager; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.BibEntryType; @@ -33,11 +34,12 @@ public DeprecatedFieldsTab(BibDatabaseContext databaseContext, DialogService dialogService, PreferencesService preferences, StateManager stateManager, + IndexingTaskManager indexingTaskManager, BibEntryTypesManager entryTypesManager, ExternalFileTypes externalFileTypes, TaskExecutor taskExecutor, JournalAbbreviationRepository journalAbbreviationRepository) { - super(false, databaseContext, suggestionProviders, undoManager, dialogService, preferences, stateManager, externalFileTypes, taskExecutor, journalAbbreviationRepository); + super(false, databaseContext, suggestionProviders, undoManager, dialogService, preferences, stateManager, externalFileTypes, taskExecutor, journalAbbreviationRepository, indexingTaskManager); this.entryTypesManager = entryTypesManager; setText(Localization.lang("Deprecated fields")); diff --git a/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java b/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java index cbffe89ad47..2c95593c33c 100644 --- a/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java +++ b/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java @@ -143,11 +143,11 @@ public EntryEditor(LibraryTab libraryTab, ExternalFileTypes externalFileTypes) { switch (event.getTransferMode()) { case COPY -> { LOGGER.debug("Mode COPY"); - fileLinker.copyFilesToFileDirAndAddToEntry(entry, files); + fileLinker.copyFilesToFileDirAndAddToEntry(entry, files, libraryTab.getIndexingTaskManager()); } case MOVE -> { LOGGER.debug("Mode MOVE"); - fileLinker.moveFilesToFileDirAndAddToEntry(entry, files); + fileLinker.moveFilesToFileDirAndAddToEntry(entry, files, libraryTab.getIndexingTaskManager()); } case LINK -> { LOGGER.debug("Mode LINK"); @@ -233,22 +233,22 @@ private void navigateToNextEntry() { private List createTabs() { // Preview tab - entryEditorTabs.add(new PreviewTab(databaseContext, dialogService, preferencesService, stateManager, ExternalFileTypes.getInstance())); + entryEditorTabs.add(new PreviewTab(databaseContext, dialogService, preferencesService, stateManager, libraryTab.getIndexingTaskManager(), ExternalFileTypes.getInstance())); // Required fields - entryEditorTabs.add(new RequiredFieldsTab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, dialogService, preferencesService, stateManager, Globals.entryTypesManager, ExternalFileTypes.getInstance(), Globals.TASK_EXECUTOR, Globals.journalAbbreviationRepository)); + entryEditorTabs.add(new RequiredFieldsTab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, dialogService, preferencesService, stateManager, libraryTab.getIndexingTaskManager(), Globals.entryTypesManager, ExternalFileTypes.getInstance(), Globals.TASK_EXECUTOR, Globals.journalAbbreviationRepository)); // Optional fields - entryEditorTabs.add(new OptionalFieldsTab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, dialogService, preferencesService, stateManager, Globals.entryTypesManager, ExternalFileTypes.getInstance(), Globals.TASK_EXECUTOR, Globals.journalAbbreviationRepository)); - entryEditorTabs.add(new OptionalFields2Tab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, dialogService, preferencesService, stateManager, Globals.entryTypesManager, ExternalFileTypes.getInstance(), Globals.TASK_EXECUTOR, Globals.journalAbbreviationRepository)); - entryEditorTabs.add(new DeprecatedFieldsTab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, dialogService, preferencesService, stateManager, Globals.entryTypesManager, ExternalFileTypes.getInstance(), Globals.TASK_EXECUTOR, Globals.journalAbbreviationRepository)); + entryEditorTabs.add(new OptionalFieldsTab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, dialogService, preferencesService, stateManager, libraryTab.getIndexingTaskManager(), Globals.entryTypesManager, ExternalFileTypes.getInstance(), Globals.TASK_EXECUTOR, Globals.journalAbbreviationRepository)); + entryEditorTabs.add(new OptionalFields2Tab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, dialogService, preferencesService, stateManager, libraryTab.getIndexingTaskManager(), Globals.entryTypesManager, ExternalFileTypes.getInstance(), Globals.TASK_EXECUTOR, Globals.journalAbbreviationRepository)); + entryEditorTabs.add(new DeprecatedFieldsTab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, dialogService, preferencesService, stateManager, libraryTab.getIndexingTaskManager(), Globals.entryTypesManager, ExternalFileTypes.getInstance(), Globals.TASK_EXECUTOR, Globals.journalAbbreviationRepository)); // Other fields - entryEditorTabs.add(new OtherFieldsTab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, dialogService, preferencesService, stateManager, Globals.entryTypesManager, ExternalFileTypes.getInstance(), Globals.TASK_EXECUTOR, Globals.journalAbbreviationRepository)); + entryEditorTabs.add(new OtherFieldsTab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, dialogService, preferencesService, stateManager, libraryTab.getIndexingTaskManager(), Globals.entryTypesManager, ExternalFileTypes.getInstance(), Globals.TASK_EXECUTOR, Globals.journalAbbreviationRepository)); // General fields from preferences for (Map.Entry> tab : entryEditorPreferences.getEntryEditorTabList().entrySet()) { - entryEditorTabs.add(new UserDefinedFieldsTab(tab.getKey(), tab.getValue(), databaseContext, libraryTab.getSuggestionProviders(), undoManager, dialogService, preferencesService, stateManager, Globals.entryTypesManager, ExternalFileTypes.getInstance(), Globals.TASK_EXECUTOR, Globals.journalAbbreviationRepository)); + entryEditorTabs.add(new UserDefinedFieldsTab(tab.getKey(), tab.getValue(), databaseContext, libraryTab.getSuggestionProviders(), undoManager, dialogService, preferencesService, stateManager, libraryTab.getIndexingTaskManager(), Globals.entryTypesManager, ExternalFileTypes.getInstance(), Globals.TASK_EXECUTOR, Globals.journalAbbreviationRepository)); } // Special tabs diff --git a/src/main/java/org/jabref/gui/entryeditor/FieldsEditorTab.java b/src/main/java/org/jabref/gui/entryeditor/FieldsEditorTab.java index 63f33c7c75b..60401b19256 100644 --- a/src/main/java/org/jabref/gui/entryeditor/FieldsEditorTab.java +++ b/src/main/java/org/jabref/gui/entryeditor/FieldsEditorTab.java @@ -33,6 +33,7 @@ import org.jabref.gui.preview.PreviewPanel; import org.jabref.gui.util.TaskExecutor; import org.jabref.logic.journals.JournalAbbreviationRepository; +import org.jabref.logic.pdf.search.indexing.IndexingTaskManager; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.field.Field; @@ -52,6 +53,7 @@ abstract class FieldsEditorTab extends EntryEditorTab { private final TaskExecutor taskExecutor; private final JournalAbbreviationRepository journalAbbreviationRepository; private final StateManager stateManager; + private final IndexingTaskManager indexingTaskManager; private PreviewPanel previewPanel; private final UndoManager undoManager; private Collection fields = new ArrayList<>(); @@ -66,7 +68,7 @@ public FieldsEditorTab(boolean compressed, StateManager stateManager, ExternalFileTypes externalFileTypes, TaskExecutor taskExecutor, - JournalAbbreviationRepository journalAbbreviationRepository) { + JournalAbbreviationRepository journalAbbreviationRepository, IndexingTaskManager indexingTaskManager) { this.isCompressed = compressed; this.databaseContext = Objects.requireNonNull(databaseContext); this.suggestionProviders = Objects.requireNonNull(suggestionProviders); @@ -77,6 +79,7 @@ public FieldsEditorTab(boolean compressed, this.taskExecutor = Objects.requireNonNull(taskExecutor); this.journalAbbreviationRepository = Objects.requireNonNull(journalAbbreviationRepository); this.stateManager = stateManager; + this.indexingTaskManager = indexingTaskManager; } private static void addColumn(GridPane gridPane, int columnIndex, List