From be0c25197d7b0198ad6a5014cc7f121a6474f49e Mon Sep 17 00:00:00 2001 From: Amish Shah Date: Thu, 25 Oct 2018 22:32:48 -0500 Subject: [PATCH 1/9] Add a preference to add files in entry editor (#4356) --- AUTHORS | 1 + CHANGELOG.md | 2 +- .../jabref/gui/entryeditor/EntryEditor.java | 11 ++- .../entryeditor/FileDragDropPreferences.java | 39 ++++++++ .../gui/fieldeditors/LinkedFilesEditor.java | 94 +------------------ .../gui/preferences/EntryEditorPrefsTab.java | 45 +++++++++ .../jabref/preferences/JabRefPreferences.java | 22 +++++ src/main/resources/l10n/JabRef_en.properties | 5 + 8 files changed, 120 insertions(+), 99 deletions(-) create mode 100644 src/main/java/org/jabref/gui/entryeditor/FileDragDropPreferences.java 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..1f68b077ae1 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 - +- Allow the user to choose behavior after dragging and dropping files in Entry Editor using Preferences. [#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..7c6ec65256c 100644 --- a/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java +++ b/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java @@ -144,18 +144,19 @@ 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) { + FileDragDropPreferences dragDropPreferences = Globals.prefs.getEntryEditorFileLinkPreference(); + if (dragDropPreferences.isRenameCopyFile()) { 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 + if (dragDropPreferences.isLinkFile()) { + LOGGER.debug("Mode LINK"); //alt on win fileHandler.addToEntry(entry, files); } - if (event.getTransferMode() == TransferMode.COPY) { - LOGGER.debug("Mode Copy"); //ctrl on win, no modifier on Xubuntu + if (dragDropPreferences.isCopyFile()) { + LOGGER.debug("Mode COPY"); //ctrl on win, no modifier on Xubuntu fileHandler.copyFilesToFileDirAndAddToEntry(entry, files); } } diff --git a/src/main/java/org/jabref/gui/entryeditor/FileDragDropPreferences.java b/src/main/java/org/jabref/gui/entryeditor/FileDragDropPreferences.java new file mode 100644 index 00000000000..37616db82bf --- /dev/null +++ b/src/main/java/org/jabref/gui/entryeditor/FileDragDropPreferences.java @@ -0,0 +1,39 @@ +package org.jabref.gui.entryeditor; + +public class FileDragDropPreferences { + + private boolean copyFile; + private boolean linkFile; + private boolean renameCopyFile; + + public FileDragDropPreferences(boolean copyFile, boolean linkFile, boolean renameCopyFile) { + this.copyFile = copyFile; + this.linkFile = linkFile; + this.renameCopyFile = renameCopyFile; + } + + public boolean isCopyFile() { + return copyFile; + } + + public boolean isLinkFile() { + return linkFile; + } + + public boolean isRenameCopyFile() { + return renameCopyFile; + } + + public void setCopyFile(boolean copyFile) { + this.copyFile = copyFile; + } + + public void setLinkFile(boolean linkFile) { + this.linkFile = linkFile; + } + + public void setRenameCopyFile(boolean renameCopyFile) { + this.renameCopyFile = renameCopyFile; + } + +} diff --git a/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.java b/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.java index 8c4a94d3517..965e087609e 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.java +++ b/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.java @@ -1,12 +1,7 @@ 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; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.scene.Node; @@ -18,19 +13,14 @@ import javafx.scene.control.ProgressBar; import javafx.scene.control.SeparatorMenuItem; import javafx.scene.control.Tooltip; -import javafx.scene.input.ClipboardContent; -import javafx.scene.input.DragEvent; -import javafx.scene.input.Dragboard; import javafx.scene.input.KeyEvent; import javafx.scene.input.MouseButton; import javafx.scene.input.MouseEvent; -import javafx.scene.input.TransferMode; import javafx.scene.layout.HBox; import javafx.scene.text.Text; import org.jabref.Globals; import org.jabref.gui.DialogService; -import org.jabref.gui.DragAndDropDataFormats; import org.jabref.gui.autocompleter.AutoCompleteSuggestionProvider; import org.jabref.gui.keyboard.KeyBinding; import org.jabref.gui.util.TaskExecutor; @@ -39,7 +29,6 @@ import org.jabref.logic.l10n.Localization; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.entry.BibEntry; -import org.jabref.model.entry.LinkedFile; import org.jabref.preferences.JabRefPreferences; import com.airhacks.afterburner.views.ViewLoader; @@ -64,95 +53,14 @@ public LinkedFilesEditor(String fieldName, DialogService dialogService, BibDatab .withTooltip(LinkedFileViewModel::getDescription) .withGraphic(LinkedFilesEditor::createFileDisplay) .withContextMenu(this::createContextMenuForFile) - .withOnMouseClickedEvent(this::handleItemMouseClick) - .setOnDragDetected(this::handleOnDragDetected) - .setOnDragDropped(this::handleOnDragDropped) - .setOnDragOver(this::handleOnDragOver); + .withOnMouseClickedEvent(this::handleItemMouseClick); 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) { - LinkedFile selectedItem = listView.getSelectionModel().getSelectedItem().getFile(); - if (selectedItem != null) { - ClipboardContent content = new ClipboardContent(); - Dragboard dragboard = listView.startDragAndDrop(TransferMode.MOVE); - //We have to use the model class here, as the content of the dragboard must be serializable - content.put(DragAndDropDataFormats.LINKED_FILE, selectedItem); - dragboard.setContent(content); - } - event.consume(); - } - - private void handleOnDragDropped(LinkedFileViewModel originalItem, DragEvent event) { - Dragboard dragboard = event.getDragboard(); - boolean success = false; - - ObservableList items = listView.itemsProperty().get(); - - if (dragboard.hasContent(DragAndDropDataFormats.LINKED_FILE)) { - - LinkedFile linkedFile = (LinkedFile) dragboard.getContent(DragAndDropDataFormats.LINKED_FILE); - LinkedFileViewModel transferedItem = null; - int draggedIdx = 0; - for (int i = 0; i < items.size(); i++) { - if (items.get(i).getFile().equals(linkedFile)) { - draggedIdx = i; - transferedItem = items.get(i); - break; - } - } - int thisIdx = items.indexOf(originalItem); - items.set(draggedIdx, originalItem); - 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(); - - } - private static Node createFileDisplay(LinkedFileViewModel linkedFile) { Node icon = linkedFile.getTypeIcon().getGraphicNode(); icon.setOnMouseClicked(event -> linkedFile.open()); diff --git a/src/main/java/org/jabref/gui/preferences/EntryEditorPrefsTab.java b/src/main/java/org/jabref/gui/preferences/EntryEditorPrefsTab.java index dd04ed460cd..7d0fb43bf95 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.FileDragDropPreferences; import org.jabref.gui.keyboard.EmacsKeyBindings; import org.jabref.logic.l10n.Localization; import org.jabref.preferences.JabRefPreferences; @@ -42,10 +43,16 @@ class EntryEditorPrefsTab extends Pane implements PrefsTab { private final JabRefPreferences prefs; private final AutoCompletePreferences autoCompletePreferences; + private final FileDragDropPreferences dragDropPreferences; + private final RadioButton copyFile; + private final RadioButton linkFile; + private final RadioButton renameCopyFile; public EntryEditorPrefsTab(JabRefPreferences prefs) { this.prefs = prefs; autoCompletePreferences = prefs.getAutoCompletePreferences(); + dragDropPreferences = prefs.getEntryEditorFileLinkPreference(); + 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 +130,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("Options to add file")); + linkFileOptions.getStyleClass().add("sectionHeader"); + copyFile = new RadioButton(Localization.lang("Copy file to current location")); + 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 +193,14 @@ public void setValues() { break; } + if (dragDropPreferences.isCopyFile()) { + copyFile.setSelected(true); + } else if (dragDropPreferences.isLinkFile()) { + 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 +259,22 @@ else if (autoCompFF.isSelected()) { } else { autoCompletePreferences.setFirstNameMode(AutoCompleteFirstNameMode.BOTH); } + + if (copyFile.isSelected()) { + dragDropPreferences.setCopyFile(true); + dragDropPreferences.setLinkFile(false); + dragDropPreferences.setRenameCopyFile(false); + } else if (linkFile.isSelected()) { + dragDropPreferences.setCopyFile(false); + dragDropPreferences.setLinkFile(true); + dragDropPreferences.setRenameCopyFile(false); + } else { + dragDropPreferences.setCopyFile(false); + dragDropPreferences.setLinkFile(false); + dragDropPreferences.setRenameCopyFile(true); + } + + prefs.storeEntryEditorFileLinkPreference(dragDropPreferences); 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..9f2238bbcfe 100644 --- a/src/main/java/org/jabref/preferences/JabRefPreferences.java +++ b/src/main/java/org/jabref/preferences/JabRefPreferences.java @@ -44,6 +44,7 @@ import org.jabref.gui.autocompleter.AutoCompleteFirstNameMode; import org.jabref.gui.autocompleter.AutoCompletePreferences; import org.jabref.gui.desktop.JabRefDesktop; +import org.jabref.gui.entryeditor.FileDragDropPreferences; import org.jabref.gui.entryeditor.EntryEditorPreferences; import org.jabref.gui.entryeditor.EntryEditorTabList; import org.jabref.gui.groups.GroupViewMode; @@ -403,6 +404,11 @@ public class JabRefPreferences implements PreferencesService { private static final String PROTECTED_TERMS_ENABLED_INTERNAL = "protectedTermsEnabledInternal"; private static final String PROTECTED_TERMS_DISABLED_INTERNAL = "protectedTermsDisabledInternal"; + //File linking Options for entry editor + private static final String ENTRY_EDITOR_COPY_FILE = "copyFile"; + private static final String ENTRY_EDITOR_LINK_FILE = "linkFile"; + private static final String ENTRY_EDITOR_RENAME_COPY_FILE = "renameCopyFile"; + //GroupViewMode private static final String GROUP_INTERSECT_UNION_VIEW_MODE = "groupIntersectUnionViewModes"; @@ -411,6 +417,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 +793,10 @@ private JabRefPreferences() { // set default theme defaults.put(JabRefPreferences.FX_THEME, ThemeLoader.MAIN_CSS); + + defaults.put(ENTRY_EDITOR_COPY_FILE, Boolean.TRUE); + defaults.put(ENTRY_EDITOR_LINK_FILE, Boolean.FALSE); + defaults.put(ENTRY_EDITOR_RENAME_COPY_FILE, Boolean.FALSE); setLanguageDependentDefaultValues(); } @@ -2019,4 +2030,15 @@ public Map getMainTableColumnSortTypes() { } return map; } + + public FileDragDropPreferences getEntryEditorFileLinkPreference() { + return new FileDragDropPreferences(getBoolean(ENTRY_EDITOR_COPY_FILE), getBoolean(ENTRY_EDITOR_LINK_FILE), + getBoolean(ENTRY_EDITOR_RENAME_COPY_FILE)); + } + + public void storeEntryEditorFileLinkPreference(FileDragDropPreferences dragDropPreferences) { + putBoolean(ENTRY_EDITOR_COPY_FILE, dragDropPreferences.isCopyFile()); + putBoolean(ENTRY_EDITOR_LINK_FILE, dragDropPreferences.isLinkFile()); + putBoolean(ENTRY_EDITOR_RENAME_COPY_FILE, dragDropPreferences.isRenameCopyFile()); + } } diff --git a/src/main/resources/l10n/JabRef_en.properties b/src/main/resources/l10n/JabRef_en.properties index d58e0cbc12d..9f586faec66 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 + +Options\ to\ add\ file=Options to add file +Copy\ file\ to\ current\ location=Copy file to current location +Link\ file\ (without\ copying)=Link file (without copying) +Copy,\ rename\ and\ link\ file=Copy, rename and link file \ No newline at end of file From 4a01a8023311655f8fb7c171b6cebef6bf33d309 Mon Sep 17 00:00:00 2001 From: Amish Shah Date: Thu, 25 Oct 2018 22:58:49 -0500 Subject: [PATCH 2/9] Fix import order --- .../java/org/jabref/gui/fieldeditors/LinkedFilesEditor.java | 1 + src/main/java/org/jabref/preferences/JabRefPreferences.java | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.java b/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.java index 965e087609e..94a4447b935 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.java +++ b/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.java @@ -1,6 +1,7 @@ package org.jabref.gui.fieldeditors; import java.util.Optional; + import javafx.beans.binding.Bindings; import javafx.event.ActionEvent; import javafx.fxml.FXML; diff --git a/src/main/java/org/jabref/preferences/JabRefPreferences.java b/src/main/java/org/jabref/preferences/JabRefPreferences.java index 9f2238bbcfe..aa8f9f9d049 100644 --- a/src/main/java/org/jabref/preferences/JabRefPreferences.java +++ b/src/main/java/org/jabref/preferences/JabRefPreferences.java @@ -44,9 +44,9 @@ import org.jabref.gui.autocompleter.AutoCompleteFirstNameMode; import org.jabref.gui.autocompleter.AutoCompletePreferences; import org.jabref.gui.desktop.JabRefDesktop; -import org.jabref.gui.entryeditor.FileDragDropPreferences; import org.jabref.gui.entryeditor.EntryEditorPreferences; import org.jabref.gui.entryeditor.EntryEditorTabList; +import org.jabref.gui.entryeditor.FileDragDropPreferences; import org.jabref.gui.groups.GroupViewMode; import org.jabref.gui.keyboard.KeyBindingRepository; import org.jabref.gui.maintable.ColumnPreferences; From 955bb78a49b24a991e98b39b6157f92026a172d3 Mon Sep 17 00:00:00 2001 From: Amish Shah Date: Fri, 26 Oct 2018 04:44:28 -0500 Subject: [PATCH 3/9] Edit changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f68b077ae1..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 -- Allow the user to choose behavior after dragging and dropping files in Entry Editor using Preferences. [#4356] +- 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) From ff29ae6e53e02f0f4b6b4ac6cef29fa461e3eb9d Mon Sep 17 00:00:00 2001 From: Amish Shah Date: Sat, 27 Oct 2018 21:03:59 -0500 Subject: [PATCH 4/9] Use enum to represent FileDragDropPreference for Entry Editor --- .../FileDragDropPreferenceType.java | 7 ++++ .../entryeditor/FileDragDropPreferences.java | 39 ------------------- 2 files changed, 7 insertions(+), 39 deletions(-) create mode 100644 src/main/java/org/jabref/gui/entryeditor/FileDragDropPreferenceType.java delete mode 100644 src/main/java/org/jabref/gui/entryeditor/FileDragDropPreferences.java 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..4dcd83a70da --- /dev/null +++ b/src/main/java/org/jabref/gui/entryeditor/FileDragDropPreferenceType.java @@ -0,0 +1,7 @@ +package org.jabref.gui.entryeditor; + +public enum FileDragDropType { + COPY, + LINK, + RENAME_COPY; +} diff --git a/src/main/java/org/jabref/gui/entryeditor/FileDragDropPreferences.java b/src/main/java/org/jabref/gui/entryeditor/FileDragDropPreferences.java deleted file mode 100644 index 37616db82bf..00000000000 --- a/src/main/java/org/jabref/gui/entryeditor/FileDragDropPreferences.java +++ /dev/null @@ -1,39 +0,0 @@ -package org.jabref.gui.entryeditor; - -public class FileDragDropPreferences { - - private boolean copyFile; - private boolean linkFile; - private boolean renameCopyFile; - - public FileDragDropPreferences(boolean copyFile, boolean linkFile, boolean renameCopyFile) { - this.copyFile = copyFile; - this.linkFile = linkFile; - this.renameCopyFile = renameCopyFile; - } - - public boolean isCopyFile() { - return copyFile; - } - - public boolean isLinkFile() { - return linkFile; - } - - public boolean isRenameCopyFile() { - return renameCopyFile; - } - - public void setCopyFile(boolean copyFile) { - this.copyFile = copyFile; - } - - public void setLinkFile(boolean linkFile) { - this.linkFile = linkFile; - } - - public void setRenameCopyFile(boolean renameCopyFile) { - this.renameCopyFile = renameCopyFile; - } - -} From dbfafc02603eaa11465ce1f0b200000f1252dbd2 Mon Sep 17 00:00:00 2001 From: Amish Shah Date: Sat, 27 Oct 2018 21:08:23 -0500 Subject: [PATCH 5/9] Changes for localization message and replaced boolean for drag and drop preference with enums --- .../jabref/gui/entryeditor/EntryEditor.java | 9 +- .../FileDragDropPreferenceType.java | 2 +- .../gui/fieldeditors/LinkedFilesEditor.java | 93 ++++++++++++++++++- .../gui/preferences/EntryEditorPrefsTab.java | 24 ++--- .../jabref/preferences/JabRefPreferences.java | 26 ++---- src/main/resources/l10n/JabRef_en.properties | 4 +- 6 files changed, 117 insertions(+), 41 deletions(-) diff --git a/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java b/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java index 7c6ec65256c..d2354877915 100644 --- a/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java +++ b/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java @@ -144,18 +144,17 @@ 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()); - FileDragDropPreferences dragDropPreferences = Globals.prefs.getEntryEditorFileLinkPreference(); + FileDragDropPreferenceType dragDropPreferencesType = Globals.prefs.getEntryEditorFileLinkPreference(); - if (dragDropPreferences.isRenameCopyFile()) { + if (dragDropPreferencesType == FileDragDropPreferenceType.RENAME_COPY) { LOGGER.debug("Mode MOVE"); //shift on win or no modifier fileHandler.addToEntryRenameAndMoveToFileDir(entry, files); } - if (dragDropPreferences.isLinkFile()) { + if (dragDropPreferencesType == FileDragDropPreferenceType.LINK) { LOGGER.debug("Mode LINK"); //alt on win fileHandler.addToEntry(entry, files); - } - if (dragDropPreferences.isCopyFile()) { + if (dragDropPreferencesType == FileDragDropPreferenceType.COPY) { LOGGER.debug("Mode COPY"); //ctrl on win, no modifier on Xubuntu fileHandler.copyFilesToFileDirAndAddToEntry(entry, files); } diff --git a/src/main/java/org/jabref/gui/entryeditor/FileDragDropPreferenceType.java b/src/main/java/org/jabref/gui/entryeditor/FileDragDropPreferenceType.java index 4dcd83a70da..16075e1986d 100644 --- a/src/main/java/org/jabref/gui/entryeditor/FileDragDropPreferenceType.java +++ b/src/main/java/org/jabref/gui/entryeditor/FileDragDropPreferenceType.java @@ -1,6 +1,6 @@ package org.jabref.gui.entryeditor; -public enum FileDragDropType { +public enum FileDragDropPreferenceType { COPY, LINK, RENAME_COPY; diff --git a/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.java b/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.java index 94a4447b935..8c4a94d3517 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.java +++ b/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.java @@ -1,8 +1,12 @@ 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; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.scene.Node; @@ -14,14 +18,19 @@ import javafx.scene.control.ProgressBar; import javafx.scene.control.SeparatorMenuItem; import javafx.scene.control.Tooltip; +import javafx.scene.input.ClipboardContent; +import javafx.scene.input.DragEvent; +import javafx.scene.input.Dragboard; import javafx.scene.input.KeyEvent; import javafx.scene.input.MouseButton; import javafx.scene.input.MouseEvent; +import javafx.scene.input.TransferMode; import javafx.scene.layout.HBox; import javafx.scene.text.Text; import org.jabref.Globals; import org.jabref.gui.DialogService; +import org.jabref.gui.DragAndDropDataFormats; import org.jabref.gui.autocompleter.AutoCompleteSuggestionProvider; import org.jabref.gui.keyboard.KeyBinding; import org.jabref.gui.util.TaskExecutor; @@ -30,6 +39,7 @@ import org.jabref.logic.l10n.Localization; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.LinkedFile; import org.jabref.preferences.JabRefPreferences; import com.airhacks.afterburner.views.ViewLoader; @@ -54,14 +64,95 @@ public LinkedFilesEditor(String fieldName, DialogService dialogService, BibDatab .withTooltip(LinkedFileViewModel::getDescription) .withGraphic(LinkedFilesEditor::createFileDisplay) .withContextMenu(this::createContextMenuForFile) - .withOnMouseClickedEvent(this::handleItemMouseClick); + .withOnMouseClickedEvent(this::handleItemMouseClick) + .setOnDragDetected(this::handleOnDragDetected) + .setOnDragDropped(this::handleOnDragDropped) + .setOnDragOver(this::handleOnDragOver); 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) { + LinkedFile selectedItem = listView.getSelectionModel().getSelectedItem().getFile(); + if (selectedItem != null) { + ClipboardContent content = new ClipboardContent(); + Dragboard dragboard = listView.startDragAndDrop(TransferMode.MOVE); + //We have to use the model class here, as the content of the dragboard must be serializable + content.put(DragAndDropDataFormats.LINKED_FILE, selectedItem); + dragboard.setContent(content); + } + event.consume(); + } + + private void handleOnDragDropped(LinkedFileViewModel originalItem, DragEvent event) { + Dragboard dragboard = event.getDragboard(); + boolean success = false; + + ObservableList items = listView.itemsProperty().get(); + + if (dragboard.hasContent(DragAndDropDataFormats.LINKED_FILE)) { + + LinkedFile linkedFile = (LinkedFile) dragboard.getContent(DragAndDropDataFormats.LINKED_FILE); + LinkedFileViewModel transferedItem = null; + int draggedIdx = 0; + for (int i = 0; i < items.size(); i++) { + if (items.get(i).getFile().equals(linkedFile)) { + draggedIdx = i; + transferedItem = items.get(i); + break; + } + } + int thisIdx = items.indexOf(originalItem); + items.set(draggedIdx, originalItem); + 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(); + + } + private static Node createFileDisplay(LinkedFileViewModel linkedFile) { Node icon = linkedFile.getTypeIcon().getGraphicNode(); icon.setOnMouseClicked(event -> linkedFile.open()); diff --git a/src/main/java/org/jabref/gui/preferences/EntryEditorPrefsTab.java b/src/main/java/org/jabref/gui/preferences/EntryEditorPrefsTab.java index 7d0fb43bf95..e4dc559c926 100644 --- a/src/main/java/org/jabref/gui/preferences/EntryEditorPrefsTab.java +++ b/src/main/java/org/jabref/gui/preferences/EntryEditorPrefsTab.java @@ -12,7 +12,7 @@ import org.jabref.gui.autocompleter.AutoCompleteFirstNameMode; import org.jabref.gui.autocompleter.AutoCompletePreferences; -import org.jabref.gui.entryeditor.FileDragDropPreferences; +import org.jabref.gui.entryeditor.FileDragDropPreferenceType; import org.jabref.gui.keyboard.EmacsKeyBindings; import org.jabref.logic.l10n.Localization; import org.jabref.preferences.JabRefPreferences; @@ -43,7 +43,6 @@ class EntryEditorPrefsTab extends Pane implements PrefsTab { private final JabRefPreferences prefs; private final AutoCompletePreferences autoCompletePreferences; - private final FileDragDropPreferences dragDropPreferences; private final RadioButton copyFile; private final RadioButton linkFile; private final RadioButton renameCopyFile; @@ -51,7 +50,6 @@ class EntryEditorPrefsTab extends Pane implements PrefsTab { public EntryEditorPrefsTab(JabRefPreferences prefs) { this.prefs = prefs; autoCompletePreferences = prefs.getAutoCompletePreferences(); - dragDropPreferences = prefs.getEntryEditorFileLinkPreference(); autoOpenForm = new CheckBox(Localization.lang("Open editor when a new entry is created")); defSource = new CheckBox(Localization.lang("Show BibTeX source by default")); @@ -134,7 +132,7 @@ public EntryEditorPrefsTab(JabRefPreferences prefs) { final ToggleGroup group = new ToggleGroup(); Label linkFileOptions = new Label(Localization.lang("Options to add file")); linkFileOptions.getStyleClass().add("sectionHeader"); - copyFile = new RadioButton(Localization.lang("Copy file to current location")); + 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); @@ -193,9 +191,10 @@ public void setValues() { break; } - if (dragDropPreferences.isCopyFile()) { + FileDragDropPreferenceType dragDropPreferenceType = prefs.getEntryEditorFileLinkPreference(); + if (dragDropPreferenceType == FileDragDropPreferenceType.COPY) { copyFile.setSelected(true); - } else if (dragDropPreferences.isLinkFile()) { + } else if (dragDropPreferenceType == FileDragDropPreferenceType.LINK) { linkFile.setSelected(true); } else { renameCopyFile.setSelected(true); @@ -261,20 +260,13 @@ else if (autoCompFF.isSelected()) { } if (copyFile.isSelected()) { - dragDropPreferences.setCopyFile(true); - dragDropPreferences.setLinkFile(false); - dragDropPreferences.setRenameCopyFile(false); + prefs.storeEntryEditorFileLinkPreference(FileDragDropPreferenceType.COPY); } else if (linkFile.isSelected()) { - dragDropPreferences.setCopyFile(false); - dragDropPreferences.setLinkFile(true); - dragDropPreferences.setRenameCopyFile(false); + prefs.storeEntryEditorFileLinkPreference(FileDragDropPreferenceType.LINK); } else { - dragDropPreferences.setCopyFile(false); - dragDropPreferences.setLinkFile(false); - dragDropPreferences.setRenameCopyFile(true); + prefs.storeEntryEditorFileLinkPreference(FileDragDropPreferenceType.RENAME_COPY); } - prefs.storeEntryEditorFileLinkPreference(dragDropPreferences); prefs.storeAutoCompletePreferences(autoCompletePreferences); } diff --git a/src/main/java/org/jabref/preferences/JabRefPreferences.java b/src/main/java/org/jabref/preferences/JabRefPreferences.java index aa8f9f9d049..f0b99baa5cc 100644 --- a/src/main/java/org/jabref/preferences/JabRefPreferences.java +++ b/src/main/java/org/jabref/preferences/JabRefPreferences.java @@ -46,7 +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.FileDragDropPreferences; +import org.jabref.gui.entryeditor.FileDragDropPreferenceType; import org.jabref.gui.groups.GroupViewMode; import org.jabref.gui.keyboard.KeyBindingRepository; import org.jabref.gui.maintable.ColumnPreferences; @@ -370,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"; @@ -404,11 +408,6 @@ public class JabRefPreferences implements PreferencesService { private static final String PROTECTED_TERMS_ENABLED_INTERNAL = "protectedTermsEnabledInternal"; private static final String PROTECTED_TERMS_DISABLED_INTERNAL = "protectedTermsDisabledInternal"; - //File linking Options for entry editor - private static final String ENTRY_EDITOR_COPY_FILE = "copyFile"; - private static final String ENTRY_EDITOR_LINK_FILE = "linkFile"; - private static final String ENTRY_EDITOR_RENAME_COPY_FILE = "renameCopyFile"; - //GroupViewMode private static final String GROUP_INTERSECT_UNION_VIEW_MODE = "groupIntersectUnionViewModes"; @@ -794,9 +793,7 @@ private JabRefPreferences() { // set default theme defaults.put(JabRefPreferences.FX_THEME, ThemeLoader.MAIN_CSS); - defaults.put(ENTRY_EDITOR_COPY_FILE, Boolean.TRUE); - defaults.put(ENTRY_EDITOR_LINK_FILE, Boolean.FALSE); - defaults.put(ENTRY_EDITOR_RENAME_COPY_FILE, Boolean.FALSE); + defaults.put(ENTRY_EDITOR_DRAG_DROP_PREFERENCE_TYPE, FileDragDropPreferenceType.COPY.name()); setLanguageDependentDefaultValues(); } @@ -2031,14 +2028,11 @@ public Map getMainTableColumnSortTypes() { return map; } - public FileDragDropPreferences getEntryEditorFileLinkPreference() { - return new FileDragDropPreferences(getBoolean(ENTRY_EDITOR_COPY_FILE), getBoolean(ENTRY_EDITOR_LINK_FILE), - getBoolean(ENTRY_EDITOR_RENAME_COPY_FILE)); + public FileDragDropPreferenceType getEntryEditorFileLinkPreference() { + return FileDragDropPreferenceType.valueOf(get(ENTRY_EDITOR_DRAG_DROP_PREFERENCE_TYPE)); } - public void storeEntryEditorFileLinkPreference(FileDragDropPreferences dragDropPreferences) { - putBoolean(ENTRY_EDITOR_COPY_FILE, dragDropPreferences.isCopyFile()); - putBoolean(ENTRY_EDITOR_LINK_FILE, dragDropPreferences.isLinkFile()); - putBoolean(ENTRY_EDITOR_RENAME_COPY_FILE, dragDropPreferences.isRenameCopyFile()); + 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 9f586faec66..68fc8a14188 100644 --- a/src/main/resources/l10n/JabRef_en.properties +++ b/src/main/resources/l10n/JabRef_en.properties @@ -2231,6 +2231,6 @@ Remember\ Password=Remember Password Use\ SSL=Use SSL Options\ to\ add\ file=Options to add file -Copy\ file\ to\ current\ location=Copy file to current location +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 \ No newline at end of file +Copy,\ rename\ and\ link\ file=Copy, rename and link file From 50bf10a330aeb3bd9b910be035a9ab405c2c17f5 Mon Sep 17 00:00:00 2001 From: Amish Shah Date: Sat, 27 Oct 2018 21:10:21 -0500 Subject: [PATCH 6/9] Change drag-drop option name in preferences --- .../java/org/jabref/gui/preferences/EntryEditorPrefsTab.java | 2 +- src/main/resources/l10n/JabRef_en.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/jabref/gui/preferences/EntryEditorPrefsTab.java b/src/main/java/org/jabref/gui/preferences/EntryEditorPrefsTab.java index e4dc559c926..21bf19b94da 100644 --- a/src/main/java/org/jabref/gui/preferences/EntryEditorPrefsTab.java +++ b/src/main/java/org/jabref/gui/preferences/EntryEditorPrefsTab.java @@ -130,7 +130,7 @@ public EntryEditorPrefsTab(JabRefPreferences prefs) { firstNameModeBoth.setToggleGroup(treatmentOfFirstNamesToggleGroup); final ToggleGroup group = new ToggleGroup(); - Label linkFileOptions = new Label(Localization.lang("Options to add file")); + 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)")); diff --git a/src/main/resources/l10n/JabRef_en.properties b/src/main/resources/l10n/JabRef_en.properties index 68fc8a14188..e4bd843bed0 100644 --- a/src/main/resources/l10n/JabRef_en.properties +++ b/src/main/resources/l10n/JabRef_en.properties @@ -2230,7 +2230,7 @@ Password\:=Password\: Remember\ Password=Remember Password Use\ SSL=Use SSL -Options\ to\ add\ file=Options to add file +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 From ca4ac4f4de0d2fd899e0b38b1a900bad3ddfd5de Mon Sep 17 00:00:00 2001 From: Amish Shah Date: Tue, 30 Oct 2018 21:40:51 -0500 Subject: [PATCH 7/9] Added behaviors to accommodate different drag-drop ways along with preference default --- .../jabref/gui/entryeditor/EntryEditor.java | 62 ++++++++++++++++--- .../FileDragDropPreferenceType.java | 2 +- .../gui/fieldeditors/LinkedFilesEditor.java | 35 +---------- .../gui/preferences/EntryEditorPrefsTab.java | 2 +- .../jabref/preferences/JabRefPreferences.java | 2 +- 5 files changed, 58 insertions(+), 45 deletions(-) diff --git a/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java b/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java index d2354877915..3ad9cae97ad 100644 --- a/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java +++ b/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java @@ -146,17 +146,61 @@ public EntryEditor(BasePanel panel, EntryEditorPreferences preferences, FileUpda FileDragDropPreferenceType dragDropPreferencesType = Globals.prefs.getEntryEditorFileLinkPreference(); - if (dragDropPreferencesType == FileDragDropPreferenceType.RENAME_COPY) { - LOGGER.debug("Mode MOVE"); //shift on win or no modifier - fileHandler.addToEntryRenameAndMoveToFileDir(entry, files); + 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 (dragDropPreferencesType == FileDragDropPreferenceType.LINK) { - LOGGER.debug("Mode 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 (dragDropPreferencesType == FileDragDropPreferenceType.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 index 16075e1986d..f8bea3ce606 100644 --- a/src/main/java/org/jabref/gui/entryeditor/FileDragDropPreferenceType.java +++ b/src/main/java/org/jabref/gui/entryeditor/FileDragDropPreferenceType.java @@ -3,5 +3,5 @@ public enum FileDragDropPreferenceType { COPY, LINK, - RENAME_COPY; + 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..3b34881bcc6 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.java +++ b/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.java @@ -70,42 +70,15 @@ public LinkedFilesEditor(String fieldName, DialogService dialogService, BibDatab .setOnDragOver(this::handleOnDragOver); 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 +116,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 21bf19b94da..2fd8a9a6653 100644 --- a/src/main/java/org/jabref/gui/preferences/EntryEditorPrefsTab.java +++ b/src/main/java/org/jabref/gui/preferences/EntryEditorPrefsTab.java @@ -264,7 +264,7 @@ else if (autoCompFF.isSelected()) { } else if (linkFile.isSelected()) { prefs.storeEntryEditorFileLinkPreference(FileDragDropPreferenceType.LINK); } else { - prefs.storeEntryEditorFileLinkPreference(FileDragDropPreferenceType.RENAME_COPY); + 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 f0b99baa5cc..eea8a2ee771 100644 --- a/src/main/java/org/jabref/preferences/JabRefPreferences.java +++ b/src/main/java/org/jabref/preferences/JabRefPreferences.java @@ -793,7 +793,7 @@ private JabRefPreferences() { // set default theme defaults.put(JabRefPreferences.FX_THEME, ThemeLoader.MAIN_CSS); - defaults.put(ENTRY_EDITOR_DRAG_DROP_PREFERENCE_TYPE, FileDragDropPreferenceType.COPY.name()); + defaults.put(ENTRY_EDITOR_DRAG_DROP_PREFERENCE_TYPE, FileDragDropPreferenceType.MOVE.name()); setLanguageDependentDefaultValues(); } From 8c6a90f2f465b97116551b6c2782ad2e46ffaccf Mon Sep 17 00:00:00 2001 From: Amish Shah Date: Tue, 30 Oct 2018 22:29:40 -0500 Subject: [PATCH 8/9] Added whitespaces after if condition --- src/main/java/org/jabref/gui/entryeditor/EntryEditor.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java b/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java index 3ad9cae97ad..c7961bff628 100644 --- a/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java +++ b/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java @@ -148,7 +148,7 @@ public EntryEditor(BasePanel panel, EntryEditorPreferences preferences, FileUpda if (dragDropPreferencesType == FileDragDropPreferenceType.MOVE) { - if(event.getTransferMode() == TransferMode.LINK) //alt on win + if (event.getTransferMode() == TransferMode.LINK) //alt on win { LOGGER.debug("Mode LINK"); fileHandler.addToEntry(entry, files); @@ -167,7 +167,7 @@ else if (event.getTransferMode() == TransferMode.COPY) //ctrl on win, no modifie if (dragDropPreferencesType == FileDragDropPreferenceType.COPY) { - if(event.getTransferMode() == TransferMode.COPY) //ctrl on win, no modifier on Xubuntu + if (event.getTransferMode() == TransferMode.COPY) //ctrl on win, no modifier on Xubuntu { LOGGER.debug("Mode MOVE"); fileHandler.addToEntryRenameAndMoveToFileDir(entry, files); @@ -186,7 +186,7 @@ else if (event.getTransferMode() == TransferMode.LINK) //alt on win if (dragDropPreferencesType == FileDragDropPreferenceType.LINK) { - if(event.getTransferMode() == TransferMode.COPY) //ctrl on win, no modifier on Xubuntu + if (event.getTransferMode() == TransferMode.COPY) //ctrl on win, no modifier on Xubuntu { LOGGER.debug("Mode COPY"); fileHandler.copyFilesToFileDirAndAddToEntry(entry, files); From 89592d673e96bec3adb5fec9c04db111ac39d85e Mon Sep 17 00:00:00 2001 From: Amish Shah Date: Tue, 30 Oct 2018 22:42:24 -0500 Subject: [PATCH 9/9] Remove unused imports --- .../java/org/jabref/gui/fieldeditors/LinkedFilesEditor.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.java b/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.java index 3b34881bcc6..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; @@ -70,7 +67,7 @@ public LinkedFilesEditor(String fieldName, DialogService dialogService, BibDatab .setOnDragOver(this::handleOnDragOver); listView.setCellFactory(cellFactory); - + Bindings.bindContentBidirectional(listView.itemsProperty().get(), viewModel.filesProperty()); setUpKeyBindings(); }