Skip to content

Commit

Permalink
Additionally check the SELECTION (available on Linux) when trying to …
Browse files Browse the repository at this point in the history
…get the contents of the clipboard
  • Loading branch information
koppor committed Dec 18, 2016
1 parent ef8ded6 commit 69ad3b9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ We refer to [GitHub issues](/~https://github.com/JabRef/jabref/issues) by using `#
## [Unreleased]

### Changed
- When copying and pasting, the X11 selection is read first and also set. [#2389](/~https://github.com/JabRef/jabref/issues/2389).
- When editing an article, the tab "Optional fields" now shows "ISSN"
- When editing a book, the tab "Optional fields" now shows "ISBN"

Expand Down
15 changes: 13 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 Optional<Clipboard> SELECTION = Optional.ofNullable(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.ifPresent(s -> s.setContents(stringSelection, this));

}

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

/**
Expand All @@ -62,7 +67,13 @@ 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 = null;
if (SELECTION.isPresent()) {
contents = SELECTION.get().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 +89,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 69ad3b9

Please sign in to comment.