Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimeon Andreev2019-04-04 09:16:09 -0400
committerAndrey Loskutov2019-04-04 09:45:51 -0400
commitf47aa33d971816803c1bcb5bb4c01e3cad5b3cc2 (patch)
treeb298bac57036185830c0ad7afcb81b52ba1a7c7d
parent34cebe7ab16eab061a9cd6e2bebfbc08502f8b00 (diff)
downloadeclipse.platform.swt-f47aa33d971816803c1bcb5bb4c01e3cad5b3cc2.tar.gz
eclipse.platform.swt-f47aa33d971816803c1bcb5bb4c01e3cad5b3cc2.tar.xz
eclipse.platform.swt-f47aa33d971816803c1bcb5bb4c01e3cad5b3cc2.zip
Bug 182598 - adjusted patch to deal with nested tree elements
The previous patch for bug 182598 did not take tree items with parent tree items into account. This led to throwing exceptions in cases which were not broken. With this change, the tree elements that are being removed are correctly iterated. Change-Id: I8632202d13995f0cc2203a52027b0deb7006085a Signed-off-by: Simeon Andreev <simeon.danailov.andreev@gmail.com> Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Table.java3
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tree.java64
2 files changed, 38 insertions, 29 deletions
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 5c95ac5153..3a8ed4dfe9 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
@@ -4233,8 +4233,7 @@ Point resizeCalculationsGTK3 (long widget, int width, int height) {
* Check the table item range [start, end) for items that are in process of
* sending {@code SWT#SetData} event. If such items exist, throw an exception.
*
- * Does nothing if the given range contains no indices,
- * or if we are below GTK 3.22.0 or are using GTK 4.
+ * Does nothing if the given range contains no indices.
*
* @param start index of first item to check
* @param end index after the last item to check
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 918daa2710..d4aa240e0c 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
@@ -2829,31 +2829,41 @@ void remove (long parentIter, int start, int end) {
if (!(0 <= start && start <= end && end < itemCount)) {
error (SWT.ERROR_INVALID_RANGE);
}
- checkSetDataInProcessBeforeRemoval(start, end + 1);
long selection = GTK.gtk_tree_view_get_selection (handle);
long iter = OS.g_malloc (GTK.GtkTreeIter_sizeof ());
if (iter == 0) error (SWT.ERROR_NO_HANDLES);
if (fixAccessibility ()) {
ignoreAccessibility = true;
}
- for (int i = start; i <= end; i++) {
- GTK.gtk_tree_model_iter_nth_child (modelHandle, iter, parentIter, start);
- int[] value = new int[1];
- GTK.gtk_tree_model_get (modelHandle, iter, ID_COLUMN, value, -1);
- TreeItem item = value [0] != -1 ? items [value [0]] : null;
- if (item != null && !item.isDisposed ()) {
- item.dispose ();
- } else {
- OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- GTK.gtk_tree_store_remove (modelHandle, iter);
- OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
+ try {
+ for (int i = start; i <= end; i++) {
+ GTK.gtk_tree_model_iter_nth_child (modelHandle, iter, parentIter, start);
+ int[] value = new int[1];
+ GTK.gtk_tree_model_get (modelHandle, iter, ID_COLUMN, value, -1);
+ TreeItem item = value [0] != -1 ? items [value [0]] : null;
+ if (item != null && !item.isDisposed ()) {
+ /*
+ * Bug 182598 - assertion failed in gtktreestore.c
+ * Removing an item while its data is being set will invalidate
+ * it, which will cause a crash in GTK.
+ */
+ if(item.settingData) {
+ throwCannotRemoveItem(i);
+ }
+ item.dispose ();
+ } else {
+ OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
+ GTK.gtk_tree_store_remove (modelHandle, iter);
+ OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
+ }
}
+ } finally {
+ if (fixAccessibility ()) {
+ ignoreAccessibility = false;
+ OS.g_object_notify (handle, OS.model);
+ }
+ OS.g_free (iter);
}
- if (fixAccessibility ()) {
- ignoreAccessibility = false;
- OS.g_object_notify (handle, OS.model);
- }
- OS.g_free (iter);
}
/**
@@ -2866,7 +2876,7 @@ void remove (long parentIter, int start, int end) {
*/
public void removeAll () {
checkWidget ();
- checkSetDataInProcessBeforeRemoval(0, items.length);
+ checkSetDataInProcessBeforeRemoval();
for (int i=0; i<items.length; i++) {
TreeItem item = items [i];
if (item != null && !item.isDisposed ()) item.release (false);
@@ -4195,16 +4205,13 @@ Point resizeCalculationsGTK3 (long widget, int width, int height) {
}
/**
- * Check the tree item range [start, end) for items that are in process of
+ * Check the tree for items that are in process of
* sending {@code SWT#SetData} event. If such items exist, throw an exception.
*
* Does nothing if the given range contains no indices,
* or if we are below GTK 3.22.0 or are using GTK 4.
- *
- * @param start index of first item to check
- * @param end index after the last item to check
*/
-void checkSetDataInProcessBeforeRemoval(int start, int end) {
+void checkSetDataInProcessBeforeRemoval() {
/*
* Bug 182598 - assertion failed in gtktreestore.c
*
@@ -4213,13 +4220,16 @@ void checkSetDataInProcessBeforeRemoval(int start, int end) {
*
* We therefore throw an exception to prevent the crash.
*/
- for (int i = start; i < end; i++) {
+ for (int i = 0; i < items.length; i++) {
TreeItem item = items[i];
if (item != null && item.settingData) {
- String message = "Cannot remove a tree item while its data is being set. "
- + "At item " + i + " in range [" + start + ", " + end + ").";
- throw new SWTException(message);
+ throwCannotRemoveItem(i);
}
}
}
+
+private void throwCannotRemoveItem(int i) {
+ String message = "Cannot remove item with index " + i + ".";
+ throw new SWTException(message);
+}
}

Back to the top