From b36e524454d2040be5c08da9c8329ee1c0044e90 Mon Sep 17 00:00:00 2001 From: Oliver Kopp Date: Sun, 18 Dec 2016 16:21:34 +0100 Subject: [PATCH] Additionally check the SELECTION (available on Linux) when trying to get the contents of the clipboard --- CHANGELOG.md | 1 + .../java/net/sf/jabref/gui/ClipBoardManager.java | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5bf606116e8c..ea26fc1880fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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" diff --git a/src/main/java/net/sf/jabref/gui/ClipBoardManager.java b/src/main/java/net/sf/jabref/gui/ClipBoardManager.java index 0027f158c01b..7aae60335708 100644 --- a/src/main/java/net/sf/jabref/gui/ClipBoardManager.java +++ b/src/main/java/net/sf/jabref/gui/ClipBoardManager.java @@ -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; @@ -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 SELECTION = Optional.ofNullable(Toolkit.getDefaultToolkit().getSystemSelection()); /** * Empty implementation of the ClipboardOwner interface. @@ -44,6 +46,8 @@ 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)); + } /** @@ -51,6 +55,7 @@ public void setClipboardContents(String aString) { */ public void setTransferableClipboardContents(Transferable transferable){ CLIPBOARD.setContents(transferable, this); + SELECTION.ifPresent(s -> s.setContents(transferable, this)); } /** @@ -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); @@ -78,9 +89,9 @@ public String getClipboardContents() { public List extractBibEntriesFromClipboard() { // Get clipboard contents, and see if TransferableBibtexEntry is among the content flavors offered Transferable content = CLIPBOARD.getContents(null); + Objects.requireNonNull(content); List result = new ArrayList<>(); - if (content.isDataFlavorSupported(TransferableBibtexEntry.entryFlavor)) { // We have determined that the clipboard data is a set of entries. try {