Skip to content

Fix #13402: Make sidebar width proportional to window size and persist across sessions #13405

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
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv

## [Unreleased]

- Sidebar width now persists across sessions and resizes proportionally to window width [#13402](https://github.com/JabRef/jabref/issues/13402)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move to the changed section


### Added

- We introduced a settings parameter to manage citations' relations local storage time-to-live with a default value set to 30 days. [#11189](https://github.com/JabRef/jabref/issues/11189)
Expand Down
39 changes: 33 additions & 6 deletions jabgui/src/main/java/org/jabref/gui/frame/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ public JabRefFrame(Stage mainStage,
initKeyBindings();
frameDndHandler.initDragAndDrop();
initBindings();
initSidebarResizeListener();
}

private void initLayout() {
Expand Down Expand Up @@ -295,13 +296,31 @@ private void updateEditorPane() {
}

public void updateHorizontalDividerPosition() {
if (mainStage.isShowing() && !sidePane.getChildren().isEmpty()) {
horizontalSplit.setDividerPositions(preferences.getGuiPreferences().getHorizontalDividerPosition() / horizontalSplit.getWidth());
horizontalDividerSubscription = EasyBind.valueAt(horizontalSplit.getDividers(), 0)
.mapObservable(SplitPane.Divider::positionProperty)
.listenToValues((_, newValue) -> preferences.getGuiPreferences().setHorizontalDividerPosition(newValue.doubleValue()));
if (mainStage.isShowing() && !sidePane.getChildren().isEmpty()) {
double savedProportion = preferences.getGuiPreferences().getHorizontalDividerPosition();

// Fix: fallback to 0.2 if saved value is invalid
if (savedProportion <= 0.0 || savedProportion >= 1.0 || Double.isNaN(savedProportion)) {
savedProportion = 0.2;
}

horizontalSplit.setDividerPositions(savedProportion);

// Subscribe to save user-adjusted sidebar position
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!

if (horizontalDividerSubscription != null) {
horizontalDividerSubscription.unsubscribe();
}

horizontalDividerSubscription = EasyBind.valueAt(horizontalSplit.getDividers(), 0)
.mapObservable(SplitPane.Divider::positionProperty)
.listenToValues((_, newValue) -> {
double newPos = newValue.doubleValue();
if (newPos > 0.0 && newPos < 1.0) {
preferences.getGuiPreferences().setHorizontalDividerPosition(newPos);
}
});
}
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

strange indent


public void updateVerticalDividerPosition() {
if (mainStage.isShowing() && panelMode.get() == PanelMode.MAIN_TABLE_AND_ENTRY_EDITOR) {
Expand Down Expand Up @@ -447,6 +466,14 @@ private void initBindings() {
EasyBind.subscribe(preferences.getWorkspacePreferences().hideTabBarProperty(), _ -> updateTabBarVisible());
}

private void initSidebarResizeListener() {
mainStage.widthProperty().addListener((obs, oldVal, newVal) -> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why no _ used here?

if (!sidePane.getChildren().isEmpty()) {
updateHorizontalDividerPosition();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, inside, always a new listener is created. This will let the memory grow and grow and grow and grow and grow.

}
});
}

private void updateTabBarVisible() {
if (preferences.getWorkspacePreferences().shouldHideTabBar() && stateManager.getOpenDatabases().size() <= 1) {
if (!tabbedPane.getStyleClass().contains("hide-tab-bar")) {
Expand Down