From 410db8aac49bca95f842630cb7694a649a978000 Mon Sep 17 00:00:00 2001 From: kataramarina <35892754+kataramarina@users.noreply.github.com> Date: Tue, 16 Jul 2024 15:28:20 +0300 Subject: [PATCH] Save unlinked local files dialog prefs (#11493) * 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 --- CHANGELOG.md | 1 + .../jabref/gui/externalfiles/DateRange.java | 14 ++++- .../gui/externalfiles/ExternalFileSorter.java | 8 +++ .../externalfiles/FileExtensionViewModel.java | 6 ++ .../UnlinkedFilesDialogView.java | 28 ++++++++- .../jabref/preferences/JabRefPreferences.java | 32 ++++++++++ .../preferences/PreferencesService.java | 2 + .../UnlinkedFilesDialogPreferences.java | 59 +++++++++++++++++++ 8 files changed, 144 insertions(+), 6 deletions(-) create mode 100644 src/main/java/org/jabref/preferences/UnlinkedFilesDialogPreferences.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 972ca5c0142..8c86afb7516 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/main/java/org/jabref/gui/externalfiles/DateRange.java b/src/main/java/org/jabref/gui/externalfiles/DateRange.java index b73f700481c..b8a6e221ec8 100644 --- a/src/main/java/org/jabref/gui/externalfiles/DateRange.java +++ b/src/main/java/org/jabref/gui/externalfiles/DateRange.java @@ -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; + } } diff --git a/src/main/java/org/jabref/gui/externalfiles/ExternalFileSorter.java b/src/main/java/org/jabref/gui/externalfiles/ExternalFileSorter.java index e425c642750..ddb23ac221e 100644 --- a/src/main/java/org/jabref/gui/externalfiles/ExternalFileSorter.java +++ b/src/main/java/org/jabref/gui/externalfiles/ExternalFileSorter.java @@ -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; } diff --git a/src/main/java/org/jabref/gui/externalfiles/FileExtensionViewModel.java b/src/main/java/org/jabref/gui/externalfiles/FileExtensionViewModel.java index 5cee5f7bc05..ece8217dfca 100644 --- a/src/main/java/org/jabref/gui/externalfiles/FileExtensionViewModel.java +++ b/src/main/java/org/jabref/gui/externalfiles/FileExtensionViewModel.java @@ -15,16 +15,22 @@ public class FileExtensionViewModel { + private final String name; private final String description; private final List 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(", ", " (", ")")); } diff --git a/src/main/java/org/jabref/gui/externalfiles/UnlinkedFilesDialogView.java b/src/main/java/org/jabref/gui/externalfiles/UnlinkedFilesDialogView.java index 3a7213feee6..1f15e3b78ac 100644 --- a/src/main/java/org/jabref/gui/externalfiles/UnlinkedFilesDialogView.java +++ b/src/main/java/org/jabref/gui/externalfiles/UnlinkedFilesDialogView.java @@ -1,6 +1,7 @@ package org.jabref.gui.externalfiles; import java.nio.file.Path; +import java.util.Objects; import javax.swing.undo.UndoManager; @@ -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; @@ -158,21 +160,21 @@ private void initDirectorySelection() { .install(fileTypeCombo); fileTypeCombo.setItems(viewModel.getFileFilters()); fileTypeCombo.valueProperty().bindBidirectional(viewModel.selectedExtensionProperty()); - fileTypeCombo.getSelectionModel().selectFirst(); + new ViewModelListCellFactory() .withText(DateRange::getDateRange) .install(fileDateCombo); fileDateCombo.setItems(viewModel.getDateFilters()); fileDateCombo.valueProperty().bindBidirectional(viewModel.selectedDateProperty()); - fileDateCombo.getSelectionModel().selectFirst(); + new ViewModelListCellFactory() .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() { @@ -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(); @@ -235,6 +256,7 @@ void browseFileDirectory() { @FXML void scanFiles() { viewModel.startSearch(); + saveConfiguration(); } @FXML diff --git a/src/main/java/org/jabref/preferences/JabRefPreferences.java b/src/main/java/org/jabref/preferences/JabRefPreferences.java index 94815af4997..3f88dd08814 100644 --- a/src/main/java/org/jabref/preferences/JabRefPreferences.java +++ b/src/main/java/org/jabref/preferences/JabRefPreferences.java @@ -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; @@ -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; @@ -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 */ @@ -505,6 +513,7 @@ public class JabRefPreferences implements PreferencesService { private JournalAbbreviationPreferences journalAbbreviationPreferences; private FieldPreferences fieldPreferences; private MergeDialogPreferences mergeDialogPreferences; + private UnlinkedFilesDialogPreferences unlinkedFilesDialogPreferences; private KeyBindingRepository keyBindingRepository; @@ -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); @@ -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 //************************************************************************************************************* diff --git a/src/main/java/org/jabref/preferences/PreferencesService.java b/src/main/java/org/jabref/preferences/PreferencesService.java index 186f78b519c..2692146ac95 100644 --- a/src/main/java/org/jabref/preferences/PreferencesService.java +++ b/src/main/java/org/jabref/preferences/PreferencesService.java @@ -147,4 +147,6 @@ public interface PreferencesService { ProtectedTermsPreferences getProtectedTermsPreferences(); MergeDialogPreferences getMergeDialogPreferences(); + + UnlinkedFilesDialogPreferences getUnlinkedFilesDialogPreferences(); } diff --git a/src/main/java/org/jabref/preferences/UnlinkedFilesDialogPreferences.java b/src/main/java/org/jabref/preferences/UnlinkedFilesDialogPreferences.java new file mode 100644 index 00000000000..aad30dceeff --- /dev/null +++ b/src/main/java/org/jabref/preferences/UnlinkedFilesDialogPreferences.java @@ -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 unlinkedFilesSelectedDateRange; + private final ObjectProperty 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 unlinkedFilesSelectedDateRangeProperty() { + return unlinkedFilesSelectedDateRange; + } + + public void setUnlinkedFilesSelectedDateRange(DateRange unlinkedFilesSelectedDateRange) { + this.unlinkedFilesSelectedDateRange.set(unlinkedFilesSelectedDateRange); + } + + public ExternalFileSorter getUnlinkedFilesSelectedSort() { + return unlinkedFilesSelectedSort.get(); + } + + public ObjectProperty unlinkedFilesSelectedSortProperty() { + return unlinkedFilesSelectedSort; + } + + public void setUnlinkedFilesSelectedSort(ExternalFileSorter unlinkedFilesSelectedSort) { + this.unlinkedFilesSelectedSort.set(unlinkedFilesSelectedSort); + } +}