Skip to content
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

Fixed preview not showing issue for an entry properly #4813

Closed
wants to merge 1 commit into from
Closed
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
22 changes: 22 additions & 0 deletions src/main/java/org/jabref/gui/BasePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ public BasePanel(JabRefFrame frame, BasePanelPreferences preferences, BibDatabas
setupMainPanel();

setupActions();
setPreviewOn(true);
Copy link
Member

Choose a reason for hiding this comment

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

Now the preview is always shown?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes at the beginning only the preference is set to be true but it's not shown until a row is pressed. As per previous logic, the preview entry in menu is ticked when the program loads but it does not show any preview even a row is clicked.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@tobiasdiez Any specific ideas about this?


this.getDatabase().registerListener(new SearchListener());
this.getDatabase().registerListener(new EntryRemovedListener());
Expand Down Expand Up @@ -702,6 +703,7 @@ private void createMainTable() {
.ifPresent(entry -> {
preview.setEntry(entry);
entryEditor.setEntry(entry);
setPreviewAction();
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand this change. Here we react to the user selecting a different entry. For me it is not clear why we need to show or hide the preview in this case (if it already shown, then we don't need to show it; and if it was not shown then it also shouldn't be shown just because the user selects a different entry).

Can you please explain the reason for this change. Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

`private void setPreviewAction() {
PreviewPreferences previewPreferences = Globals.prefs.getPreviewPreferences();
boolean enabled = previewPreferences.isPreviewPanelEnabled();
PreviewPreferences newPreviewPreferences = previewPreferences.getBuilder()
.withPreviewPanelEnabled(enabled)
.build();
Globals.prefs.storePreviewPreferences(newPreviewPreferences);
setPreviewActive(enabled);
}

It gets the current value of whether the preview panel is enabled or disabled. And if enabled the preview is shown. the setPreviewActive(enabled); method call is the part which is responsible for showing the preview and the panel in the UI (previous logic)

` private void setPreviewOn(Boolean previewOn) {
PreviewPreferences previewPreferences = Globals.prefs.getPreviewPreferences();
PreviewPreferences newPreviewPreferences = previewPreferences.getBuilder()
.withPreviewPanelEnabled(previewOn)
.build();
Globals.prefs.storePreviewPreferences(newPreviewPreferences);

}`

This method only sets the panel to be enabled. But it's not yet shown in the UI. since setPreviewActive(enabled); is not called in this method.

Thus;

At the beginning by calling setPreviewOn() method enables the preview panel (Not shown in the UI) and the when a row is clicked setPreviewAction() method is called and based on whether the panel is active or not (Panel can be disabled by clicking on the menu item) the preview is shown or not.

}));

// TODO: Register these actions globally
Expand Down Expand Up @@ -1411,4 +1413,24 @@ public void action() {
preview.print();
}
}

private void setPreviewAction() {
PreviewPreferences previewPreferences = Globals.prefs.getPreviewPreferences();
boolean enabled = previewPreferences.isPreviewPanelEnabled();
PreviewPreferences newPreviewPreferences = previewPreferences.getBuilder()
.withPreviewPanelEnabled(enabled)
.build();
Globals.prefs.storePreviewPreferences(newPreviewPreferences);
setPreviewActive(enabled);
}

private void setPreviewOn(Boolean previewOn) {
PreviewPreferences previewPreferences = Globals.prefs.getPreviewPreferences();
PreviewPreferences newPreviewPreferences = previewPreferences.getBuilder()
.withPreviewPanelEnabled(previewOn)
.build();
Globals.prefs.storePreviewPreferences(newPreviewPreferences);

}

}