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

Add Ctrl+J to jump to a field #12276

Open
koppor opened this issue Jan 30, 2018 · 22 comments
Open

Add Ctrl+J to jump to a field #12276

koppor opened this issue Jan 30, 2018 · 22 comments
Assignees
Labels
good first issue An issue intended for project-newcomers. Varies in difficulty.

Comments

@koppor
Copy link
Member

koppor commented Jan 30, 2018

I hardly remember where which field is stored in the entry editor. I would like to have Ctrl+J, where i have to type a filed name and then can select the field using the cursor keys and enter. Then, it jumps to the right field editor in the entry editor.

@koppor koppor added the good first issue An issue intended for project-newcomers. Varies in difficulty. label Sep 2, 2019
@koppor
Copy link
Member Author

koppor commented Sep 22, 2021

Refs #6856

@Zea1901
Copy link

Zea1901 commented Oct 12, 2023

Hi, I'm looking to do a few issues for a university project (my first time). Is this still something your looking to do? Thx.

@koppor
Copy link
Member Author

koppor commented Oct 23, 2023

@Zea1901 There is no pull request referencing this issue - and no one assigned. You can still go ahead if time allows.

@atrayees
Copy link

Hello! I just went through the Developer Documentation and the Contribution Guide, and I would like to work on this issue. Could I go ahead? Thanks.

@koppor
Copy link
Member Author

koppor commented Feb 29, 2024

@atrayees Sure, go ahead! Let's see how things turn out. Could be a difficult JavaFX one...

@ThiloteE
Copy link
Member

@atrayees since there has not been any activity, I assume you have dropped the issue. Be aware you can unassign yourself from Github.
image

@anehemya
Copy link

Hello! would it be possible to work on this issue with a group of mine? Thanks!

@ThiloteE
Copy link
Member

ThiloteE commented Oct 9, 2024

As a general advice for newcomers: check out https://github.com/JabRef/jabref/blob/main/CONTRIBUTING.md for a start. Also, https://devdocs.jabref.org/getting-into-the-code/guidelines-for-setting-up-a-local-workspace is worth having a look at. Feel free to ask if you have any questions here on GitHub or also at JabRef's Gitter chat.

Try to open a (draft) pull request early on, so that people can see you are working on the issue and so that they can see the direction the pull request is heading towards. This way, you will likely receive valuable feedback.

@JudeSurin
Copy link

Refs JabRef#6856

Hi, I'm interested in taking on this issue. May I take it?

@ThiloteE
Copy link
Member

ThiloteE commented Oct 9, 2024

@JudeSurin Sure :-) I think this is a very useful feature request!

@JudeSurin
Copy link

entry editor
2 questions:

  1. Where can I find which field is stored in the entry editor?
  2. Is there a link to a discord where I can communicate with the community?

@JudeSurin
Copy link

Important question: I noticed that the Ctrl+ J issue was posted in 2018. I'm curious to ask if Ctrl+ J is assigned a specific function already or is it empty and I can implement the function in the issue?

@JudeSurin
Copy link

This is an updated version of the code that I created with comments. Can you please look through it and supply me with feedback? I intend on making these changes in Launcher.java
Code: package org.jabref.gui;

import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import org.jabref.gui.util.BaseDialog;
import org.jabref.model.entry.BibEntry;

import java.util.List;

public class EntryEditor {

private BibDatabaseContext bibDatabaseContext;
private StateManager stateManager;

@FXML
private void initialize() {
    // Existing initialization code...

    // Add event filter for Ctrl+J
    getScene().addEventFilter(KeyEvent.KEY_PRESSED, event -> {
        if (event.isControlDown() && event.getCode() == KeyCode.J) {
            handleCtrlJ();
            event.consume();
        }
    });
}

private void handleCtrlJ() {
    String fileName = showFileNameInputDialog();
    if (fileName != null && !fileName.isEmpty()) {
        List<BibEntry> matchingEntries = searchEntriesByFileName(fileName);
        if (!matchingEntries.isEmpty()) {
            BibEntry selectedEntry = showSelectionDialog(matchingEntries);
            if (selectedEntry != null) {
                openEntryEditor(selectedEntry);
            }
        } else {
            dialogService.showWarningDialogAndWait("No matching entries", "No entries found matching the file name: " + fileName);
        }
    }
}

private String showFileNameInputDialog() {
    TextInputDialog dialog = new TextInputDialog();
    dialog.setTitle("Jump to Entry");
    dialog.setHeaderText("Enter file name to search for:");
    dialog.setContentText("File name:");
    return dialog.showAndWait().orElse(null);
}

private List<BibEntry> searchEntriesByFileName(String fileName) {
    return bibDatabaseContext.getDatabase().getEntries().stream()
            .filter(entry -> entry.getFiles().stream()
                    .anyMatch(file -> file.getFileName().toLowerCase().contains(fileName.toLowerCase())))
            .collect(Collectors.toList());
}

private BibEntry showSelectionDialog(List<BibEntry> entries) {
    EntrySelectionDialog dialog = new EntrySelectionDialog(entries);
    return dialog.showAndWait().orElse(null);
}

private void openEntryEditor(BibEntry entry) {
    stateManager.setActiveEntry(entry);
    // Logic to open the entry editor and focus on the file field
    // This would depend on how JabRef's UI is structured
}

// Inner class for entry selection dialog
private class EntrySelectionDialog extends BaseDialog<BibEntry> {
    private ListView<BibEntry> entryListView;

    public EntrySelectionDialog(List<BibEntry> entries) {
        this.setTitle("Select Entry");
        this.setHeaderText("Select an entry to jump to:");

        entryListView = new ListView<>(FXCollections.observableArrayList(entries));
        entryListView.setCellFactory(lv -> new ListCell<BibEntry>() {
            @Override
            protected void updateItem(BibEntry entry, boolean empty) {
                super.updateItem(entry, empty);
                if (empty || entry == null) {
                    setText(null);
                } else {
                    setText(entry.getCiteKeyOptional().orElse("") + ": " + entry.getTitle().orElse(""));
                }
            }
        });

        entryListView.setOnKeyPressed(event -> {
            if (event.getCode() == KeyCode.ENTER) {
                setResult(entryListView.getSelectionModel().getSelectedItem());
                close();
            }
        });

        getDialogPane().setContent(entryListView);
        getDialogPane().getButtonTypes().addAll(ButtonType.OK, ButtonType.CANCEL);
    }

    @Override
    protected BibEntry call() throws Exception {
        return entryListView.getSelectionModel().getSelectedItem();
    }
}

}

@koppor
Copy link
Member Author

koppor commented Oct 14, 2024

2 questions:

1. Where can I find which field is stored in the entry editor?

Start code reading at org.jabref.gui.entryeditor.EntryEditor#allPossibleTabs

2. Is there a link to a discord where I can communicate with the community?

We recently updated our contribution page. The link to our gitter chat should be obious: https://github.com/JabRef/jabref/blob/main/CONTRIBUTING.md#contributing

@koppor
Copy link
Member Author

koppor commented Oct 14, 2024

Important question: I noticed that the Ctrl+ J issue was posted in 2018. I'm curious to ask if Ctrl+ J is assigned a specific function already or is it empty and I can implement the function in the issue?

Check org.jabref.gui.keyboard.KeyBinding - no keybinding for Ctlr+J yet.

You could also have checked the preferences:

image

@koppor
Copy link
Member Author

koppor commented Oct 14, 2024

This is an updated version of the code that I created with comments.

I assume you used ChatGPT for that?

Maybe ask it how to contribute to an open source project. A howto is there https://github.com/JabRef/jabref/blob/main/CONTRIBUTING.md#contributing

Please value our time and take this task as opportunity to learn implementing something in a larger project. Becoming a master in coding still takes 10.000 hours. AI can only support you, but not do the complete work for you. See also https://roe.dev/blog/using-ai-in-open-source

@JudeSurin
Copy link

JudeSurin commented Oct 14, 2024 via email

@JudeSurin
Copy link

JudeSurin commented Oct 14, 2024 via email

@JudeSurin
Copy link

Good morning! Quick question: For the Issue, do you mean field or file in this response: "I would like to have Ctrl+J, where i have to type a filed name and then can select the field using the cursor keys and enter." For the issue.
I hardly remember where which field is stored in the entry editor. I would like to have Ctrl+J, where i have to type a filed name and then can select the field using the cursor keys and enter. Then, it jumps to the right field editor in the entry editor.

@koppor
Copy link
Member Author

koppor commented Oct 18, 2024

Good morning! Quick question: For the Issue, do you mean field or file in this response:

"field"

Rephrasing:

Where is the editor for the field "doi"?

image

  1. I press Ctrl+J
  2. A popup appears where I can type in a field name. This text box has automcomplete enabled. It auto completes all fields available in the current (!) entry editor
  3. I press Enter
  4. Poup closes
  5. Entry editor switches tab
  6. Entry editor focues the field

For the example:

  1. I enter doi as field name
  2. Tab general is focussed
  3. Field "DOI" is focussed.

@aleeraudales
Copy link

Refs JabRef#6856

I am working with Jude Surin on this issue if I could also be added to it.

@koppor koppor added 📍 Assigned Assigned by assign-issue-action (or manually assigned) and removed 📍 Assigned Assigned by assign-issue-action (or manually assigned) labels Nov 9, 2024
@koppor
Copy link
Member Author

koppor commented Dec 2, 2024

@aleeraudales and @JudeSurin: Please submit a pull request with your code to https://github.com/jabref/jabref/pulls. It is very hard for us to review code posted as issue comment.

Code hint: Call org.jabref.gui.entryeditor.EntryEditor#setFocusToField to focus a field.

@koppor koppor transferred this issue from JabRef/jabref-koppor Dec 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue An issue intended for project-newcomers. Varies in difficulty.
Projects
Status: Assigned
Development

No branches or pull requests

7 participants