Skip to content

Commit

Permalink
fixed 'copy key and link' (#6871)
Browse files Browse the repository at this point in the history
* 'copy key and link' from right-click menu creates a string that is not a url. it includes the url, but it also includes the key... it works now

* updated authorlist

* added entry to change log

* 'copy key and link' now sets html content again and also sets a fallback string

* Update src/main/java/org/jabref/gui/edit/CopyMoreAction.java

Co-authored-by: Oliver Kopp <kopp.dev@gmail.com>

* CHANGELOG.md

* Remove obsolete method

Remove obsolete method

Co-authored-by: Oliver Kopp <kopp.dev@gmail.com>
Co-authored-by: Carl Christian Snethlage <50491877+calixtus@users.noreply.github.com>
Co-authored-by: Siedlerchr <siedlerkiller@gmail.com>
  • Loading branch information
4 people committed Sep 29, 2020
1 parent 8a44d41 commit 2d92025
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -39,6 +39,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- We fixed an issue where the `.sav` file was not deleted upon exiting JabRef. [#6109](https://github.com/JabRef/jabref/issues/6109)
- We fixed a linked identifier icon inconsistency. [#6705](https://github.com/JabRef/jabref/issues/6705)
- We fixed the wrong behavior that font size changes are not reflected in dialogs. [#6039](https://github.com/JabRef/jabref/issues/6039)
- We fixed the failure to Copy citation key and link. [#5835](https://github.com/JabRef/jabref/issues/5835)
- We fixed an issue where the sort order of the entry table was reset after a restart of JabRef. [#6898](https://github.com/JabRef/jabref/pull/6898)
- We fixed an issue where no longer a warning was displayed when inserting references into LibreOffice with an invalid "ReferenceParagraphFormat". [#6907](https://github.com/JabRef/jabref/pull/60907).
- We fixed an issue where a selected field was not removed after the first click in the custom entry types dialog [#6934](https://github.com/JabRef/jabref/issues/6934)
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/org/jabref/gui/ClipBoardManager.java
Expand Up @@ -73,7 +73,7 @@ public static void addX11Support(TextInputControl input) {
// using InvalidationListener because of https://bugs.openjdk.java.net/browse/JDK-8176270
observable -> Platform.runLater(() -> {
String newValue = input.getSelectedText();
if (!newValue.isEmpty() && primary != null) {
if (!newValue.isEmpty() && (primary != null)) {
primary.setContents(new StringSelection(newValue), null);
}
}));
Expand Down Expand Up @@ -105,7 +105,7 @@ public static String getContents() {
public static String getContentsPrimary() {
if (primary != null) {
Transferable contents = primary.getContents(null);
if (contents != null && contents.isDataFlavorSupported(DataFlavor.stringFlavor)) {
if ((contents != null) && contents.isDataFlavorSupported(DataFlavor.stringFlavor)) {
try {
return (String) contents.getTransferData(DataFlavor.stringFlavor);
} catch (UnsupportedFlavorException | IOException e) {
Expand Down Expand Up @@ -137,9 +137,10 @@ public void setPrimaryClipboardContent(ClipboardContent content) {
}
}

public void setHtmlContent(String html) {
public void setHtmlContent(String html, String fallbackPlain) {
final ClipboardContent content = new ClipboardContent();
content.putHtml(html);
content.putString(fallbackPlain);
clipboard.setContent(content);
setPrimaryClipboardContent(content);
}
Expand Down Expand Up @@ -181,7 +182,7 @@ private List<BibEntry> handleBibTeXData(String entries) {
}

private List<BibEntry> handleStringData(String data) {
if (data == null || data.isEmpty()) {
if ((data == null) || data.isEmpty()) {
return Collections.emptyList();
}

Expand Down
5 changes: 4 additions & 1 deletion src/main/java/org/jabref/gui/edit/CopyMoreAction.java
Expand Up @@ -207,6 +207,7 @@ private void copyKeyAndLink() {
List<BibEntry> entries = stateManager.getSelectedEntries();

StringBuilder keyAndLink = new StringBuilder();
StringBuilder fallbackString = new StringBuilder();

List<BibEntry> entriesWithKey = entries.stream()
.filter(BibEntry::hasCitationKey)
Expand All @@ -222,9 +223,11 @@ private void copyKeyAndLink() {
String url = entry.getField(StandardField.URL).orElse("");
keyAndLink.append(url.isEmpty() ? key : String.format("<a href=\"%s\">%s</a>", url, key));
keyAndLink.append(OS.NEWLINE);
fallbackString.append(url.isEmpty() ? key : String.format("%s - %s", key, url));
fallbackString.append(OS.NEWLINE);
}

clipBoardManager.setHtmlContent(keyAndLink.toString());
clipBoardManager.setHtmlContent(keyAndLink.toString(), fallbackString.toString());

if (entriesWithKey.size() == entries.size()) {
// All entries had keys.
Expand Down

0 comments on commit 2d92025

Please sign in to comment.