Bug 518414 - [gtk] Package explorer double click opens currently
selected (highlighted) resource
Added row-activation handler for Tree/Table/List to know when
double-click triggers a 'row-activated' event. Prevent Default Selection
from triggered when double clicking the expander triangle.
Tested in child Eclipse, double-clicking/enter on a file gains focus as
before.
Double-click the expand triangle or anywhere else does not open the
current highlighted item.
Change-Id: I4727906525d3ce379e66514f74209522261706c7
Signed-off-by: Xi Yan <xixiyan@redhat.com>
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/List.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/List.java
index 595ea12..86da9b8 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/List.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/List.java
@@ -49,6 +49,7 @@
static final int TEXT_COLUMN = 0;
double cachedAdjustment, currentAdjustment;
+ boolean rowActivated;
/**
* Constructs a new instance of this class given its parent
@@ -907,14 +908,27 @@
}
}
- //If Mouse double-click pressed, manually send a DefaultSelection. See Bug 312568.
- if (gdkEvent.type == GDK.GDK_2BUTTON_PRESS) {
+ /*
+ * Bug 312568: If mouse double-click pressed, manually send a DefaultSelection.
+ * Bug 518414: Added rowActivated guard flag to only send a DefaultSelection when the
+ * double-click triggers a 'row-activated' signal. Note that this relies on the fact
+ * that 'row-activated' signal comes before double-click event. This prevents
+ * opening of the current highlighted item when double clicking on any expander arrow.
+ */
+ if (gdkEvent.type == GDK.GDK_2BUTTON_PRESS && rowActivated) {
sendTreeDefaultSelection ();
+ rowActivated = false;
}
return result;
}
+@Override
+long /*int*/ gtk_row_activated (long /*int*/ tree, long /*int*/ path, long /*int*/ column) {
+ rowActivated = true;
+ return 0;
+}
+
@Override
long /*int*/ gtk_key_press_event (long /*int*/ widget, long /*int*/ event) {
@@ -977,19 +991,20 @@
}
}
-//Used to emulate DefaultSelection event. See Bug 312568.
-//Feature in GTK. 'row-activation' event comes before DoubleClick event.
-//This is causing the editor not to get focus after doubleclick.
-//The solution is to manually send the DefaultSelection event after a doubleclick,
-//and to emulate it for Space/Return.
+/**
+ * Used to emulate DefaultSelection event. See Bug 312568.
+ * Feature in GTK. 'row-activation' event comes before DoubleClick event.
+ * This is causing the editor not to get focus after double-click.
+ * The solution is to manually send the DefaultSelection event after a double-click,
+ * and to emulate it for Space/Return.
+ */
void sendTreeDefaultSelection() {
//Note, similar DefaultSelectionHandling in SWT List/Table/Tree
Event event = new Event ();
event.index = this.getFocusIndex ();
- if (event.index >= 0)
- event.text = this.getItem (event.index);
+ if (event.index >= 0) event.text = this.getItem (event.index);
sendSelectionEvent (SWT.DefaultSelection, event, false);
}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Table.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Table.java
index 5db25e2..8c9a392 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Table.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Table.java
@@ -94,6 +94,7 @@
double cachedAdjustment, currentAdjustment;
int pixbufHeight, pixbufWidth;
boolean boundsChangedSinceLastDraw;
+ boolean rowActivated;
static final int CHECKED_COLUMN = 0;
static final int GRAYED_COLUMN = 1;
@@ -2140,15 +2141,29 @@
}
}
- //If Mouse double-click pressed, manually send a DefaultSelection. See Bug 312568.
- if (gdkEvent.type == GDK.GDK_2BUTTON_PRESS) {
+ /*
+ * Bug 312568: If mouse double-click pressed, manually send a DefaultSelection.
+ * Bug 518414: Added rowActivated guard flag to only send a DefaultSelection when the
+ * double-click triggers a 'row-activated' signal. Note that this relies on the fact
+ * that 'row-activated' signal comes before double-click event. This prevents
+ * opening of the current highlighted item when double clicking on any expander arrow.
+ */
+ if (gdkEvent.type == GDK.GDK_2BUTTON_PRESS && rowActivated) {
sendTreeDefaultSelection ();
+ rowActivated = false;
}
return result;
}
@Override
+long /*int*/ gtk_row_activated (long /*int*/ tree, long /*int*/ path, long /*int*/ column) {
+ rowActivated = true;
+ return 0;
+}
+
+
+@Override
long /*int*/ gtk_key_press_event (long /*int*/ widget, long /*int*/ event) {
GdkEventKey keyEvent = new GdkEventKey ();
OS.memmove (keyEvent, event, GdkEventKey.sizeof);
@@ -2176,11 +2191,13 @@
}
}
-//Used to emulate DefaultSelection event. See Bug 312568.
-//Feature in GTK. 'row-activation' event comes before DoubleClick event.
-//This is causing the editor not to get focus after doubleclick.
-//The solution is to manually send the DefaultSelection event after a doubleclick,
-//and to emulate it for Space/Return.
+/**
+ * Used to emulate DefaultSelection event. See Bug 312568.
+ * Feature in GTK. 'row-activation' event comes before DoubleClick event.
+ * This is causing the editor not to get focus after double-click.
+ * The solution is to manually send the DefaultSelection event after a double-click,
+ * and to emulate it for Space/Return.
+ */
void sendTreeDefaultSelection() {
//Note, similar DefaultSelectionHandling in SWT List/Table/Tree
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tree.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tree.java
index 2189f7b..1963655 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tree.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tree.java
@@ -101,6 +101,7 @@
Color headerBackground, headerForeground;
String headerCSSBackground, headerCSSForeground;
boolean boundsChangedSinceLastDraw;
+ boolean rowActivated;
static final int ID_COLUMN = 0;
static final int CHECKED_COLUMN = 1;
@@ -2177,15 +2178,28 @@
}
}
- //If Mouse double-click pressed, manually send a DefaultSelection. See Bug 312568.
- if (gdkEvent.type == GDK.GDK_2BUTTON_PRESS) {
+ /*
+ * Bug 312568: If mouse double-click pressed, manually send a DefaultSelection.
+ * Bug 518414: Added rowActivated guard flag to only send a DefaultSelection when the
+ * double-click triggers a 'row-activated' signal. Note that this relies on the fact
+ * that 'row-activated' signal comes before double-click event. This prevents
+ * opening of the current highlighted item when double clicking on any expander arrow.
+ */
+ if (gdkEvent.type == GDK.GDK_2BUTTON_PRESS && rowActivated) {
sendTreeDefaultSelection ();
+ rowActivated = false;
}
return result;
}
@Override
+long /*int*/ gtk_row_activated (long /*int*/ tree, long /*int*/ path, long /*int*/ column) {
+ rowActivated = true;
+ return 0;
+}
+
+@Override
long /*int*/ gtk_key_press_event (long /*int*/ widget, long /*int*/ event) {
GdkEventKey keyEvent = new GdkEventKey ();
OS.memmove (keyEvent, event, GdkEventKey.sizeof);
@@ -2213,11 +2227,13 @@
}
}
-//Used to emulate DefaultSelection event. See Bug 312568.
-//Feature in GTK. 'row-activation' event comes before DoubleClick event.
-//This is causing the editor not to get focus after doubleclick.
-//The solution is to manually send the DefaultSelection event after a doubleclick,
-//and to emulate it for Space/Return.
+/**
+ * Used to emulate DefaultSelection event. See Bug 312568.
+ * Feature in GTK. 'row-activation' event comes before DoubleClick event.
+ * This is causing the editor not to get focus after double-click.
+ * The solution is to manually send the DefaultSelection event after a double-click,
+ * and to emulate it for Space/Return.
+ */
void sendTreeDefaultSelection() {
//Note, similar DefaultSelectionHandling in SWT List/Table/Tree
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Widget.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Widget.java
index d2b568f..11946f5 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Widget.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Widget.java
@@ -864,8 +864,9 @@
long /*int*/ gtk_row_activated (long /*int*/ tree, long /*int*/ path, long /*int*/ column) {
return 0;
- //Note on SWT Tree/Table/List. This signal is no longer used. Instead SendDefaultSelection is
- //Manually emitted. See Bug 312568.
+ // Note on SWT Tree/Table/List. This signal is no longer used for sending events, instead
+ // Send DefaultSelection is manually emitted. We use this function to know whether a
+ // 'row-activated' is triggered. See Bug 312568, 518414.
}
long /*int*/ gtk_row_deleted (long /*int*/ model, long /*int*/ path) {