Skip to content

Commit

Permalink
Rename "user" to "userAndHost" (adapt test mocks and fix two typos)
Browse files Browse the repository at this point in the history
  • Loading branch information
koppor committed Jun 7, 2023
1 parent e9e1d3f commit 7025d45
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public LatexCitationsTabViewModel(BibDatabaseContext databaseContext,
this.preferencesService = preferencesService;
this.taskExecutor = taskExecutor;
this.dialogService = dialogService;
this.directory = new SimpleObjectProperty<>(databaseContext.getMetaData().getLatexFileDirectory(preferencesService.getFilePreferences().getUser())
this.directory = new SimpleObjectProperty<>(databaseContext.getMetaData().getLatexFileDirectory(preferencesService.getFilePreferences().getUserAndHost())
.orElse(FileUtil.getInitialDirectory(databaseContext, preferencesService.getFilePreferences().getWorkingDirectory())));
this.citationList = FXCollections.observableArrayList();
this.status = new SimpleObjectProperty<>(Status.IN_PROGRESS);
Expand Down Expand Up @@ -130,7 +130,7 @@ private void cancelSearch() {

private Collection<Citation> searchAndParse(String citeKey) throws IOException {
// we need to check whether the user meanwhile set the LaTeX file directory or the database changed locations
Path newDirectory = databaseContext.getMetaData().getLatexFileDirectory(preferencesService.getFilePreferences().getUser())
Path newDirectory = databaseContext.getMetaData().getLatexFileDirectory(preferencesService.getFilePreferences().getUserAndHost())
.orElse(FileUtil.getInitialDirectory(databaseContext, preferencesService.getFilePreferences().getWorkingDirectory()));

if (latexParserResult == null || !newDirectory.equals(directory.get())) {
Expand Down Expand Up @@ -172,7 +172,7 @@ public void setLatexDirectory() {
.withInitialDirectory(directory.get()).build();

dialogService.showDirectorySelectionDialog(directoryDialogConfiguration).ifPresent(selectedDirectory ->
databaseContext.getMetaData().setLatexFileDirectory(preferencesService.getFilePreferences().getUser(), selectedDirectory.toAbsolutePath()));
databaseContext.getMetaData().setLatexFileDirectory(preferencesService.getFilePreferences().getUserAndHost(), selectedDirectory.toAbsolutePath()));

init(currentEntry);
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/jabref/gui/groups/GroupDialogViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ private void setupValidation() {
* @return an absolute path if LatexFileDirectory exists; otherwise, returns input
*/
private Path getAbsoluteTexGroupPath(String input) {
Optional<Path> latexFileDirectory = currentDatabase.getMetaData().getLatexFileDirectory(preferencesService.getFilePreferences().getUser());
Optional<Path> latexFileDirectory = currentDatabase.getMetaData().getLatexFileDirectory(preferencesService.getFilePreferences().getUserAndHost());
return latexFileDirectory.map(path -> path.resolve(input)).orElse(Path.of(input));
}

Expand Down Expand Up @@ -444,7 +444,7 @@ public void texGroupBrowse() {
.addExtensionFilter(StandardFileType.AUX)
.withDefaultExtension(StandardFileType.AUX)
.withInitialDirectory(currentDatabase.getMetaData()
.getLatexFileDirectory(preferencesService.getFilePreferences().getUser())
.getLatexFileDirectory(preferencesService.getFilePreferences().getUserAndHost())
.orElse(FileUtil.getInitialDirectory(currentDatabase, preferencesService.getFilePreferences().getWorkingDirectory()))).build();
dialogService.showFileOpenDialog(fileDialogConfiguration)
.ifPresent(file -> texGroupFilePathProperty.setValue(
Expand All @@ -459,7 +459,7 @@ public void openHelpPage() {
private List<Path> getFileDirectoriesAsPaths() {
List<Path> fileDirs = new ArrayList<>();
MetaData metaData = currentDatabase.getMetaData();
metaData.getLatexFileDirectory(preferencesService.getFilePreferences().getUser()).ifPresent(fileDirs::add);
metaData.getLatexFileDirectory(preferencesService.getFilePreferences().getUserAndHost()).ifPresent(fileDirs::add);

return fileDirs;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ public void setValues() {
selectedEncodingProperty.setValue(metaData.getEncoding().orElse(StandardCharsets.UTF_8));
selectedDatabaseModeProperty.setValue(metaData.getMode().orElse(BibDatabaseMode.BIBLATEX));
generalFileDirectoryProperty.setValue(metaData.getDefaultFileDirectory().orElse("").trim());
userSpecificFileDirectoryProperty.setValue(metaData.getUserFileDirectory(preferencesService.getFilePreferences().getUser()).orElse("").trim());
laTexFileDirectoryProperty.setValue(metaData.getLatexFileDirectory(preferencesService.getFilePreferences().getUser()).map(Path::toString).orElse(""));
userSpecificFileDirectoryProperty.setValue(metaData.getUserFileDirectory(preferencesService.getFilePreferences().getUserAndHost()).orElse("").trim());
laTexFileDirectoryProperty.setValue(metaData.getLatexFileDirectory(preferencesService.getFilePreferences().getUserAndHost()).map(Path::toString).orElse(""));
}

@Override
Expand All @@ -80,16 +80,16 @@ public void storeSettings() {

String userSpecificFileDirectory = userSpecificFileDirectoryProperty.getValue();
if (userSpecificFileDirectory.isEmpty()) {
newMetaData.clearUserFileDirectory(preferencesService.getFilePreferences().getUser());
newMetaData.clearUserFileDirectory(preferencesService.getFilePreferences().getUserAndHost());
} else {
newMetaData.setUserFileDirectory(preferencesService.getFilePreferences().getUser(), userSpecificFileDirectory);
newMetaData.setUserFileDirectory(preferencesService.getFilePreferences().getUserAndHost(), userSpecificFileDirectory);
}

String latexFileDirectory = laTexFileDirectoryProperty.getValue();
if (latexFileDirectory.isEmpty()) {
newMetaData.clearLatexFileDirectory(preferencesService.getFilePreferences().getUser());
newMetaData.clearLatexFileDirectory(preferencesService.getFilePreferences().getUserAndHost());
} else {
newMetaData.setLatexFileDirectory(preferencesService.getFilePreferences().getUser(), Path.of(latexFileDirectory));
newMetaData.setLatexFileDirectory(preferencesService.getFilePreferences().getUserAndHost(), Path.of(latexFileDirectory));
}

databaseContext.setMetaData(newMetaData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public ParseLatexDialogViewModel(BibDatabaseContext databaseContext,
this.taskExecutor = taskExecutor;
this.preferencesService = preferencesService;
this.fileMonitor = fileMonitor;
this.latexFileDirectory = new SimpleStringProperty(databaseContext.getMetaData().getLatexFileDirectory(preferencesService.getFilePreferences().getUser())
this.latexFileDirectory = new SimpleStringProperty(databaseContext.getMetaData().getLatexFileDirectory(preferencesService.getFilePreferences().getUserAndHost())
.orElse(FileUtil.getInitialDirectory(databaseContext, preferencesService.getFilePreferences().getWorkingDirectory()))
.toAbsolutePath().toString());
this.root = new SimpleObjectProperty<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public List<Path> getFileDirectories(FilePreferences preferences) {
List<Path> fileDirs = new ArrayList<>();

// 1. Metadata user-specific directory
metaData.getUserFileDirectory(preferences.getUser())
metaData.getUserFileDirectory(preferences.getUserAndHost())
.ifPresent(userFileDirectory -> fileDirs.add(getFileDirectoryPath(userFileDirectory)));

// 2. Metadata general directory
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/org/jabref/preferences/FilePreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class FilePreferences {

public static final String[] DEFAULT_FILENAME_PATTERNS = new String[] {"[bibtexkey]", "[bibtexkey] - [title]"};

private final StringProperty user = new SimpleStringProperty();
private final StringProperty userAndHost = new SimpleStringProperty();
private final SimpleStringProperty mainFileDirectory = new SimpleStringProperty();
private final BooleanProperty storeFilesRelativeToBibFile = new SimpleBooleanProperty();
private final StringProperty fileNamePattern = new SimpleStringProperty();
Expand All @@ -35,9 +35,9 @@ public class FilePreferences {
private final ObjectProperty<Path> workingDirectory = new SimpleObjectProperty<>();
private final ObservableSet<ExternalFileType> externalFileTypes = FXCollections.observableSet(new TreeSet<>(Comparator.comparing(ExternalFileType::getName)));
private final BooleanProperty createBackup = new SimpleBooleanProperty();
private final ObjectProperty<Path> backupDiretory = new SimpleObjectProperty<>();
private final ObjectProperty<Path> backupDirectory = new SimpleObjectProperty<>();

public FilePreferences(String user,
public FilePreferences(String userAndHost,
String mainFileDirectory,
boolean storeFilesRelativeToBibFile,
String fileNamePattern,
Expand All @@ -48,7 +48,7 @@ public FilePreferences(String user,
Set<ExternalFileType> externalFileTypes,
boolean createBackup,
Path backupDirectory) {
this.user.setValue(user);
this.userAndHost.setValue(userAndHost);
this.mainFileDirectory.setValue(mainFileDirectory);
this.storeFilesRelativeToBibFile.setValue(storeFilesRelativeToBibFile);
this.fileNamePattern.setValue(fileNamePattern);
Expand All @@ -58,11 +58,11 @@ public FilePreferences(String user,
this.workingDirectory.setValue(workingDirectory);
this.externalFileTypes.addAll(externalFileTypes);
this.createBackup.setValue(createBackup);
this.backupDiretory.setValue(backupDirectory);
this.backupDirectory.setValue(backupDirectory);
}

public String getUser() {
return user.getValue();
public String getUserAndHost() {
return userAndHost.getValue();
}

public Optional<Path> getMainFileDirectory() {
Expand Down Expand Up @@ -170,14 +170,14 @@ public BooleanProperty createBackupProperty() {
}

public ObjectProperty<Path> backupDirectoryProperty() {
return this.backupDiretory;
return this.backupDirectory;
}

public void setBackupDirectory(Path backupPath) {
this.backupDiretory.set(backupPath);
this.backupDirectory.set(backupPath);
}

public Path getBackupDirectory() {
return this.backupDiretory.getValue();
return this.backupDirectory.getValue();
}
}
10 changes: 5 additions & 5 deletions src/main/java/org/jabref/preferences/InternalPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ public class InternalPreferences {

private final ObjectProperty<Version> ignoredVersion;
private final ObjectProperty<Path> lastPreferencesExportPath;
private final StringProperty user;
private final StringProperty userAndHost;
private final BooleanProperty memoryStickMode;

public InternalPreferences(Version ignoredVersion,
Path exportPath,
String user,
String userAndHost,
boolean memoryStickMode) {
this.ignoredVersion = new SimpleObjectProperty<>(ignoredVersion);
this.lastPreferencesExportPath = new SimpleObjectProperty<>(exportPath);
this.user = new SimpleStringProperty(user);
this.userAndHost = new SimpleStringProperty(userAndHost);
this.memoryStickMode = new SimpleBooleanProperty(memoryStickMode);
}

Expand Down Expand Up @@ -52,8 +52,8 @@ public void setLastPreferencesExportPath(Path lastPreferencesExportPath) {
this.lastPreferencesExportPath.set(lastPreferencesExportPath);
}

public String getUser() {
return user.get();
public String getUserAndHost() {
return userAndHost.get();
}

public boolean isMemoryStickMode() {
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/jabref/preferences/JabRefPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,7 @@ private JabRefPreferences() {
defaults.put(FILE_BROWSER_COMMAND, "");
}

// versioncheck defaults
// version check defaults
defaults.put(VERSION_IGNORED_UPDATE, "");

// preview
Expand Down Expand Up @@ -1996,7 +1996,7 @@ public InternalPreferences getInternalPreferences() {
internalPreferences = new InternalPreferences(
Version.parse(get(VERSION_IGNORED_UPDATE)),
getPath(PREFS_EXPORT_PATH, OS.getNativeDesktop().getDefaultFileChooserDirectory()),
getUser(),
getUserAndHost(),
getBoolean(MEMORY_STICK_MODE));

EasyBind.listen(internalPreferences.ignoredVersionProperty(),
Expand All @@ -2018,7 +2018,7 @@ public InternalPreferences getInternalPreferences() {
return internalPreferences;
}

private String getUser() {
private String getUserAndHost() {
if (StringUtil.isNotBlank(userName)) {
return userName;
}
Expand Down Expand Up @@ -2117,7 +2117,7 @@ public FilePreferences getFilePreferences() {
}

filePreferences = new FilePreferences(
getInternalPreferences().getUser(),
getInternalPreferences().getUserAndHost(),
getPath(MAIN_FILE_DIRECTORY, OS.getNativeDesktop().getDefaultFileChooserDirectory()).toString(),
getBoolean(STORE_RELATIVE_TO_BIB),
get(IMPORT_FILENAMEPATTERN),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void setUp(@TempDir Path temporaryFolder) {
when(preferencesService.getBibEntryPreferences()).thenReturn(mock(BibEntryPreferences.class));
when(preferencesService.getBibEntryPreferences().getKeywordSeparator()).thenReturn(',');
when(preferencesService.getFilePreferences()).thenReturn(mock(FilePreferences.class));
when(preferencesService.getFilePreferences().getUser()).thenReturn("MockedUser");
when(preferencesService.getFilePreferences().getUserAndHost()).thenReturn("MockedUser-mockedhost");
when(preferencesService.getGroupsPreferences()).thenReturn(groupsPreferences);

bibDatabaseContext.setMetaData(metaData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private static void initBibEntries() throws IOException {
@BeforeEach
void setUp() throws IOException {
filePreferences = mock(FilePreferences.class);
when(filePreferences.getUser()).thenReturn(tempDir.toAbsolutePath().toString());
when(filePreferences.getUserAndHost()).thenReturn(tempDir.toAbsolutePath().toString());
when(filePreferences.shouldStoreFilesRelativeToBibFile()).thenReturn(false);

BibDatabaseMode bibDatabaseMode = BibDatabaseMode.BIBTEX;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ void setUp() throws IOException {
encoding = Charset.defaultCharset();

filePreferences = mock(FilePreferences.class);
when(filePreferences.getUser()).thenReturn(tempDir.toAbsolutePath().toString());
when(filePreferences.getUserAndHost()).thenReturn(tempDir.toAbsolutePath().toString());
when(filePreferences.shouldStoreFilesRelativeToBibFile()).thenReturn(false);

importer = new PdfXmpImporter(xmpPreferences);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void setup() {
this.databaseContext = mock(BibDatabaseContext.class);
when(databaseContext.getFileDirectories(Mockito.any())).thenReturn(Collections.singletonList(Path.of("src/test/resources/pdfs")));
this.filePreferences = mock(FilePreferences.class);
when(filePreferences.getUser()).thenReturn("test");
when(filePreferences.getUserAndHost()).thenReturn("testuser-testhost");
when(filePreferences.getMainFileDirectory()).thenReturn(Optional.empty());
when(filePreferences.shouldStoreFilesRelativeToBibFile()).thenReturn(true);
}
Expand Down

0 comments on commit 7025d45

Please sign in to comment.