Skip to content

Commit

Permalink
Additionally check the SELECTION when trying to get the contents of t…
Browse files Browse the repository at this point in the history
…he clipboard
  • Loading branch information
koppor committed Dec 18, 2016
1 parent a376287 commit 59b09d8
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/main/java/net/sf/jabref/gui/ClipBoardManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;

import net.sf.jabref.Globals;
Expand All @@ -28,6 +29,7 @@ public class ClipBoardManager implements ClipboardOwner {
private static final Log LOGGER = LogFactory.getLog(ClipBoardManager.class);

private static final Clipboard CLIPBOARD = Toolkit.getDefaultToolkit().getSystemClipboard();
private static final Clipboard SELECTION = Toolkit.getDefaultToolkit().getSystemSelection();

/**
* Empty implementation of the ClipboardOwner interface.
Expand All @@ -44,13 +46,16 @@ public void lostOwnership(Clipboard aClipboard, Transferable aContents) {
public void setClipboardContents(String aString) {
StringSelection stringSelection = new StringSelection(aString);
CLIPBOARD.setContents(stringSelection, this);
SELECTION.setContents(stringSelection, this);

}

/**
* Places the string into the clipboard using a {@link Transferable}.
*/
public void setTransferableClipboardContents(Transferable transferable){
CLIPBOARD.setContents(transferable, this);
SELECTION.setContents(transferable, this);
}

/**
Expand All @@ -62,7 +67,10 @@ public void setTransferableClipboardContents(Transferable transferable){
public String getClipboardContents() {
String result = "";
//odd: the Object param of getContents is not currently used
Transferable contents = CLIPBOARD.getContents(null);
Transferable contents = SELECTION.getContents(null);
if (contents == null) {
contents = CLIPBOARD.getContents(null);
}
if ((contents != null) && contents.isDataFlavorSupported(DataFlavor.stringFlavor)) {
try {
result = (String) contents.getTransferData(DataFlavor.stringFlavor);
Expand All @@ -78,9 +86,9 @@ public String getClipboardContents() {
public List<BibEntry> extractBibEntriesFromClipboard() {
// Get clipboard contents, and see if TransferableBibtexEntry is among the content flavors offered
Transferable content = CLIPBOARD.getContents(null);
Objects.requireNonNull(content);
List<BibEntry> result = new ArrayList<>();


if (content.isDataFlavorSupported(TransferableBibtexEntry.entryFlavor)) {
// We have determined that the clipboard data is a set of entries.
try {
Expand Down

0 comments on commit 59b09d8

Please sign in to comment.