Skip to content

Commit bc3a22a

Browse files
committed
Tab change can now handle >> container
1 parent 3ffdfe3 commit bc3a22a

File tree

1 file changed

+82
-2
lines changed

1 file changed

+82
-2
lines changed

bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/handlers/TraversePageHandler.java

Lines changed: 82 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
import java.lang.reflect.Method;
1717
import org.eclipse.core.commands.ExecutionEvent;
1818
import org.eclipse.swt.SWT;
19+
import org.eclipse.swt.custom.CTabFolder;
20+
import org.eclipse.swt.custom.CTabItem;
1921
import org.eclipse.swt.widgets.Control;
2022
import org.eclipse.swt.widgets.Display;
2123
import org.eclipse.swt.widgets.Shell;
@@ -38,20 +40,98 @@ public class TraversePageHandler extends WidgetMethodHandler {
3840
public final Object execute(final ExecutionEvent event) {
3941
Control focusControl = Display.getCurrent().getFocusControl();
4042
if (focusControl != null) {
43+
boolean forward = "next".equals(methodName); //$NON-NLS-1$
44+
// System.out.println(methodName);
4145
int traversal = "next".equals(methodName) ? SWT.TRAVERSE_PAGE_NEXT : SWT.TRAVERSE_PAGE_PREVIOUS; //$NON-NLS-1$
46+
// int traversal = getTraversalDirection(forward);
4247
Control control = focusControl;
4348
do {
44-
if (control.traverse(traversal))
49+
if (control instanceof CTabFolder folder && isFinalItemInCTabFolder(folder, forward)
50+
&& !areHiddenItems(folder)) {
51+
// System.out.println(isFinalItemInCTabFolder(folder, forward));
52+
53+
loopToSecondToFirstItemInCTabFolder(folder, forward);
54+
traversal = getTraversalDirection(!forward); // we are in the second-to-last item in the given
55+
// direction. Now, use the Traverse-event to move back by one
56+
}
57+
if (control.traverse(traversal)) {
58+
// System.out.println("here"); //$NON-NLS-1$
4559
return null;
46-
if (control instanceof Shell)
60+
}
61+
if (control instanceof Shell) {
62+
// System.out.println("there"); //$NON-NLS-1$
4763
return null;
64+
}
4865
control = control.getParent();
4966
} while (control != null);
5067
}
5168

5269
return null;
5370
}
5471

72+
private int getTraversalDirection(boolean direction) {
73+
return direction ? SWT.TRAVERSE_PAGE_NEXT : SWT.TRAVERSE_PAGE_PREVIOUS;
74+
}
75+
76+
/**
77+
* Sets the current selection to the second-to-last item in the given direction.
78+
*
79+
* @param folder
80+
* @param forward
81+
*/
82+
private void loopToSecondToFirstItemInCTabFolder(CTabFolder folder, boolean forward) {
83+
if (forward) {
84+
folder.showItem(folder.getItem(0));
85+
folder.setSelection(1);
86+
} else {
87+
int itemCount = folder.getItemCount();
88+
folder.setSelection(itemCount - 2);
89+
}
90+
}
91+
92+
/**
93+
* {@return Returns whether the folder has currently selected the final item in
94+
* the given direction.}
95+
*
96+
* @param folder the CTabFolder which we want to inspect
97+
* @param forward whether we want to traverse forwards of backwards
98+
*/
99+
private boolean isFinalItemInCTabFolder(CTabFolder folder, boolean forward) {
100+
folder.update();
101+
102+
// System.out.println("Amount of Items: " + items); //$NON-NLS-1$
103+
CTabItem currentFolder = folder.getSelection();
104+
CTabItem lastFolder = null;
105+
if (forward) {
106+
int itemCount = folder.getItemCount();
107+
// currentFolder.isShowing();
108+
// System.out.println("Item Count: " + itemCount); //$NON-NLS-1$
109+
// System.out.println("Current folder: " + currentFolder.getText()); //$NON-NLS-1$
110+
111+
lastFolder = folder.getItem(itemCount - 1);
112+
// System.out.println("Last folder: " + lastFolder.getText()); //$NON-NLS-1$
113+
// for (CTabItem i : folder.getItems()) {
114+
// System.out.println(i.getText() + " is shown: " + i.isShowing()); //$NON-NLS-1$
115+
116+
// }
117+
118+
} else {
119+
lastFolder = folder.getItem(0);
120+
}
121+
// System.out.println("Current == Last: " + currentFolder.equals(lastFolder)); //$NON-NLS-1$
122+
123+
return currentFolder.equals(lastFolder);
124+
}
125+
126+
private boolean areHiddenItems(CTabFolder folder) {
127+
for (CTabItem i : folder.getItems()) {
128+
if (!i.isShowing()) {
129+
return true;
130+
}
131+
}
132+
return false;
133+
}
134+
55135
/**
56136
* Looks up the traverse(int) method on the given focus control.
57137
*

0 commit comments

Comments
 (0)