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

Refactor file preferences #6779

Merged
merged 17 commits into from
Sep 1, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Refactored FilePreferences to immutable class
  • Loading branch information
calixtus committed Aug 23, 2020
commit 4147133a8049a66141f2194623def131a70e03a0
19 changes: 13 additions & 6 deletions src/main/java/org/jabref/gui/importer/ImportEntriesViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,14 @@ public class ImportEntriesViewModel extends AbstractViewModel {
* @param databaseContext the database to import into
* @param task the task executed for parsing the selected files(s).
*/
public ImportEntriesViewModel(BackgroundTask<ParserResult> task, TaskExecutor taskExecutor, BibDatabaseContext databaseContext, DialogService dialogService, UndoManager undoManager, PreferencesService preferences, StateManager stateManager, FileUpdateMonitor fileUpdateMonitor) {
public ImportEntriesViewModel(BackgroundTask<ParserResult> task,
TaskExecutor taskExecutor,
BibDatabaseContext databaseContext,
DialogService dialogService,
UndoManager undoManager,
PreferencesService preferences,
StateManager stateManager,
FileUpdateMonitor fileUpdateMonitor) {
this.taskExecutor = taskExecutor;
this.databaseContext = databaseContext;
this.dialogService = dialogService;
Expand Down Expand Up @@ -94,9 +101,9 @@ public ObservableList<BibEntry> getEntries() {
}

public boolean hasDuplicate(BibEntry entry) {
return findInternalDuplicate(entry).isPresent()
||
new DuplicateCheck(Globals.entryTypesManager).containsDuplicate(databaseContext.getDatabase(), entry, databaseContext.getMode()).isPresent();
return findInternalDuplicate(entry).isPresent() ||
new DuplicateCheck(Globals.entryTypesManager)
.containsDuplicate(databaseContext.getDatabase(), entry, databaseContext.getMode()).isPresent();
}

/**
Expand Down Expand Up @@ -132,8 +139,8 @@ public void importEntries(List<BibEntry> entriesToImport, boolean shouldDownload
}

// Remember the selection in the dialog
FilePreferences filePreferences = preferences.getFilePreferences();
filePreferences.setShouldDownloadLinkedFiles(shouldDownloadFiles);
FilePreferences filePreferences = preferences.getFilePreferences()
.withShouldDownloadLinkedFiles(shouldDownloadFiles);
preferences.storeFilePreferences(filePreferences);

if (shouldDownloadFiles) {
Expand Down
12 changes: 9 additions & 3 deletions src/main/java/org/jabref/model/metadata/FilePreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class FilePreferences {
private final boolean bibLocationAsPrimary;
private final String fileNamePattern;
private final String fileDirPattern;
private boolean shouldDownloadLinkedFiles;
private final boolean shouldDownloadLinkedFiles;

public FilePreferences(String user,
String mainFileDirectory,
Expand Down Expand Up @@ -56,7 +56,13 @@ public boolean shouldDownloadLinkedFiles() {
return shouldDownloadLinkedFiles;
}

public void setShouldDownloadLinkedFiles(boolean shouldDownloadLinkedFiles) {
this.shouldDownloadLinkedFiles = shouldDownloadLinkedFiles;
public FilePreferences withShouldDownloadLinkedFiles(boolean newShouldDownloadLinkedFiles) {
return new FilePreferences(
this.user,
this.mainFileDirectory,
this.bibLocationAsPrimary,
this.fileNamePattern,
this.fileDirPattern,
newShouldDownloadLinkedFiles);
}
}