Skip to content

Commit

Permalink
Store preview divider pos in entry editor (#11285)
Browse files Browse the repository at this point in the history
* Store preview divider pos in entry editor


Fixes #11281

* checkstyle
  • Loading branch information
Siedlerchr authored May 8, 2024
1 parent 045f815 commit fb93c2f
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
- We fixed an issue where drag and dropping entries created a shallow copy. [#11160](https://github.com/JabRef/jabref/issues/11160)
- We fixed an issue where imports to a custom group would only work for the first entry [#11085](https://github.com/JabRef/jabref/issues/11085), [#11269](https://github.com/JabRef/jabref/issues/11269)
- We fixed an issue where a new entry was not added to the selected group [#8933](https://github.com/JabRef/jabref/issues/8933)
- We fixed an issue where the horizontal position of the Entry Preview inside the entry editor was not remembered across restarts [#11281](https://github.com/JabRef/jabref/issues/11281)

### Removed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public static JournalPopupEnabled fromString(String status) {
private final ObjectProperty<JournalPopupEnabled> enablementStatus;
private final BooleanProperty shouldShowSciteTab;
private final BooleanProperty showUserCommentsFields;
private final DoubleProperty previewWidthDividerPosition;

public EntryEditorPreferences(Map<String, Set<Field>> entryEditorTabList,
Map<String, Set<Field>> defaultEntryEditorTabList,
Expand All @@ -62,7 +63,8 @@ public EntryEditorPreferences(Map<String, Set<Field>> entryEditorTabList,
boolean autolinkFilesEnabled,
JournalPopupEnabled journalPopupEnabled,
boolean showSciteTab,
boolean showUserCommentsFields) {
boolean showUserCommentsFields,
double previewWidthDividerPosition) {

this.entryEditorTabList = new SimpleMapProperty<>(FXCollections.observableMap(entryEditorTabList));
this.defaultEntryEditorTabList = new SimpleMapProperty<>(FXCollections.observableMap(defaultEntryEditorTabList));
Expand All @@ -77,6 +79,7 @@ public EntryEditorPreferences(Map<String, Set<Field>> entryEditorTabList,
this.enablementStatus = new SimpleObjectProperty<>(journalPopupEnabled);
this.shouldShowSciteTab = new SimpleBooleanProperty(showSciteTab);
this.showUserCommentsFields = new SimpleBooleanProperty(showUserCommentsFields);
this.previewWidthDividerPosition = new SimpleDoubleProperty(previewWidthDividerPosition);
}

public ObservableMap<String, Set<Field>> getEntryEditorTabs() {
Expand Down Expand Up @@ -226,4 +229,19 @@ public BooleanProperty showUserCommentsFieldsProperty() {
public void setShowUserCommentsFields(boolean showUserCommentsFields) {
this.showUserCommentsFields.set(showUserCommentsFields);
}

public void setPreviewWidthDividerPosition(double previewWidthDividerPosition) {
this.previewWidthDividerPosition.set(previewWidthDividerPosition);
}

/**
* Holds the horizontal divider position when the Preview is shown in the entry editor
*/
public DoubleProperty previewWidthDividerPositionProperty() {
return previewWidthDividerPosition;
}

public Double getPreviewWidthDividerPosition() {
return previewWidthDividerPosition.get();
}
}
15 changes: 15 additions & 0 deletions src/main/java/org/jabref/gui/entryeditor/FieldsEditorTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.jabref.preferences.PreferencesService;

import com.tobiasdiez.easybind.EasyBind;
import com.tobiasdiez.easybind.Subscription;

/**
* A single tab displayed in the EntryEditor holding several FieldEditors.
Expand All @@ -61,6 +62,7 @@ abstract class FieldsEditorTab extends EntryEditorTab {
private PreviewPanel previewPanel;
private final UndoManager undoManager;
private Collection<Field> fields = new ArrayList<>();
private Subscription dividerPositionSubscription;

public FieldsEditorTab(boolean compressed,
BibDatabaseContext databaseContext,
Expand Down Expand Up @@ -258,9 +260,22 @@ private void initPanel() {
container.getItems().remove(previewPanel);
} else {
container.getItems().add(1, previewPanel);
container.setDividerPositions(preferences.getEntryEditorPreferences().getPreviewWidthDividerPosition());
}
});

// save position
dividerPositionSubscription = EasyBind.valueAt(container.getDividers(), 0)
.mapObservable(SplitPane.Divider::positionProperty)
.subscribeToValues(this::savePreviewWidthDividerPosition);
setContent(container);
}
}

private void savePreviewWidthDividerPosition(Number position) {
if (!preferences.getPreviewPreferences().shouldShowPreviewAsExtraTab()) {
preferences.getEntryEditorPreferences().setPreviewWidthDividerPosition(position.doubleValue());
}
}
}

10 changes: 8 additions & 2 deletions src/main/java/org/jabref/preferences/JabRefPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ public class JabRefPreferences implements PreferencesService {
public static final String BIBLATEX_DEFAULT_MODE = "biblatexMode";
public static final String NAMES_AS_IS = "namesAsIs";
public static final String ENTRY_EDITOR_HEIGHT = "entryEditorHeightFX";
/**
* Holds the horizontal divider position of the preview view when it is shown inside the entry editor
*/
public static final String ENTRY_EDITOR_PREVIEW_DIVIDER_POS = "entryEditorPreviewDividerPos";
public static final String AUTO_RESIZE_MODE = "autoResizeMode";
public static final String WINDOW_MAXIMISED = "windowMaximised";
public static final String WINDOW_FULLSCREEN = "windowFullscreen";
Expand Down Expand Up @@ -602,6 +606,7 @@ private JabRefPreferences() {
defaults.put(WINDOW_FULLSCREEN, Boolean.FALSE);
defaults.put(AUTO_RESIZE_MODE, Boolean.FALSE); // By default disable "Fit table horizontally on the screen"
defaults.put(ENTRY_EDITOR_HEIGHT, 0.65);
defaults.put(ENTRY_EDITOR_PREVIEW_DIVIDER_POS, 0.5);
defaults.put(NAMES_AS_IS, Boolean.FALSE); // "Show names unchanged"
defaults.put(NAMES_FIRST_LAST, Boolean.FALSE); // "Show 'Firstname Lastname'"
defaults.put(NAMES_NATBIB, Boolean.TRUE); // "Natbib style"
Expand Down Expand Up @@ -1488,7 +1493,8 @@ public EntryEditorPreferences getEntryEditorPreferences() {
getBoolean(AUTOLINK_FILES_ENABLED),
EntryEditorPreferences.JournalPopupEnabled.fromString(get(JOURNAL_POPUP)),
getBoolean(SHOW_SCITE_TAB),
getBoolean(SHOW_USER_COMMENTS_FIELDS));
getBoolean(SHOW_USER_COMMENTS_FIELDS),
getDouble(ENTRY_EDITOR_PREVIEW_DIVIDER_POS));

EasyBind.listen(entryEditorPreferences.entryEditorTabs(), (obs, oldValue, newValue) -> storeEntryEditorTabs(newValue));
// defaultEntryEditorTabs are read-only
Expand All @@ -1503,7 +1509,7 @@ public EntryEditorPreferences getEntryEditorPreferences() {
EasyBind.listen(entryEditorPreferences.enableJournalPopupProperty(), (obs, oldValue, newValue) -> put(JOURNAL_POPUP, newValue.toString()));
EasyBind.listen(entryEditorPreferences.shouldShowLSciteTabProperty(), (obs, oldValue, newValue) -> putBoolean(SHOW_SCITE_TAB, newValue));
EasyBind.listen(entryEditorPreferences.showUserCommentsFieldsProperty(), (obs, oldValue, newValue) -> putBoolean(SHOW_USER_COMMENTS_FIELDS, newValue));

EasyBind.listen(entryEditorPreferences.previewWidthDividerPositionProperty(), (obs, oldValue, newValue) -> putDouble(ENTRY_EDITOR_PREVIEW_DIVIDER_POS, newValue.doubleValue()));
return entryEditorPreferences;
}

Expand Down

0 comments on commit fb93c2f

Please sign in to comment.