Skip to content

Commit

Permalink
Merge branch 'Display_username' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
calixtus authored Oct 22, 2023
2 parents 936d7ec + 0d8df17 commit e23031f
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
## [Unreleased]

### Added
- We added a hover on user-specific file directory. If the mouse is on hower, JabRef displays: user: {username}, host: {hostname}. [#572](https://github.com/koppor/jabref/issues/572)

### Changed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@
</Button>

<Label text="%User-specific file directory"
GridPane.columnIndex="0" GridPane.rowIndex="2"/>
GridPane.columnIndex="0" GridPane.rowIndex="2">
</Label>
<TextField fx:id="userSpecificFileDirectory"
GridPane.columnIndex="1" GridPane.rowIndex="2"/>

<Button onAction="#browseUserSpecificFileDirectory"
styleClass="icon-button,narrow" prefHeight="20.0" prefWidth="20.0"
GridPane.columnIndex="2" GridPane.rowIndex="2">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import java.nio.charset.Charset;

import javafx.beans.binding.Bindings;
import javafx.fxml.FXML;
import javafx.scene.control.ComboBox;
import javafx.scene.control.TextField;
import javafx.scene.control.Tooltip;

import org.jabref.gui.libraryproperties.AbstractPropertiesTabView;
import org.jabref.gui.util.ViewModelListCellFactory;
Expand All @@ -31,6 +33,8 @@ public GeneralPropertiesView(BibDatabaseContext databaseContext) {
ViewLoader.view(this)
.root(this)
.load();
// Get the ViewModel
viewModel.setUsername(preferencesService.getFilePreferences().getUserAndHost());
}

@Override
Expand All @@ -53,9 +57,11 @@ public void initialize() {
.install(databaseMode);
databaseMode.itemsProperty().bind(viewModel.databaseModesProperty());
databaseMode.valueProperty().bindBidirectional(viewModel.selectedDatabaseModeProperty());

generalFileDirectory.textProperty().bindBidirectional(viewModel.generalFileDirectoryPropertyProperty());
userSpecificFileDirectory.textProperty().bindBidirectional(viewModel.userSpecificFileDirectoryProperty());
Tooltip tooltip = new Tooltip();
tooltip.textProperty().bind(Bindings.concat("Host: ", viewModel.hostPropertyProperty(), "\nUsername: ", viewModel.usernamePropertyProperty()));
userSpecificFileDirectory.setTooltip(tooltip);
laTexFileDirectory.textProperty().bindBidirectional(viewModel.laTexFileDirectoryProperty());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.jabref.gui.libraryproperties.general;

import java.net.InetAddress;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
Expand Down Expand Up @@ -33,6 +34,10 @@ public class GeneralPropertiesViewModel implements PropertiesTabViewModel {
private final SimpleObjectProperty<BibDatabaseMode> selectedDatabaseModeProperty = new SimpleObjectProperty<>(BibDatabaseMode.BIBLATEX);
private final StringProperty generalFileDirectoryProperty = new SimpleStringProperty("");
private final StringProperty userSpecificFileDirectoryProperty = new SimpleStringProperty("");
private final StringProperty hostProperty = new SimpleStringProperty("");


private final StringProperty usernameProperty = new SimpleStringProperty("");
private final StringProperty laTexFileDirectoryProperty = new SimpleStringProperty("");

private final DialogService dialogService;
Expand Down Expand Up @@ -61,6 +66,16 @@ public void setValues() {
selectedDatabaseModeProperty.setValue(metaData.getMode().orElse(BibDatabaseMode.BIBLATEX));
generalFileDirectoryProperty.setValue(metaData.getDefaultFileDirectory().orElse("").trim());
userSpecificFileDirectoryProperty.setValue(metaData.getUserFileDirectory(preferencesService.getFilePreferences().getUserAndHost()).orElse("").trim());
userSpecificFileDirectoryProperty.setValue(metaData.getUserFileDirectory(preferencesService.getFilePreferences().getUserAndHost()).map(path -> usernameProperty.getValue() + ": " + path).orElse("").trim());
String username = preferencesService.getFilePreferences().getUserAndHost(); // get the username
usernameProperty.setValue(username);
try {
InetAddress localHost = InetAddress.getLocalHost();
hostProperty.set(localHost.getHostName()); // get the host Name
} catch (Exception e) {
hostProperty.set("N/A"); // if fail to get host, display N/A(Not Available)
}

laTexFileDirectoryProperty.setValue(metaData.getLatexFileDirectory(preferencesService.getFilePreferences().getUserAndHost()).map(Path::toString).orElse(""));
}

Expand Down Expand Up @@ -141,4 +156,16 @@ public StringProperty userSpecificFileDirectoryProperty() {
public StringProperty laTexFileDirectoryProperty() {
return this.laTexFileDirectoryProperty;
}

public void setUsername(String username) {
usernameProperty.setValue(username);
}

public StringProperty usernamePropertyProperty() {
return usernameProperty;
}

public StringProperty hostPropertyProperty() {
return hostProperty;
}
}

0 comments on commit e23031f

Please sign in to comment.