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

Jump to entry key cli (WIP) #659

Closed
wants to merge 12 commits into from

Conversation

u7282852
Copy link

Addresses Issue: #540
Command line now supports option "jumpToEntryKey" or "-j" folowed by one entrykey argument.
Upon start up, jabref will search the imported files for the entrykey and focus this library and select this entry.

However, I am experiencing issues when there are previously opened databases that are not opened through the command line. The last database within the previously opened databases seems to always be the library focused on start up as they seem to run on a different thread or something.

Currently the key is searched only in the imported files specified in the commandline [BIBTEX_FILE] fields. I also request some assistance as to how I can search the previously opened/edited databases as well for the entrykey.

Mandatory checks

  • Change in CHANGELOG.md described in a way that is understandable for the average user (if applicable)
  • Tests created for changes (if applicable)
  • Manually tested changed features in running JabRef (always required)
  • Screenshots added in PR description (for UI changes)
  • Checked developer's documentation: Is the information available and up to date? If not, I outlined it in this pull request.
  • Checked documentation: Is the information available and up to date? If not, I created an issue at https://github.com/JabRef/user-documentation/issues or, even better, I submitted a pull request to the documentation repository.

Copy link
Owner

@koppor koppor left a comment

Choose a reason for hiding this comment

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

Some small comments.

Please include it and submit to the main repo

return;
}
}
LOGGER.error("Could not find given citation key to jump to");
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
LOGGER.error("Could not find given citation key to jump to");
LOGGER.error("Could not find citation key {} to jump to", citationKey);

Here, System.out.println is OK, because it was a CLI which outputs to the console. Please also add the output to the console. -- Maybe, even replace logger completely:

System.out.println("Could not find citation key %0 in any library", citationKey);

See https://devdocs.jabref.org/code-howtos/localization.html for steps for the localiaztion.

@@ -773,6 +777,18 @@ private Optional<ParserResult> fetch(String fetchCommand) {
}
}

private void jumpToEntryKey(List<ParserResult> loaded, String citationKey) {
// search for this key in imported files
Copy link
Owner

Choose a reason for hiding this comment

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

Remove this line, because the for each loop makes it clear somehow.

@@ -288,6 +296,14 @@ private static Options getOptions() {
.argName("CITEKEY1[,CITEKEY2][,CITEKEYn] | PDF1[,PDF2][,PDFn] | all")
.build());

options.addOption(Option
.builder("j")
.longOpt("jumpToEntryKey")
Copy link
Owner

Choose a reason for hiding this comment

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

Rename to jumpToKey. (We use CitationKey throughout JabRef. Sometimes also BibtexKey. Never EntryKey. With key you are on the safe side ^^)

options.addOption(Option
.builder("j")
.longOpt("jumpToEntryKey")
.desc(String.format("%s: '%s'", Localization.lang("Jump to the BibEntry of the given key."), "-j key"))
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
.desc(String.format("%s: '%s'", Localization.lang("Jump to the BibEntry of the given key."), "-j key"))
.desc(String.format("%s: '%s'", Localization.lang("Jump to the entry of the given citation key."), "-j key"))

boolean focusDifferent = false;
Optional<BibEntry> focusedEntry = Optional.empty();
for (ParserResult parserResult : parserResults) {
// Make sure this parser result is its own library instead of imported BibTex entries
Copy link
Owner

Choose a reason for hiding this comment

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

Write "BibTeX" always with capital X

Comment on lines 223 to 224
}
if (parserResult.getEntryToFocus().isPresent() && focusDifferent) {
Copy link
Owner

Choose a reason for hiding this comment

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

Should that be } else if (...?

@koppor
Copy link
Owner

koppor commented Oct 24, 2023

I also request some assistance as to how I can search the previously opened/edited databases as well for the entrykey.

I found org.jabref.gui.JabRefGUI#openLastEditedDatabases, which opens the libraries. Maybe this helps to understand the control flow of opening.

I think, the place could be https://github.com/JabRef/jabref/blob/31f137bcf22c15314f9bc951b694286b34ab2f2f/src/main/java/org/jabref/gui/importer/actions/OpenDatabaseAction.java#L178-L178.

The above LOC also answers the following, doesn't it?

The last database within the previously opened databases seems to always be the library focused on start up as they seem to run on a different thread or something.

@koppor koppor force-pushed the main branch 2 times, most recently from 9799dc4 to d6a0e59 Compare October 27, 2023 01:32
CHANGELOG.md Outdated Show resolved Hide resolved
src/main/java/org/jabref/cli/JabRefCLI.java Outdated Show resolved Hide resolved
src/main/java/org/jabref/gui/LibraryTab.java Outdated Show resolved Hide resolved
@koppor
Copy link
Owner

koppor commented Nov 15, 2023

Follow-up at JabRef#10578. Closing this one. The other PR is the same branch, but more committers can see it!

@koppor koppor closed this Nov 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants