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

Open specified folder in library properties #12223

Merged
merged 6 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
- We changed the defualt [unwanted charachters](https://docs.jabref.org/setup/citationkeypatterns#removing-unwanted-characters) in the citation key generator and allow a dash (`-`) and colon (`:`) being part of a citation key. [#12144](https://github.com/JabRef/jabref/pull/12144)
- The CitationKey column is now a default shown column for the entry table. [#10510](https://github.com/JabRef/jabref/issues/10510)
- We disabled the actions "Open Terminal here" and "Reveal in file explorer" for unsaved libraries. [#11920](https://github.com/JabRef/jabref/issues/11920)
- JabRef now opens the corresponding directory in the library properties when "Browse" is clicked. [#12223](https://github.com/JabRef/jabref/pull/12223)

### Fixed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Optional;

import javafx.beans.property.BooleanProperty;
import javafx.beans.property.ListProperty;
Expand All @@ -18,6 +20,7 @@
import org.jabref.gui.libraryproperties.PropertiesTabViewModel;
import org.jabref.gui.util.DirectoryDialogConfiguration;
import org.jabref.logic.l10n.Encodings;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.preferences.CliPreferences;
import org.jabref.logic.shared.DatabaseLocation;
import org.jabref.model.database.BibDatabaseContext;
Expand All @@ -40,16 +43,12 @@ public class GeneralPropertiesViewModel implements PropertiesTabViewModel {

private final BibDatabaseContext databaseContext;
private final MetaData metaData;
private final DirectoryDialogConfiguration directoryDialogConfiguration;

GeneralPropertiesViewModel(BibDatabaseContext databaseContext, DialogService dialogService, CliPreferences preferences) {
this.dialogService = dialogService;
this.preferences = preferences;
this.databaseContext = databaseContext;
this.metaData = databaseContext.getMetaData();

this.directoryDialogConfiguration = new DirectoryDialogConfiguration.Builder()
.withInitialDirectory(preferences.getFilePreferences().getWorkingDirectory()).build();
}

@Override
Expand Down Expand Up @@ -96,16 +95,22 @@ public void storeSettings() {
}

public void browseLibrarySpecificDir() {
DirectoryDialogConfiguration directoryDialogConfiguration = new DirectoryDialogConfiguration.Builder()
.withInitialDirectory(getBrowseDirectory(librarySpecificDirectoryProperty.getValue())).build();
dialogService.showDirectorySelectionDialog(directoryDialogConfiguration)
.ifPresent(dir -> librarySpecificDirectoryProperty.setValue(dir.toAbsolutePath().toString()));
}

public void browseUserDir() {
DirectoryDialogConfiguration directoryDialogConfiguration = new DirectoryDialogConfiguration.Builder()
.withInitialDirectory(getBrowseDirectory(userSpecificFileDirectoryProperty.getValue())).build();
dialogService.showDirectorySelectionDialog(directoryDialogConfiguration)
.ifPresent(dir -> userSpecificFileDirectoryProperty.setValue(dir.toAbsolutePath().toString()));
}

public void browseLatexDir() {
DirectoryDialogConfiguration directoryDialogConfiguration = new DirectoryDialogConfiguration.Builder()
.withInitialDirectory(getBrowseDirectory(laTexFileDirectoryProperty.getValue())).build();
dialogService.showDirectorySelectionDialog(directoryDialogConfiguration)
.ifPresent(dir -> laTexFileDirectoryProperty.setValue(dir.toAbsolutePath().toString()));
}
Expand Down Expand Up @@ -141,4 +146,19 @@ public StringProperty userSpecificFileDirectoryProperty() {
public StringProperty laTexFileDirectoryProperty() {
return this.laTexFileDirectoryProperty;
}

private Path getBrowseDirectory(String configuredDir) {
if (configuredDir.isEmpty()) {
return preferences.getFilePreferences().getWorkingDirectory();
}
Optional<Path> foundPath = this.databaseContext.getFileDirectories(preferences.getFilePreferences()).stream()
.filter(path -> path.toString().endsWith(configuredDir))
.filter(Files::exists).findFirst();

if (foundPath.isEmpty()) {
dialogService.notify(Localization.lang("Path %0 could not be resolved. Using working dir.", configuredDir));
return preferences.getFilePreferences().getWorkingDirectory();
}
return foundPath.get();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,10 @@ public List<Path> getFileDirectories(FilePreferences preferences) {
// Paths are a) ordered and b) should be contained only once in the result
LinkedHashSet<Path> fileDirs = new LinkedHashSet<>(3);

Optional<Path> userFileDirectory = metaData.getUserFileDirectory(preferences.getUserAndHost()).map(dir -> getFileDirectoryPath(dir));
Optional<Path> userFileDirectory = metaData.getUserFileDirectory(preferences.getUserAndHost()).map(this::getFileDirectoryPath);
userFileDirectory.ifPresent(fileDirs::add);

Optional<Path> librarySpecificFileDirectory = metaData.getLibrarySpecificFileDirectory().map(dir -> getFileDirectoryPath(dir));
Optional<Path> librarySpecificFileDirectory = metaData.getLibrarySpecificFileDirectory().map(this::getFileDirectoryPath);
librarySpecificFileDirectory.ifPresent(fileDirs::add);

// fileDirs.isEmpty() is true after these two if there are no directories set in the BIB file itself:
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1059,6 +1059,8 @@ Expected\ syntax\ for\ --fetch\='<name\ of\ fetcher>\:<query>'=Expected syntax f
Library-specific\ file\ directory=Library-specific file directory
User-specific\ file\ directory=User-specific file directory
LaTeX\ file\ directory=LaTeX file directory
Path\ %0\ could\ not\ be\ resolved.\ Using\ working\ dir.=Path %0 could not be resolved. Using working dir.


You\ must\ enter\ an\ integer\ value\ in\ the\ interval\ 1025-65535=You must enter an integer value in the interval 1025-65535
Autocomplete\ names\ in\ 'Firstname\ Lastname'\ format\ only=Autocomplete names in 'Firstname Lastname' format only
Expand Down