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

Pressing "tab" when last textField of entry editor Tab is in focus will move to the next Tab. #12087

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv

### Added

- We added a way to navigate through Tabs in Entry Editor by pressing "tab" when the last TextField of a Tab is in focus. [#11937](https://github.com/JabRef/jabref/issues/11937)
- We added a "view as BibTeX" option before importing an entry from the citation relation tab. [#11826](https://github.com/JabRef/jabref/issues/11826)
- We added probable search hits instead of exact matches. Sorting by hit score can be done by the new score table column. [#11542](https://github.com/JabRef/jabref/pull/11542)
- We added support finding LaTeX-encoded special characters based on plain Unicode and vice versa. [#11542](https://github.com/JabRef/jabref/pull/11542)
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/org/jabref/gui/entryeditor/EntryEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import javafx.scene.control.MenuItem;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.scene.control.TextField;
import javafx.scene.input.DataFormat;
import javafx.scene.input.KeyEvent;
import javafx.scene.input.TransferMode;
Expand All @@ -36,6 +37,7 @@
import org.jabref.gui.entryeditor.fileannotationtab.FileAnnotationTab;
import org.jabref.gui.entryeditor.fileannotationtab.FulltextSearchResultsTab;
import org.jabref.gui.externalfiles.ExternalFilesEntryLinker;
import org.jabref.gui.fieldeditors.EditorTextField;
import org.jabref.gui.help.HelpAction;
import org.jabref.gui.importer.GrobidOptInDialogHelper;
import org.jabref.gui.keyboard.KeyBinding;
Expand Down Expand Up @@ -142,6 +144,7 @@ public EntryEditor(LibraryTab libraryTab, UndoAction undoAction, RedoAction redo
this.previewTabs = this.allPossibleTabs.stream().filter(OffersPreview.class::isInstance).map(OffersPreview.class::cast).toList();

setupDragAndDrop(libraryTab);
EditorTextField.entryContext(tabbed);

EasyBind.subscribe(tabbed.getSelectionModel().selectedItemProperty(), tab -> {
EntryEditorTab activeTab = (EntryEditorTab) tab;
Expand Down Expand Up @@ -472,4 +475,20 @@ public void nextPreviewStyle() {
public void previousPreviewStyle() {
this.previewTabs.forEach(OffersPreview::previousPreviewStyle);
}

public static boolean checkLastTextField(TabPane tabs, TextField textField) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please make this non-static.

Copy link
Author

Choose a reason for hiding this comment

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

Hey,
Sorry, I'm not sure how. I believe I can make checkLastTextField non-static and use the tabbed TabPane in the EntryEditor instead. But in doing this, I would need to create a new instance of EntryEditor in EditorTextField which will require the following arguments: EntryEditor(LibraryTab libraryTab, UndoAction undoAction, RedoAction redoAction). -> which I'm not sure how to get from EditorTextField.
Please guide me how I could do this.
Thankyou!

Copy link
Member

Choose a reason for hiding this comment

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

Why would you need a new instance of an entry editor? We only have one.
How about this?

Copy link
Author

@Noah-Martin1 Noah-Martin1 Oct 26, 2024

Choose a reason for hiding this comment

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

If im calling the non-static method checkLastTextField that's in EntryEditor, that uses private TabPane tabbed from EditorTextField. It requires me to create a new instance of EntryEditor in EditorTextField. I believe
Screenshot 2024-10-26 at 11 56 59 pm

Copy link
Member

Choose a reason for hiding this comment

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

If you create a new instance of an EntryEditor your changes would not affect the one we are displaying. There is only one EntryEditor. You probably have to inject a reference to the object you need.
But I believe there is a more serious architectural flaw, if you are trying to get a reference to to the big container node.
Why would you need the entry editor? Why would you need the TabbedPane? And what exactly do you need from the TabbedPane?

Copy link
Member

@calixtus calixtus Oct 26, 2024

Choose a reason for hiding this comment

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

You can 'inject' a method selectNextTab or sthg as a functional interface if really necessary.

Copy link
Author

Choose a reason for hiding this comment

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

I need the TabPane to get the last Field of a tab and to select the next Tab

FieldsEditorTab currentTab = (FieldsEditorTab) tabs.getSelectionModel().getSelectedItem();
Collection<Field> shownFields = currentTab.getShownFields();
Field lastField = null;
for (Field field : shownFields) {
lastField = field;
}
if (textField != null && lastField != null) {
if (textField.getId() == null) {
Comment on lines +482 to +487
Copy link
Collaborator

Choose a reason for hiding this comment

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

Pease use Optionals in place of nulls.

return false;
}
return lastField.getDisplayName().equalsIgnoreCase(textField.getId());
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public CitationKeyEditor(Field field,
undoManager,
dialogService);

textField.setId(field.getDisplayName());
establishBinding(textField, viewModel.textProperty(), keyBindingRepository, undoAction, redoAction);
textField.initContextMenu(Collections::emptyList, keyBindingRepository);
new EditorValidator(preferences).configureValidation(viewModel.getFieldValidator().getValidationStatus(), textField);
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/org/jabref/gui/fieldeditors/EditorTextField.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,34 @@
import javafx.fxml.Initializable;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.MenuItem;
import javafx.scene.control.TabPane;
import javafx.scene.control.TextField;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;

import org.jabref.gui.ClipBoardManager;
import org.jabref.gui.entryeditor.EntryEditor;
import org.jabref.gui.fieldeditors.contextmenu.EditorContextAction;
import org.jabref.gui.keyboard.KeyBindingRepository;

public class EditorTextField extends TextField implements Initializable, ContextMenuAddable {

public static TabPane tabs;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please make it non-static.

private final ContextMenu contextMenu = new ContextMenu();
private Runnable additionalPasteActionHandler = () -> {
// No additional paste behavior
};

public EditorTextField() {
this("");
this.addEventFilter(KeyEvent.KEY_PRESSED, event -> {
String keyText = event.getText();
if ("\t".equals(keyText) && EntryEditor.checkLastTextField(tabs, this)) {
tabs.getSelectionModel().selectNext();
event.consume();
}
});
}

public EditorTextField(final String text) {
Expand All @@ -38,6 +49,10 @@ public EditorTextField(final String text) {
ClipBoardManager.addX11Support(this);
}

public static void entryContext(TabPane tab) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Non-static.

tabs = tab;
}

@Override
public void initContextMenu(final Supplier<List<MenuItem>> items, KeyBindingRepository keyBindingRepository) {
setOnContextMenuRequested(event -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public MarkdownEditor(Field field, SuggestionProvider<?> suggestionProvider, Fie
}

@Override
protected TextInputControl createTextInputControl() {
protected TextInputControl createTextInputControl(Field field) {
return new EditorTextArea() {
@Override
public void paste() {
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/org/jabref/gui/fieldeditors/PersonsEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ public PersonsEditor(final Field field,
KeyBindingRepository keyBindingRepository = preferences.getKeyBindingRepository();

this.viewModel = new PersonsEditorViewModel(field, suggestionProvider, preferences.getAutoCompletePreferences(), fieldCheckers, undoManager);
textInput = isMultiLine ? new EditorTextArea() : new EditorTextField();
textInput = isMultiLine
? new EditorTextArea()
: new EditorTextField();

textInput.setId(field.getName());
decoratedStringProperty = new UiThreadStringProperty(viewModel.textProperty());
establishBinding(textInput, decoratedStringProperty, keyBindingRepository, undoAction, redoAction);
((ContextMenuAddable) textInput).initContextMenu(EditorMenus.getNameMenu(textInput), keyBindingRepository);
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/org/jabref/gui/fieldeditors/SimpleEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public SimpleEditor(final Field field,
this.viewModel = new SimpleEditorViewModel(field, suggestionProvider, fieldCheckers, undoManager);
this.isMultiLine = isMultiLine;

textInput = createTextInputControl();
textInput = createTextInputControl(field);
HBox.setHgrow(textInput, Priority.ALWAYS);

establishBinding(textInput, viewModel.textProperty(), preferences.getKeyBindingRepository(), undoAction, redoAction);
Expand All @@ -54,8 +54,10 @@ public SimpleEditor(final Field field,
new EditorValidator(preferences).configureValidation(viewModel.getFieldValidator().getValidationStatus(), textInput);
}

protected TextInputControl createTextInputControl() {
return isMultiLine ? new EditorTextArea() : new EditorTextField();
protected TextInputControl createTextInputControl(Field field) {
TextInputControl inputControl = isMultiLine ? new EditorTextArea() : new EditorTextField();
inputControl.setId(field.getName());
return inputControl;
}

@Override
Expand Down
Loading