diff --git a/CHANGELOG.md b/CHANGELOG.md index 52485dda5ce..daff870eb51 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/jabgui/src/main/java/org/jabref/gui/frame/JabRefFrame.java b/jabgui/src/main/java/org/jabref/gui/frame/JabRefFrame.java index 4280e9b5ff4..7e10ecdbcc0 100644 --- a/jabgui/src/main/java/org/jabref/gui/frame/JabRefFrame.java +++ b/jabgui/src/main/java/org/jabref/gui/frame/JabRefFrame.java @@ -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"; - + 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; @@ -213,6 +214,7 @@ public JabRefFrame(Stage mainStage, initKeyBindings(); frameDndHandler.initDragAndDrop(); initBindings(); + initSidebarResizeListener(); } private void initLayout() { @@ -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); + + 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); + } + }); + } } - } public void updateVerticalDividerPosition() { if (mainStage.isShowing() && panelMode.get() == PanelMode.MAIN_TABLE_AND_ENTRY_EDITOR) { @@ -447,6 +463,14 @@ private void initBindings() { EasyBind.subscribe(preferences.getWorkspacePreferences().hideTabBarProperty(), _ -> updateTabBarVisible()); } + private void initSidebarResizeListener() { + mainStage.widthProperty().addListener((obs, oldVal, newVal) -> { + if (!sidePane.getChildren().isEmpty()) { + updateHorizontalDividerPosition(); + } + }); + } + private void updateTabBarVisible() { if (preferences.getWorkspacePreferences().shouldHideTabBar() && stateManager.getOpenDatabases().size() <= 1) { if (!tabbedPane.getStyleClass().contains("hide-tab-bar")) {