Skip to content
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

Add a preference to add files in entry editor #4408

Merged
merged 9 commits into from
Nov 1, 2018
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Alexsandro Lauber
Ali Ayan
Alick Zhao
Ambrogio Oliva
Amish Shah
Andreas Amann
Andreas Buhr
Andreas Rudert
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <kbd>Ctrl<kbd> + <kbd>E<kbd>. [#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)



Expand Down
64 changes: 54 additions & 10 deletions src/main/java/org/jabref/gui/entryeditor/EntryEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,19 +144,63 @@ public EntryEditor(BasePanel panel, EntryEditorPreferences preferences, FileUpda
if (event.getDragboard().hasContent(DataFormat.FILES)) {
List<Path> 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);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.jabref.gui.entryeditor;

public enum FileDragDropPreferenceType {
COPY,
LINK,
MOVE;
}
36 changes: 1 addition & 35 deletions src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<LinkedFileViewModel> items = listView.itemsProperty().get();

if (dragboard.hasFiles()) {
List<LinkedFileViewModel> 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) {
Expand Down Expand Up @@ -143,11 +113,7 @@ private void handleOnDragDropped(LinkedFileViewModel originalItem, DragEvent eve
items.set(thisIdx, transferedItem);
success = true;
}
if (dragboard.hasFiles()) {
List<LinkedFileViewModel> linkedFiles = dragboard.getFiles().stream().map(File::toPath).map(viewModel::fromFile).collect(Collectors.toList());
items.addAll(linkedFiles);
success = true;
}

event.setDropCompleted(success);
event.consume();

Expand Down
37 changes: 37 additions & 0 deletions src/main/java/org/jabref/gui/preferences/EntryEditorPrefsTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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"));
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}

Expand Down
16 changes: 16 additions & 0 deletions src/main/java/org/jabref/preferences/JabRefPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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;
/**
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -2019,4 +2027,12 @@ public Map<String, SortType> 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());
}
}
5 changes: 5 additions & 0 deletions src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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