8
8
9
9
import javax .swing .undo .UndoManager ;
10
10
11
- import javafx .beans .property .BooleanProperty ;
12
11
import javafx .scene .Node ;
13
12
import javafx .scene .control .Tooltip ;
14
13
20
19
import org .jabref .gui .undo .NamedCompound ;
21
20
import org .jabref .gui .undo .UndoableChangeType ;
22
21
import org .jabref .gui .undo .UndoableFieldChange ;
23
- import org .jabref .gui .util .DefaultTaskExecutor ;
24
22
import org .jabref .logic .bibtex .BibEntryWriter ;
25
23
import org .jabref .logic .bibtex .InvalidFieldValueException ;
26
24
import org .jabref .logic .bibtex .LatexFieldFormatter ;
@@ -44,13 +42,11 @@ public class SourceTab extends EntryEditorTab {
44
42
private final BibDatabaseMode mode ;
45
43
private final BasePanel panel ;
46
44
private CodeArea codeArea ;
47
- private BooleanProperty movingToDifferentEntry ;
48
45
private UndoManager undoManager ;
49
46
50
- public SourceTab (BasePanel panel , BooleanProperty movingToDifferentEntry ) {
47
+ public SourceTab (BasePanel panel ) {
51
48
this .mode = panel .getBibDatabaseContext ().getMode ();
52
49
this .panel = panel ;
53
- this .movingToDifferentEntry = movingToDifferentEntry ;
54
50
this .setText (Localization .lang ("%0 source" , mode .getFormattedName ()));
55
51
this .setTooltip (new Tooltip (Localization .lang ("Show/edit %0 source" , mode .getFormattedName ())));
56
52
this .setGraphic (IconTheme .JabRefIcon .SOURCE .getGraphicNode ());
@@ -80,27 +76,20 @@ public void updateSourcePane(BibEntry entry) {
80
76
}
81
77
}
82
78
83
- private Node createSourceEditor (BibEntry entry , BibDatabaseMode mode ) {
79
+ private Node createSourceEditor (BibDatabaseMode mode ) {
84
80
codeArea = new CodeArea ();
85
81
codeArea .setWrapText (true );
86
82
codeArea .lookup (".styled-text-area" ).setStyle (
87
83
"-fx-font-size: " + Globals .prefs .getFontSizeFX () + "pt;" );
88
84
// store source if new tab is selected (if this one is not focused anymore)
89
85
EasyBind .subscribe (codeArea .focusedProperty (), focused -> {
90
86
if (!focused ) {
91
- storeSource (entry );
92
- }
93
- });
94
-
95
- // store source if new entry is selected in the maintable and the source tab is focused
96
- EasyBind .subscribe (movingToDifferentEntry , newEntrySelected -> {
97
- if (newEntrySelected && codeArea .focusedProperty ().get ()) {
98
- DefaultTaskExecutor .runInJavaFXThread (() -> storeSource (entry ));
87
+ storeSource ();
99
88
}
100
89
});
101
90
102
91
try {
103
- String srcString = getSourceString (entry , mode );
92
+ String srcString = getSourceString (this . currentEntry , mode );
104
93
codeArea .appendText (srcString );
105
94
} catch (IOException ex ) {
106
95
codeArea .appendText (ex .getMessage () + "\n \n " +
@@ -126,10 +115,10 @@ public boolean shouldShow(BibEntry entry) {
126
115
127
116
@ Override
128
117
protected void bindToEntry (BibEntry entry ) {
129
- this .setContent (createSourceEditor (entry , mode ));
118
+ this .setContent (createSourceEditor (mode ));
130
119
}
131
120
132
- private void storeSource (BibEntry entry ) {
121
+ private void storeSource () {
133
122
if (codeArea .getText ().isEmpty ()) {
134
123
return ;
135
124
}
@@ -157,42 +146,42 @@ private void storeSource(BibEntry entry) {
157
146
String newKey = newEntry .getCiteKeyOptional ().orElse (null );
158
147
159
148
if (newKey != null ) {
160
- entry .setCiteKey (newKey );
149
+ currentEntry .setCiteKey (newKey );
161
150
} else {
162
- entry .clearCiteKey ();
151
+ currentEntry .clearCiteKey ();
163
152
}
164
153
165
154
// First, remove fields that the user has removed.
166
- for (Map .Entry <String , String > field : entry .getFieldMap ().entrySet ()) {
155
+ for (Map .Entry <String , String > field : currentEntry .getFieldMap ().entrySet ()) {
167
156
String fieldName = field .getKey ();
168
157
String fieldValue = field .getValue ();
169
158
170
159
if (InternalBibtexFields .isDisplayableField (fieldName ) && !newEntry .hasField (fieldName )) {
171
160
compound .addEdit (
172
- new UndoableFieldChange (entry , fieldName , fieldValue , null ));
173
- entry .clearField (fieldName );
161
+ new UndoableFieldChange (currentEntry , fieldName , fieldValue , null ));
162
+ currentEntry .clearField (fieldName );
174
163
}
175
164
}
176
165
177
166
// Then set all fields that have been set by the user.
178
167
for (Map .Entry <String , String > field : newEntry .getFieldMap ().entrySet ()) {
179
168
String fieldName = field .getKey ();
180
- String oldValue = entry .getField (fieldName ).orElse (null );
169
+ String oldValue = currentEntry .getField (fieldName ).orElse (null );
181
170
String newValue = field .getValue ();
182
171
if (!Objects .equals (oldValue , newValue )) {
183
172
// Test if the field is legally set.
184
173
new LatexFieldFormatter (Globals .prefs .getLatexFieldFormatterPreferences ())
185
174
.format (newValue , fieldName );
186
175
187
- compound .addEdit (new UndoableFieldChange (entry , fieldName , oldValue , newValue ));
188
- entry .setField (fieldName , newValue );
176
+ compound .addEdit (new UndoableFieldChange (currentEntry , fieldName , oldValue , newValue ));
177
+ currentEntry .setField (fieldName , newValue );
189
178
}
190
179
}
191
180
192
181
// See if the user has changed the entry type:
193
- if (!Objects .equals (newEntry .getType (), entry .getType ())) {
194
- compound .addEdit (new UndoableChangeType (entry , entry .getType (), newEntry .getType ()));
195
- entry .setType (newEntry .getType ());
182
+ if (!Objects .equals (newEntry .getType (), currentEntry .getType ())) {
183
+ compound .addEdit (new UndoableChangeType (currentEntry , currentEntry .getType (), newEntry .getType ()));
184
+ currentEntry .setType (newEntry .getType ());
196
185
}
197
186
compound .end ();
198
187
undoManager .addEdit (compound );
@@ -214,7 +203,7 @@ private void storeSource(BibEntry entry) {
214
203
if (!keepEditing ) {
215
204
// Revert
216
205
try {
217
- codeArea .replaceText (0 , codeArea .getText ().length (), getSourceString (entry , mode ));
206
+ codeArea .replaceText (0 , codeArea .getText ().length (), getSourceString (this . currentEntry , mode ));
218
207
} catch (IOException e ) {
219
208
LOGGER .debug ("Incorrect source" , e );
220
209
}
0 commit comments