Skip to content

Commit

Permalink
Tab change can now handle >> container
Browse files Browse the repository at this point in the history
  • Loading branch information
jannisCode committed Oct 17, 2024
1 parent 3ffdfe3 commit bc3a22a
Showing 1 changed file with 82 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import java.lang.reflect.Method;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CTabFolder;
import org.eclipse.swt.custom.CTabItem;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
Expand All @@ -38,20 +40,98 @@ public class TraversePageHandler extends WidgetMethodHandler {
public final Object execute(final ExecutionEvent event) {
Control focusControl = Display.getCurrent().getFocusControl();
if (focusControl != null) {
boolean forward = "next".equals(methodName); //$NON-NLS-1$
// System.out.println(methodName);
int traversal = "next".equals(methodName) ? SWT.TRAVERSE_PAGE_NEXT : SWT.TRAVERSE_PAGE_PREVIOUS; //$NON-NLS-1$
// int traversal = getTraversalDirection(forward);
Control control = focusControl;
do {
if (control.traverse(traversal))
if (control instanceof CTabFolder folder && isFinalItemInCTabFolder(folder, forward)
&& !areHiddenItems(folder)) {
// System.out.println(isFinalItemInCTabFolder(folder, forward));

loopToSecondToFirstItemInCTabFolder(folder, forward);
traversal = getTraversalDirection(!forward); // we are in the second-to-last item in the given
// direction. Now, use the Traverse-event to move back by one
}
if (control.traverse(traversal)) {
// System.out.println("here"); //$NON-NLS-1$
return null;
if (control instanceof Shell)
}
if (control instanceof Shell) {
// System.out.println("there"); //$NON-NLS-1$
return null;
}
control = control.getParent();
} while (control != null);
}

return null;
}

private int getTraversalDirection(boolean direction) {
return direction ? SWT.TRAVERSE_PAGE_NEXT : SWT.TRAVERSE_PAGE_PREVIOUS;
}

/**
* Sets the current selection to the second-to-last item in the given direction.
*
* @param folder
* @param forward
*/
private void loopToSecondToFirstItemInCTabFolder(CTabFolder folder, boolean forward) {
if (forward) {
folder.showItem(folder.getItem(0));
folder.setSelection(1);
} else {
int itemCount = folder.getItemCount();
folder.setSelection(itemCount - 2);
}
}

/**
* {@return Returns whether the folder has currently selected the final item in
* the given direction.}
*
* @param folder the CTabFolder which we want to inspect
* @param forward whether we want to traverse forwards of backwards
*/
private boolean isFinalItemInCTabFolder(CTabFolder folder, boolean forward) {
folder.update();

// System.out.println("Amount of Items: " + items); //$NON-NLS-1$
CTabItem currentFolder = folder.getSelection();
CTabItem lastFolder = null;
if (forward) {
int itemCount = folder.getItemCount();
// currentFolder.isShowing();
// System.out.println("Item Count: " + itemCount); //$NON-NLS-1$
// System.out.println("Current folder: " + currentFolder.getText()); //$NON-NLS-1$

lastFolder = folder.getItem(itemCount - 1);
// System.out.println("Last folder: " + lastFolder.getText()); //$NON-NLS-1$
// for (CTabItem i : folder.getItems()) {
// System.out.println(i.getText() + " is shown: " + i.isShowing()); //$NON-NLS-1$

// }

} else {
lastFolder = folder.getItem(0);
}
// System.out.println("Current == Last: " + currentFolder.equals(lastFolder)); //$NON-NLS-1$

return currentFolder.equals(lastFolder);
}

private boolean areHiddenItems(CTabFolder folder) {
for (CTabItem i : folder.getItems()) {
if (!i.isShowing()) {
return true;
}
}
return false;
}

/**
* Looks up the traverse(int) method on the given focus control.
*
Expand Down

0 comments on commit bc3a22a

Please sign in to comment.