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

Extract preview panel #12165

Merged
merged 29 commits into from
Nov 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
d9d596e
initial
calixtus Sep 6, 2024
465d61c
Add some code comments
koppor Nov 8, 2024
96a3f69
Merge branch 'main' into extract-preview-panel
koppor Nov 8, 2024
60b5ca1
Fix OpenRewrite
koppor Nov 8, 2024
8663864
Fix checkstyle
koppor Nov 8, 2024
4a70fce
Fix CommentsTabTest
koppor Nov 8, 2024
b1e9044
Merge remote-tracking branch 'origin/main' into extract-preview-panel
koppor Nov 8, 2024
3484d2a
Try to move
koppor Nov 8, 2024
5c793ca
Fix imports
koppor Nov 8, 2024
f558318
WIP
koppor Nov 8, 2024
24f63aa
Add JavaDoc
koppor Nov 8, 2024
be10da9
Add checks for present PreviewPanel
calixtus Nov 8, 2024
89ca91c
Merge branch 'extract-preview-panel' of github.com:JabRef/jabref into…
koppor Nov 8, 2024
d5bb5bd
Fi xsetCurrentlyEditedEntry
koppor Nov 8, 2024
efbfdf3
Fix single tab preview
koppor Nov 8, 2024
66c1d1b
Remove comment
koppor Nov 8, 2024
11a84c9
Remove OffersPreview interface
calixtus Nov 8, 2024
c4ce7d2
Disable setupMainPanel
koppor Nov 8, 2024
c97d979
Remove orphaned constructor and method arguments
calixtus Nov 8, 2024
cb34bd9
WIP
koppor Nov 8, 2024
ec86a45
Merge branch 'extract-preview-panel' of github.com:JabRef/jabref into…
koppor Nov 8, 2024
78dd30f
Set PreviewPanel into a SplitPane to be removable
calixtus Nov 8, 2024
defb822
Add workaround
koppor Nov 8, 2024
681ba8b
Nearly working
koppor Nov 8, 2024
2563dd1
Merge branch 'extract-preview-panel' of github.com:JabRef/jabref into…
koppor Nov 8, 2024
dd8e077
Introduce TabWithPreviewPanel (and final fixes)
koppor Nov 9, 2024
24b612c
Add CHANGELOG.md entry
koppor Nov 9, 2024
c55c644
Remove parameters
koppor Nov 9, 2024
eb073aa
Add JavaDoc comment
koppor Nov 10, 2024
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 @@ -113,6 +113,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
- We fixed an issue where web search preferences "Custom API key" table modifications not discarded. [#11925](https://github.com/JabRef/jabref/issues/11925)
- We fixed an issue when opening attached files in [extra file columns](https://docs.jabref.org/finding-sorting-and-cleaning-entries/filelinks#adding-additional-columns-to-entry-table-for-file-types). [#12005](https://github.com/JabRef/jabref/issues/12005)
- We fixed an issue where trying to open a library from a failed mounted directory on Mac would cause an error. [#10548](https://github.com/JabRef/jabref/issues/10548)
- We fixed an issue when the preview was out of sync. [#9172](https://github.com/JabRef/jabref/issues/9172)
- We fixed an issue where identifier paste couldn't work with Unicode REPLACEMENT CHARACTER. [#11986](https://github.com/JabRef/jabref/issues/11986)

### Removed
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/org/jabref/gui/LibraryTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -589,9 +589,6 @@ public void showAndEdit(BibEntry entry) {
entryEditor.requestFocus();
}

/**
* Removes the bottom component.
*/
public void closeBottomPane() {
mode = PanelMode.MAIN_TABLE;
splitPane.getItems().remove(entryEditor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ public boolean areAllChangesDenied() {

@FXML
private void initialize() {
PreviewViewer previewViewer = new PreviewViewer(database, dialogService, preferences, themeManager, taskExecutor);
PreviewViewer previewViewer = new PreviewViewer(dialogService, preferences, themeManager, taskExecutor);
previewViewer.setDatabaseContext(database);
DatabaseChangeDetailsViewFactory databaseChangeDetailsViewFactory = new DatabaseChangeDetailsViewFactory(database, dialogService, themeManager, preferences, entryTypesManager, previewViewer, taskExecutor);

viewModel = new ExternalChangesResolverViewModel(changes, undoManager);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ public EntryChangeDetailsView(BibEntry oldEntry,
onDisk.getStyleClass().add("lib-change-header");

// we need a copy here as we otherwise would set the same entry twice
PreviewViewer previewClone = new PreviewViewer(databaseContext, dialogService, preferences, themeManager, taskExecutor);
PreviewViewer previewClone = new PreviewViewer(dialogService, preferences, themeManager, taskExecutor);
previewClone.setDatabaseContext(databaseContext);

// The scroll bar used is not part of ScrollPane, but the attached WebView.
WebView previewCloneView = (WebView) previewClone.getContent();
Expand Down
20 changes: 4 additions & 16 deletions src/main/java/org/jabref/gui/entryeditor/CommentsTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,22 @@
import javafx.scene.layout.Priority;
import javafx.scene.layout.RowConstraints;

import org.jabref.gui.DialogService;
import org.jabref.gui.autocompleter.SuggestionProviders;
import org.jabref.gui.fieldeditors.FieldEditorFX;
import org.jabref.gui.fieldeditors.FieldNameLabel;
import org.jabref.gui.fieldeditors.MarkdownEditor;
import org.jabref.gui.icon.IconTheme;
import org.jabref.gui.preferences.GuiPreferences;
import org.jabref.gui.theme.ThemeManager;
import org.jabref.gui.preview.PreviewPanel;
import org.jabref.gui.undo.RedoAction;
import org.jabref.gui.undo.UndoAction;
import org.jabref.gui.util.OptionalObjectProperty;
import org.jabref.logic.journals.JournalAbbreviationRepository;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.util.TaskExecutor;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.field.Field;
import org.jabref.model.entry.field.StandardField;
import org.jabref.model.entry.field.UserSpecificCommentField;
import org.jabref.model.search.query.SearchQuery;

public class CommentsTab extends FieldsEditorTab {
public static final String NAME = "Comments";
Expand All @@ -51,25 +47,17 @@ public CommentsTab(GuiPreferences preferences,
UndoManager undoManager,
UndoAction undoAction,
RedoAction redoAction,
DialogService dialogService,
ThemeManager themeManager,
TaskExecutor taskExecutor,
JournalAbbreviationRepository journalAbbreviationRepository,
OptionalObjectProperty<SearchQuery> searchQueryProperty) {
super(
false,
PreviewPanel previewPanel) {
super(false,
databaseContext,
suggestionProviders,
undoManager,
undoAction,
redoAction,
dialogService,
preferences,
themeManager,
taskExecutor,
journalAbbreviationRepository,
searchQueryProperty
);
previewPanel);
this.defaultOwner = preferences.getOwnerPreferences().getDefaultOwner().toLowerCase(Locale.ROOT).replaceAll("[^a-z0-9]", "-");
setText(Localization.lang("Comments"));
setGraphic(IconTheme.JabRefIcons.COMMENT.getGraphicNode());
Expand Down
23 changes: 13 additions & 10 deletions src/main/java/org/jabref/gui/entryeditor/DeprecatedFieldsTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,20 @@

import javafx.scene.control.Tooltip;

import org.jabref.gui.DialogService;
import org.jabref.gui.autocompleter.SuggestionProviders;
import org.jabref.gui.icon.IconTheme;
import org.jabref.gui.preferences.GuiPreferences;
import org.jabref.gui.theme.ThemeManager;
import org.jabref.gui.preview.PreviewPanel;
import org.jabref.gui.undo.RedoAction;
import org.jabref.gui.undo.UndoAction;
import org.jabref.gui.util.OptionalObjectProperty;
import org.jabref.logic.journals.JournalAbbreviationRepository;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.util.TaskExecutor;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.database.BibDatabaseMode;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.BibEntryType;
import org.jabref.model.entry.BibEntryTypesManager;
import org.jabref.model.entry.field.Field;
import org.jabref.model.search.query.SearchQuery;

import com.tobiasdiez.easybind.EasyBind;

Expand All @@ -40,14 +36,21 @@ public DeprecatedFieldsTab(BibDatabaseContext databaseContext,
UndoManager undoManager,
UndoAction undoAction,
RedoAction redoAction,
DialogService dialogService,
GuiPreferences preferences,
ThemeManager themeManager,
BibEntryTypesManager entryTypesManager,
TaskExecutor taskExecutor,
JournalAbbreviationRepository journalAbbreviationRepository,
OptionalObjectProperty<SearchQuery> searchQueryProperty) {
super(false, databaseContext, suggestionProviders, undoManager, undoAction, redoAction, dialogService, preferences, themeManager, taskExecutor, journalAbbreviationRepository, searchQueryProperty);
PreviewPanel previewPanel) {
super(
false,
databaseContext,
suggestionProviders,
undoManager,
undoAction,
redoAction,
preferences,
journalAbbreviationRepository,
previewPanel
);
this.entryTypesManager = entryTypesManager;

setText(Localization.lang("Deprecated fields"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,15 @@

import javax.swing.undo.UndoManager;

import org.jabref.gui.DialogService;
import org.jabref.gui.autocompleter.SuggestionProviders;
import org.jabref.gui.preferences.GuiPreferences;
import org.jabref.gui.theme.ThemeManager;
import org.jabref.gui.preview.PreviewPanel;
import org.jabref.gui.undo.RedoAction;
import org.jabref.gui.undo.UndoAction;
import org.jabref.gui.util.OptionalObjectProperty;
import org.jabref.logic.journals.JournalAbbreviationRepository;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.util.TaskExecutor;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntryTypesManager;
import org.jabref.model.search.query.SearchQuery;

public class DetailOptionalFieldsTab extends OptionalFieldsTabBase {

Expand All @@ -25,13 +21,10 @@ public DetailOptionalFieldsTab(BibDatabaseContext databaseContext,
UndoManager undoManager,
UndoAction undoAction,
RedoAction redoAction,
DialogService dialogService,
GuiPreferences preferences,
ThemeManager themeManager,
BibEntryTypesManager entryTypesManager,
TaskExecutor taskExecutor,
JournalAbbreviationRepository journalAbbreviationRepository,
OptionalObjectProperty<SearchQuery> searchQueryProperty) {
PreviewPanel previewPanel) {
super(
Localization.lang("Optional fields 2"),
false,
Expand All @@ -40,13 +33,10 @@ public DetailOptionalFieldsTab(BibDatabaseContext databaseContext,
undoManager,
undoAction,
redoAction,
dialogService,
preferences,
themeManager,
entryTypesManager,
taskExecutor,
journalAbbreviationRepository,
searchQueryProperty
previewPanel
);
}
}
61 changes: 39 additions & 22 deletions src/main/java/org/jabref/gui/entryeditor/EntryEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.io.File;
import java.nio.file.Path;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
Expand Down Expand Up @@ -43,6 +42,7 @@
import org.jabref.gui.menus.ChangeEntryTypeMenu;
import org.jabref.gui.mergeentries.FetchAndMergeEntry;
import org.jabref.gui.preferences.GuiPreferences;
import org.jabref.gui.preview.PreviewPanel;
import org.jabref.gui.theme.ThemeManager;
import org.jabref.gui.undo.CountingUndoManager;
import org.jabref.gui.undo.RedoAction;
Expand All @@ -69,6 +69,7 @@
import com.tobiasdiez.easybind.EasyBind;
import com.tobiasdiez.easybind.Subscription;
import jakarta.inject.Inject;
import org.jspecify.annotations.NonNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -91,6 +92,7 @@ public class EntryEditor extends BorderPane {
private final BibDatabaseContext databaseContext;
private final EntryEditorPreferences entryEditorPreferences;
private final ExternalFilesEntryLinker fileLinker;
private final PreviewPanel previewPanel;
private final DirectoryMonitorManager directoryMonitorManager;
private final UndoAction undoAction;
private final RedoAction redoAction;
Expand Down Expand Up @@ -121,7 +123,6 @@ public class EntryEditor extends BorderPane {
@Inject private AiService aiService;

private final List<EntryEditorTab> allPossibleTabs;
private final Collection<OffersPreview> previewTabs;

public EntryEditor(LibraryTab libraryTab, UndoAction undoAction, RedoAction redoAction) {
this.libraryTab = libraryTab;
Expand All @@ -135,14 +136,22 @@ public EntryEditor(LibraryTab libraryTab, UndoAction undoAction, RedoAction redo
.load();

this.entryEditorPreferences = preferences.getEntryEditorPreferences();
this.fileLinker = new ExternalFilesEntryLinker(preferences.getExternalApplicationsPreferences(), preferences.getFilePreferences(), databaseContext, dialogService);
this.fileLinker = new ExternalFilesEntryLinker(preferences.getExternalApplicationsPreferences(), preferences.getFilePreferences(), dialogService, stateManager);
this.previewPanel = new PreviewPanel(
dialogService,
preferences.getKeyBindingRepository(),
preferences,
themeManager,
taskExecutor,
stateManager,
libraryTab.searchQueryProperty());
this.previewPanel.setDatabase(databaseContext);

setupKeyBindings();

this.allPossibleTabs = createTabs();
this.previewTabs = this.allPossibleTabs.stream().filter(OffersPreview.class::isInstance).map(OffersPreview.class::cast).toList();

setupDragAndDrop(libraryTab);
setupDragAndDrop();

EasyBind.subscribe(tabbed.getSelectionModel().selectedItemProperty(), tab -> {
EntryEditorTab activeTab = (EntryEditorTab) tab;
Expand All @@ -155,11 +164,18 @@ public EntryEditor(LibraryTab libraryTab, UndoAction undoAction, RedoAction redo
(obs, oldValue, newValue) -> {
if (currentlyEditedEntry != null) {
adaptVisibleTabs();
Tab tab = tabbed.getSelectionModel().selectedItemProperty().get();
if (newValue && tab instanceof FieldsEditorTab fieldsEditorTab) {
fieldsEditorTab.removePreviewPanelFromThisTab();
}
if (tab instanceof TabWithPreviewPanel previewTab) {
previewTab.handleFocus();
}
}
});
}

private void setupDragAndDrop(LibraryTab libraryTab) {
private void setupDragAndDrop() {
this.setOnDragOver(event -> {
if (event.getDragboard().hasFiles()) {
event.acceptTransferModes(TransferMode.COPY, TransferMode.MOVE, TransferMode.LINK);
Expand Down Expand Up @@ -267,21 +283,21 @@ private void navigateToNextEntry() {
private List<EntryEditorTab> createTabs() {
List<EntryEditorTab> tabs = new LinkedList<>();

tabs.add(new PreviewTab(databaseContext, dialogService, preferences, themeManager, taskExecutor, libraryTab.searchQueryProperty()));
tabs.add(new PreviewTab(databaseContext, preferences, previewPanel));

// Required, optional (important+detail), deprecated, and "other" fields
tabs.add(new RequiredFieldsTab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, undoAction, redoAction, dialogService, preferences, themeManager, bibEntryTypesManager, taskExecutor, journalAbbreviationRepository, libraryTab.searchQueryProperty()));
tabs.add(new ImportantOptionalFieldsTab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, undoAction, redoAction, dialogService, preferences, themeManager, bibEntryTypesManager, taskExecutor, journalAbbreviationRepository, libraryTab.searchQueryProperty()));
tabs.add(new DetailOptionalFieldsTab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, undoAction, redoAction, dialogService, preferences, themeManager, bibEntryTypesManager, taskExecutor, journalAbbreviationRepository, libraryTab.searchQueryProperty()));
tabs.add(new DeprecatedFieldsTab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, undoAction, redoAction, dialogService, preferences, themeManager, bibEntryTypesManager, taskExecutor, journalAbbreviationRepository, libraryTab.searchQueryProperty()));
tabs.add(new OtherFieldsTab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, undoAction, redoAction, dialogService, preferences, themeManager, bibEntryTypesManager, taskExecutor, journalAbbreviationRepository, libraryTab.searchQueryProperty()));
tabs.add(new RequiredFieldsTab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, undoAction, redoAction, preferences, bibEntryTypesManager, journalAbbreviationRepository, previewPanel));
tabs.add(new ImportantOptionalFieldsTab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, undoAction, redoAction, preferences, bibEntryTypesManager, journalAbbreviationRepository, previewPanel));
tabs.add(new DetailOptionalFieldsTab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, undoAction, redoAction, preferences, bibEntryTypesManager, journalAbbreviationRepository, previewPanel));
tabs.add(new DeprecatedFieldsTab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, undoAction, redoAction, preferences, bibEntryTypesManager, journalAbbreviationRepository, previewPanel));
tabs.add(new OtherFieldsTab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, undoAction, redoAction, preferences, bibEntryTypesManager, journalAbbreviationRepository, previewPanel));

// Comment Tab: Tab for general and user-specific comments
tabs.add(new CommentsTab(preferences, databaseContext, libraryTab.getSuggestionProviders(), undoManager, undoAction, redoAction, dialogService, themeManager, taskExecutor, journalAbbreviationRepository, libraryTab.searchQueryProperty()));
tabs.add(new CommentsTab(preferences, databaseContext, libraryTab.getSuggestionProviders(), undoManager, undoAction, redoAction, journalAbbreviationRepository, previewPanel));

Map<String, Set<Field>> entryEditorTabList = getAdditionalUserConfiguredTabs();
for (Map.Entry<String, Set<Field>> tab : entryEditorTabList.entrySet()) {
tabs.add(new UserDefinedFieldsTab(tab.getKey(), tab.getValue(), databaseContext, libraryTab.getSuggestionProviders(), undoManager, undoAction, redoAction, dialogService, preferences, themeManager, taskExecutor, journalAbbreviationRepository, libraryTab.searchQueryProperty()));
tabs.add(new UserDefinedFieldsTab(tab.getKey(), tab.getValue(), databaseContext, libraryTab.getSuggestionProviders(), undoManager, undoAction, redoAction, preferences, journalAbbreviationRepository, previewPanel));
}

tabs.add(new MathSciNetTab());
Expand Down Expand Up @@ -374,8 +390,12 @@ public BibEntry getCurrentlyEditedEntry() {
return currentlyEditedEntry;
}

public void setCurrentlyEditedEntry(BibEntry currentlyEditedEntry) {
this.currentlyEditedEntry = Objects.requireNonNull(currentlyEditedEntry);
public void setCurrentlyEditedEntry(@NonNull BibEntry currentlyEditedEntry) {
if (Objects.equals(this.currentlyEditedEntry, currentlyEditedEntry)) {
return;
}

this.currentlyEditedEntry = currentlyEditedEntry;

// Subscribe to type changes for rebuilding the currently visible tab
if (typeSubscription != null) {
Expand All @@ -385,16 +405,13 @@ public void setCurrentlyEditedEntry(BibEntry currentlyEditedEntry) {
typeSubscription = EasyBind.subscribe(this.currentlyEditedEntry.typeProperty(), type -> {
typeLabel.setText(new TypedBibEntry(currentlyEditedEntry, databaseContext.getMode()).getTypeForDisplay());
adaptVisibleTabs();
setupToolBar();
getSelectedTab().notifyAboutFocus(currentlyEditedEntry);
});

adaptVisibleTabs();
setupToolBar();

if (entryEditorPreferences.showSourceTabByDefault()) {
tabbed.getSelectionModel().select(sourceTab);
}
getSelectedTab().notifyAboutFocus(currentlyEditedEntry);
}

private EntryEditorTab getSelectedTab() {
Expand Down Expand Up @@ -457,10 +474,10 @@ public void setFocusToField(Field field) {
}

public void nextPreviewStyle() {
this.previewTabs.forEach(OffersPreview::nextPreviewStyle);
this.previewPanel.nextPreviewStyle();
}

public void previousPreviewStyle() {
this.previewTabs.forEach(OffersPreview::previousPreviewStyle);
this.previewPanel.previousPreviewStyle();
}
}
Loading