Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent CARON2019-04-03 19:38:49 +0000
committerEric Williams2019-04-05 13:07:55 +0000
commit84153c9002a622b5a8568e5f5a4914d93cffa6ad (patch)
treee9c334585f704f34af358bf356a6b270fc2b2971
parent2e52075bb0b979126f91ea4266b889158c892241 (diff)
downloadeclipse.platform.swt-84153c9002a622b5a8568e5f5a4914d93cffa6ad.tar.gz
eclipse.platform.swt-84153c9002a622b5a8568e5f5a4914d93cffa6ad.tar.xz
eclipse.platform.swt-84153c9002a622b5a8568e5f5a4914d93cffa6ad.zip
Bug 545073 - [GTK] MouseNavigation pastes text on middle click
Change-Id: I7fa01f6520c43acd5dd39e5ba1ead6d5e2de9b0e Signed-off-by: Laurent CARON <laurent.caron@gmail.com>
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/MouseNavigator.java10
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java44
2 files changed, 38 insertions, 16 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/MouseNavigator.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/MouseNavigator.java
index a501f9205b..784b942612 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/MouseNavigator.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/MouseNavigator.java
@@ -1,5 +1,5 @@
/**
- * Copyright (c) 2018 Laurent CARON.
+ * Copyright (c) 2019 Laurent CARON.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -33,6 +33,7 @@ class MouseNavigator {
private Point originalMouseLocation;
private final Listener mouseDownListener, mouseUpListener, paintListener, mouseMoveListener, focusOutListener;
private boolean hasHBar, hasVBar;
+ private Cursor previousCursor;
MouseNavigator(final StyledText styledText) {
if (styledText == null) {
@@ -69,12 +70,12 @@ class MouseNavigator {
parent.addListener(SWT.FocusOut, focusOutListener);
}
- private void onMouseDown(Event e) {
+ void onMouseDown(Event e) {
if ((e.button != 2) || navigationActivated) {
return;
}
- if (!parent.isVisible() || !parent.getEnabled()) {
+ if (!parent.isVisible() || !parent.getEnabled() || parent.middleClickPressed) {
return;
}
@@ -86,6 +87,7 @@ class MouseNavigator {
}
navigationActivated = true;
+ previousCursor = parent.getCursor();
parent.setCursor(parent.getDisplay().getSystemCursor(SWT.CURSOR_ARROW));
originalMouseLocation = getMouseLocation();
parent.redraw();
@@ -129,7 +131,7 @@ class MouseNavigator {
}
private void deactivate() {
- parent.setCursor(parent.getDisplay().getSystemCursor(SWT.CURSOR_ARROW));
+ parent.setCursor(previousCursor);
navigationActivated = false;
originalMouseLocation = null;
parent.redraw();
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java
index eb071d9a98..4d23d60e73 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java
@@ -173,6 +173,7 @@ public class StyledText extends Canvas {
AccessibleTextExtendedAdapter accTextExtendedAdapter;
AccessibleAdapter accAdapter;
MouseNavigator mouseNavigator;
+ boolean middleClickPressed;
//block selection
boolean blockSelection;
@@ -6138,18 +6139,23 @@ void handleMouseDown(Event event) {
if (dragDetect && checkDragDetect(event)) return;
//paste clipboard selection
- boolean mouseNavigationRunning = mouseNavigator != null && mouseNavigator.navigationActivated;
- if (event.button == 2 && !mouseNavigationRunning) {
- String text = (String)getClipboardContent(DND.SELECTION_CLIPBOARD);
- if (text != null && text.length() > 0) {
- // position cursor
- doMouseLocationChange(event.x, event.y, false);
- // insert text
- Event e = new Event();
- e.start = selection.x;
- e.end = selection.y;
- e.text = getModelDelimitedText(text);
- sendKeyEvent(e);
+ if (event.button == 2) {
+ // On GTK, if mouseNavigator is enabled we have to distinguish a short middle-click (to paste content) from
+ // a long middle-click (mouse navigation started)
+ if (IS_GTK && mouseNavigator != null) {
+ middleClickPressed = true;
+ getDisplay().timerExec(200, ()->{
+ boolean click = middleClickPressed;
+ middleClickPressed = false;
+ if (click && mouseNavigator !=null) {
+ mouseNavigator.onMouseDown(event);
+ } else {
+ pasteOnMiddleClick(event);
+ }
+ });
+ return;
+ } else {
+ pasteOnMiddleClick(event);
}
}
@@ -6209,6 +6215,7 @@ void handleMouseMove(Event event) {
* Autoscrolling ends when the mouse button is released.
*/
void handleMouseUp(Event event) {
+ middleClickPressed = false;
clickCount = 0;
endAutoScroll();
if (event.button == 1) {
@@ -7475,6 +7482,19 @@ public void paste(){
sendKeyEvent(event);
}
}
+private void pasteOnMiddleClick(Event event) {
+ String text = (String)getClipboardContent(DND.SELECTION_CLIPBOARD);
+ if (text != null && text.length() > 0) {
+ // position cursor
+ doMouseLocationChange(event.x, event.y, false);
+ // insert text
+ Event e = new Event();
+ e.start = selection.x;
+ e.end = selection.y;
+ e.text = getModelDelimitedText(text);
+ sendKeyEvent(e);
+ }
+}
/**
* Prints the widget's text to the default printer.
*

Back to the top