Skip to content

Commit

Permalink
Changes for localization message and replaced boolean for drag and dr…
Browse files Browse the repository at this point in the history
…op preference with enums
  • Loading branch information
shahamish150294 committed Oct 28, 2018
1 parent 0475e71 commit 66443c0
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 41 deletions.
9 changes: 4 additions & 5 deletions src/main/java/org/jabref/gui/entryeditor/EntryEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,18 +144,17 @@ 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());

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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.jabref.gui.entryeditor;

public enum FileDragDropType {
public enum FileDragDropPreferenceType {
COPY,
LINK,
RENAME_COPY;
Expand Down
93 changes: 92 additions & 1 deletion src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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<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) {
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<LinkedFileViewModel> 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<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 static Node createFileDisplay(LinkedFileViewModel linkedFile) {
Node icon = linkedFile.getTypeIcon().getGraphicNode();
icon.setOnMouseClicked(event -> linkedFile.open());
Expand Down
24 changes: 8 additions & 16 deletions src/main/java/org/jabref/gui/preferences/EntryEditorPrefsTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -43,15 +43,13 @@ 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"));
Expand Down Expand Up @@ -126,7 +124,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);
Expand Down Expand Up @@ -186,9 +184,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);
Expand Down Expand Up @@ -254,20 +253,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);
}

Expand Down
26 changes: 10 additions & 16 deletions src/main/java/org/jabref/preferences/JabRefPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -369,6 +369,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 @@ -403,11 +407,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";

Expand Down Expand Up @@ -793,9 +792,7 @@ private JabRefPreferences() {
// set default theme
defaults.put(JabRefPreferences.FX_THEME, ThemeLoader.DEFAULT_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();
}
Expand Down Expand Up @@ -2031,14 +2028,11 @@ public Map<String, SortType> 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());
}
}
4 changes: 2 additions & 2 deletions src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2235,6 +2235,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
Copy,\ rename\ and\ link\ file=Copy, rename and link file

0 comments on commit 66443c0

Please sign in to comment.