Skip to content

Commit

Permalink
Introduce SELECTION, which is said to be available on Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
koppor committed Dec 18, 2016
1 parent 59b09d8 commit af278a4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 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
11 changes: 7 additions & 4 deletions src/main/java/net/sf/jabref/gui/ClipBoardManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +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();
private static final Optional<Clipboard> SELECTION = Optional.ofNullable(Toolkit.getDefaultToolkit().getSystemSelection());

/**
* Empty implementation of the ClipboardOwner interface.
Expand All @@ -46,7 +46,7 @@ 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);
SELECTION.ifPresent(s -> s.setContents(stringSelection, this));

}

Expand All @@ -55,7 +55,7 @@ public void setClipboardContents(String aString) {
*/
public void setTransferableClipboardContents(Transferable transferable){
CLIPBOARD.setContents(transferable, this);
SELECTION.setContents(transferable, this);
SELECTION.ifPresent(s -> s.setContents(transferable, this));
}

/**
Expand All @@ -67,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 = SELECTION.getContents(null);
Transferable contents = null;
if (SELECTION.isPresent()) {
contents = SELECTION.get().getContents(null);
}
if (contents == null) {
contents = CLIPBOARD.getContents(null);
}
Expand Down

0 comments on commit af278a4

Please sign in to comment.