-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
11802: add new KeyBinding for bibliographic data shortcut #11842
base: main
Are you sure you want to change the base?
Changes from all commits
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 |
---|---|---|
@@ -1,15 +1,14 @@ | ||
package org.jabref.gui.fieldeditors.identifier; | ||
|
||
import java.util.Optional; | ||
|
||
import javax.swing.undo.UndoManager; | ||
|
||
import com.airhacks.afterburner.injection.Injector; | ||
import com.airhacks.afterburner.views.ViewLoader; | ||
import jakarta.inject.Inject; | ||
import javafx.fxml.FXML; | ||
import javafx.scene.Parent; | ||
import javafx.scene.control.Button; | ||
import javafx.scene.control.Tooltip; | ||
import javafx.scene.input.KeyEvent; | ||
import javafx.scene.layout.HBox; | ||
|
||
import org.jabref.gui.DialogService; | ||
import org.jabref.gui.StateManager; | ||
import org.jabref.gui.autocompleter.SuggestionProvider; | ||
|
@@ -18,33 +17,40 @@ | |
import org.jabref.gui.fieldeditors.FieldEditorFX; | ||
import org.jabref.gui.fieldeditors.contextmenu.DefaultMenu; | ||
import org.jabref.gui.fieldeditors.contextmenu.EditorMenus; | ||
import org.jabref.gui.keyboard.KeyBinding; | ||
import org.jabref.gui.preferences.GuiPreferences; | ||
import org.jabref.logic.integrity.FieldCheckers; | ||
import org.jabref.logic.l10n.Localization; | ||
import org.jabref.logic.util.TaskExecutor; | ||
import org.jabref.model.entry.BibEntry; | ||
import org.jabref.model.entry.field.Field; | ||
|
||
import com.airhacks.afterburner.injection.Injector; | ||
import com.airhacks.afterburner.views.ViewLoader; | ||
import jakarta.inject.Inject; | ||
import javax.swing.undo.UndoManager; | ||
import java.util.Optional; | ||
|
||
import static org.jabref.model.entry.field.StandardField.DOI; | ||
import static org.jabref.model.entry.field.StandardField.EPRINT; | ||
import static org.jabref.model.entry.field.StandardField.ISBN; | ||
import static org.jabref.model.entry.field.StandardField.*; | ||
|
||
public class IdentifierEditor extends HBox implements FieldEditorFX { | ||
|
||
@FXML private BaseIdentifierEditorViewModel<?> viewModel; | ||
@FXML private EditorTextArea textArea; | ||
@FXML private Button fetchInformationByIdentifierButton; | ||
@FXML private Button lookupIdentifierButton; | ||
|
||
@Inject private DialogService dialogService; | ||
@Inject private TaskExecutor taskExecutor; | ||
@Inject private GuiPreferences preferences; | ||
@Inject private UndoManager undoManager; | ||
@Inject private StateManager stateManager; | ||
@FXML | ||
private BaseIdentifierEditorViewModel<?> viewModel; | ||
@FXML | ||
private EditorTextArea textArea; | ||
@FXML | ||
private Button fetchInformationByIdentifierButton; | ||
@FXML | ||
private Button lookupIdentifierButton; | ||
|
||
@Inject | ||
private DialogService dialogService; | ||
@Inject | ||
private TaskExecutor taskExecutor; | ||
@Inject | ||
private GuiPreferences preferences; | ||
@Inject | ||
private UndoManager undoManager; | ||
@Inject | ||
private StateManager stateManager; | ||
Comment on lines
+35
to
+53
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please do not reformat the code. All JabRef code should be consistently formatted. Check our guidelines for setting up a workspace. With that configuration, this should not happen. |
||
|
||
private Optional<BibEntry> entry = Optional.empty(); | ||
|
||
|
@@ -56,6 +62,9 @@ public IdentifierEditor(Field field, | |
// but we need the injected vars to create the viewmodels. | ||
Injector.registerExistingAndInject(this); | ||
|
||
initKeyBindings(); | ||
|
||
|
||
Comment on lines
+66
to
+67
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No double empty lines. |
||
switch (field) { | ||
case DOI -> | ||
this.viewModel = new DoiIdentifierEditorViewModel(suggestionProvider, fieldCheckers, dialogService, taskExecutor, preferences, undoManager, stateManager); | ||
|
@@ -71,8 +80,8 @@ public IdentifierEditor(Field field, | |
} | ||
|
||
ViewLoader.view(this) | ||
.root(this) | ||
.load(); | ||
.root(this) | ||
.load(); | ||
Comment on lines
-74
to
+84
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please no code reformatting |
||
|
||
textArea.textProperty().bindBidirectional(viewModel.textProperty()); | ||
|
||
|
@@ -90,6 +99,15 @@ public IdentifierEditor(Field field, | |
new EditorValidator(preferences).configureValidation(viewModel.getFieldValidator().getValidationStatus(), textArea); | ||
} | ||
|
||
private void initKeyBindings() { | ||
addEventFilter(KeyEvent.KEY_PRESSED, event -> { | ||
Optional<KeyBinding> keyBinding = preferences.getKeyBindingRepository().mapToKeyBinding(event); | ||
if (keyBinding.isPresent() && keyBinding.get() == KeyBinding.GET_BIBLIOGRAPHIC_DATA) { | ||
this.fetchInformationByIdentifier(); | ||
} | ||
}); | ||
Comment on lines
+103
to
+108
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This feels wrong. All other keybindings work differently. You already correctly added it into There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @koppor Just because I couldnt get it to work with org.jabref.gui.actions.ActionFactory#configureIconButton (locally). When i have following modal open: and press F1, nothing happens. Then i stumpled upon org.jabref.gui.frame.JabRefFrame#initKeyBindings And then I copied that code and at least i now i have the wanted behavior. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It sounds like the keyevent is consumed before reaching the Dialog... Maybe you can try to follow the keyevent? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The event doesnt Seem to be Consumed. But there are also buttons that work that way, like: I Suspect that it matters where The Button is mounted. But this for sure seems like a bug (in JabRef) to me, could some try to reproduced it to verify? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have a mac and there the KeyEvent is always going through the top menu, so F1 always triggers the "online help" menu item and thus opens the default help page. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll reset the branch and, try again. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The only hint I currently have is that one should try with a minimal JavaFX app. Maybe https://github.com/Siedlerchr/javafxreproducer? |
||
} | ||
|
||
public BaseIdentifierEditorViewModel<?> getViewModel() { | ||
return viewModel; | ||
} | ||
|
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 fix checkstyle: space messing