-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Feat/field jumping 12276 #14120
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
base: main
Are you sure you want to change the base?
Feat/field jumping 12276 #14120
Changes from 11 commits
3f5ce74
383e22f
cf9cdc7
fbda3f4
0755740
84529b8
848ff0b
fb5f482
d188809
ae000fc
ff0e43f
fc798a2
60c494b
d5c4405
0dffbf0
57da947
27e03f6
fbcb65a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -171,15 +171,11 @@ public EntryEditor(Supplier<LibraryTab> tabSupplier, UndoAction undoAction, Redo | |
| }); | ||
|
|
||
| stateManager.getSelectedEntries().addListener((InvalidationListener) _ -> { | ||
| if (stateManager.getSelectedEntries().isEmpty()) { | ||
| // [impl->req~entry-editor.keep-showing~1] | ||
| // No change in the entry editor | ||
| // We allow users to edit the "old" entry | ||
| } else { | ||
| setCurrentlyEditedEntry(stateManager.getSelectedEntries().getFirst()); | ||
| } | ||
| } | ||
| ); | ||
| if (!stateManager.getSelectedEntries().isEmpty()) { | ||
| setCurrentlyEditedEntry(stateManager.getSelectedEntries().getFirst()); | ||
| Platform.runLater(() -> tabbed.requestFocus()); | ||
|
||
| } | ||
| }); | ||
|
|
||
| EasyBind.listen(preferences.getPreviewPreferences().showPreviewAsExtraTabProperty(), | ||
| (_, _, newValue) -> { | ||
|
|
@@ -261,13 +257,25 @@ private void setupKeyBindings() { | |
| close(); | ||
| event.consume(); | ||
| break; | ||
| case JUMP_TO_FIELD: | ||
| showJumpToFieldDialog(); | ||
| event.consume(); | ||
| break; | ||
|
||
| default: | ||
| // Pass other keys to parent | ||
| } | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| private void showJumpToFieldDialog() { | ||
| if (getCurrentlyEditedEntry() == null) { | ||
| return; | ||
| } | ||
| JumpToFieldDialog dialog = new JumpToFieldDialog(this); | ||
| dialog.showAndWait(); | ||
| } | ||
|
|
||
| @FXML | ||
| private void close() { | ||
| stateManager.getEditorShowing().set(false); | ||
|
|
@@ -420,6 +428,10 @@ public BibEntry getCurrentlyEditedEntry() { | |
| return currentlyEditedEntry; | ||
| } | ||
|
|
||
| public List<EntryEditorTab> getAllPossibleTabs() { | ||
| return allPossibleTabs; | ||
| } | ||
|
|
||
| public void setCurrentlyEditedEntry(@NonNull BibEntry currentlyEditedEntry) { | ||
| if (Objects.equals(this.currentlyEditedEntry, currentlyEditedEntry)) { | ||
| return; | ||
|
|
@@ -434,15 +446,26 @@ public void setCurrentlyEditedEntry(@NonNull BibEntry currentlyEditedEntry) { | |
| } | ||
|
|
||
| typeSubscription = EasyBind.subscribe(this.currentlyEditedEntry.typeProperty(), _ -> { | ||
| typeLabel.setText(new TypedBibEntry(currentlyEditedEntry, tabSupplier.get().getBibDatabaseContext().getMode()).getTypeForDisplay()); | ||
| typeLabel.setText(new TypedBibEntry(this.currentlyEditedEntry, tabSupplier.get().getBibDatabaseContext().getMode()).getTypeForDisplay()); | ||
| adaptVisibleTabs(); | ||
| setupToolBar(); | ||
| getSelectedTab().notifyAboutFocus(currentlyEditedEntry); | ||
| getSelectedTab().notifyAboutFocus(this.currentlyEditedEntry); | ||
| }); | ||
|
|
||
| typeLabel.setText(new TypedBibEntry(currentlyEditedEntry, tabSupplier.get().getBibDatabaseContext().getMode()).getTypeForDisplay()); | ||
|
|
||
| adaptVisibleTabs(); | ||
|
|
||
| setupToolBar(); | ||
|
|
||
| if (preferences.getEntryEditorPreferences().showSourceTabByDefault()) { | ||
| tabbed.getSelectionModel().select(sourceTab); | ||
| } | ||
|
|
||
| EntryEditorTab selectedTab = getSelectedTab(); | ||
| if (selectedTab != null) { | ||
| Platform.runLater(() -> selectedTab.notifyAboutFocus(currentlyEditedEntry)); | ||
| } | ||
| } | ||
|
|
||
| private EntryEditorTab getSelectedTab() { | ||
|
|
@@ -492,6 +515,10 @@ private void fetchAndMerge(EntryBasedFetcher fetcher) { | |
| new FetchAndMergeEntry(tabSupplier.get().getBibDatabaseContext(), taskExecutor, preferences, dialogService, undoManager).fetchAndMerge(currentlyEditedEntry, fetcher); | ||
| } | ||
|
|
||
| public void jumpToField(String fieldName) { | ||
| setFocusToField(org.jabref.model.entry.field.FieldFactory.parseField(fieldName)); | ||
| } | ||
|
|
||
| public void setFocusToField(Field field) { | ||
| UiTaskExecutor.runInJavaFXThread(() -> { | ||
| Field actualField = field; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| package org.jabref.gui.entryeditor; | ||
|
|
||
| import javafx.application.Platform; | ||
| import javafx.fxml.FXML; | ||
| import javafx.scene.control.Button; | ||
| import javafx.scene.control.ButtonType; | ||
| import javafx.scene.control.TextField; | ||
|
|
||
| import org.jabref.gui.util.BaseDialog; | ||
| import org.jabref.logic.l10n.Localization; | ||
|
|
||
| import com.airhacks.afterburner.views.ViewLoader; | ||
| import org.controlsfx.control.textfield.TextFields; | ||
|
|
||
| public class JumpToFieldDialog extends BaseDialog<Void> { | ||
| @FXML private TextField searchField; | ||
| private final EntryEditor entryEditor; | ||
| private JumpToFieldViewModel viewModel; | ||
|
|
||
| public JumpToFieldDialog(EntryEditor entryEditor) { | ||
| this.entryEditor = entryEditor; | ||
| this.setTitle(Localization.lang("Jump to field")); | ||
|
|
||
| ViewLoader.view(this) | ||
| .load() | ||
| .setAsDialogPane(this); | ||
|
|
||
| this.getDialogPane().getButtonTypes().setAll(ButtonType.OK, ButtonType.CANCEL); | ||
|
|
||
| this.setResultConverter(button -> { | ||
| if (button == ButtonType.OK) { | ||
| jumpToSelectedField(); | ||
| } | ||
| return null; | ||
| }); | ||
|
|
||
| Platform.runLater(() -> searchField.requestFocus()); | ||
| } | ||
|
|
||
| @FXML | ||
| private void initialize() { | ||
| viewModel = new JumpToFieldViewModel(this.entryEditor); | ||
| searchField.textProperty().bindBidirectional(viewModel.searchTextProperty()); | ||
| TextFields.bindAutoCompletion(searchField, viewModel.getFieldNames()); | ||
|
|
||
| searchField.setOnAction(event -> { | ||
| Button okButton = (Button) getDialogPane().lookupButton(ButtonType.OK); | ||
| if (okButton != null) { | ||
| okButton.fire(); | ||
| } | ||
| event.consume(); | ||
| }); | ||
| } | ||
|
|
||
| private void jumpToSelectedField() { | ||
| String selectedField = searchField.getText(); | ||
|
|
||
| if (selectedField != null && !selectedField.isEmpty()) { | ||
| String fieldToJumpTo = selectedField.toLowerCase(); | ||
| entryEditor.jumpToField(fieldToJumpTo); | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| package org.jabref.gui.entryeditor; | ||
|
|
||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| import javafx.beans.property.SimpleStringProperty; | ||
| import javafx.beans.property.StringProperty; | ||
|
|
||
| import org.jabref.gui.AbstractViewModel; | ||
| import org.jabref.model.entry.field.Field; | ||
|
|
||
| public class JumpToFieldViewModel extends AbstractViewModel { | ||
|
|
||
| private final StringProperty searchText = new SimpleStringProperty(""); | ||
| private final EntryEditor entryEditor; | ||
|
|
||
| public JumpToFieldViewModel(EntryEditor entryEditor) { | ||
| this.entryEditor = entryEditor; | ||
| } | ||
|
|
||
| public StringProperty searchTextProperty() { | ||
| return searchText; | ||
| } | ||
|
|
||
| public List<String> getFieldNames() { | ||
| if (entryEditor.getCurrentlyEditedEntry() == null) { | ||
| return Collections.emptyList(); | ||
| } | ||
|
|
||
| List<String> fieldNames = entryEditor.getAllPossibleTabs().stream() | ||
| .filter(FieldsEditorTab.class::isInstance) | ||
| .map(FieldsEditorTab.class::cast) | ||
| .flatMap(tab -> tab.getShownFields().stream()) | ||
| .map(Field::getName) | ||
| .distinct() | ||
| .sorted() | ||
| .collect(Collectors.toList()); | ||
| return fieldNames; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
|
|
||
| <?import javafx.scene.control.DialogPane?> | ||
| <?import javafx.scene.control.TextField?> | ||
| <?import javafx.scene.layout.VBox?> | ||
|
|
||
| <DialogPane prefWidth="300" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" | ||
| fx:controller="org.jabref.gui.entryeditor.JumpToFieldDialog"> | ||
| <content> | ||
| <VBox> | ||
| <TextField fx:id="searchField" promptText="%Type a field name"/> | ||
| </VBox> | ||
| </content> | ||
| </DialogPane> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,9 @@ record BlankWorkspace() implements UiCommand { | |
| record JumpToEntryKey(String citationKey) implements UiCommand { | ||
| } | ||
|
|
||
| record JumpToField() implements UiCommand { | ||
| } | ||
|
|
||
|
||
| record OpenLibraries(List<Path> toImport) implements UiCommand { | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please keep this as it referes to implementation spec