1
1
package org .jabref .gui .entryeditor ;
2
2
3
+ import java .io .File ;
4
+ import java .nio .file .Path ;
3
5
import java .util .ArrayList ;
4
6
import java .util .LinkedList ;
5
7
import java .util .List ;
16
18
import javafx .scene .control .MenuItem ;
17
19
import javafx .scene .control .Tab ;
18
20
import javafx .scene .control .TabPane ;
21
+ import javafx .scene .input .DataFormat ;
19
22
import javafx .scene .input .KeyEvent ;
23
+ import javafx .scene .input .TransferMode ;
20
24
import javafx .scene .layout .BorderPane ;
21
25
26
+ import org .jabref .Globals ;
22
27
import org .jabref .gui .BasePanel ;
23
28
import org .jabref .gui .DialogService ;
24
29
import org .jabref .gui .GUIGlobals ;
25
30
import org .jabref .gui .actions .ActionFactory ;
26
31
import org .jabref .gui .actions .GenerateBibtexKeySingleAction ;
27
32
import org .jabref .gui .actions .StandardActions ;
28
33
import org .jabref .gui .entryeditor .fileannotationtab .FileAnnotationTab ;
34
+ import org .jabref .gui .externalfiles .NewDroppedFileHandler ;
35
+ import org .jabref .gui .externalfiletype .ExternalFileTypes ;
29
36
import org .jabref .gui .help .HelpAction ;
30
37
import org .jabref .gui .keyboard .KeyBinding ;
31
38
import org .jabref .gui .menus .ChangeEntryTypeMenu ;
41
48
import org .jabref .model .database .BibDatabaseContext ;
42
49
import org .jabref .model .entry .BibEntry ;
43
50
import org .jabref .model .util .FileUpdateMonitor ;
51
+ import org .jabref .preferences .JabRefPreferences ;
44
52
45
53
import com .airhacks .afterburner .views .ViewLoader ;
46
54
import org .fxmisc .easybind .EasyBind ;
47
55
import org .fxmisc .easybind .Subscription ;
56
+ import org .slf4j .Logger ;
57
+ import org .slf4j .LoggerFactory ;
48
58
49
59
/**
50
60
* GUI component that allows editing of the fields of a BibEntry (i.e. the
58
68
*/
59
69
public class EntryEditor extends BorderPane {
60
70
71
+ private static final Logger LOGGER = LoggerFactory .getLogger (EntryEditor .class );
72
+
61
73
private final BibDatabaseContext databaseContext ;
62
74
private final CountingUndoManager undoManager ;
63
75
private final BasePanel panel ;
@@ -79,15 +91,24 @@ public class EntryEditor extends BorderPane {
79
91
80
92
private final EntryEditorPreferences preferences ;
81
93
private final DialogService dialogService ;
94
+ private final NewDroppedFileHandler fileHandler ;
82
95
83
- public EntryEditor (BasePanel panel , EntryEditorPreferences preferences , FileUpdateMonitor fileMonitor , DialogService dialogService ) {
96
+ public EntryEditor (BasePanel panel , EntryEditorPreferences preferences , FileUpdateMonitor fileMonitor , DialogService dialogService , ExternalFileTypes externalFileTypes ) {
84
97
this .panel = panel ;
85
98
this .databaseContext = panel .getBibDatabaseContext ();
86
99
this .undoManager = panel .getUndoManager ();
87
100
this .preferences = Objects .requireNonNull (preferences );
88
101
this .fileMonitor = fileMonitor ;
89
102
this .dialogService = dialogService ;
90
103
104
+ fileHandler = new NewDroppedFileHandler (dialogService , databaseContext , externalFileTypes ,
105
+ Globals .prefs .getFileDirectoryPreferences (),
106
+ Globals .prefs .getCleanupPreferences (Globals .journalAbbreviationLoader ).getFileDirPattern (),
107
+ Globals .prefs .getImportFormatPreferences (),
108
+ Globals .prefs .getUpdateFieldPreferences (),
109
+ Globals .getFileUpdateMonitor (),
110
+ Globals .prefs .get (JabRefPreferences .IMPORT_FILENAMEPATTERN ));
111
+
91
112
ViewLoader .view (this )
92
113
.root (this )
93
114
.load ();
@@ -109,6 +130,40 @@ public EntryEditor(BasePanel panel, EntryEditorPreferences preferences, FileUpda
109
130
setupKeyBindings ();
110
131
111
132
tabs = createTabs ();
133
+
134
+ this .setOnDragOver (event -> {
135
+ if (event .getDragboard ().hasFiles ()) {
136
+ event .acceptTransferModes (TransferMode .COPY , TransferMode .MOVE , TransferMode .LINK );
137
+ }
138
+ event .consume ();
139
+ });
140
+
141
+ this .setOnDragDropped (event -> {
142
+ BibEntry entry = this .getEntry ();
143
+ boolean success = false ;
144
+ if (event .getDragboard ().hasContent (DataFormat .FILES )) {
145
+ List <Path > files = event .getDragboard ().getFiles ().stream ().map (File ::toPath ).collect (Collectors .toList ());
146
+
147
+ if (event .getTransferMode () == TransferMode .MOVE ) {
148
+
149
+ LOGGER .debug ("Mode MOVE" ); //shift on win or no modifier
150
+ fileHandler .addToEntryRenameAndMoveToFileDir (entry , files );
151
+ }
152
+ if (event .getTransferMode () == TransferMode .LINK ) {
153
+ LOGGER .debug ("Node LINK" ); //alt on win
154
+ fileHandler .addToEntry (entry , files );
155
+
156
+ }
157
+ if (event .getTransferMode () == TransferMode .COPY ) {
158
+ LOGGER .debug ("Mode Copy" ); //ctrl on win, no modifier on Xubuntu
159
+ fileHandler .copyFilesToFileDirAndAddToEntry (entry , files );
160
+ }
161
+ }
162
+
163
+ event .setDropCompleted (success );
164
+ event .consume ();
165
+
166
+ });
112
167
}
113
168
114
169
/**
0 commit comments