Repository navigation
Reintroduce custom entry editor tabs with two-column preferences UI #16598
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c73cf0c
Reintroduce custom entry editor tabs with two-column preferences UI
koppor 1fd291d
Keep duplicate-named custom tabs when applying stored tab order
koppor 5e36f52
Unregister entry listener when field tabs are disposed
koppor 2ba2dda
Coalesce deferred refreshes of user-defined field tabs
koppor cd6be73
Revert unrelated doc comment reindentation
koppor 83dd678
Fix CHANGELOG link style (heylogs dot-space-link-style)
koppor 8aa9264
Store custom entry editor tabs as JSON map in a single preference key
koppor 1f49523
Move old custom-tab format handling into PreferencesMigrations
koppor 3ab7e3d
Keep custom-tab preference key private to JabRefGuiPreferences
koppor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
jabgui/src/main/java/org/jabref/gui/entryeditor/UserDefinedFieldsTab.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| package org.jabref.gui.entryeditor; | ||
|
|
||
| import java.util.Optional; | ||
| import java.util.SequencedSet; | ||
| import java.util.concurrent.atomic.AtomicBoolean; | ||
|
|
||
| import javax.swing.undo.UndoManager; | ||
|
|
||
| import javafx.application.Platform; | ||
| import javafx.beans.property.BooleanProperty; | ||
| import javafx.beans.property.SimpleBooleanProperty; | ||
|
|
||
| import org.jabref.gui.StateManager; | ||
| import org.jabref.gui.icon.IconTheme; | ||
| import org.jabref.gui.preferences.GuiPreferences; | ||
| import org.jabref.gui.preview.PreviewPanel; | ||
| import org.jabref.gui.undo.RedoAction; | ||
| import org.jabref.gui.undo.UndoAction; | ||
| import org.jabref.logic.journals.JournalAbbreviationRepository; | ||
| import org.jabref.model.database.BibDatabaseContext; | ||
| import org.jabref.model.entry.BibEntry; | ||
| import org.jabref.model.entry.event.FieldChangedEvent; | ||
| import org.jabref.model.entry.field.Field; | ||
|
|
||
| import com.google.common.eventbus.Subscribe; | ||
| import com.tobiasdiez.easybind.EasyBind; | ||
| import org.jspecify.annotations.NullMarked; | ||
|
|
||
| /// A user-defined tab showing the fields resolved from a [EntryEditorTabModel.CustomizedFieldsTab] | ||
| /// (configured in the entry editor preferences). | ||
| @NullMarked | ||
| public class UserDefinedFieldsTab extends FieldsEditorTab { | ||
|
|
||
| private final EntryEditorTabModel.CustomizedFieldsTab model; | ||
|
|
||
| /// Replaces the base class's content-driven visibility: a regex pattern's matches change when fields | ||
| /// are set or cleared on the *same* entry (e.g. from the Main or Source tab), which the base class's | ||
| /// entry-switch-only evaluation would miss. | ||
| private final BooleanProperty hasResolvedFields = new SimpleBooleanProperty(); | ||
|
|
||
| /// The entry whose event bus this tab is subscribed to, for live refresh of regex-captured fields. | ||
| private Optional<BibEntry> subscribedEntry = Optional.empty(); | ||
|
|
||
| /// Set while a refresh is queued on the FX thread (events may arrive from background threads, | ||
| /// e.g. fetchers), so bursts of field changes coalesce into one refresh instead of one each. | ||
| private final AtomicBoolean refreshQueued = new AtomicBoolean(); | ||
|
|
||
| public UserDefinedFieldsTab(EntryEditorTabModel.CustomizedFieldsTab model, | ||
| UndoManager undoManager, | ||
| UndoAction undoAction, | ||
| RedoAction redoAction, | ||
| GuiPreferences preferences, | ||
| JournalAbbreviationRepository journalAbbreviationRepository, | ||
| StateManager stateManager, | ||
| PreviewPanel previewPanel) { | ||
| super( | ||
| false, | ||
| undoManager, | ||
| undoAction, | ||
| redoAction, | ||
| preferences, | ||
| journalAbbreviationRepository, | ||
| stateManager, | ||
| previewPanel); | ||
|
|
||
| this.model = model; | ||
|
|
||
| setContentDrivenVisibility(hasResolvedFields); | ||
| EasyBind.subscribe(currentEntryProperty(), entry -> | ||
| hasResolvedFields.set((entry != null) && !model.resolveFields(entry).isEmpty())); | ||
|
|
||
| setText(model.name()); | ||
| setGraphic(IconTheme.JabRefIcons.OPTIONAL.getGraphicNode()); | ||
| } | ||
|
|
||
| @Override | ||
| protected SequencedSet<Field> determineFieldsToShow(BibEntry entry) { | ||
| return model.resolveFields(entry); | ||
| } | ||
|
|
||
| @Override | ||
| protected void bindToEntry(BibEntry entry) { | ||
| if (subscribedEntry.filter(current -> current == entry).isEmpty()) { | ||
| subscribedEntry.ifPresent(previous -> previous.unregisterListener(this)); | ||
| entry.registerListener(this); | ||
| subscribedEntry = Optional.of(entry); | ||
| } | ||
| super.bindToEntry(entry); | ||
| } | ||
|
|
||
| @Override | ||
| protected void dispose() { | ||
| // The entry's event bus holds listeners strongly; without unregistering, a discarded tab | ||
| // instance would be retained (and keep reacting) for as long as the entry lives. | ||
| subscribedEntry.ifPresent(entry -> entry.unregisterListener(this)); | ||
| subscribedEntry = Optional.empty(); | ||
| super.dispose(); | ||
| } | ||
|
|
||
| /// Refreshes the tab when a field is set or cleared from outside (Main tab, Source tab, fetchers, | ||
| /// undo, β¦), since that can change which fields a regex pattern captures. Event bursts coalesce | ||
| /// into a single deferred refresh, and the refresh reads the entry's state at callback time (the | ||
| /// event's payload is deliberately ignored), so a queued callback can never apply stale state. | ||
| /// Rebuilds only when the resolved field set actually changes, so typing inside this tab's | ||
| /// editors never steals focus. | ||
| @Subscribe | ||
| public void listen(FieldChangedEvent event) { | ||
| if (refreshQueued.getAndSet(true)) { | ||
| return; | ||
| } | ||
| Platform.runLater(() -> { | ||
| // Cleared before refreshing: an event arriving while we refresh must queue a new callback. | ||
| refreshQueued.set(false); | ||
| BibEntry entry = getCurrentEntry(); | ||
| if (entry == null) { | ||
| return; | ||
|
qodo-free-for-open-source-projects[bot] marked this conversation as resolved.
|
||
| } | ||
| SequencedSet<Field> target = determineFieldsToShow(entry); | ||
| hasResolvedFields.set(!target.isEmpty()); | ||
| if ((gridPane != null) && !target.equals(editors.keySet())) { | ||
| setupPanel(stateManager.getActiveDatabase().orElse(new BibDatabaseContext()), entry, false); | ||
| } | ||
| }); | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.