-
Notifications
You must be signed in to change notification settings - Fork 15
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
Changes from 3 commits
2862c6d
ec85052
1c14b13
69563fc
c7b62dc
7b8c1f5
e6a6a9e
6b76bbc
0179274
d6d17e8
6907f80
07ea22d
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 | ||||
---|---|---|---|---|---|---|
|
@@ -277,6 +277,10 @@ public void processArguments() { | |||||
doAuxImport(loaded); | ||||||
} | ||||||
|
||||||
if (!cli.isBlank() && cli.isJumpToEntryKey()) { | ||||||
jumpToEntryKey(loaded, cli.getJumpToEntryKey()); | ||||||
} | ||||||
|
||||||
this.parserResults = loaded; | ||||||
} | ||||||
|
||||||
|
@@ -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 | ||||||
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"); | ||||||
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.
Suggested change
Here,
See https://devdocs.jabref.org/code-howtos/localization.html for steps for the localiaztion. |
||||||
} | ||||||
|
||||||
public boolean isBlank() { | ||||||
return cli.isBlank(); | ||||||
} | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -169,6 +169,14 @@ public String getWriteMetadatatoPdf() { | |||||
cl.hasOption("embeddBibfileInPdf") ? cl.getOptionValue("embeddBibfileInPdf") : null; | ||||||
} | ||||||
|
||||||
public String getJumpToEntryKey() { | ||||||
return cl.getOptionValue("jumpToEntryKey"); | ||||||
} | ||||||
|
||||||
public boolean isJumpToEntryKey() { | ||||||
return cl.hasOption("jumpToEntryKey"); | ||||||
} | ||||||
|
||||||
private static Options getOptions() { | ||||||
Options options = new Options(); | ||||||
|
||||||
|
@@ -288,6 +296,14 @@ private static Options getOptions() { | |||||
.argName("CITEKEY1[,CITEKEY2][,CITEKEYn] | PDF1[,PDF2][,PDFn] | all") | ||||||
.build()); | ||||||
|
||||||
options.addOption(Option | ||||||
.builder("j") | ||||||
.longOpt("jumpToEntryKey") | ||||||
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. Rename to |
||||||
.desc(String.format("%s: '%s'", Localization.lang("Jump to the BibEntry of the given key."), "-j key")) | ||||||
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.
Suggested change
|
||||||
.hasArg() | ||||||
.argName("ENTRYKEY") | ||||||
.build()); | ||||||
|
||||||
return options; | ||||||
} | ||||||
|
||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ | |
import org.jabref.logic.shared.exception.InvalidDBMSConnectionPropertiesException; | ||
import org.jabref.logic.shared.exception.NotASharedDatabaseException; | ||
import org.jabref.logic.util.WebViewStore; | ||
import org.jabref.model.entry.BibEntry; | ||
import org.jabref.model.strings.StringUtil; | ||
import org.jabref.model.util.FileUpdateMonitor; | ||
import org.jabref.preferences.GuiPreferences; | ||
|
@@ -201,14 +202,29 @@ private void openDatabases() { | |
.orElse(preferencesService.getGuiPreferences() | ||
.getLastFocusedFile()) | ||
.toAbsolutePath(); | ||
// check whether there is a jump to entry and need to focus different file | ||
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 | ||
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. Write "BibTeX" always with capital |
||
if (parserResult.getEntryToFocus().isPresent() && !parserResult.toOpenTab()) { | ||
focusDifferent = true; | ||
focusedEntry = parserResult.getEntryToFocus(); | ||
break; | ||
} | ||
} | ||
|
||
// Add all bibDatabases databases to the frame: | ||
boolean first = false; | ||
for (ParserResult parserResult : parserResults) { | ||
// Define focused tab | ||
if (parserResult.getPath().filter(path -> path.toAbsolutePath().equals(focusedFile)).isPresent()) { | ||
if (parserResult.getPath().filter(path -> path.toAbsolutePath().equals(focusedFile)).isPresent() && !focusDifferent) { | ||
first = true; | ||
} | ||
if (parserResult.getEntryToFocus().isPresent() && focusDifferent) { | ||
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. Should that be |
||
first = true; | ||
focusDifferent = false; | ||
} | ||
|
||
if (parserResult.getDatabase().isShared()) { | ||
try { | ||
|
@@ -279,6 +295,11 @@ private void openDatabases() { | |
|
||
OpenDatabaseAction.performPostOpenActions(libraryTab, pr); | ||
} | ||
// focus a particular entry if CLI has received a jump to entry key command | ||
if (focusedEntry.isPresent()) { | ||
mainFrame.getCurrentLibraryTab().clearAndSelect(focusedEntry.get()); | ||
mainFrame.showLibraryTab(mainFrame.getCurrentLibraryTab()); | ||
} | ||
|
||
LOGGER.debug("Finished adding panels"); | ||
} | ||
|
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.
Remove this line, because the for each loop makes it clear somehow.