Bug 266868 - Mnemonic traversal
Summary: Mnemonic traversal
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.5   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Silenio Quarti CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-03-03 10:42 EST by Dave Smith CLA
Modified: 2019-09-06 15:35 EDT (History)
3 users (show)

See Also:


Attachments
Example Visa Screen snap (37.09 KB, image/jpeg)
2009-03-03 11:37 EST, Dave Smith CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Dave Smith CLA 2009-03-03 10:42:34 EST
I would like to be able to have multiple widgets with the same mnemonic accelerator. When pressing the accelerator more than once it should just go to the next widget in the list. This is standard windows behavior. The current SWT implementation always goes back to the shell and starts at the beginning of the widget tree  regardless of which widget  fired the event, although shell is being told which widget fired the event. It would seem that we should use the tab order logic where we call getRoot() to get a tabbing list of widgets and then find the control that caused the Mnemonic traversal and start looking for match on the next widget.

The required change ...

in Control 
boolean translateMnemonic (int keyval, GdkEventKey gdkEvent) {
..

This section ...
if (setKeyState (event, gdkEvent)) {
		return translateMnemonic (event, null) || shell.translateMnemonic (event, this);


shell should implement translateMnemonic along the lines of traversal so we would go to the next matching control ...

A snip from the traversal code modified ...

if(inTraversal)
{
return false;
}
inTraversal=true;

Control [] list = computeTabList ();
int length = list.length;
int index = 0;
while (index < length) {
	if (list [index] == currentControl) break;
	index++;
}

if (index == length) return false;
int start = index, offset = (next) ? 1 : -1;
while ((index = ((index + offset + length) % length)) != start) {
	Control control = list [index];
	// ask the control to traverse and if OK stop otherwise keep going
        if(control.translateMnemonic (event, null)) return true;
}
inTraversal=false;
return false;


	
}
Comment 1 Felipe Heidrich CLA 2009-03-03 11:11:47 EST
IMO, this is not a normal usage for mnemonic. Point me to an UI in windows that is doing this.

I don't think we should change the current implementation for mnemonic. Maybe the application can hook SWT.Traverse and enforce this behaviour themselves.

Steve to comment.
Comment 2 Dave Smith CLA 2009-03-03 11:37:16 EST
Created attachment 127336 [details]
Example Visa Screen snap 

Attached screen cap from Vista, Firefox 3.0.6, Options screen, Alt-H toggles between Search Engines and Help.
Comment 3 Steve Northover CLA 2009-03-16 14:51:24 EDT
Here is some example code:

import org.eclipse.swt.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

public class PR_266868 {
	public static void main(String[] args) {
		Display display = new Display();
		Shell shell = new Shell(display);
		shell.setLayout(new FillLayout());
		Button b1 = new Button (shell, SWT.PUSH);
		b1.setText("b1 - &A");
		Button b2 = new Button (shell, SWT.PUSH);
		b2.setText("b2 - &A");
		shell.pack();
		shell.open();
		display.addFilter(SWT.Selection, new Listener () {
			public void handleEvent (Event e) {
				System.out.println(e);
			}
		});
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
		display.dispose();
	}
}
Comment 4 Steve Northover CLA 2009-03-16 14:56:13 EDT
The behavior would be a bit strange.  The first traversal would send the selection event for b1, then the next traversal would run it for b2 (but only if there had already been a selection in b2 that was caused by traversal).  If the selection event had come from the mouse or the keyboard (ie. space bar), then the selection should run?  Should it run when the last mnemonic control was selected somehow?
Comment 5 Dave Smith CLA 2009-03-16 15:04:21 EDT
Under Windows/GTK the logic is if there is more than one match it only assigns focus to the control does not activate it. So in your example the next button matching in the tabbing sequence would get focus. I would add another button to your example that has &B. So alt A would toggle focus between the buttons and Alt B would fire a selection on the button.

Comment 6 Eclipse Webmaster CLA 2019-09-06 15:35:16 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.