Skip to content

Commit

Permalink
WIP: Rename General File Directory to Library-Specific File Directory (
Browse files Browse the repository at this point in the history
…#12037)

* Change enum & localisation preferences from "General File Directory" to "Library File Directory"

* change 'generalFileDirectory' to 'libraryFileDirectory' in codebase

* change 'generalFileDirectory' to 'libraryFileDirectory' in test code

* change 'General file directory' to 'Library file directory' in places that were previously missed.

* amendment to prior commits: should show up in GUI as "Library-specific File Directory". Have followed convention for "User-Specific File Directory" where this is referred to outside of UI prompts as "Library File Directory"

* update CHANGELOG.md to document activity in this branch.

* Additional/missed locations: change 'General File Directory' to 'Library-specific File Directory'

* Per Koppor's instructions: unify front/back end to "Library-specific File Directory"

* update code comments to reflect change from library file directory to library-specific file directory

* updated en localisation per unit tests:
1. removed unused general file directory key
2. made Library-specific file directory key all-lowercase per unit test requirements.

---------

Co-authored-by: rl712 <[email protected]>
  • Loading branch information
tomeg09 and rl712 authored Oct 24, 2024
1 parent a94dd11 commit 404394f
Show file tree
Hide file tree
Showing 19 changed files with 52 additions and 51 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
- We changed instances of 'Search Selected' to 'Search Pre-configured' in Web Search Preferences UI. [#11871](https://github.com/JabRef/jabref/pull/11871)
- We added a new CSS style class `main-table` for the main table. [#11881](https://github.com/JabRef/jabref/pull/11881)
- When renaming a file, the old extension is now used if there is none provided in the new name. [#11903](https://github.com/JabRef/jabref/issues/11903)
- We changed the name of the library-based file directory from 'General File Directory' to 'Library-specific File Directory' per issue [#571](https://github.com/koppor/jabref/issues/571)

### Fixed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ private String getDifferenceString(MetaDataDiff.DifferenceType changeType) {
Localization.lang("Save actions");
case MODE ->
Localization.lang("Library mode");
case GENERAL_FILE_DIRECTORY ->
Localization.lang("General file directory");
case LIBRARY_SPECIFIC_FILE_DIRECTORY ->
Localization.lang("Library-specific file directory");
case CONTENT_SELECTOR ->
Localization.lang("Content selectors");
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@

<Label styleClass="sectionHeader" text="%Override default file directories"
GridPane.columnSpan="3" GridPane.rowIndex="0"/>
<Label text="%General file directory"
<Label text="%Library-specific file directory"
GridPane.columnIndex="0" GridPane.rowIndex="1"/>
<TextField fx:id="generalFileDirectory"
<TextField fx:id="librarySpecificFileDirectory"
GridPane.columnIndex="1" GridPane.rowIndex="1"/>
<Button onAction="#browseGeneralFileDirectory"
<Button onAction="#browseLibrarySpecificFileDirectory"
styleClass="icon-button,narrow" prefHeight="20.0" prefWidth="20.0"
GridPane.columnIndex="2" GridPane.rowIndex="1">
<graphic>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
public class GeneralPropertiesView extends AbstractPropertiesTabView<GeneralPropertiesViewModel> {
@FXML private ComboBox<Charset> encoding;
@FXML private ComboBox<BibDatabaseMode> databaseMode;
@FXML private TextField generalFileDirectory;
@FXML private TextField librarySpecificFileDirectory;
@FXML private TextField userSpecificFileDirectory;
@FXML private TextField laTexFileDirectory;

Expand Down Expand Up @@ -54,14 +54,14 @@ public void initialize() {
databaseMode.itemsProperty().bind(viewModel.databaseModesProperty());
databaseMode.valueProperty().bindBidirectional(viewModel.selectedDatabaseModeProperty());

generalFileDirectory.textProperty().bindBidirectional(viewModel.generalFileDirectoryPropertyProperty());
librarySpecificFileDirectory.textProperty().bindBidirectional(viewModel.librarySpecificDirectoryPropertyProperty());
userSpecificFileDirectory.textProperty().bindBidirectional(viewModel.userSpecificFileDirectoryProperty());
laTexFileDirectory.textProperty().bindBidirectional(viewModel.laTexFileDirectoryProperty());
}

@FXML
public void browseGeneralFileDirectory() {
viewModel.browseGeneralDir();
public void browseLibrarySpecificFileDirectory() {
viewModel.browseLibrarySpecificDir();
}

@FXML
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class GeneralPropertiesViewModel implements PropertiesTabViewModel {
private final ObjectProperty<Charset> selectedEncodingProperty = new SimpleObjectProperty<>(Encodings.getCharsets().getFirst());
private final ListProperty<BibDatabaseMode> databaseModesProperty = new SimpleListProperty<>(FXCollections.observableArrayList(BibDatabaseMode.values()));
private final SimpleObjectProperty<BibDatabaseMode> selectedDatabaseModeProperty = new SimpleObjectProperty<>(BibDatabaseMode.BIBLATEX);
private final StringProperty generalFileDirectoryProperty = new SimpleStringProperty("");
private final StringProperty librarySpecificDirectoryProperty = new SimpleStringProperty("");
private final StringProperty userSpecificFileDirectoryProperty = new SimpleStringProperty("");
private final StringProperty laTexFileDirectoryProperty = new SimpleStringProperty("");

Expand Down Expand Up @@ -59,7 +59,7 @@ public void setValues() {

selectedEncodingProperty.setValue(metaData.getEncoding().orElse(StandardCharsets.UTF_8));
selectedDatabaseModeProperty.setValue(metaData.getMode().orElse(BibDatabaseMode.BIBLATEX));
generalFileDirectoryProperty.setValue(metaData.getDefaultFileDirectory().orElse("").trim());
librarySpecificDirectoryProperty.setValue(metaData.getLibrarySpecificFileDirectory().orElse("").trim());
userSpecificFileDirectoryProperty.setValue(metaData.getUserFileDirectory(preferences.getFilePreferences().getUserAndHost()).orElse("").trim());
laTexFileDirectoryProperty.setValue(metaData.getLatexFileDirectory(preferences.getFilePreferences().getUserAndHost()).map(Path::toString).orElse(""));
}
Expand All @@ -71,11 +71,11 @@ public void storeSettings() {
newMetaData.setEncoding(selectedEncodingProperty.getValue());
newMetaData.setMode(selectedDatabaseModeProperty.getValue());

String generalFileDirectory = generalFileDirectoryProperty.getValue().trim();
if (generalFileDirectory.isEmpty()) {
newMetaData.clearDefaultFileDirectory();
String librarySpecificFileDirectory = librarySpecificDirectoryProperty.getValue().trim();
if (librarySpecificFileDirectory.isEmpty()) {
newMetaData.clearLibrarySpecificFileDirectory();
} else {
newMetaData.setDefaultFileDirectory(generalFileDirectory);
newMetaData.setLibrarySpecificFileDirectory(librarySpecificFileDirectory);
}

String userSpecificFileDirectory = userSpecificFileDirectoryProperty.getValue();
Expand All @@ -95,9 +95,9 @@ public void storeSettings() {
databaseContext.setMetaData(newMetaData);
}

public void browseGeneralDir() {
public void browseLibrarySpecificDir() {
dialogService.showDirectorySelectionDialog(directoryDialogConfiguration)
.ifPresent(dir -> generalFileDirectoryProperty.setValue(dir.toAbsolutePath().toString()));
.ifPresent(dir -> librarySpecificDirectoryProperty.setValue(dir.toAbsolutePath().toString()));
}

public void browseUserDir() {
Expand Down Expand Up @@ -130,8 +130,8 @@ public SimpleObjectProperty<BibDatabaseMode> selectedDatabaseModeProperty() {
return selectedDatabaseModeProperty;
}

public StringProperty generalFileDirectoryPropertyProperty() {
return this.generalFileDirectoryProperty;
public StringProperty librarySpecificDirectoryPropertyProperty() {
return this.librarySpecificDirectoryProperty;
}

public StringProperty userSpecificFileDirectoryProperty() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public enum DifferenceType {
CONTENT_SELECTOR,
DEFAULT_KEY_PATTERN,
ENCODING,
GENERAL_FILE_DIRECTORY,
LIBRARY_SPECIFIC_FILE_DIRECTORY,
GROUPS,
KEY_PATTERNS,
LATEX_FILE_DIRECTORY,
Expand Down Expand Up @@ -114,7 +114,7 @@ public List<Difference> getDifferences(GlobalCitationKeyPatterns globalCitationK
addToListIfDiff(changes, DifferenceType.DEFAULT_KEY_PATTERN, originalMetaData.getDefaultCiteKeyPattern(), newMetaData.getDefaultCiteKeyPattern());
addToListIfDiff(changes, DifferenceType.SAVE_ACTIONS, originalMetaData.getSaveActions(), newMetaData.getSaveActions());
addToListIfDiff(changes, DifferenceType.MODE, originalMetaData.getMode(), newMetaData.getMode());
addToListIfDiff(changes, DifferenceType.GENERAL_FILE_DIRECTORY, originalMetaData.getDefaultFileDirectory(), newMetaData.getDefaultFileDirectory());
addToListIfDiff(changes, DifferenceType.LIBRARY_SPECIFIC_FILE_DIRECTORY, originalMetaData.getLibrarySpecificFileDirectory(), newMetaData.getLibrarySpecificFileDirectory());
addToListIfDiff(changes, DifferenceType.CONTENT_SELECTOR, originalMetaData.getContentSelectors(), newMetaData.getContentSelectors());
return changes;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static Map<String, String> getSerializedStringMap(MetaData metaData,
stringyMetaData.putAll(serializeCiteKeyPatterns(metaData, globalCiteKeyPatterns));
metaData.getMode().ifPresent(
mode -> stringyMetaData.put(MetaData.DATABASE_TYPE, Collections.singletonList(mode.getAsString())));
metaData.getDefaultFileDirectory().ifPresent(
metaData.getLibrarySpecificFileDirectory().ifPresent(
path -> stringyMetaData.put(MetaData.FILE_DIRECTORY, Collections.singletonList(path.trim())));
metaData.getUserFileDirectories().forEach((user, path) -> stringyMetaData
.put(MetaData.FILE_DIRECTORY + '-' + user, Collections.singletonList(path.trim())));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public MetaData parse(MetaData metaData, Map<String, String> data, Character key
// edge case, it might be one special field e.g. article from biblatex-apa, but we can't distinguish this from any other field and rather prefer to handle it as UnknownField
metaData.addContentSelector(ContentSelectors.parse(FieldFactory.parseField(entry.getKey().substring(MetaData.SELECTOR_META_PREFIX.length())), StringUtil.unquote(entry.getValue(), MetaData.ESCAPE_CHARACTER)));
} else if (entry.getKey().equals(MetaData.FILE_DIRECTORY)) {
metaData.setDefaultFileDirectory(parseDirectory(entry.getValue()));
metaData.setLibrarySpecificFileDirectory(parseDirectory(entry.getValue()));
} else if (entry.getKey().startsWith(MetaData.FILE_DIRECTORY + '-')) {
// The user name starts directly after FILE_DIRECTORY + '-'
String user = entry.getKey().substring(MetaData.FILE_DIRECTORY.length() + 1);
Expand Down Expand Up @@ -170,7 +170,7 @@ public MetaData parse(MetaData metaData, Map<String, String> data, Character key
* We do not use unescaped value (created by @link{#getAsList(java.lang.String)}),
* because this leads to difficulties with UNC names.
*
* No normalization is done - the general file directory could be passed as Mac OS X path, but the user could sit on Windows.
* No normalization is done - the library-specific file directory could be passed as Mac OS X path, but the user could sit on Windows.
*
* @param value the raw value (as stored in the .bib file)
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public boolean isStudy() {
* <ol>
* <li>next to the .bib file.</li>
* <li>the preferences can specify a default one.</li>
* <li>the database's metadata can specify a general directory.</li>
* <li>the database's metadata can specify a library-specific directory.</li>
* <li>the database's metadata can specify a user-specific directory.</li>
* </ol>
* <p>
Expand All @@ -166,12 +166,12 @@ public List<Path> getFileDirectories(FilePreferences preferences) {
Optional<Path> userFileDirectory = metaData.getUserFileDirectory(preferences.getUserAndHost()).map(dir -> getFileDirectoryPath(dir));
userFileDirectory.ifPresent(fileDirs::add);

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

// fileDirs.isEmpty() is true after these two if there are no directories set in the BIB file itself:
// 1) no user-specific file directory set (in the metadata of the bib file) and
// 2) no general file directory is set (in the metadata of the bib file)
// 2) no library-specific file directory is set (in the metadata of the bib file)

// BIB file directory or main file directory (according to (global) preferences)
if (preferences.shouldStoreFilesRelativeToBibFile()) {
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/org/jabref/model/metadata/MetaData.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public class MetaData {
private FieldFormatterCleanups saveActions;
private BibDatabaseMode mode;
private boolean isProtected;
private String defaultFileDirectory;
private String librarySpecificFileDirectory;
private final ContentSelectors contentSelectors = new ContentSelectors();
private final Map<String, List<String>> unknownMetaData = new HashMap<>();
private boolean isEventPropagationEnabled = true;
Expand Down Expand Up @@ -221,12 +221,12 @@ public List<String> getContentSelectorValuesForField(Field field) {
return contentSelectors.getSelectorValuesForField(field);
}

public Optional<String> getDefaultFileDirectory() {
return Optional.ofNullable(defaultFileDirectory);
public Optional<String> getLibrarySpecificFileDirectory() {
return Optional.ofNullable(librarySpecificFileDirectory);
}

public void setDefaultFileDirectory(String path) {
defaultFileDirectory = Objects.requireNonNull(path).trim();
public void setLibrarySpecificFileDirectory(String path) {
librarySpecificFileDirectory = Objects.requireNonNull(path).trim();
postChange();
}

Expand All @@ -248,8 +248,8 @@ public void markAsProtected() {
postChange();
}

public void clearDefaultFileDirectory() {
defaultFileDirectory = null;
public void clearLibrarySpecificFileDirectory() {
librarySpecificFileDirectory = null;
postChange();
}

Expand Down Expand Up @@ -398,19 +398,19 @@ public boolean equals(Object o) {
&& Objects.equals(defaultCiteKeyPattern, that.defaultCiteKeyPattern)
&& Objects.equals(saveActions, that.saveActions)
&& (mode == that.mode)
&& Objects.equals(defaultFileDirectory, that.defaultFileDirectory)
&& Objects.equals(librarySpecificFileDirectory, that.librarySpecificFileDirectory)
&& Objects.equals(contentSelectors, that.contentSelectors)
&& Objects.equals(versionDBStructure, that.versionDBStructure);
}

@Override
public int hashCode() {
return Objects.hash(isProtected, groupsRoot.getValue(), encoding, encodingExplicitlySupplied, saveOrder, citeKeyPatterns, userFileDirectory,
laTexFileDirectory, defaultCiteKeyPattern, saveActions, mode, defaultFileDirectory, contentSelectors, versionDBStructure);
laTexFileDirectory, defaultCiteKeyPattern, saveActions, mode, librarySpecificFileDirectory, contentSelectors, versionDBStructure);
}

@Override
public String toString() {
return "MetaData [citeKeyPatterns=" + citeKeyPatterns + ", userFileDirectory=" + userFileDirectory + ", laTexFileDirectory=" + laTexFileDirectory + ", groupsRoot=" + groupsRoot + ", encoding=" + encoding + ", saveOrderConfig=" + saveOrder + ", defaultCiteKeyPattern=" + defaultCiteKeyPattern + ", saveActions=" + saveActions + ", mode=" + mode + ", isProtected=" + isProtected + ", defaultFileDirectory=" + defaultFileDirectory + ", contentSelectors=" + contentSelectors + ", encodingExplicitlySupplied=" + encodingExplicitlySupplied + ", VersionDBStructure=" + versionDBStructure + "]";
return "MetaData [citeKeyPatterns=" + citeKeyPatterns + ", userFileDirectory=" + userFileDirectory + ", laTexFileDirectory=" + laTexFileDirectory + ", groupsRoot=" + groupsRoot + ", encoding=" + encoding + ", saveOrderConfig=" + saveOrder + ", defaultCiteKeyPattern=" + defaultCiteKeyPattern + ", saveActions=" + saveActions + ", mode=" + mode + ", isProtected=" + isProtected + ", librarySpecificFileDirectory=" + librarySpecificFileDirectory + ", contentSelectors=" + contentSelectors + ", encodingExplicitlySupplied=" + encodingExplicitlySupplied + ", VersionDBStructure=" + versionDBStructure + "]";
}
}
2 changes: 1 addition & 1 deletion src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1056,7 +1056,7 @@ Waiting\ for\ background\ tasks\ to\ finish.\ Quit\ anyway?=Waiting for backgrou
Find\ and\ remove\ duplicate\ citation\ keys=Find and remove duplicate citation keys
Expected\ syntax\ for\ --fetch\='<name\ of\ fetcher>\:<query>'=Expected syntax for --fetch='<name of fetcher>:<query>'

General\ file\ directory=General file directory
Library-specific\ file\ directory=Library-specific file directory
User-specific\ file\ directory=User-specific file directory
LaTeX\ file\ directory=LaTeX file directory

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void setUp(@TempDir Path bibFolder) throws IOException {
Files.createDirectory(pdfPath);

MetaData metaData = new MetaData();
metaData.setDefaultFileDirectory(pdfPath.toAbsolutePath().toString());
metaData.setLibrarySpecificFileDirectory(pdfPath.toAbsolutePath().toString());
BibDatabaseContext context = new BibDatabaseContext(new BibDatabase(), metaData);
Files.createFile(bibFolder.resolve("test.bib"));
context.setDatabasePath(bibFolder.resolve("test.bib"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void setUp(@TempDir Path bibFolder) throws IOException {
Files.createFile(fileBefore);

MetaData metaData = new MetaData();
metaData.setDefaultFileDirectory(defaultFileFolder.toAbsolutePath().toString());
metaData.setLibrarySpecificFileDirectory(defaultFileFolder.toAbsolutePath().toString());
databaseContext = new BibDatabaseContext(new BibDatabase(), metaData);
Files.createFile(bibFolder.resolve("test.bib"));
databaseContext.setDatabasePath(bibFolder.resolve("test.bib"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void setUp(@TempDir Path bibFolder) throws IOException {
Files.createFile(fileBefore);

MetaData metaData = new MetaData();
metaData.setDefaultFileDirectory(newFileFolder.toAbsolutePath().toString());
metaData.setLibrarySpecificFileDirectory(newFileFolder.toAbsolutePath().toString());

BibDatabaseContext databaseContext = new BibDatabaseContext(new BibDatabase(), metaData);
Files.createFile(testBibFolder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,7 @@ void writeProtectedFlag() throws Exception {

@Test
void writeFileDirectories() throws Exception {
metaData.setDefaultFileDirectory("\\Literature\\");
metaData.setLibrarySpecificFileDirectory("\\Literature\\");
metaData.setUserFileDirectory("defaultOwner-user", "D:\\Documents");
metaData.setLatexFileDirectory("defaultOwner-user", Path.of("D:\\Latex"));

Expand Down
Loading

0 comments on commit 404394f

Please sign in to comment.