Skip to content

Commit 5fe0fc9

Browse files
fedejeanneCopilot
andcommitted
Revert CTabFolder-specific traversal workaround in TraversePageHandler
Restores the standard focus-traversal behavior in TraversePageHandler by removing the special-casing that was added for CTabFolder (loop-to-first/ last-item logic, hidden-item detection, and the top-level CTabFolder lookup helpers introduced by #2864 and the earlier fix for #4135). This special-casing was a workaround for CTabFolder not looping over its own tabs when using Ctrl+PageUp/PageDown. That is now fixed directly in SWT's CTabFolder.onPageTraversal (see eclipse-platform/eclipse.platform.swt#3448), which makes this handler's workaround unnecessary and, in some cases, incorrect (e.g. it bypassed the chevron/drop-down list when tabs did not fit). Requires eclipse-platform/eclipse.platform.swt#3448 to be merged/available for the circular navigation behavior to still work correctly. Fixes #4135 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 429f446 commit 5fe0fc9

1 file changed

Lines changed: 1 addition & 66 deletions

File tree

bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/TraversePageHandler.java

Lines changed: 1 addition & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,8 @@
1313
*******************************************************************************/
1414
package org.eclipse.ui.internal.handlers;
1515
import java.lang.reflect.Method;
16-
import java.util.Arrays;
1716
import org.eclipse.core.commands.ExecutionEvent;
1817
import org.eclipse.swt.SWT;
19-
import org.eclipse.swt.custom.CTabFolder;
20-
import org.eclipse.swt.custom.CTabItem;
2118
import org.eclipse.swt.widgets.Control;
2219
import org.eclipse.swt.widgets.Display;
2320
import org.eclipse.swt.widgets.Shell;
@@ -38,16 +35,9 @@ public final Object execute(final ExecutionEvent event) {
3835
Control focusControl = Display.getCurrent().getFocusControl();
3936
if (focusControl != null) {
4037
boolean forward = "next".equals(methodName); //$NON-NLS-1$
41-
int traversalDirection = translateToTraversalDirection(forward);
38+
final int traversalDirection = translateToTraversalDirection(forward);
4239
Control control = focusControl;
4340
do {
44-
if (control instanceof CTabFolder) {
45-
CTabFolder folder = getTopLevelCTabFolderInParentHierarchy(control);
46-
if (isFinalItemInCTabFolder(folder, forward) && !hasHiddenItem(folder)) {
47-
loopToFirstOrLastItem(folder, forward);
48-
traversalDirection = translateToTraversalDirection(!forward);
49-
}
50-
}
5141
if (control.traverse(traversalDirection)) {
5242
return null;
5343
}
@@ -60,65 +50,10 @@ public final Object execute(final ExecutionEvent event) {
6050
return null;
6151
}
6252

63-
/**
64-
* @param c a {@code Control}.
65-
* @return the top-level {@code CTabFolder} in the parent hierarchy.
66-
*/
67-
private CTabFolder getTopLevelCTabFolderInParentHierarchy(Control c) {
68-
Control current = c;
69-
CTabFolder ret = null;
70-
do {
71-
if (current instanceof CTabFolder folder) {
72-
ret = folder;
73-
}
74-
current = current.getParent();
75-
} while (current != null);
76-
return ret;
77-
}
78-
79-
private boolean hasHiddenItem(CTabFolder folder) {
80-
return Arrays.stream(folder.getItems()).anyMatch(i -> !i.isShowing());
81-
}
82-
8353
private int translateToTraversalDirection(boolean forward) {
8454
return forward ? SWT.TRAVERSE_PAGE_NEXT : SWT.TRAVERSE_PAGE_PREVIOUS;
8555
}
8656

87-
/**
88-
* Sets the current selection to the first or last item the given direction.
89-
*
90-
* @param folder the CTabFolder which we want to inspect
91-
* @param forward whether we want to traverse forwards of backwards
92-
*/
93-
private void loopToFirstOrLastItem(CTabFolder folder, boolean forward) {
94-
if (forward) {
95-
folder.showItem(folder.getItem(0));
96-
folder.setSelection(1);
97-
} else {
98-
int itemCount = folder.getItemCount();
99-
folder.setSelection(itemCount - 2);
100-
}
101-
}
102-
103-
/**
104-
* {@return Returns whether the folder has currently selected the final item in
105-
* the given direction.}
106-
*
107-
* @param folder the CTabFolder which we want to inspect
108-
* @param forward whether we want to traverse forwards of backwards
109-
*/
110-
private boolean isFinalItemInCTabFolder(CTabFolder folder, boolean forward) {
111-
CTabItem currentFolder = folder.getSelection();
112-
CTabItem lastFolder = null;
113-
if (forward) {
114-
int itemCount = folder.getItemCount();
115-
lastFolder = folder.getItem(itemCount - 1);
116-
} else {
117-
lastFolder = folder.getItem(0);
118-
}
119-
return currentFolder.equals(lastFolder);
120-
}
121-
12257
/**
12358
* Looks up the traverse(int) method on the given focus control.
12459
*

0 commit comments

Comments
 (0)