Skip to content

Commit

Permalink
Mark old filelist as deprecated
Browse files Browse the repository at this point in the history
Pass Preferences Service instead of Preferences
  • Loading branch information
Siedlerchr committed Mar 19, 2018
1 parent 38e087e commit 298a28f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@
*
* For use when downloading files, this class also offers a progress bar and a "Downloading..."
* label that can be hidden when the download is complete.
* @deprecated Use {@link LinkedFileEditDialogView}
*/
@Deprecated
public class FileListEntryEditor {

private static final Pattern REMOTE_LINK_PATTERN = Pattern.compile("[a-z]+://.*");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.jabref.gui.DialogService;
import org.jabref.gui.StateManager;
import org.jabref.gui.externalfiletype.ExternalFileType;
import org.jabref.preferences.PreferencesService;

public class LinkedFileEditDialogController extends AbstractController<LinkedFilesEditDialogViewModel> {

Expand All @@ -23,9 +24,11 @@ public class LinkedFileEditDialogController extends AbstractController<LinkedFil
@Inject private StateManager stateManager;
@Inject private LinkedFilesWrapper linkedFilesWrapper;

@Inject private PreferencesService preferences;

@FXML
private void initialize() {
viewModel = new LinkedFilesEditDialogViewModel(linkedFilesWrapper.getLinkedFile(), stateManager.getActiveDatabase().get(), dialogService);
viewModel = new LinkedFilesEditDialogViewModel(linkedFilesWrapper.getLinkedFile(), stateManager.getActiveDatabase().get(), dialogService, preferences);
fileType.itemsProperty().bindBidirectional(viewModel.externalFileTypeProperty());
description.textProperty().bindBidirectional(viewModel.descriptionProperty());
link.textProperty().bindBidirectional(viewModel.linkProperty());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import javafx.beans.property.StringProperty;
import javafx.collections.FXCollections;

import org.jabref.Globals;
import org.jabref.gui.AbstractViewModel;
import org.jabref.gui.DialogService;
import org.jabref.gui.externalfiletype.ExternalFileType;
Expand All @@ -26,6 +25,7 @@
import org.jabref.model.entry.LinkedFile;
import org.jabref.model.util.FileHelper;
import org.jabref.preferences.JabRefPreferences;
import org.jabref.preferences.PreferencesService;

public class LinkedFilesEditDialogViewModel extends AbstractViewModel {

Expand All @@ -36,10 +36,12 @@ public class LinkedFilesEditDialogViewModel extends AbstractViewModel {
private final ObjectProperty<ExternalFileType> selectedExternalFileType = new SimpleObjectProperty<>();
private final BibDatabaseContext database;
private final DialogService dialogService;
private final PreferencesService preferences;

public LinkedFilesEditDialogViewModel(LinkedFile linkedFile, BibDatabaseContext database, DialogService dialogService) {
public LinkedFilesEditDialogViewModel(LinkedFile linkedFile, BibDatabaseContext database, DialogService dialogService, PreferencesService preferences2) {
this.database = database;
this.dialogService = dialogService;
this.preferences = preferences2;
externalfilesTypes.set(FXCollections.observableArrayList(ExternalFileTypes.getInstance().getExternalFileTypeSelection()));
setValues(linkedFile);
}
Expand All @@ -61,9 +63,9 @@ private void checkExtension() {
public void openBrowseDialog() {
String fileText = linkProperty().get();

Optional<Path> file = FileHelper.expandFilename(database, fileText, Globals.prefs.getFileDirectoryPreferences());
Optional<Path> file = FileHelper.expandFilename(database, fileText, preferences.getFileDirectoryPreferences());

Path workingDir = file.orElse(Paths.get(Globals.prefs.get(JabRefPreferences.WORKING_DIRECTORY)));
Path workingDir = file.orElse(Paths.get(preferences.get(JabRefPreferences.WORKING_DIRECTORY)));
String fileName = Paths.get(fileText).getFileName().toString();

FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder()
Expand All @@ -73,10 +75,10 @@ public void openBrowseDialog() {

dialogService.showFileOpenDialog(fileDialogConfiguration).ifPresent(path -> {
// Store the directory for next time:
Globals.prefs.put(JabRefPreferences.WORKING_DIRECTORY, path.toString());
preferences.put(JabRefPreferences.WORKING_DIRECTORY, path.toString());

// If the file is below the file directory, make the path relative:
List<Path> fileDirectories = database.getFileDirectoriesAsPaths(Globals.prefs.getFileDirectoryPreferences());
List<Path> fileDirectories = database.getFileDirectoriesAsPaths(preferences.getFileDirectoryPreferences());
path = FileUtil.shortenFileName(path, fileDirectories);

linkProperty().set(path.toString());
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/org/jabref/preferences/PreferencesService.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.jabref.gui.keyboard.KeyBindingRepository;
import org.jabref.logic.journals.JournalAbbreviationPreferences;
import org.jabref.model.metadata.FileDirectoryPreferences;

public interface PreferencesService {
JournalAbbreviationPreferences getJournalAbbreviationPreferences();
Expand All @@ -11,4 +12,10 @@ public interface PreferencesService {
KeyBindingRepository getKeyBindingRepository();

void storeJournalAbbreviationPreferences(JournalAbbreviationPreferences abbreviationsPreferences);

FileDirectoryPreferences getFileDirectoryPreferences();

String get(String key);

void put(String key, String value);
}

0 comments on commit 298a28f

Please sign in to comment.