Skip to content

Commit

Permalink
Move sidePaneWidth from GuiPreferences to SidePanePreferences
Browse files Browse the repository at this point in the history
  • Loading branch information
HoussemNasri committed Jun 29, 2022
1 parent 99f2ff8 commit a60d0e2
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 27 deletions.
4 changes: 2 additions & 2 deletions src/main/java/org/jabref/gui/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -475,8 +475,8 @@ private void updateSidePane() {

private void setDividerPosition() {
if (mainStage.isShowing() && !sidePane.getChildren().isEmpty()) {
splitPane.setDividerPositions(prefs.getGuiPreferences().getSidePaneWidth() / splitPane.getWidth());
dividerSubscription = EasyBind.subscribe(sidePane.widthProperty(), width -> prefs.getGuiPreferences().setSidePaneWidth(width.doubleValue()));
splitPane.setDividerPositions(prefs.getSidePanePreferences().getSidePaneWidth() / splitPane.getWidth());
dividerSubscription = EasyBind.subscribe(sidePane.widthProperty(), width -> prefs.getSidePanePreferences().setSidePaneWidth(width.doubleValue()));
}
}

Expand Down
18 changes: 1 addition & 17 deletions src/main/java/org/jabref/preferences/GuiPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ public class GuiPreferences {

private final ObjectProperty<DiffMode> mergeDiffMode;

private final DoubleProperty sidePaneWidth;

public GuiPreferences(double positionX,
double positionY,
double sizeX,
Expand All @@ -44,8 +42,7 @@ public GuiPreferences(double positionX,
Path lastFocusedFile,
FileHistory fileHistory,
String lastSelectedIdBasedFetcher,
DiffMode mergeDiffMode,
double sidePaneWidth) {
DiffMode mergeDiffMode) {
this.positionX = new SimpleDoubleProperty(positionX);
this.positionY = new SimpleDoubleProperty(positionY);
this.sizeX = new SimpleDoubleProperty(sizeX);
Expand All @@ -55,7 +52,6 @@ public GuiPreferences(double positionX,
this.lastFocusedFile = new SimpleObjectProperty<>(lastFocusedFile);
this.lastSelectedIdBasedFetcher = new SimpleStringProperty(lastSelectedIdBasedFetcher);
this.mergeDiffMode = new SimpleObjectProperty<>(mergeDiffMode);
this.sidePaneWidth = new SimpleDoubleProperty(sidePaneWidth);
this.fileHistory = fileHistory;
}

Expand Down Expand Up @@ -166,16 +162,4 @@ public ObjectProperty<DiffMode> mergeDiffModeProperty() {
public void setMergeDiffMode(DiffMode mergeDiffMode) {
this.mergeDiffMode.set(mergeDiffMode);
}

public double getSidePaneWidth() {
return sidePaneWidth.get();
}

public DoubleProperty sidePaneWidthProperty() {
return sidePaneWidth;
}

public void setSidePaneWidth(double sidePaneWidth) {
this.sidePaneWidth.set(sidePaneWidth);
}
}
11 changes: 5 additions & 6 deletions src/main/java/org/jabref/preferences/JabRefPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ private JabRefPreferences() {
defaults.put(CITE_COMMAND, "\\cite"); // obsoleted by the app-specific ones (not any more?)

defaults.put(LAST_USED_EXPORT, "");
defaults.put(SIDE_PANE_WIDTH, 0.15);
defaults.put(SIDE_PANE_WIDTH, 300);

defaults.put(MAIN_FONT_SIZE, 9);
defaults.put(OVERRIDE_DEFAULT_FONT_SIZE, false);
Expand Down Expand Up @@ -2481,14 +2481,15 @@ public SidePanePreferences getSidePanePreferences() {
sidePanePreferences = new SidePanePreferences(
getVisibleSidePanes(),
getSidePanePreferredPositions(),
getInt(SELECTED_FETCHER_INDEX));
getInt(SELECTED_FETCHER_INDEX),
getDouble(SIDE_PANE_WIDTH));

sidePanePreferences.visiblePanes().addListener((InvalidationListener) listener ->
storeVisibleSidePanes(sidePanePreferences.visiblePanes()));
sidePanePreferences.getPreferredPositions().addListener((InvalidationListener) listener ->
storeSidePanePreferredPositions(sidePanePreferences.getPreferredPositions()));
EasyBind.listen(sidePanePreferences.webSearchFetcherSelectedProperty(), (obs, oldValue, newValue) -> putInt(SELECTED_FETCHER_INDEX, newValue));

EasyBind.subscribe(sidePanePreferences.sidePaneWidthProperty(), width -> putDouble(SIDE_PANE_WIDTH, width.doubleValue()));
return sidePanePreferences;
}

Expand Down Expand Up @@ -2567,8 +2568,7 @@ public GuiPreferences getGuiPreferences() {
Path.of(get(LAST_FOCUSED)),
getFileHistory(),
get(ID_ENTRY_GENERATOR),
DiffMode.parse(get(MERGE_ENTRIES_DIFF_MODE)),
getDouble(SIDE_PANE_WIDTH));
DiffMode.parse(get(MERGE_ENTRIES_DIFF_MODE)));

EasyBind.listen(guiPreferences.positionXProperty(), (obs, oldValue, newValue) -> putDouble(POS_X, newValue.doubleValue()));
EasyBind.listen(guiPreferences.positionYProperty(), (obs, oldValue, newValue) -> putDouble(POS_Y, newValue.doubleValue()));
Expand All @@ -2587,7 +2587,6 @@ public GuiPreferences getGuiPreferences() {
guiPreferences.getFileHistory().getHistory().addListener((InvalidationListener) change -> storeFileHistory(guiPreferences.getFileHistory()));
EasyBind.listen(guiPreferences.lastSelectedIdBasedFetcherProperty(), (obs, oldValue, newValue) -> put(ID_ENTRY_GENERATOR, newValue));
EasyBind.listen(guiPreferences.mergeDiffModeProperty(), (obs, oldValue, newValue) -> put(MERGE_ENTRIES_DIFF_MODE, newValue.name()));
EasyBind.listen(guiPreferences.sidePaneWidthProperty(), (obs, oldValue, newValue) -> putDouble(SIDE_PANE_WIDTH, newValue.doubleValue()));

return guiPreferences;
}
Expand Down
22 changes: 20 additions & 2 deletions src/main/java/org/jabref/preferences/SidePanePreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import java.util.Map;
import java.util.Set;

import javafx.beans.property.DoubleProperty;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableMap;
Expand All @@ -16,12 +18,16 @@ public class SidePanePreferences {
private final ObservableMap<SidePaneType, Integer> preferredPositions;
private final IntegerProperty webSearchFetcherSelected;

private final DoubleProperty sidePaneWidth;

public SidePanePreferences(Set<SidePaneType> visiblePanes,
Map<SidePaneType, Integer> preferredPositions,
int webSearchFetcherSelected) {
Map<SidePaneType, Integer> preferredPositions,
int webSearchFetcherSelected,
double sidePaneWidth) {
this.visiblePanes = FXCollections.observableSet(visiblePanes);
this.preferredPositions = FXCollections.observableMap(preferredPositions);
this.webSearchFetcherSelected = new SimpleIntegerProperty(webSearchFetcherSelected);
this.sidePaneWidth = new SimpleDoubleProperty(sidePaneWidth);
}

public ObservableSet<SidePaneType> visiblePanes() {
Expand All @@ -48,4 +54,16 @@ public IntegerProperty webSearchFetcherSelectedProperty() {
public void setWebSearchFetcherSelected(int webSearchFetcherSelected) {
this.webSearchFetcherSelected.set(webSearchFetcherSelected);
}

public DoubleProperty sidePaneWidthProperty() {
return sidePaneWidth;
}

public double getSidePaneWidth() {
return sidePaneWidthProperty().get();
}

public void setSidePaneWidth(double width) {
sidePaneWidthProperty().set(width);
}
}

0 comments on commit a60d0e2

Please sign in to comment.