Skip to content

Commit 6dbd06a

Browse files
committed
Make TreeItem.getExpanded consistent across platforms #2834
When the children of a previously expanded TreeItem are removed, the call to getExpanded() should continue to return "true". On both Linux and MacOS, this property is not persisted and therefore stored in a local variable. But on Linux, a call to getExpanded() still returns the result from a call to the GTK API. To harmonize the behavior between the different operating systems, following changes are done: 1) The call to getExpanded() now always returns the local variable, similar to how it's done for MacOS. 2) The call to setExpanded() doesn't modify the tree item if it is already expanded or a leaf node.
1 parent 941ff78 commit 6dbd06a

File tree

4 files changed

+15
-8
lines changed

4 files changed

+15
-8
lines changed

bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeItem.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -535,10 +535,7 @@ public boolean getChecked () {
535535
*/
536536
public boolean getExpanded () {
537537
checkWidget();
538-
long path = GTK.gtk_tree_model_get_path (parent.modelHandle, handle);
539-
boolean answer = GTK.gtk_tree_view_row_expanded (parent.handle, path);
540-
GTK.gtk_tree_path_free (path);
541-
return answer;
538+
return isExpanded;
542539
}
543540

544541
/**
@@ -1226,7 +1223,8 @@ public void setChecked (boolean checked) {
12261223
public void setExpanded (boolean expanded) {
12271224
checkWidget();
12281225
long path = GTK.gtk_tree_model_get_path (parent.modelHandle, handle);
1229-
if (expanded != GTK.gtk_tree_view_row_expanded (parent.handle, path)) {
1226+
// Do nothing when the item is a leaf or already expanded
1227+
if (expanded != GTK.gtk_tree_view_row_expanded (parent.handle, path) && GTK.gtk_tree_model_iter_n_children (parent.modelHandle, handle) != 0) {
12301228
if (expanded) {
12311229
OS.g_signal_handlers_block_matched (parent.handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, TEST_EXPAND_ROW);
12321230
GTK.gtk_tree_view_expand_row (parent.handle, path, false);
@@ -1237,9 +1235,9 @@ public void setExpanded (boolean expanded) {
12371235
GTK.gtk_tree_view_collapse_row (parent.handle, path);
12381236
OS.g_signal_handlers_unblock_matched (parent.handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, TEST_COLLAPSE_ROW);
12391237
}
1238+
isExpanded = expanded;
12401239
}
12411240
GTK.gtk_tree_path_free (path);
1242-
isExpanded = expanded;
12431241
}
12441242

12451243

tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_TreeItem.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,13 +550,22 @@ public void test_getBoundsI() {
550550

551551
@Test
552552
public void test_getExpanded() {
553+
assertFalse(treeItem.getExpanded());
554+
// do nothing when the item is a leaf
555+
treeItem.setExpanded(true);
553556
assertFalse(treeItem.getExpanded());
554557
// there must be at least one subitem before you can set the treeitem expanded
555558
new TreeItem(treeItem, 0);
556559
treeItem.setExpanded(true);
557560
assertTrue(treeItem.getExpanded());
558561
treeItem.setExpanded(false);
559562
assertFalse(treeItem.getExpanded());
563+
treeItem.setExpanded(true);
564+
treeItem.removeAll();
565+
assertTrue(treeItem.getExpanded());
566+
// do nothing when the item is a leaf
567+
treeItem.setExpanded(false);
568+
assertTrue(treeItem.getExpanded());
560569
}
561570

562571
@Test

tests/org.eclipse.swt.tests/META-INF/MANIFEST.MF

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
22
Bundle-ManifestVersion: 2
33
Bundle-Name: Eclipse SWT Tests
44
Bundle-SymbolicName: org.eclipse.swt.tests
5-
Bundle-Version: 3.107.1000.qualifier
5+
Bundle-Version: 3.107.1100.qualifier
66
Bundle-Vendor: Eclipse.org
77
Export-Package: org.eclipse.swt.tests.junit,
88
org.eclipse.swt.tests.junit.performance

tests/org.eclipse.swt.tests/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<relativePath>../../local-build/local-build-parent/</relativePath>
2121
</parent>
2222
<artifactId>org.eclipse.swt.tests</artifactId>
23-
<version>3.107.1000-SNAPSHOT</version>
23+
<version>3.107.1100-SNAPSHOT</version>
2424
<packaging>eclipse-test-plugin</packaging>
2525
<properties>
2626
<tycho.testArgLine></tycho.testArgLine>

0 commit comments

Comments
 (0)