Skip to content

Commit

Permalink
Fix moving of file into library (#12001)
Browse files Browse the repository at this point in the history
* Fix comments

* Improve comment

* Fix variable name

* Add list of entries to ImportFilesResultItemViewModel

If any error, no double entries in result set

* Fix support to move files into library

* Handle existing files in the case of "Copy"

* Add link to PR

* Fix mocking for CitationsRelationTabViewModelTest

* Use Files.isSameFile

* Clean filenames at "getValidFileName"

* Add JavaDoc comment

* Rewrite LinkedFileHandler to do the renaming, too

* Remove unused method

* Introduce DragDrop.handleDropOfFiles (to avoid code duplication)

* Group file related methods together (in BibEntry)

* Remove unused methods

* Refine CHANGELOG.md

* Avoid double-addition when linking files

* Fix condition

* Fix flag

* Add notification also on move/copy if file exists

* Fix checkstyle error

* Streamline code

* Fix target directory creation

* Fix compilation, and remove Index Manager from ImportHandler

* Remove IndexManager from EntryEditor

* Update CommentsTabTest.java

---------

Co-authored-by: Loay Ghreeb <loayahmed655@gmail.com>
  • Loading branch information
koppor and LoayGhreeb authored Oct 23, 2024
1 parent bffdb8b commit 650d4a2
Show file tree
Hide file tree
Showing 29 changed files with 321 additions and 299 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
- We added a different background color to the search bar to indicate when the search syntax is wrong. [#11658](https://github.com/JabRef/jabref/pull/11658)
- We added a setting which always adds the literal "Cited on pages" text before each JStyle citation. [#11691](https://github.com/JabRef/jabref/pull/11732)
- We added a new plain citation parser that uses LLMs. [#11825](https://github.com/JabRef/jabref/issues/11825)
- We added support for modifier keys when dropping a file on an entry in the main table. [#12001](https://github.com/JabRef/jabref/pull/12001)
- We added an importer for SSRN URLs. [#12021](https://github.com/JabRef/jabref/pull/12021)
- We added a compare button to the duplicates in the citation relations tab to open the "Possible duplicate entries" window. [#11192](https://github.com/JabRef/jabref/issues/11192)
- We added automatic browser extension install on Windows for Chrome and Edge. [#6076](https://github.com/JabRef/jabref/issues/6076)
Expand All @@ -48,6 +49,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
- JabRef respects the [configuration for storing files relative to the .bib file](https://docs.jabref.org/finding-sorting-and-cleaning-entries/filelinks#directories-for-files) in more cases. [#11492](https://github.com/JabRef/jabref/pull/11492)
- JabRef does not show finished background tasks in the status bar popup. [#11821](https://github.com/JabRef/jabref/pull/11821)
- We enhanced the indexing speed. [#11502](https://github.com/JabRef/jabref/pull/11502)
- When dropping a file into the main table, after copy or move, the file is now put in the [configured directory and renamed according to the configured patterns](https://docs.jabref.org/finding-sorting-and-cleaning-entries/filelinks#filename-format-and-file-directory-pattern). [#12001](https://github.com/JabRef/jabref/pull/12001)
- ⚠️ Renamed command line parameters `embeddBibfileInPdf` to `embedBibFileInPdf`, `writeMetadatatoPdf` to `writeMetadataToPdf`, and `writeXMPtoPdf` to `writeXmpToPdf`. [#11575](https://github.com/JabRef/jabref/pull/11575)
- The browse button for a Custom theme now opens in the directory of the current used CSS file. [#11597](https://github.com/JabRef/jabref/pull/11597)
- The browse button for a Custom exporter now opens in the directory of the current used exporter file. [#11717](https://github.com/JabRef/jabref/pull/11717)
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/org/jabref/gui/entryeditor/CommentsTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.jabref.gui.util.OptionalObjectProperty;
import org.jabref.logic.journals.JournalAbbreviationRepository;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.search.IndexManager;
import org.jabref.logic.util.TaskExecutor;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;
Expand All @@ -56,7 +55,6 @@ public CommentsTab(GuiPreferences preferences,
ThemeManager themeManager,
TaskExecutor taskExecutor,
JournalAbbreviationRepository journalAbbreviationRepository,
IndexManager indexManager,
OptionalObjectProperty<SearchQuery> searchQueryProperty) {
super(
false,
Expand All @@ -70,7 +68,6 @@ public CommentsTab(GuiPreferences preferences,
themeManager,
taskExecutor,
journalAbbreviationRepository,
indexManager,
searchQueryProperty
);
this.defaultOwner = preferences.getOwnerPreferences().getDefaultOwner().toLowerCase(Locale.ROOT).replaceAll("[^a-z0-9]", "-");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import org.jabref.gui.util.OptionalObjectProperty;
import org.jabref.logic.journals.JournalAbbreviationRepository;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.search.IndexManager;
import org.jabref.logic.util.TaskExecutor;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.database.BibDatabaseMode;
Expand Down Expand Up @@ -47,9 +46,8 @@ public DeprecatedFieldsTab(BibDatabaseContext databaseContext,
BibEntryTypesManager entryTypesManager,
TaskExecutor taskExecutor,
JournalAbbreviationRepository journalAbbreviationRepository,
IndexManager indexManager,
OptionalObjectProperty<SearchQuery> searchQueryProperty) {
super(false, databaseContext, suggestionProviders, undoManager, undoAction, redoAction, dialogService, preferences, themeManager, taskExecutor, journalAbbreviationRepository, indexManager, searchQueryProperty);
super(false, databaseContext, suggestionProviders, undoManager, undoAction, redoAction, dialogService, preferences, themeManager, taskExecutor, journalAbbreviationRepository, searchQueryProperty);
this.entryTypesManager = entryTypesManager;

setText(Localization.lang("Deprecated fields"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import org.jabref.gui.util.OptionalObjectProperty;
import org.jabref.logic.journals.JournalAbbreviationRepository;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.search.IndexManager;
import org.jabref.logic.util.TaskExecutor;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntryTypesManager;
Expand All @@ -32,7 +31,6 @@ public DetailOptionalFieldsTab(BibDatabaseContext databaseContext,
BibEntryTypesManager entryTypesManager,
TaskExecutor taskExecutor,
JournalAbbreviationRepository journalAbbreviationRepository,
IndexManager indexManager,
OptionalObjectProperty<SearchQuery> searchQueryProperty) {
super(
Localization.lang("Optional fields 2"),
Expand All @@ -48,7 +46,6 @@ public DetailOptionalFieldsTab(BibDatabaseContext databaseContext,
entryTypesManager,
taskExecutor,
journalAbbreviationRepository,
indexManager,
searchQueryProperty
);
}
Expand Down
37 changes: 14 additions & 23 deletions src/main/java/org/jabref/gui/entryeditor/EntryEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import org.jabref.gui.undo.CountingUndoManager;
import org.jabref.gui.undo.RedoAction;
import org.jabref.gui.undo.UndoAction;
import org.jabref.gui.util.DragDrop;
import org.jabref.gui.util.UiTaskExecutor;
import org.jabref.logic.ai.AiService;
import org.jabref.logic.bibtex.TypedBibEntry;
Expand Down Expand Up @@ -171,21 +172,11 @@ private void setupDragAndDrop(LibraryTab libraryTab) {
boolean success = false;

if (event.getDragboard().hasContent(DataFormat.FILES)) {
List<Path> draggedFiles = event.getDragboard().getFiles().stream().map(File::toPath).collect(Collectors.toList());
switch (event.getTransferMode()) {
case COPY -> {
LOGGER.debug("Mode COPY");
fileLinker.copyFilesToFileDirAndAddToEntry(entry, draggedFiles, libraryTab.getIndexManager());
}
case MOVE -> {
LOGGER.debug("Mode MOVE");
fileLinker.moveFilesToFileDirRenameAndAddToEntry(entry, draggedFiles, libraryTab.getIndexManager());
}
case LINK -> {
LOGGER.debug("Mode LINK");
fileLinker.addFilesToEntry(entry, draggedFiles);
}
}
TransferMode transferMode = event.getTransferMode();
List<Path> files = event.getDragboard().getFiles().stream().map(File::toPath).collect(Collectors.toList());
// Modifiers do not work on macOS: https://bugs.openjdk.org/browse/JDK-8264172
// Similar code as org.jabref.gui.externalfiles.ImportHandler.importFilesInBackground
DragDrop.handleDropOfFiles(files, transferMode, fileLinker, entry);
success = true;
}

Expand Down Expand Up @@ -276,21 +267,21 @@ private void navigateToNextEntry() {
private List<EntryEditorTab> createTabs() {
List<EntryEditorTab> tabs = new LinkedList<>();

tabs.add(new PreviewTab(databaseContext, dialogService, preferences, themeManager, taskExecutor, libraryTab.getIndexManager(), libraryTab.searchQueryProperty()));
tabs.add(new PreviewTab(databaseContext, dialogService, preferences, themeManager, taskExecutor, libraryTab.searchQueryProperty()));

// Required, optional (important+detail), deprecated, and "other" fields
tabs.add(new RequiredFieldsTab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, undoAction, redoAction, dialogService, preferences, themeManager, bibEntryTypesManager, taskExecutor, journalAbbreviationRepository, libraryTab.getIndexManager(), libraryTab.searchQueryProperty()));
tabs.add(new ImportantOptionalFieldsTab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, undoAction, redoAction, dialogService, preferences, themeManager, bibEntryTypesManager, taskExecutor, journalAbbreviationRepository, libraryTab.getIndexManager(), libraryTab.searchQueryProperty()));
tabs.add(new DetailOptionalFieldsTab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, undoAction, redoAction, dialogService, preferences, themeManager, bibEntryTypesManager, taskExecutor, journalAbbreviationRepository, libraryTab.getIndexManager(), libraryTab.searchQueryProperty()));
tabs.add(new DeprecatedFieldsTab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, undoAction, redoAction, dialogService, preferences, themeManager, bibEntryTypesManager, taskExecutor, journalAbbreviationRepository, libraryTab.getIndexManager(), libraryTab.searchQueryProperty()));
tabs.add(new OtherFieldsTab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, undoAction, redoAction, dialogService, preferences, themeManager, bibEntryTypesManager, taskExecutor, journalAbbreviationRepository, libraryTab.getIndexManager(), libraryTab.searchQueryProperty()));
tabs.add(new RequiredFieldsTab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, undoAction, redoAction, dialogService, preferences, themeManager, bibEntryTypesManager, taskExecutor, journalAbbreviationRepository, libraryTab.searchQueryProperty()));
tabs.add(new ImportantOptionalFieldsTab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, undoAction, redoAction, dialogService, preferences, themeManager, bibEntryTypesManager, taskExecutor, journalAbbreviationRepository, libraryTab.searchQueryProperty()));
tabs.add(new DetailOptionalFieldsTab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, undoAction, redoAction, dialogService, preferences, themeManager, bibEntryTypesManager, taskExecutor, journalAbbreviationRepository, libraryTab.searchQueryProperty()));
tabs.add(new DeprecatedFieldsTab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, undoAction, redoAction, dialogService, preferences, themeManager, bibEntryTypesManager, taskExecutor, journalAbbreviationRepository, libraryTab.searchQueryProperty()));
tabs.add(new OtherFieldsTab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, undoAction, redoAction, dialogService, preferences, themeManager, bibEntryTypesManager, taskExecutor, journalAbbreviationRepository, libraryTab.searchQueryProperty()));

// Comment Tab: Tab for general and user-specific comments
tabs.add(new CommentsTab(preferences, databaseContext, libraryTab.getSuggestionProviders(), undoManager, undoAction, redoAction, dialogService, themeManager, taskExecutor, journalAbbreviationRepository, libraryTab.getIndexManager(), libraryTab.searchQueryProperty()));
tabs.add(new CommentsTab(preferences, databaseContext, libraryTab.getSuggestionProviders(), undoManager, undoAction, redoAction, dialogService, themeManager, taskExecutor, journalAbbreviationRepository, libraryTab.searchQueryProperty()));

Map<String, Set<Field>> entryEditorTabList = getAdditionalUserConfiguredTabs();
for (Map.Entry<String, Set<Field>> tab : entryEditorTabList.entrySet()) {
tabs.add(new UserDefinedFieldsTab(tab.getKey(), tab.getValue(), databaseContext, libraryTab.getSuggestionProviders(), undoManager, undoAction, redoAction, dialogService, preferences, themeManager, taskExecutor, journalAbbreviationRepository, libraryTab.getIndexManager(), libraryTab.searchQueryProperty()));
tabs.add(new UserDefinedFieldsTab(tab.getKey(), tab.getValue(), databaseContext, libraryTab.getSuggestionProviders(), undoManager, undoAction, redoAction, dialogService, preferences, themeManager, taskExecutor, journalAbbreviationRepository, libraryTab.searchQueryProperty()));
}

tabs.add(new MathSciNetTab());
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/org/jabref/gui/entryeditor/FieldsEditorTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import org.jabref.gui.undo.UndoAction;
import org.jabref.gui.util.OptionalObjectProperty;
import org.jabref.logic.journals.JournalAbbreviationRepository;
import org.jabref.logic.search.IndexManager;
import org.jabref.logic.util.TaskExecutor;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;
Expand Down Expand Up @@ -64,7 +63,6 @@ abstract class FieldsEditorTab extends EntryEditorTab implements OffersPreview {
private final JournalAbbreviationRepository journalAbbreviationRepository;
private PreviewPanel previewPanel;
private final UndoManager undoManager;
private final IndexManager indexManager;
private final OptionalObjectProperty<SearchQuery> searchQueryProperty;
private Collection<Field> fields = new ArrayList<>();
@SuppressWarnings("FieldCanBeLocal")
Expand All @@ -81,7 +79,6 @@ public FieldsEditorTab(boolean compressed,
ThemeManager themeManager,
TaskExecutor taskExecutor,
JournalAbbreviationRepository journalAbbreviationRepository,
IndexManager indexManager,
OptionalObjectProperty<SearchQuery> searchQueryProperty) {
this.isCompressed = compressed;
this.databaseContext = Objects.requireNonNull(databaseContext);
Expand All @@ -94,7 +91,6 @@ public FieldsEditorTab(boolean compressed,
this.themeManager = themeManager;
this.taskExecutor = Objects.requireNonNull(taskExecutor);
this.journalAbbreviationRepository = Objects.requireNonNull(journalAbbreviationRepository);
this.indexManager = indexManager;
this.searchQueryProperty = searchQueryProperty;
}

Expand Down Expand Up @@ -265,7 +261,6 @@ private void initPanel() {
preferences,
themeManager,
taskExecutor,
indexManager,
searchQueryProperty);
EasyBind.subscribe(preferences.getPreviewPreferences().showPreviewAsExtraTabProperty(), show -> {
if (show) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import org.jabref.gui.util.OptionalObjectProperty;
import org.jabref.logic.journals.JournalAbbreviationRepository;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.search.IndexManager;
import org.jabref.logic.util.TaskExecutor;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntryTypesManager;
Expand All @@ -32,7 +31,6 @@ public ImportantOptionalFieldsTab(BibDatabaseContext databaseContext,
BibEntryTypesManager entryTypesManager,
TaskExecutor taskExecutor,
JournalAbbreviationRepository journalAbbreviationRepository,
IndexManager indexManager,
OptionalObjectProperty<SearchQuery> searchQueryProperty) {
super(
Localization.lang("Optional fields"),
Expand All @@ -48,7 +46,6 @@ public ImportantOptionalFieldsTab(BibDatabaseContext databaseContext,
entryTypesManager,
taskExecutor,
journalAbbreviationRepository,
indexManager,
searchQueryProperty
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import org.jabref.gui.util.OptionalObjectProperty;
import org.jabref.logic.journals.JournalAbbreviationRepository;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.search.IndexManager;
import org.jabref.logic.util.TaskExecutor;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.database.BibDatabaseMode;
Expand All @@ -45,7 +44,6 @@ public OptionalFieldsTabBase(String title,
BibEntryTypesManager entryTypesManager,
TaskExecutor taskExecutor,
JournalAbbreviationRepository journalAbbreviationRepository,
IndexManager indexManager,
OptionalObjectProperty<SearchQuery> searchQueryProperty) {
super(true,
databaseContext,
Expand All @@ -58,7 +56,6 @@ public OptionalFieldsTabBase(String title,
themeManager,
taskExecutor,
journalAbbreviationRepository,
indexManager,
searchQueryProperty);
this.entryTypesManager = entryTypesManager;
this.isImportantOptionalFields = isImportantOptionalFields;
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/org/jabref/gui/entryeditor/OtherFieldsTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.jabref.gui.util.OptionalObjectProperty;
import org.jabref.logic.journals.JournalAbbreviationRepository;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.search.IndexManager;
import org.jabref.logic.util.TaskExecutor;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.database.BibDatabaseMode;
Expand Down Expand Up @@ -52,7 +51,6 @@ public OtherFieldsTab(BibDatabaseContext databaseContext,
BibEntryTypesManager entryTypesManager,
TaskExecutor taskExecutor,
JournalAbbreviationRepository journalAbbreviationRepository,
IndexManager indexManager,
OptionalObjectProperty<SearchQuery> searchQueryProperty) {
super(false,
databaseContext,
Expand All @@ -65,7 +63,6 @@ public OtherFieldsTab(BibDatabaseContext databaseContext,
themeManager,
taskExecutor,
journalAbbreviationRepository,
indexManager,
searchQueryProperty);

this.entryTypesManager = entryTypesManager;
Expand Down
Loading

0 comments on commit 650d4a2

Please sign in to comment.