-
-
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
Don't register any database changes to the indexer while dropping a file #8334
Changes from 2 commits
dfc912d
1c312ae
9f85d37
6596726
b905428
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 |
---|---|---|
|
@@ -43,11 +43,13 @@ | |
import org.jabref.gui.util.ViewModelTableRowFactory; | ||
import org.jabref.logic.importer.ImportCleanup; | ||
import org.jabref.logic.l10n.Localization; | ||
import org.jabref.logic.pdf.search.indexing.PdfIndexer; | ||
import org.jabref.logic.util.OS; | ||
import org.jabref.model.database.BibDatabaseContext; | ||
import org.jabref.model.database.BibDatabaseMode; | ||
import org.jabref.model.database.event.EntriesAddedEvent; | ||
import org.jabref.model.entry.BibEntry; | ||
import org.jabref.preferences.FilePreferences; | ||
import org.jabref.preferences.PreferencesService; | ||
|
||
import com.google.common.eventbus.Subscribe; | ||
|
@@ -69,6 +71,8 @@ public class MainTable extends TableView<BibEntryTableViewModel> { | |
private long lastKeyPressTime; | ||
private String columnSearchTerm; | ||
|
||
private final FilePreferences filePreferences; | ||
|
||
public MainTable(MainTableDataModel model, | ||
LibraryTab libraryTab, | ||
BibDatabaseContext database, | ||
|
@@ -178,6 +182,8 @@ public MainTable(MainTableDataModel model, | |
this.jumpToSearchKey(getSortOrder().get(0), key); | ||
}); | ||
|
||
filePreferences = preferencesService.getFilePreferences(); | ||
|
||
database.getDatabase().registerListener(this); | ||
} | ||
|
||
|
@@ -375,20 +381,30 @@ private void handleOnDragDropped(TableRow<BibEntryTableViewModel> row, BibEntryT | |
switch (ControlHelper.getDroppingMouseLocation(row, event)) { | ||
case TOP, BOTTOM -> importHandler.importFilesInBackground(files).executeWith(Globals.TASK_EXECUTOR); | ||
case CENTER -> { | ||
BibEntry entry = target.getEntry(); | ||
switch (event.getTransferMode()) { | ||
case LINK -> { | ||
LOGGER.debug("Mode LINK"); // shift on win or no modifier | ||
importHandler.getLinker().addFilesToEntry(entry, files); | ||
} | ||
case MOVE -> { | ||
LOGGER.debug("Mode MOVE"); // alt on win | ||
importHandler.getLinker().moveFilesToFileDirAndAddToEntry(entry, files); | ||
} | ||
case COPY -> { | ||
LOGGER.debug("Mode Copy"); // ctrl on win | ||
importHandler.getLinker().copyFilesToFileDirAndAddToEntry(entry, files); | ||
try { | ||
BibEntry entry = target.getEntry(); | ||
switch (event.getTransferMode()) { | ||
case LINK -> { | ||
LOGGER.debug("Mode LINK"); // shift on win or no modifier | ||
importHandler.getLinker().addFilesToEntry(entry, files); | ||
} | ||
case MOVE -> { | ||
LOGGER.debug("Mode MOVE"); // alt on win | ||
libraryTab.getIndexingTaskManager().setBlockingNewTasks(true); | ||
importHandler.getLinker().moveFilesToFileDirAndAddToEntry(entry, files); | ||
libraryTab.getIndexingTaskManager().setBlockingNewTasks(false); | ||
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. Instead of this
In this way, you make sure that 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. So if I understand that right I would need to make the blocking() method of IndexingTaskManager return a 'closable', right? I could define that as a lambda that resets the flag. 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. That sounds good! 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. Tried it and it was easy enough - so I think I got what you meant. Thanks for the hint! |
||
libraryTab.getIndexingTaskManager().addToIndex(PdfIndexer.of(database, filePreferences), entry, database); | ||
} | ||
case COPY -> { | ||
LOGGER.debug("Mode Copy"); // ctrl on win | ||
libraryTab.getIndexingTaskManager().setBlockingNewTasks(true); | ||
importHandler.getLinker().copyFilesToFileDirAndAddToEntry(entry, files); | ||
libraryTab.getIndexingTaskManager().setBlockingNewTasks(false); | ||
libraryTab.getIndexingTaskManager().addToIndex(PdfIndexer.of(database, filePreferences), entry, database); | ||
} | ||
} | ||
} catch (IOException e) { | ||
LOGGER.error("Failed to obtain PDFIndexer.", e); | ||
} | ||
} | ||
} | ||
|
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.
Is there a reason why this blocking shouldn't be added directly to the
importHandler
(or linker)?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.
Not all users of importHandler have access to the IndexingTaskManager unfortunately.
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.
Mhh, do you have an example where this occurs? The whole linker/import handler stuff arose from the fact that there were many very similarly-looking code blocks scattered around the code base, that all handled imports in a similar but same way. Was a huge headache, so I would like not to introduce special handling in certain situations again.
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.
Oh, that sounds like a good reason to do it directly in the import handler.
The PreviewPanel was my concern, but I passed it along and made it work.