Skip to content

Commit

Permalink
Save unlinked local files dialog prefs (#11493)
Browse files Browse the repository at this point in the history
* Added saving of selected options for unlinked local files dialog (#11493)

* Update CHANGELOG.md

* Removed not needed checkbox from dialog, resolved comments

---------

Co-authored-by: Oliver Kopp <[email protected]>
  • Loading branch information
kataramarina and koppor authored Jul 16, 2024
1 parent 7de6d59 commit 410db8a
Show file tree
Hide file tree
Showing 8 changed files with 144 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv

- We added support for selecting and using CSL Styles in JabRef's OpenOffice/LibreOffice integration for inserting bibliographic and in-text citations into a document. [#2146](https://github.com/JabRef/jabref/issues/2146), [#8893](https://github.com/JabRef/jabref/issues/8893)
- Added minimal support for [biblatex data annotation](https://mirrors.ctan.org/macros/latex/contrib/biblatex/doc/biblatex.pdf#subsection.3.7) fields in .layout files. [#11505](https://github.com/JabRef/jabref/issues/11505)
- Added saving of selected options in the [Lookup -> Search for unlinked local files dialog](https://docs.jabref.org/collect/findunlinkedfiles#link-the-pdfs-to-your-bib-library). [#11439](https://github.com/JabRef/jabref/issues/11439)

### Changed

Expand Down
14 changes: 11 additions & 3 deletions src/main/java/org/jabref/gui/externalfiles/DateRange.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,19 @@ public enum DateRange {

private final String dateRange;

DateRange(String dateRange) {
DateRange(String dateRange) {
this.dateRange = dateRange;
}

public static DateRange parse(String name) {
try {
return DateRange.valueOf(name);
} catch (IllegalArgumentException e) {
return ALL_TIME;
}
}

public String getDateRange() {
return dateRange;
}
return dateRange;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ public enum ExternalFileSorter {
this.sorter = sorter;
}

public static ExternalFileSorter parse(String name) {
try {
return ExternalFileSorter.valueOf(name);
} catch (IllegalArgumentException e) {
return DEFAULT;
}
}

public String getSorter() {
return sorter;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,22 @@

public class FileExtensionViewModel {

private final String name;
private final String description;
private final List<String> extensions;
private final FilePreferences filePreferences;

FileExtensionViewModel(FileType fileType, FilePreferences filePreferences) {
this.name = fileType.getName();
this.description = Localization.lang("%0 file", fileType.getName());
this.extensions = fileType.getExtensionsWithAsteriskAndDot();
this.filePreferences = filePreferences;
}

public String getName() {
return this.name;
}

public String getDescription() {
return this.description + extensions.stream().collect(Collectors.joining(", ", " (", ")"));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.jabref.gui.externalfiles;

import java.nio.file.Path;
import java.util.Objects;

import javax.swing.undo.UndoManager;

Expand Down Expand Up @@ -46,6 +47,7 @@
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.util.FileUpdateMonitor;
import org.jabref.preferences.PreferencesService;
import org.jabref.preferences.UnlinkedFilesDialogPreferences;

import com.airhacks.afterburner.views.ViewLoader;
import com.tobiasdiez.easybind.EasyBind;
Expand Down Expand Up @@ -158,21 +160,21 @@ private void initDirectorySelection() {
.install(fileTypeCombo);
fileTypeCombo.setItems(viewModel.getFileFilters());
fileTypeCombo.valueProperty().bindBidirectional(viewModel.selectedExtensionProperty());
fileTypeCombo.getSelectionModel().selectFirst();

new ViewModelListCellFactory<DateRange>()
.withText(DateRange::getDateRange)
.install(fileDateCombo);
fileDateCombo.setItems(viewModel.getDateFilters());
fileDateCombo.valueProperty().bindBidirectional(viewModel.selectedDateProperty());
fileDateCombo.getSelectionModel().selectFirst();

new ViewModelListCellFactory<ExternalFileSorter>()
.withText(ExternalFileSorter::getSorter)
.install(fileSortCombo);
fileSortCombo.setItems(viewModel.getSorters());
fileSortCombo.valueProperty().bindBidirectional(viewModel.selectedSortProperty());
fileSortCombo.getSelectionModel().selectFirst();

directoryPathField.setText(bibDatabaseContext.getFirstExistingFileDir(preferencesService.getFilePreferences()).map(Path::toString).orElse(""));
loadSavedConfiguration();
}

private void initUnlinkedFilesList() {
Expand Down Expand Up @@ -227,6 +229,25 @@ private void initButtons() {
scanButton.disableProperty().bind(viewModel.taskActiveProperty().or(viewModel.directoryPathValidationStatus().validProperty().not()));
}

private void loadSavedConfiguration() {
UnlinkedFilesDialogPreferences unlinkedFilesDialogPreferences = preferencesService.getUnlinkedFilesDialogPreferences();

FileExtensionViewModel selectedExtension = fileTypeCombo.getItems()
.stream()
.filter(item -> Objects.equals(item.getName(), unlinkedFilesDialogPreferences.getUnlinkedFilesSelectedExtension()))
.findFirst()
.orElseThrow();
fileTypeCombo.getSelectionModel().select(selectedExtension);
fileDateCombo.getSelectionModel().select(unlinkedFilesDialogPreferences.getUnlinkedFilesSelectedDateRange());
fileSortCombo.getSelectionModel().select(unlinkedFilesDialogPreferences.getUnlinkedFilesSelectedSort());
}

public void saveConfiguration() {
preferencesService.getUnlinkedFilesDialogPreferences().setUnlinkedFilesSelectedExtension(fileTypeCombo.getValue().getName());
preferencesService.getUnlinkedFilesDialogPreferences().setUnlinkedFilesSelectedDateRange(fileDateCombo.getValue());
preferencesService.getUnlinkedFilesDialogPreferences().setUnlinkedFilesSelectedSort(fileSortCombo.getValue());
}

@FXML
void browseFileDirectory() {
viewModel.browseFileDirectory();
Expand All @@ -235,6 +256,7 @@ void browseFileDirectory() {
@FXML
void scanFiles() {
viewModel.startSearch();
saveConfiguration();
}

@FXML
Expand Down
32 changes: 32 additions & 0 deletions src/main/java/org/jabref/preferences/JabRefPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
import org.jabref.gui.autocompleter.AutoCompletePreferences;
import org.jabref.gui.duplicationFinder.DuplicateResolverDialog;
import org.jabref.gui.entryeditor.EntryEditorPreferences;
import org.jabref.gui.externalfiles.DateRange;
import org.jabref.gui.externalfiles.ExternalFileSorter;
import org.jabref.gui.externalfiletype.ExternalFileType;
import org.jabref.gui.externalfiletype.ExternalFileTypes;
import org.jabref.gui.groups.GroupViewMode;
Expand Down Expand Up @@ -103,6 +105,7 @@
import org.jabref.logic.shared.prefs.SharedDatabasePreferences;
import org.jabref.logic.shared.security.Password;
import org.jabref.logic.util.OS;
import org.jabref.logic.util.StandardFileType;
import org.jabref.logic.util.Version;
import org.jabref.logic.util.io.AutoLinkPreferences;
import org.jabref.logic.util.io.FileHistory;
Expand Down Expand Up @@ -347,6 +350,11 @@ public class JabRefPreferences implements PreferencesService {
public static final String VALIDATE_IN_ENTRY_EDITOR = "validateInEntryEditor";
public static final String SHOW_SCITE_TAB = "showSciteTab";

// Lookup -> Unlinked Files Search dialog preferences
public static final String UNLINKED_FILES_SELECTED_EXTENSION = "unlinkedFilesSelectedExtension";
public static final String UNLINKED_FILES_SELECTED_DATE_RANGE = "unlinkedFilesSelectedDateRange";
public static final String UNLINKED_FILES_SELECTED_SORT = "unlinkedFilesSelectedSort";

/**
* The OpenOffice/LibreOffice connection preferences are: OO_PATH main directory for OO/LO installation, used to detect location on Win/macOS when using manual connect OO_EXECUTABLE_PATH path to soffice-file OO_JARS_PATH directory that contains juh.jar, jurt.jar, ridl.jar, unoil.jar OO_SYNC_WHEN_CITING true if the reference list is updated when adding a new citation OO_SHOW_PANEL true if the OO panel is shown on startup OO_USE_ALL_OPEN_DATABASES true if all databases should be used when citing OO_BIBLIOGRAPHY_STYLE_FILE path to the used style file OO_EXTERNAL_STYLE_FILES list with paths to external style files STYLES_*_* size and position of "Select style" dialog
*/
Expand Down Expand Up @@ -505,6 +513,7 @@ public class JabRefPreferences implements PreferencesService {
private JournalAbbreviationPreferences journalAbbreviationPreferences;
private FieldPreferences fieldPreferences;
private MergeDialogPreferences mergeDialogPreferences;
private UnlinkedFilesDialogPreferences unlinkedFilesDialogPreferences;

private KeyBindingRepository keyBindingRepository;

Expand Down Expand Up @@ -693,6 +702,10 @@ private JabRefPreferences() {
defaults.put(PROTECTED_TERMS_ENABLED_EXTERNAL, "");
defaults.put(PROTECTED_TERMS_DISABLED_EXTERNAL, "");

defaults.put(UNLINKED_FILES_SELECTED_EXTENSION, StandardFileType.ANY_FILE.name());
defaults.put(UNLINKED_FILES_SELECTED_DATE_RANGE, DateRange.ALL_TIME.name());
defaults.put(UNLINKED_FILES_SELECTED_SORT, ExternalFileSorter.DEFAULT.name());

// OpenOffice/LibreOffice
if (OS.WINDOWS) {
defaults.put(OO_EXECUTABLE_PATH, OpenOfficePreferences.DEFAULT_WIN_EXEC_PATH);
Expand Down Expand Up @@ -2651,6 +2664,25 @@ public MergeDialogPreferences getMergeDialogPreferences() {
return mergeDialogPreferences;
}

@Override
public UnlinkedFilesDialogPreferences getUnlinkedFilesDialogPreferences() {
if (unlinkedFilesDialogPreferences != null) {
return unlinkedFilesDialogPreferences;
}

unlinkedFilesDialogPreferences = new UnlinkedFilesDialogPreferences(
get(UNLINKED_FILES_SELECTED_EXTENSION),
DateRange.parse(get(UNLINKED_FILES_SELECTED_DATE_RANGE)),
ExternalFileSorter.parse(get(UNLINKED_FILES_SELECTED_SORT))
);

EasyBind.listen(unlinkedFilesDialogPreferences.unlinkedFilesSelectedExtensionProperty(), (obs, oldValue, newValue) -> put(UNLINKED_FILES_SELECTED_EXTENSION, newValue));
EasyBind.listen(unlinkedFilesDialogPreferences.unlinkedFilesSelectedDateRangeProperty(), (obs, oldValue, newValue) -> put(UNLINKED_FILES_SELECTED_DATE_RANGE, newValue.name()));
EasyBind.listen(unlinkedFilesDialogPreferences.unlinkedFilesSelectedSortProperty(), (obs, oldValue, newValue) -> put(UNLINKED_FILES_SELECTED_SORT, newValue.name()));

return unlinkedFilesDialogPreferences;
}

//*************************************************************************************************************
// Misc preferences
//*************************************************************************************************************
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/jabref/preferences/PreferencesService.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,6 @@ public interface PreferencesService {
ProtectedTermsPreferences getProtectedTermsPreferences();

MergeDialogPreferences getMergeDialogPreferences();

UnlinkedFilesDialogPreferences getUnlinkedFilesDialogPreferences();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package org.jabref.preferences;

import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;

import org.jabref.gui.externalfiles.DateRange;
import org.jabref.gui.externalfiles.ExternalFileSorter;

public class UnlinkedFilesDialogPreferences {
private final StringProperty unlinkedFilesSelectedExtension;
private final ObjectProperty<DateRange> unlinkedFilesSelectedDateRange;
private final ObjectProperty<ExternalFileSorter> unlinkedFilesSelectedSort;

public UnlinkedFilesDialogPreferences(String unlinkedFilesSelectedExtension,
DateRange unlinkedFilesSelectedDateRange,
ExternalFileSorter unlinkedFilesSelectedSort) {
this.unlinkedFilesSelectedExtension = new SimpleStringProperty(unlinkedFilesSelectedExtension);
this.unlinkedFilesSelectedDateRange = new SimpleObjectProperty<>(unlinkedFilesSelectedDateRange);
this.unlinkedFilesSelectedSort = new SimpleObjectProperty<>(unlinkedFilesSelectedSort);
}

public String getUnlinkedFilesSelectedExtension() {
return unlinkedFilesSelectedExtension.get();
}

public StringProperty unlinkedFilesSelectedExtensionProperty() {
return unlinkedFilesSelectedExtension;
}

public void setUnlinkedFilesSelectedExtension(String unlinkedFilesSelectedExtension) {
this.unlinkedFilesSelectedExtension.set(unlinkedFilesSelectedExtension);
}

public DateRange getUnlinkedFilesSelectedDateRange() {
return unlinkedFilesSelectedDateRange.get();
}

public ObjectProperty<DateRange> unlinkedFilesSelectedDateRangeProperty() {
return unlinkedFilesSelectedDateRange;
}

public void setUnlinkedFilesSelectedDateRange(DateRange unlinkedFilesSelectedDateRange) {
this.unlinkedFilesSelectedDateRange.set(unlinkedFilesSelectedDateRange);
}

public ExternalFileSorter getUnlinkedFilesSelectedSort() {
return unlinkedFilesSelectedSort.get();
}

public ObjectProperty<ExternalFileSorter> unlinkedFilesSelectedSortProperty() {
return unlinkedFilesSelectedSort;
}

public void setUnlinkedFilesSelectedSort(ExternalFileSorter unlinkedFilesSelectedSort) {
this.unlinkedFilesSelectedSort.set(unlinkedFilesSelectedSort);
}
}

0 comments on commit 410db8a

Please sign in to comment.