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
Closed
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
- We added a fetcher for [LOBID](https://lobid.org/resources/api) resources. [koppor#386](https://github.com/koppor/jabref/issues/386)
- When in `biblatex` mode, the [integrity check](https://docs.jabref.org/finding-sorting-and-cleaning-entries/checkintegrity) for journal titles now also checks the field `journal`.
- We added support for pushing citations to [TeXShop](https://pages.uoregon.edu/koch/texshop/) on macOS [forum#2699](https://discourse.jabref.org/t/push-to-texshop-mac/2699).
- We added ability to jump to an entry in the command line using -j CITATIONKEY [BIBTEXFILES]. [koppor#540](https://github.com/koppor/jabref/issues/540)
u7282852 marked this conversation as resolved.
Show resolved Hide resolved

### Changed

Expand Down
9 changes: 4 additions & 5 deletions src/main/java/org/jabref/cli/ArgumentProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,8 @@ public void processArguments() {
doAuxImport(loaded);
}

if (!cli.isBlank() && cli.isJumpToEntryKey()) {
jumpToEntryKey(loaded, cli.getJumpToEntryKey());
if (!cli.isBlank() && cli.isJumpToKey()) {
jumpToKey(loaded, cli.getJumpToKey());
}

this.parserResults = loaded;
Expand Down Expand Up @@ -777,16 +777,15 @@ private Optional<ParserResult> fetch(String fetchCommand) {
}
}

private void jumpToEntryKey(List<ParserResult> loaded, String citationKey) {
// search for this key in imported files
private void jumpToKey(List<ParserResult> loaded, String citationKey) {
for (ParserResult parserResult : loaded) {
Optional<BibEntry> entry = parserResult.getDatabase().getEntryByCitationKey(citationKey);
if (entry.isPresent()) {
parserResult.setEntryToFocus(entry.get());
return;
}
}
LOGGER.error("Could not find given citation key to jump to");
System.out.printf("Could not find citation key %s in any library%n", citationKey);
}

public boolean isBlank() {
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/org/jabref/cli/JabRefCLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,12 @@ public String getWriteMetadatatoPdf() {
cl.hasOption("embeddBibfileInPdf") ? cl.getOptionValue("embeddBibfileInPdf") : null;
}

public String getJumpToEntryKey() {
return cl.getOptionValue("jumpToEntryKey");
public String getJumpToKey() {
return cl.getOptionValue("jumpToKey");
}

public boolean isJumpToEntryKey() {
return cl.hasOption("jumpToEntryKey");
public boolean isJumpToKey() {
return cl.hasOption("jumpToKey");
}

private static Options getOptions() {
Expand Down Expand Up @@ -298,10 +298,10 @@ private static Options getOptions() {

options.addOption(Option
.builder("j")
.longOpt("jumpToEntryKey")
.desc(String.format("%s: '%s'", Localization.lang("Jump to the BibEntry of the given key."), "-j key"))
.longOpt("jumpToKey")
.desc(String.format("%s: '%s'", Localization.lang("Jump to the entry of the given citation key."), "-j key"))
.hasArg()
.argName("ENTRYKEY")
.argName("CITEKEY")
u7282852 marked this conversation as resolved.
Show resolved Hide resolved
.build());

return options;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/JabRefGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ private void openDatabases() {
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
// Make sure this parser result is its own library instead of imported BibTeX entries
if (parserResult.getEntryToFocus().isPresent() && !parserResult.toOpenTab()) {
focusDifferent = true;
focusedEntry = parserResult.getEntryToFocus();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/LibraryTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public Node createLoadingAnimationLayout() {
public void onDatabaseLoadingStarted() {
Node loadingLayout = createLoadingAnimationLayout();
getMainTable().placeholderProperty().setValue(loadingLayout);
frame.addTab(this, true);
frame.addTab(this, false);
u7282852 marked this conversation as resolved.
Show resolved Hide resolved
}

public void onDatabaseLoadingSucceed(ParserResult result) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,10 @@ public void openFiles(List<Path> filesToOpen) {
openTheFile(theFile);
fileHistory.newFile(theFile);
});
} else if (toRaise != null) {
} else if (toRaise != null && frame.getCurrentLibraryTab() == null) {
// If no files are remaining to open, this could mean that a file was
// already open. If so, we may have to raise the correct tab:
// If there is already a library focused, do not show this library
frame.showLibraryTab(toRaise);
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -974,6 +974,8 @@ Write\ BibTeXEntry\ as\ metadata\ to\ PDF.=Write BibTeXEntry as metadata to PDF.
Write\ metadata\ for\ all\ PDFs\ in\ current\ library?=Write metadata for all PDFs in current library?
Writing\ metadata...=Writing metadata...

Jump\ to\ the\ entry\ of\ the\ given\ citation\ key.=Jump to the entry of the given citation key.

Embed\ BibTeXEntry\ in\ PDF.=Embed BibTeXEntry in PDF.
File\ '%0'\ is\ write\ protected.=File '%0' is write protected.
Write\ BibTeXEntry\ as\ XMP\ metadata\ to\ PDF.=Write BibTeXEntry as XMP metadata to PDF.
Expand Down