Skip to content

Commit bd680bc

Browse files
Maximilian WittmerMaximilian Wittmer
authored andcommitted
Make the ToolBar in the Find/Replace Overlay accessible eclipse-platform#1910
Makes the Find/Replace Overlay options accessible by tabbing through the different option buttons. Implements a new "AccessibleToolBar" class which wraps the ToolBar and allows for being natively accessibly by using the normal traversal mechanism provided by SWT. fixes eclipse-platform#1910
1 parent 2a83f92 commit bd680bc

File tree

4 files changed

+94
-19
lines changed

4 files changed

+94
-19
lines changed

bundles/org.eclipse.ui.workbench.texteditor/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: %pluginName
44
Bundle-SymbolicName: org.eclipse.ui.workbench.texteditor; singleton:=true
5-
Bundle-Version: 3.17.400.qualifier
5+
Bundle-Version: 3.18.0.qualifier
66
Bundle-Activator: org.eclipse.ui.internal.texteditor.TextEditorPlugin
77
Bundle-ActivationPolicy: lazy
88
Bundle-Vendor: %providerName
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package org.eclipse.ui.texteditor;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
import org.eclipse.swt.SWT;
7+
import org.eclipse.swt.events.TraverseEvent;
8+
import org.eclipse.swt.events.TraverseListener;
9+
import org.eclipse.swt.graphics.Color;
10+
import org.eclipse.swt.layout.GridLayout;
11+
import org.eclipse.swt.widgets.Composite;
12+
import org.eclipse.swt.widgets.ToolBar;
13+
import org.eclipse.swt.widgets.ToolItem;
14+
15+
import org.eclipse.jface.layout.GridLayoutFactory;
16+
17+
/**
18+
* This class wraps the ToolBar to make it possible to use tabulator-keys to
19+
* navigate between the buttons of a ToolBar. For this, we simulate a singular
20+
* ToolBar by putting each ToolItem into it's own ToolBar and composing them
21+
* into a Composite. Since the "Enter" keypress could not previously trigger
22+
* activation behavior, we listen for it manually and send according events if
23+
* necessary.
24+
*
25+
* @since 3.18
26+
*/
27+
class AccessibleToolBar extends Composite {
28+
29+
private List<ToolBar> toolBars = new ArrayList<>();
30+
31+
public AccessibleToolBar(Composite parent) {
32+
super(parent, SWT.NONE);
33+
GridLayoutFactory.fillDefaults().numColumns(0).spacing(0, 0).margins(0, 0).applyTo(this);
34+
}
35+
36+
/**
37+
* Creates a ToolItem handled by this ToolBar and returns it. Will add a
38+
* KeyListener which will catch all "Enter"-Keypresses.
39+
*
40+
* @param styleBits the StyleBits to apply to the created ToolItem
41+
* @return a newly created ToolItem
42+
*/
43+
public ToolItem createToolItem(int styleBits) {
44+
ToolBar parent = new ToolBar(this, SWT.FLAT | SWT.HORIZONTAL);
45+
ToolItem result = new ToolItem(parent, styleBits);
46+
47+
addToolItemTraverseListener(parent, result);
48+
49+
((GridLayout) getLayout()).numColumns++;
50+
51+
toolBars.add(parent);
52+
return result;
53+
}
54+
55+
private void addToolItemTraverseListener(ToolBar parent, ToolItem result) {
56+
parent.addTraverseListener(new TraverseListener() {
57+
58+
@Override
59+
public void keyTraversed(TraverseEvent e) {
60+
if (e.keyCode == SWT.CR || e.keyCode == SWT.KEYPAD_CR) {
61+
result.setSelection(!result.getSelection());
62+
e.doit = false;
63+
}
64+
}
65+
66+
});
67+
}
68+
69+
@Override
70+
public void setBackground(Color color) {
71+
super.setBackground(color);
72+
for (ToolBar bar : toolBars) { // we need to color each toolbar separately
73+
bar.setBackground(color);
74+
}
75+
}
76+
77+
}

bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/FindReplaceAction.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -376,9 +376,6 @@ public void run() {
376376
}
377377
}
378378

379-
/**
380-
* @since 3.17
381-
*/
382379
private void showDialog() {
383380
final FindReplaceDialog dialog;
384381
final boolean isEditable;

bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/FindReplaceOverlay.java

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
import org.eclipse.swt.widgets.Scrollable;
4545
import org.eclipse.swt.widgets.Shell;
4646
import org.eclipse.swt.widgets.Text;
47-
import org.eclipse.swt.widgets.ToolBar;
4847
import org.eclipse.swt.widgets.ToolItem;
4948
import org.eclipse.swt.widgets.Widget;
5049

@@ -91,7 +90,7 @@ class FindReplaceOverlay extends Dialog {
9190
private Composite searchContainer;
9291
private Composite searchBarContainer;
9392
private Text searchBar;
94-
private ToolBar searchTools;
93+
private AccessibleToolBar searchTools;
9594

9695
private ToolItem searchInSelectionButton;
9796
private ToolItem wholeWordSearchButton;
@@ -104,7 +103,7 @@ class FindReplaceOverlay extends Dialog {
104103
private Composite replaceContainer;
105104
private Composite replaceBarContainer;
106105
private Text replaceBar;
107-
private ToolBar replaceTools;
106+
private AccessibleToolBar replaceTools;
108107
private ToolItem replaceButton;
109108
private ToolItem replaceAllButton;
110109

@@ -193,6 +192,7 @@ private void performSearchOnEnter(boolean isShiftPressed) {
193192
@Override
194193
public void keyPressed(KeyEvent e) {
195194
e.doit = false;
195+
System.out.println(e.keyCode);
196196
if ((e.stateMask & SWT.CTRL) != 0 && (e.keyCode == 'F' || e.keyCode == 'f')) {
197197
close();
198198
} else if ((e.stateMask & SWT.CTRL) != 0 && (e.keyCode == 'R' || e.keyCode == 'r')) {
@@ -450,7 +450,7 @@ private void retrieveBackgroundColor() {
450450
}
451451

452452
private void createSearchTools() {
453-
searchTools = new ToolBar(searchContainer, SWT.HORIZONTAL);
453+
searchTools = new AccessibleToolBar(searchContainer);
454454
GridDataFactory.fillDefaults().grab(false, true).align(GridData.CENTER, GridData.END).applyTo(searchTools);
455455

456456
createWholeWordsButton();
@@ -459,9 +459,9 @@ private void createSearchTools() {
459459
createAreaSearchButton();
460460

461461
@SuppressWarnings("unused")
462-
ToolItem separator = new ToolItem(searchTools, SWT.SEPARATOR);
462+
ToolItem separator = searchTools.createToolItem(SWT.SEPARATOR);
463463

464-
searchUpButton = new ToolItem(searchTools, SWT.PUSH);
464+
searchUpButton = searchTools.createToolItem(SWT.PUSH);
465465
searchUpButton.setImage(FindReplaceOverlayImages.get(FindReplaceOverlayImages.OBJ_FIND_PREV));
466466
searchUpButton.setToolTipText(FindReplaceMessages.FindReplaceOverlay_upSearchButton_toolTip);
467467
searchUpButton.addSelectionListener(new SelectionListener() {
@@ -476,7 +476,7 @@ public void widgetDefaultSelected(SelectionEvent e) {
476476
// Do Nothing
477477
}
478478
});
479-
searchDownButton = new ToolItem(searchTools, SWT.PUSH);
479+
searchDownButton = searchTools.createToolItem(SWT.PUSH);
480480
searchDownButton.setSelection(true); // by default, search down
481481
searchDownButton.setImage(FindReplaceOverlayImages.get(FindReplaceOverlayImages.OBJ_FIND_NEXT));
482482
searchDownButton.setToolTipText(FindReplaceMessages.FindReplaceOverlay_downSearchButton_toolTip);
@@ -493,7 +493,7 @@ public void widgetDefaultSelected(SelectionEvent e) {
493493
// Do nothing
494494
}
495495
});
496-
searchAllButton = new ToolItem(searchTools, SWT.PUSH);
496+
searchAllButton = searchTools.createToolItem(SWT.PUSH);
497497
searchAllButton.setImage(FindReplaceOverlayImages.get(FindReplaceOverlayImages.OBJ_SEARCH_ALL));
498498
searchAllButton.setToolTipText(FindReplaceMessages.FindReplaceOverlay_searchAllButton_toolTip);
499499
searchAllButton.addSelectionListener(new SelectionListener() {
@@ -513,7 +513,7 @@ public void widgetDefaultSelected(SelectionEvent e) {
513513
}
514514

515515
private void createAreaSearchButton() {
516-
searchInSelectionButton = new ToolItem(searchTools, SWT.CHECK);
516+
searchInSelectionButton = searchTools.createToolItem(SWT.CHECK);
517517
searchInSelectionButton.setImage(FindReplaceOverlayImages.get(FindReplaceOverlayImages.OBJ_SEARCH_IN_AREA));
518518
searchInSelectionButton.setToolTipText(FindReplaceMessages.FindReplaceOverlay_searchInSelectionButton_toolTip);
519519
searchInSelectionButton.setSelection(findReplaceLogic.isActive(SearchOptions.WHOLE_WORD));
@@ -533,7 +533,7 @@ public void widgetDefaultSelected(SelectionEvent e) {
533533
}
534534

535535
private void createRegexSearchButton() {
536-
regexSearchButton = new ToolItem(searchTools, SWT.CHECK);
536+
regexSearchButton = searchTools.createToolItem(SWT.CHECK);
537537
regexSearchButton.setImage(FindReplaceOverlayImages.get(FindReplaceOverlayImages.OBJ_FIND_REGEX));
538538
regexSearchButton.setToolTipText(FindReplaceMessages.FindReplaceOverlay_regexSearchButton_toolTip);
539539
regexSearchButton.setSelection(findReplaceLogic.isActive(SearchOptions.REGEX));
@@ -554,7 +554,7 @@ public void widgetDefaultSelected(SelectionEvent e) {
554554
}
555555

556556
private void createCaseSensitiveButton() {
557-
caseSensitiveSearchButton = new ToolItem(searchTools, SWT.CHECK);
557+
caseSensitiveSearchButton = searchTools.createToolItem(SWT.CHECK);
558558
caseSensitiveSearchButton.setImage(FindReplaceOverlayImages.get(FindReplaceOverlayImages.OBJ_CASE_SENSITIVE));
559559
caseSensitiveSearchButton.setToolTipText(FindReplaceMessages.FindReplaceOverlay_caseSensitiveButton_toolTip);
560560
caseSensitiveSearchButton.setSelection(findReplaceLogic.isActive(SearchOptions.CASE_SENSITIVE));
@@ -574,7 +574,7 @@ public void widgetDefaultSelected(SelectionEvent e) {
574574
}
575575

576576
private void createWholeWordsButton() {
577-
wholeWordSearchButton = new ToolItem(searchTools, SWT.CHECK);
577+
wholeWordSearchButton = searchTools.createToolItem(SWT.CHECK);
578578
wholeWordSearchButton.setImage(FindReplaceOverlayImages.get(FindReplaceOverlayImages.OBJ_WHOLE_WORD));
579579
wholeWordSearchButton.setToolTipText(FindReplaceMessages.FindReplaceOverlay_wholeWordsButton_toolTip);
580580
wholeWordSearchButton.setSelection(findReplaceLogic.isActive(SearchOptions.WHOLE_WORD));
@@ -596,9 +596,10 @@ public void widgetDefaultSelected(SelectionEvent e) {
596596
private void createReplaceTools() {
597597
Color warningColor = JFaceColors.getErrorText(getShell().getDisplay());
598598

599-
replaceTools = new ToolBar(replaceContainer, SWT.HORIZONTAL);
599+
replaceTools = new AccessibleToolBar(replaceContainer);
600600
GridDataFactory.fillDefaults().grab(false, true).align(GridData.CENTER, GridData.END).applyTo(replaceTools);
601-
replaceButton = new ToolItem(replaceTools, SWT.PUSH);
601+
602+
replaceButton = replaceTools.createToolItem(SWT.PUSH);
602603
replaceButton.setImage(FindReplaceOverlayImages.get(FindReplaceOverlayImages.OBJ_REPLACE));
603604
replaceButton.setToolTipText(FindReplaceMessages.FindReplaceOverlay_replaceButton_toolTip);
604605
replaceButton.addSelectionListener(new SelectionListener() {
@@ -617,7 +618,7 @@ public void widgetDefaultSelected(SelectionEvent e) {
617618
// Do nothing
618619
}
619620
});
620-
replaceAllButton = new ToolItem(replaceTools, SWT.PUSH);
621+
replaceAllButton = replaceTools.createToolItem(SWT.PUSH);
621622
replaceAllButton.setImage(FindReplaceOverlayImages.get(FindReplaceOverlayImages.OBJ_REPLACE_ALL));
622623
replaceAllButton.setToolTipText(FindReplaceMessages.FindReplaceOverlay_replaceAllButton_toolTip);
623624
replaceAllButton.addSelectionListener(new SelectionListener() {

0 commit comments

Comments
 (0)