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 all 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
- We added a highlighted diff regarding changes to the Group Tree Structure of a bib file, made outside JabRef. [#11221](https://github.com/JabRef/jabref/issues/11221)
- We added a new setting in the 'Entry Editor' preferences to hide the 'File Annotations' tab when no annotations are available. [#13143](https://github.com/JabRef/jabref/issues/13143)
- We added support for multi-file import across different formats. [#13269](https://github.com/JabRef/jabref/issues/13269)
- We made the sidebar (SidePane) width persist across sessions and resize proportionally to the window width. [#13402](https://github.com/JabRef/jabref/issues/13402)

### Changed

Expand Down
36 changes: 30 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 @@ -83,8 +83,9 @@ public class JabRefFrame extends BorderPane implements LibraryTabContainer, UiMe
private enum PanelMode { MAIN_TABLE, MAIN_TABLE_AND_ENTRY_EDITOR }

public static final String FRAME_TITLE = "JabRef";

Copy link
Member

Choose a reason for hiding this comment

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

Why more spaces?

private static final Logger LOGGER = LoggerFactory.getLogger(JabRefFrame.class);
private static final double DEFAULT_SIDEBAR_DIVIDER_POSITION = 0.2;

private final GuiPreferences preferences;
private final AiService aiService;
Expand Down Expand Up @@ -213,6 +214,7 @@ public JabRefFrame(Stage mainStage,
initKeyBindings();
frameDndHandler.initDragAndDrop();
initBindings();
initSidebarResizeListener();
}

private void initLayout() {
Expand Down Expand Up @@ -296,12 +298,26 @@ 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()));
double savedProportion = preferences.getGuiPreferences().getHorizontalDividerPosition();
if (Double.isNaN(savedProportion) || savedProportion <= 0 || savedProportion >= 1) {
savedProportion = DEFAULT_SIDEBAR_DIVIDER_POSITION;
}
horizontalSplit.setDividerPositions(savedProportion);
Copy link
Member

Choose a reason for hiding this comment

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

Indent is off


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 +463,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