diff --git a/AUTHORS b/AUTHORS index 04adf86cb9d..05f6f4111da 100644 --- a/AUTHORS +++ b/AUTHORS @@ -13,6 +13,7 @@ Alexsandro Lauber Ali Ayan Alick Zhao Ambrogio Oliva +Amish Shah Andreas Amann Andreas Buhr Andreas Rudert diff --git a/CHANGELOG.md b/CHANGELOG.md index bab3e63099a..f2119c71557 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,7 +36,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `# - We added a new keyboard shortcut so that the entry editor could be closed by Ctrl + E. [#4222] (https://github.com/JabRef/jabref/issues/4222) - We added an option in the preference dialog box, that allows user to pick the dark or light theme option. [#4130] (https://github.com/JabRef/jabref/issues/4130) - We updated updated the Related Articles tab to accept JSON from the new version of the Mr. DLib service - +- We added an option in the preference dialog box that allows user to choose behavior after dragging and dropping files in Entry Editor. [#4356](https://github.com/JabRef/jabref/issues/4356) diff --git a/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java b/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java index 46ae9d3d32d..c7961bff628 100644 --- a/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java +++ b/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java @@ -144,19 +144,63 @@ public EntryEditor(BasePanel panel, EntryEditorPreferences preferences, FileUpda if (event.getDragboard().hasContent(DataFormat.FILES)) { List files = event.getDragboard().getFiles().stream().map(File::toPath).collect(Collectors.toList()); - if (event.getTransferMode() == TransferMode.MOVE) { - - LOGGER.debug("Mode MOVE"); //shift on win or no modifier - fileHandler.addToEntryRenameAndMoveToFileDir(entry, files); + FileDragDropPreferenceType dragDropPreferencesType = Globals.prefs.getEntryEditorFileLinkPreference(); + + if (dragDropPreferencesType == FileDragDropPreferenceType.MOVE) + { + if (event.getTransferMode() == TransferMode.LINK) //alt on win + { + LOGGER.debug("Mode LINK"); + fileHandler.addToEntry(entry, files); + } + else if (event.getTransferMode() == TransferMode.COPY) //ctrl on win, no modifier on Xubuntu + { + LOGGER.debug("Mode COPY"); + fileHandler.copyFilesToFileDirAndAddToEntry(entry, files); + } + else + { + LOGGER.debug("Mode MOVE"); //shift on win or no modifier + fileHandler.addToEntryRenameAndMoveToFileDir(entry, files); + } } - if (event.getTransferMode() == TransferMode.LINK) { - LOGGER.debug("Node LINK"); //alt on win - fileHandler.addToEntry(entry, files); + if (dragDropPreferencesType == FileDragDropPreferenceType.COPY) + { + if (event.getTransferMode() == TransferMode.COPY) //ctrl on win, no modifier on Xubuntu + { + LOGGER.debug("Mode MOVE"); + fileHandler.addToEntryRenameAndMoveToFileDir(entry, files); + } + else if (event.getTransferMode() == TransferMode.LINK) //alt on win + { + LOGGER.debug("Mode LINK"); + fileHandler.addToEntry(entry, files); + } + else + { + LOGGER.debug("Mode COPY"); //shift on win or no modifier + fileHandler.copyFilesToFileDirAndAddToEntry(entry, files); + } } - if (event.getTransferMode() == TransferMode.COPY) { - LOGGER.debug("Mode Copy"); //ctrl on win, no modifier on Xubuntu - fileHandler.copyFilesToFileDirAndAddToEntry(entry, files); + + if (dragDropPreferencesType == FileDragDropPreferenceType.LINK) + { + if (event.getTransferMode() == TransferMode.COPY) //ctrl on win, no modifier on Xubuntu + { + LOGGER.debug("Mode COPY"); + fileHandler.copyFilesToFileDirAndAddToEntry(entry, files); + } + else if (event.getTransferMode() == TransferMode.LINK) //alt on win + { + LOGGER.debug("Mode MOVE"); + fileHandler.addToEntryRenameAndMoveToFileDir(entry, files); + } + else + { + LOGGER.debug("Mode LINK"); //shift on win or no modifier + fileHandler.addToEntry(entry, files); + } } } diff --git a/src/main/java/org/jabref/gui/entryeditor/FileDragDropPreferenceType.java b/src/main/java/org/jabref/gui/entryeditor/FileDragDropPreferenceType.java new file mode 100644 index 00000000000..f8bea3ce606 --- /dev/null +++ b/src/main/java/org/jabref/gui/entryeditor/FileDragDropPreferenceType.java @@ -0,0 +1,7 @@ +package org.jabref.gui.entryeditor; + +public enum FileDragDropPreferenceType { + COPY, + LINK, + MOVE; +} diff --git a/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.java b/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.java index 8c4a94d3517..b782ae80c61 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.java +++ b/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.java @@ -1,9 +1,6 @@ package org.jabref.gui.fieldeditors; -import java.io.File; -import java.util.List; import java.util.Optional; -import java.util.stream.Collectors; import javafx.beans.binding.Bindings; import javafx.collections.ObservableList; @@ -71,41 +68,14 @@ public LinkedFilesEditor(String fieldName, DialogService dialogService, BibDatab listView.setCellFactory(cellFactory); - setUpFilesDragAndDrop(); Bindings.bindContentBidirectional(listView.itemsProperty().get(), viewModel.filesProperty()); setUpKeyBindings(); } - private void setUpFilesDragAndDrop() { - listView.setOnDragOver(event -> { - if (event.getDragboard().hasFiles()) { - event.acceptTransferModes(TransferMode.COPY, TransferMode.LINK); - } - }); - - listView.setOnDragDropped(event -> { - Dragboard dragboard = event.getDragboard(); - boolean success = false; - ObservableList items = listView.itemsProperty().get(); - - if (dragboard.hasFiles()) { - List linkedFiles = dragboard.getFiles().stream().map(File::toPath).map(viewModel::fromFile).collect(Collectors.toList()); - items.addAll(linkedFiles); - success = true; - } - event.setDropCompleted(success); - event.consume(); - }); - - } - private void handleOnDragOver(LinkedFileViewModel originalItem, DragEvent event) { if ((event.getGestureSource() != originalItem) && event.getDragboard().hasContent(DragAndDropDataFormats.LINKED_FILE)) { event.acceptTransferModes(TransferMode.MOVE); } - if (event.getDragboard().hasFiles()) { - event.acceptTransferModes(TransferMode.COPY, TransferMode.LINK); - } } private void handleOnDragDetected(@SuppressWarnings("unused") LinkedFileViewModel linkedFile, MouseEvent event) { @@ -143,11 +113,7 @@ private void handleOnDragDropped(LinkedFileViewModel originalItem, DragEvent eve items.set(thisIdx, transferedItem); success = true; } - if (dragboard.hasFiles()) { - List linkedFiles = dragboard.getFiles().stream().map(File::toPath).map(viewModel::fromFile).collect(Collectors.toList()); - items.addAll(linkedFiles); - success = true; - } + event.setDropCompleted(success); event.consume(); diff --git a/src/main/java/org/jabref/gui/preferences/EntryEditorPrefsTab.java b/src/main/java/org/jabref/gui/preferences/EntryEditorPrefsTab.java index dd04ed460cd..2fd8a9a6653 100644 --- a/src/main/java/org/jabref/gui/preferences/EntryEditorPrefsTab.java +++ b/src/main/java/org/jabref/gui/preferences/EntryEditorPrefsTab.java @@ -12,6 +12,7 @@ import org.jabref.gui.autocompleter.AutoCompleteFirstNameMode; import org.jabref.gui.autocompleter.AutoCompletePreferences; +import org.jabref.gui.entryeditor.FileDragDropPreferenceType; import org.jabref.gui.keyboard.EmacsKeyBindings; import org.jabref.logic.l10n.Localization; import org.jabref.preferences.JabRefPreferences; @@ -42,10 +43,14 @@ class EntryEditorPrefsTab extends Pane implements PrefsTab { private final JabRefPreferences prefs; private final AutoCompletePreferences autoCompletePreferences; + private final RadioButton copyFile; + private final RadioButton linkFile; + private final RadioButton renameCopyFile; public EntryEditorPrefsTab(JabRefPreferences prefs) { this.prefs = prefs; autoCompletePreferences = prefs.getAutoCompletePreferences(); + autoOpenForm = new CheckBox(Localization.lang("Open editor when a new entry is created")); defSource = new CheckBox(Localization.lang("Show BibTeX source by default")); emacsMode = new CheckBox(Localization.lang("Use Emacs key bindings")); @@ -123,6 +128,20 @@ public EntryEditorPrefsTab(JabRefPreferences prefs) { firstNameModeAbbr.setToggleGroup(treatmentOfFirstNamesToggleGroup); firstNameModeFull.setToggleGroup(treatmentOfFirstNamesToggleGroup); firstNameModeBoth.setToggleGroup(treatmentOfFirstNamesToggleGroup); + + final ToggleGroup group = new ToggleGroup(); + Label linkFileOptions = new Label(Localization.lang("Default drag & drop action")); + linkFileOptions.getStyleClass().add("sectionHeader"); + copyFile = new RadioButton(Localization.lang("Copy file to default file folder")); + linkFile = new RadioButton(Localization.lang("Link file (without copying)")); + renameCopyFile = new RadioButton(Localization.lang("Copy, rename and link file")); + builder.add(linkFileOptions, 1, 23); + builder.add(copyFile, 1, 24); + builder.add(linkFile, 1, 25); + builder.add(renameCopyFile, 1, 26); + copyFile.setToggleGroup(group); + linkFile.setToggleGroup(group); + renameCopyFile.setToggleGroup(group); } @Override @@ -172,6 +191,15 @@ public void setValues() { break; } + FileDragDropPreferenceType dragDropPreferenceType = prefs.getEntryEditorFileLinkPreference(); + if (dragDropPreferenceType == FileDragDropPreferenceType.COPY) { + copyFile.setSelected(true); + } else if (dragDropPreferenceType == FileDragDropPreferenceType.LINK) { + linkFile.setSelected(true); + } else { + renameCopyFile.setSelected(true); + } + // similar for emacs CTRL-a and emacs mode emacsRebindCtrlA.setDisable(!emacsMode.isSelected()); // Autocomplete fields is only enabled when autocompletion is selected @@ -230,6 +258,15 @@ else if (autoCompFF.isSelected()) { } else { autoCompletePreferences.setFirstNameMode(AutoCompleteFirstNameMode.BOTH); } + + if (copyFile.isSelected()) { + prefs.storeEntryEditorFileLinkPreference(FileDragDropPreferenceType.COPY); + } else if (linkFile.isSelected()) { + prefs.storeEntryEditorFileLinkPreference(FileDragDropPreferenceType.LINK); + } else { + prefs.storeEntryEditorFileLinkPreference(FileDragDropPreferenceType.MOVE); + } + prefs.storeAutoCompletePreferences(autoCompletePreferences); } diff --git a/src/main/java/org/jabref/preferences/JabRefPreferences.java b/src/main/java/org/jabref/preferences/JabRefPreferences.java index cbc7c80163c..eea8a2ee771 100644 --- a/src/main/java/org/jabref/preferences/JabRefPreferences.java +++ b/src/main/java/org/jabref/preferences/JabRefPreferences.java @@ -46,6 +46,7 @@ import org.jabref.gui.desktop.JabRefDesktop; import org.jabref.gui.entryeditor.EntryEditorPreferences; import org.jabref.gui.entryeditor.EntryEditorTabList; +import org.jabref.gui.entryeditor.FileDragDropPreferenceType; import org.jabref.gui.groups.GroupViewMode; import org.jabref.gui.keyboard.KeyBindingRepository; import org.jabref.gui.maintable.ColumnPreferences; @@ -369,6 +370,10 @@ public class JabRefPreferences implements PreferencesService { // Id Entry Generator Preferences public static final String ID_ENTRY_GENERATOR = "idEntryGenerator"; + + //File linking Options for entry editor + public static final String ENTRY_EDITOR_DRAG_DROP_PREFERENCE_TYPE = "DragDropPreferenceType"; + // Preview private static final String PREVIEW_STYLE = "previewStyle"; private static final String CYCLE_PREVIEW_POS = "cyclePreviewPos"; @@ -411,6 +416,7 @@ public class JabRefPreferences implements PreferencesService { // Helper string private static final String USER_HOME = System.getProperty("user.home"); + // The only instance of this class: private static JabRefPreferences singleton; /** @@ -786,6 +792,8 @@ private JabRefPreferences() { // set default theme defaults.put(JabRefPreferences.FX_THEME, ThemeLoader.MAIN_CSS); + + defaults.put(ENTRY_EDITOR_DRAG_DROP_PREFERENCE_TYPE, FileDragDropPreferenceType.MOVE.name()); setLanguageDependentDefaultValues(); } @@ -2019,4 +2027,12 @@ public Map getMainTableColumnSortTypes() { } return map; } + + public FileDragDropPreferenceType getEntryEditorFileLinkPreference() { + return FileDragDropPreferenceType.valueOf(get(ENTRY_EDITOR_DRAG_DROP_PREFERENCE_TYPE)); + } + + public void storeEntryEditorFileLinkPreference(FileDragDropPreferenceType type) { + put(ENTRY_EDITOR_DRAG_DROP_PREFERENCE_TYPE, type.name()); + } } diff --git a/src/main/resources/l10n/JabRef_en.properties b/src/main/resources/l10n/JabRef_en.properties index d58e0cbc12d..e4bd843bed0 100644 --- a/src/main/resources/l10n/JabRef_en.properties +++ b/src/main/resources/l10n/JabRef_en.properties @@ -2229,3 +2229,8 @@ Keystore\:=Keystore\: Password\:=Password\: Remember\ Password=Remember Password Use\ SSL=Use SSL + +Default\ drag\ &\ drop\ action=Default drag & drop action +Copy\ file\ to\ default\ file\ folder=Copy file to default file folder +Link\ file\ (without\ copying)=Link file (without copying) +Copy,\ rename\ and\ link\ file=Copy, rename and link file