forked from JabRef/jabref
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Copy cite command should respect preferences (JabRef#10707)
* Fix Copy cite command should respect preferences Fixes JabRef#10615 * add changelog fix checsktyle * Fix CHANGELOG.md * Add missing "citation" to "key" * Add debug message at error in logic in CopyMoreAction * Add fallback if preference could not be parsed * Fix key binding setting * More relaxed parsing * Streamline code in AbstractPushToApplication * Add more test cases for configured citation command * Streamline code for copy action * Update src/main/java/org/jabref/gui/preferences/external/ExternalTabViewModel.java * Fix test --------- Co-authored-by: Oliver Kopp <[email protected]>
- Loading branch information
1 parent
6014172
commit 11d90a1
Showing
13 changed files
with
174 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/main/java/org/jabref/logic/push/CitationCommandString.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package org.jabref.logic.push; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public record CitationCommandString(String prefix, String delimiter, String suffix) { | ||
private static final Logger LOGGER = LoggerFactory.getLogger(CitationCommandString.class); | ||
private static final String CITE_KEY1 = "key1"; | ||
private static final String CITE_KEY2 = "key2"; | ||
|
||
@Override | ||
public String toString() { | ||
return prefix + CITE_KEY1 + delimiter + CITE_KEY2 + suffix; | ||
} | ||
|
||
public static CitationCommandString from(String completeCiteCommand) { | ||
int indexKey1 = completeCiteCommand.indexOf(CITE_KEY1); | ||
int indexKey2 = completeCiteCommand.indexOf(CITE_KEY2); | ||
if (indexKey1 < 0 || indexKey2 < 0 || indexKey2 < (indexKey1 + CITE_KEY1.length())) { | ||
LOGGER.info("Wrong indexes {} {} for completeCiteCommand {}. Using default delimiter and suffix.", indexKey1, indexKey2, completeCiteCommand); | ||
if (completeCiteCommand.isEmpty()) { | ||
completeCiteCommand = "\\cite{"; | ||
} else if (!completeCiteCommand.endsWith("{")) { | ||
completeCiteCommand += "{"; | ||
} | ||
return new CitationCommandString(completeCiteCommand, ",", "}"); | ||
} | ||
|
||
String prefix = completeCiteCommand.substring(0, indexKey1); | ||
String delim = completeCiteCommand.substring(completeCiteCommand.lastIndexOf(CITE_KEY1) + CITE_KEY1.length(), indexKey2); | ||
String suffix = completeCiteCommand.substring(completeCiteCommand.lastIndexOf(CITE_KEY2) + CITE_KEY2.length()); | ||
return new CitationCommandString(prefix, delim, suffix); | ||
} | ||
} |
Oops, something went wrong.