Skip to content

Commit b702a3d

Browse files
committed
Refactoring to clean code after changes made
1 parent 35d272d commit b702a3d

File tree

6 files changed

+46
-81
lines changed

6 files changed

+46
-81
lines changed

src/main/java/org/jabref/gui/preferences/linkedfiles/LinkedFilesTab.fxml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,10 @@
8383

8484

8585
<HBox alignment="CENTER_LEFT" spacing="10.0">
86-
<CheckBox fx:id="copyLinkedFiles" text="%Copy/move files when copying/moving entries."/>
87-
<Label text="%Enter default database filepath:" GridPane.rowIndex="1"/>
88-
<TextField fx:id="copyLinkedFilesDirectoryPath" HBox.hgrow="ALWAYS"/>
86+
<CheckBox fx:id="copyLinkedFiles" text="%Copy/move files when copying/moving entries"/>
87+
<Label text="%Enter default database filepath" GridPane.rowIndex="1"/>
88+
<TextField fx:id="linkedFileDirectory" HBox.hgrow="ALWAYS"/>
8989
</HBox>
9090

91-
<Label text="%File directory pattern" GridPane.rowIndex="1"/>
92-
<TextField fx:id="linkedFileDirectory" GridPane.columnIndex="1" GridPane.rowIndex="1"
93-
prefWidth="300" minWidth="300" maxWidth="300"/>
91+
9492
</fx:root>

src/main/java/org/jabref/gui/preferences/linkedfiles/LinkedFilesTab.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,13 @@ public class LinkedFilesTab extends AbstractPreferenceTabView<LinkedFilesTabView
3737

3838
@FXML private ComboBox<String> fileNamePattern;
3939
@FXML private TextField fileDirectoryPattern;
40-
@FXML private TextField linkedFileDirectory;
4140

4241
@FXML private CheckBox confirmLinkedFileDelete;
4342
@FXML private CheckBox moveToTrash;
43+
4444
@FXML private CheckBox copyLinkedFiles;
45-
@FXML private TextField copyLinkedFilesDirectoryPath;
45+
@FXML private TextField linkedFileDirectory;
46+
4647

4748
private final ControlsFxVisualizer validationVisualizer = new ControlsFxVisualizer();
4849

@@ -69,11 +70,8 @@ public void initialize() {
6970
moveToTrash.selectedProperty().bindBidirectional(viewModel.moveToTrashProperty());
7071
moveToTrash.setDisable(!NativeDesktop.get().moveToTrashSupported());
7172

72-
//added:
7373
copyLinkedFiles.selectedProperty().bindBidirectional(viewModel.copyLinkedFilesProperty());
74-
//copyLinkedFiles.selectedProperty().set(true);
75-
copyLinkedFilesDirectoryPath.textProperty().bindBidirectional(viewModel.copyLinkedFilesDirectoryPathProperty());
76-
74+
linkedFileDirectory.textProperty().bindBidirectional(viewModel.linkedFileDirectoryProperty());
7775

7876
autolinkFileStartsBibtex.selectedProperty().bindBidirectional(viewModel.autolinkFileStartsBibtexProperty());
7977
autolinkFileExactBibtex.selectedProperty().bindBidirectional(viewModel.autolinkFileExactBibtexProperty());
@@ -84,8 +82,6 @@ public void initialize() {
8482
fileNamePattern.valueProperty().bindBidirectional(viewModel.fileNamePatternProperty());
8583
fileNamePattern.itemsProperty().bind(viewModel.defaultFileNamePatternsProperty());
8684
fileDirectoryPattern.textProperty().bindBidirectional(viewModel.fileDirectoryPatternProperty());
87-
linkedFileDirectory.textProperty().bindBidirectional(viewModel.linkedFileDirectoryProperty());
88-
8985
confirmLinkedFileDelete.selectedProperty().bindBidirectional(viewModel.confirmLinkedFileDeleteProperty());
9086

9187
ActionFactory actionFactory = new ActionFactory();

src/main/java/org/jabref/gui/preferences/linkedfiles/LinkedFilesTabViewModel.java

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@
44
import java.nio.file.InvalidPathException;
55
import java.nio.file.Path;
66

7-
import javafx.beans.property.*;
7+
import javafx.beans.property.BooleanProperty;
8+
import javafx.beans.property.ListProperty;
9+
import javafx.beans.property.SimpleBooleanProperty;
10+
import javafx.beans.property.SimpleListProperty;
11+
import javafx.beans.property.SimpleStringProperty;
12+
import javafx.beans.property.StringProperty;
813
import javafx.collections.FXCollections;
914

1015
import org.jabref.gui.DialogService;
@@ -34,11 +39,10 @@ public class LinkedFilesTabViewModel implements PreferenceTabViewModel {
3439
private final BooleanProperty fulltextIndex = new SimpleBooleanProperty();
3540
private final StringProperty fileNamePatternProperty = new SimpleStringProperty();
3641
private final StringProperty fileDirectoryPatternProperty = new SimpleStringProperty();
37-
private final StringProperty linkedFileDirectoryProperty = new SimpleStringProperty();
3842
private final BooleanProperty confirmLinkedFileDeleteProperty = new SimpleBooleanProperty();
3943
private final BooleanProperty moveToTrashProperty = new SimpleBooleanProperty();
4044
private final BooleanProperty copyLinkedFilesProperty = new SimpleBooleanProperty();
41-
private final StringProperty copyLinkedFilesDirectoryPathProperty = new SimpleStringProperty();
45+
private final StringProperty linkedFileDirectoryProperty = new SimpleStringProperty();
4246

4347
private final Validator mainFileDirValidator;
4448

@@ -80,11 +84,10 @@ public void setValues() {
8084
fulltextIndex.setValue(filePreferences.shouldFulltextIndexLinkedFiles());
8185
fileNamePatternProperty.setValue(filePreferences.getFileNamePattern());
8286
fileDirectoryPatternProperty.setValue(filePreferences.getFileDirectoryPattern());
83-
linkedFileDirectoryProperty.setValue(filePreferences.getLinkedFileDirectory());
8487
confirmLinkedFileDeleteProperty.setValue(filePreferences.confirmDeleteLinkedFile());
8588
moveToTrashProperty.setValue(filePreferences.moveToTrash());
8689
copyLinkedFilesProperty.setValue(filePreferences.copyLinkedFiles());
87-
copyLinkedFilesDirectoryPathProperty.setValue(filePreferences.getCopyLinkedFilesDirectoryPath());
90+
linkedFileDirectoryProperty.setValue(filePreferences.getLinkedFileDirectory());
8891

8992
// Autolink preferences
9093
switch (autoLinkPreferences.getCitationKeyDependency()) {
@@ -103,9 +106,7 @@ public void storeSettings() {
103106
filePreferences.setStoreFilesRelativeToBibFile(useBibLocationAsPrimaryProperty.getValue());
104107
filePreferences.setFileNamePattern(fileNamePatternProperty.getValue());
105108
filePreferences.setFileDirectoryPattern(fileDirectoryPatternProperty.getValue());
106-
filePreferences.setLinkedFileDirectory(linkedFileDirectoryProperty.getValue());
107109
filePreferences.setFulltextIndexLinkedFiles(fulltextIndex.getValue());
108-
filePreferences.setLinkedFilesPath(copyLinkedFilesDirectoryPathProperty.getValue());
109110

110111
// Autolink preferences
111112
if (autolinkFileStartsBibtexProperty.getValue()) {
@@ -120,8 +121,7 @@ public void storeSettings() {
120121
filePreferences.confirmDeleteLinkedFile(confirmLinkedFileDeleteProperty.getValue());
121122
filePreferences.moveToTrash(moveToTrashProperty.getValue());
122123
filePreferences.copyLinkedFiles(copyLinkedFilesProperty.getValue());
123-
//filePreferences.CopyLinkedFilesDirectoryPath(copyLinkedFilesDirectoryPathProperty.getValue());
124-
124+
filePreferences.setLinkedFileDirectory(linkedFileDirectoryProperty.getValue());
125125
}
126126

127127
ValidationStatus mainFileDirValidationStatus() {
@@ -187,10 +187,6 @@ public StringProperty fileDirectoryPatternProperty() {
187187
return fileDirectoryPatternProperty;
188188
}
189189

190-
public StringProperty linkedFileDirectoryProperty() {
191-
return linkedFileDirectoryProperty;
192-
}
193-
194190
public BooleanProperty useMainFileDirectoryProperty() {
195191
return useMainFileDirectoryProperty;
196192
}
@@ -207,8 +203,8 @@ public BooleanProperty copyLinkedFilesProperty() {
207203
return this.copyLinkedFilesProperty;
208204
}
209205

210-
public StringProperty copyLinkedFilesDirectoryPathProperty() {
211-
return copyLinkedFilesDirectoryPathProperty;
206+
public StringProperty linkedFileDirectoryProperty() {
207+
return linkedFileDirectoryProperty;
212208
}
213209
}
214210

src/main/java/org/jabref/logic/FilePreferences.java

Lines changed: 16 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import javafx.beans.property.SimpleStringProperty;
1111
import javafx.beans.property.StringProperty;
1212

13-
import org.jabref.gui.util.uithreadaware.UiThreadObservableList;
1413
import org.jabref.model.strings.StringUtil;
1514

1615
/**
@@ -25,51 +24,47 @@ public class FilePreferences {
2524
private final BooleanProperty storeFilesRelativeToBibFile = new SimpleBooleanProperty();
2625
private final StringProperty fileNamePattern = new SimpleStringProperty();
2726
private final StringProperty fileDirectoryPattern = new SimpleStringProperty();
28-
private final StringProperty linkedFileDirectory = new SimpleStringProperty();
2927
private final BooleanProperty downloadLinkedFiles = new SimpleBooleanProperty();
3028
private final BooleanProperty fulltextIndexLinkedFiles = new SimpleBooleanProperty();
3129
private final ObjectProperty<Path> workingDirectory = new SimpleObjectProperty<>();
3230
private final BooleanProperty createBackup = new SimpleBooleanProperty();
3331
private final ObjectProperty<Path> backupDirectory = new SimpleObjectProperty<>();
3432
private final BooleanProperty confirmDeleteLinkedFile = new SimpleBooleanProperty();
3533
private final BooleanProperty moveToTrash = new SimpleBooleanProperty();
36-
private final BooleanProperty copyLinkedFiles = new SimpleBooleanProperty();
37-
private final StringProperty CopyLinkedFilesDirectoryPath = new SimpleStringProperty();
3834
private final BooleanProperty shouldKeepDownloadUrl = new SimpleBooleanProperty();
39-
private final StringProperty directoryPath = new SimpleStringProperty();
35+
private final BooleanProperty copyLinkedFiles = new SimpleBooleanProperty();
36+
private final StringProperty linkedFileDirectory = new SimpleStringProperty();
4037

4138
public FilePreferences(String userAndHost,
4239
String mainFileDirectory,
4340
boolean storeFilesRelativeToBibFile,
4441
String fileNamePattern,
4542
String fileDirectoryPattern,
46-
String linkedFileDirectory,
4743
boolean downloadLinkedFiles,
4844
boolean fulltextIndexLinkedFiles,
4945
Path workingDirectory,
5046
boolean createBackup,
5147
Path backupDirectory,
5248
boolean confirmDeleteLinkedFile,
5349
boolean moveToTrash,
50+
boolean shouldKeepDownloadUrl,
5451
boolean copyLinkedFiles,
55-
String CopyLinkedFilesDirectoryPath,
56-
boolean shouldKeepDownloadUrl) {
52+
String linkedFileDirectory) {
5753
this.userAndHost.setValue(userAndHost);
5854
this.mainFileDirectory.setValue(mainFileDirectory);
5955
this.storeFilesRelativeToBibFile.setValue(storeFilesRelativeToBibFile);
6056
this.fileNamePattern.setValue(fileNamePattern);
6157
this.fileDirectoryPattern.setValue(fileDirectoryPattern);
62-
this.linkedFileDirectory.setValue(linkedFileDirectory);
6358
this.downloadLinkedFiles.setValue(downloadLinkedFiles);
6459
this.fulltextIndexLinkedFiles.setValue(fulltextIndexLinkedFiles);
6560
this.workingDirectory.setValue(workingDirectory);
6661
this.createBackup.setValue(createBackup);
6762
this.backupDirectory.setValue(backupDirectory);
6863
this.confirmDeleteLinkedFile.setValue(confirmDeleteLinkedFile);
6964
this.moveToTrash.setValue(moveToTrash);
70-
this.copyLinkedFiles.setValue(copyLinkedFiles);
71-
this.CopyLinkedFilesDirectoryPath.setValue(CopyLinkedFilesDirectoryPath);
7265
this.shouldKeepDownloadUrl.setValue(shouldKeepDownloadUrl);
66+
this.copyLinkedFiles.setValue(copyLinkedFiles);
67+
this.linkedFileDirectory.setValue(linkedFileDirectory);
7368
}
7469

7570
public String getUserAndHost() {
@@ -124,26 +119,14 @@ public String getFileDirectoryPattern() {
124119
return fileDirectoryPattern.get();
125120
}
126121

127-
public String getLinkedFileDirectory() {
128-
return linkedFileDirectory.get();
129-
}
130-
131122
public StringProperty fileDirectoryPatternProperty() {
132123
return fileDirectoryPattern;
133124
}
134125

135-
public StringProperty linkedFileDirectoryProperty() {
136-
return linkedFileDirectory;
137-
}
138-
139126
public void setFileDirectoryPattern(String fileDirectoryPattern) {
140127
this.fileDirectoryPattern.set(fileDirectoryPattern);
141128
}
142129

143-
public void setLinkedFileDirectory(String linkedFileDirectory) {
144-
this.linkedFileDirectory.set(linkedFileDirectory);
145-
}
146-
147130
public boolean shouldDownloadLinkedFiles() {
148131
return downloadLinkedFiles.get();
149132
}
@@ -251,18 +234,16 @@ public BooleanProperty copyLinkedFilesProperty() {
251234
public void copyLinkedFiles(boolean copyLinkedFiles) {
252235
this.copyLinkedFiles.set(copyLinkedFiles);
253236
}
254-
public String CopyLinkedFilesDirectoryPath() {
255-
return CopyLinkedFilesDirectoryPath.get();
237+
238+
public String getLinkedFileDirectory() {
239+
return linkedFileDirectory.get();
256240
}
257-
//good
258-
public StringProperty copyLinkedFilesDirectoryPathProperty() {
259-
return CopyLinkedFilesDirectoryPath;
260-
}//good
261-
public String getCopyLinkedFilesDirectoryPath() {
262-
return CopyLinkedFilesDirectoryPath.get();
263-
}//good
264-
public void setLinkedFilesPath (String directoryPath) {
265-
this.directoryPath.set(directoryPath);
266-
}//good
267241

242+
public StringProperty linkedFileDirectoryProperty() {
243+
return linkedFileDirectory;
244+
}
245+
246+
public void setLinkedFileDirectory(String linkedFileDirectory) {
247+
this.linkedFileDirectory.set(linkedFileDirectory);
248+
}
268249
}

src/main/java/org/jabref/logic/preferences/JabRefCliPreferences.java

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ public class JabRefCliPreferences implements CliPreferences {
231231
public static final String CONFIRM_LINKED_FILE_DELETE = "confirmLinkedFileDelete";
232232
public static final String TRASH_INSTEAD_OF_DELETE = "trashInsteadOfDelete";
233233
public static final String COPY_LINKED_FILES = "copyLinkedFiles";
234-
public static final String COPY_LINKED_FILES_DIRECTORY_PATH = "copyLinkedFilesDirectoryPath";
234+
public static final String LINKED_FILEDIRPATTERN = "linkedFileDirPattern";
235235
public static final String WARN_BEFORE_OVERWRITING_KEY = "warnBeforeOverwritingKey";
236236
public static final String AVOID_OVERWRITING_KEY = "avoidOverwritingKey";
237237
public static final String AUTOLINK_EXACT_KEY_ONLY = "autolinkExactKeyOnly";
@@ -255,7 +255,6 @@ public class JabRefCliPreferences implements CliPreferences {
255255
public static final String CLEANUP_FIELD_FORMATTERS = "CleanUpFormatters";
256256
public static final String IMPORT_FILENAMEPATTERN = "importFileNamePattern";
257257
public static final String IMPORT_FILEDIRPATTERN = "importFileDirPattern";
258-
public static final String IMPORT_FILEDIRPATTERN1 = "importFileDirPattern1";
259258
public static final String NAME_FORMATTER_VALUE = "nameFormatterFormats";
260259
public static final String NAME_FORMATER_KEY = "nameFormatterNames";
261260
public static final String SHOW_RECOMMENDATIONS = "showRecommendations";
@@ -609,8 +608,9 @@ protected JabRefCliPreferences() {
609608
defaults.put(STORE_RELATIVE_TO_BIB, Boolean.TRUE);
610609

611610
defaults.put(AUTOLINK_EXACT_KEY_ONLY, Boolean.FALSE);
611+
612612
defaults.put(COPY_LINKED_FILES, Boolean.TRUE);
613-
//defaults.put(COPY_LINKED_FILES_DIRECTORY_PATH, Boolean.TRUE);
613+
defaults.put(LINKED_FILEDIRPATTERN, "");
614614

615615
defaults.put(AUTOLINK_FILES_ENABLED, Boolean.TRUE);
616616
defaults.put(LOCAL_AUTO_SAVE, Boolean.FALSE);
@@ -629,7 +629,6 @@ protected JabRefCliPreferences() {
629629
defaults.put(IMPORT_FILENAMEPATTERN, FilePreferences.DEFAULT_FILENAME_PATTERNS[1]);
630630
// Default empty String to be backwards compatible
631631
defaults.put(IMPORT_FILEDIRPATTERN, "");
632-
defaults.put(IMPORT_FILEDIRPATTERN1, "");
633632
// Download files by default
634633
defaults.put(DOWNLOAD_LINKED_FILES, true);
635634
// Create Fulltext-Index by default
@@ -1548,12 +1547,6 @@ public FieldPreferences getFieldPreferences() {
15481547
protected boolean moveToTrashSupported() {
15491548
return false;
15501549
}
1551-
protected boolean copyLinkedFilesSupported() {
1552-
return false;
1553-
}
1554-
protected String copyLinkedFilesDirectoryPathSupported(){
1555-
return "fuck this";
1556-
}
15571550

15581551
@Override
15591552
public FilePreferences getFilePreferences() {
@@ -1567,7 +1560,6 @@ public FilePreferences getFilePreferences() {
15671560
getBoolean(STORE_RELATIVE_TO_BIB),
15681561
get(IMPORT_FILENAMEPATTERN),
15691562
get(IMPORT_FILEDIRPATTERN),
1570-
get(IMPORT_FILEDIRPATTERN1),
15711563
getBoolean(DOWNLOAD_LINKED_FILES),
15721564
getBoolean(FULLTEXT_INDEX_LINKED_FILES),
15731565
Path.of(get(WORKING_DIRECTORY)),
@@ -1577,26 +1569,25 @@ public FilePreferences getFilePreferences() {
15771569
getBoolean(CONFIRM_LINKED_FILE_DELETE),
15781570
// We make use of the fallback, because we need AWT being initialized, which is not the case at the constructor JabRefPreferences()
15791571
getBoolean(TRASH_INSTEAD_OF_DELETE, moveToTrashSupported()),
1580-
getBoolean(COPY_LINKED_FILES, copyLinkedFilesSupported()),
1581-
get(COPY_LINKED_FILES_DIRECTORY_PATH, copyLinkedFilesDirectoryPathSupported()),
1582-
getBoolean(KEEP_DOWNLOAD_URL));
1572+
getBoolean(KEEP_DOWNLOAD_URL),
1573+
getBoolean(COPY_LINKED_FILES),
1574+
get(LINKED_FILEDIRPATTERN));
15831575

15841576
EasyBind.listen(getInternalPreferences().getUserAndHostProperty(), (obs, oldValue, newValue) -> filePreferences.getUserAndHostProperty().setValue(newValue));
15851577
EasyBind.listen(filePreferences.mainFileDirectoryProperty(), (obs, oldValue, newValue) -> put(MAIN_FILE_DIRECTORY, newValue));
15861578
EasyBind.listen(filePreferences.storeFilesRelativeToBibFileProperty(), (obs, oldValue, newValue) -> putBoolean(STORE_RELATIVE_TO_BIB, newValue));
15871579
EasyBind.listen(filePreferences.fileNamePatternProperty(), (obs, oldValue, newValue) -> put(IMPORT_FILENAMEPATTERN, newValue));
15881580
EasyBind.listen(filePreferences.fileDirectoryPatternProperty(), (obs, oldValue, newValue) -> put(IMPORT_FILEDIRPATTERN, newValue));
1589-
EasyBind.listen(filePreferences.linkedFileDirectoryProperty(), (obs, oldValue, newValue) -> put(IMPORT_FILEDIRPATTERN1, newValue));
15901581
EasyBind.listen(filePreferences.downloadLinkedFilesProperty(), (obs, oldValue, newValue) -> putBoolean(DOWNLOAD_LINKED_FILES, newValue));
15911582
EasyBind.listen(filePreferences.fulltextIndexLinkedFilesProperty(), (obs, oldValue, newValue) -> putBoolean(FULLTEXT_INDEX_LINKED_FILES, newValue));
15921583
EasyBind.listen(filePreferences.workingDirectoryProperty(), (obs, oldValue, newValue) -> put(WORKING_DIRECTORY, newValue.toString()));
15931584
EasyBind.listen(filePreferences.createBackupProperty(), (obs, oldValue, newValue) -> putBoolean(CREATE_BACKUP, newValue));
15941585
EasyBind.listen(filePreferences.backupDirectoryProperty(), (obs, oldValue, newValue) -> put(BACKUP_DIRECTORY, newValue.toString()));
15951586
EasyBind.listen(filePreferences.confirmDeleteLinkedFileProperty(), (obs, oldValue, newValue) -> putBoolean(CONFIRM_LINKED_FILE_DELETE, newValue));
15961587
EasyBind.listen(filePreferences.moveToTrashProperty(), (obs, oldValue, newValue) -> putBoolean(TRASH_INSTEAD_OF_DELETE, newValue));
1597-
EasyBind.listen(filePreferences.copyLinkedFilesProperty(), (obs, oldValue, newValue) -> putBoolean(COPY_LINKED_FILES, newValue));
1598-
EasyBind.listen(filePreferences.copyLinkedFilesDirectoryPathProperty(), (obs, oldValue, newValue) -> put(COPY_LINKED_FILES, newValue));
15991588
EasyBind.listen(filePreferences.shouldKeepDownloadUrlProperty(), (obs, oldValue, newValue) -> putBoolean(KEEP_DOWNLOAD_URL, newValue));
1589+
EasyBind.listen(filePreferences.copyLinkedFilesProperty(), (obs, oldValue, newValue) -> putBoolean(COPY_LINKED_FILES, newValue));
1590+
EasyBind.listen(filePreferences.linkedFileDirectoryProperty(), (obs, oldValue, newValue) -> put(LINKED_FILEDIRPATTERN, newValue));
16001591

16011592
return filePreferences;
16021593
}

src/main/resources/l10n/JabRef_en.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2889,3 +2889,6 @@ Open\ welcome\ tab=Open welcome tab
28892889
Current\ JabRef\ version\:\ %0=Current JabRef version: %0
28902890
Download\ development\ version=Download development version
28912891
CHANGELOG=CHANGELOG
2892+
2893+
Copy/move\ files\ when\ copying/moving\ entries=Copy/move files when copying/moving entries
2894+
Enter\ default\ database\ filepath=Enter default database filepath

0 commit comments

Comments
 (0)